Unverified Commit 416a80dd authored by Francesc Guasch's avatar Francesc Guasch Committed by GitHub
Browse files

Feature #763 config (#1066)

feature(config): enforce config validation

* doc(test): configuration to test nodes
* test(config): check configuration is ok

closes issue #763
parent 1cbdb01f
......@@ -48,6 +48,19 @@ $ERROR_VM{Void} = $@;
no warnings "experimental::signatures";
use feature qw(signatures);
our %VALID_CONFIG = (
vm => undef
,warn_error => undef
,db => {user => undef, password => undef, hostname => undef}
,ldap => { admin_user => { dn => undef, password => undef }
,filter => undef
,base => undef
,auth => undef
,admin_group => undef
,ravada_posix_group => undef
}
);
=head1 NAME
Ravada - Remove Virtual Desktop Manager
......@@ -1272,6 +1285,7 @@ sub _init_config {
eval { $CONFIG = YAML::LoadFile($file) };
die "ERROR: Format error in config file $file\n$@" if $@;
_check_config($CONFIG);
if ( !$CONFIG->{vm} ) {
my %default_vms = %VALID_VM;
......@@ -1324,6 +1338,24 @@ sub _create_vm_kvm {
return $vm_kvm;
}
sub _check_config($config_orig = {} , $valid_config = \%VALID_CONFIG ) {
return 1 if !defined $config_orig;
my %config = %$config_orig;
for my $key (sort keys %$valid_config) {
if ( $config{$key} && ref($valid_config->{$key})) {
my $ok = _check_config( $config{$key} , $valid_config->{$key} );
return 0 if !$ok;
}
delete $config{$key};
}
if ( keys %config ) {
warn "Error: Unknown config entry \n".Dumper(\%config) if ! $0 =~ /\.t$/;
return 0;
}
return 1;
}
=head2 disconnect_vm
Disconnect all the Virtual Managers connections.
......
use warnings;
use strict;
use Test::More;
use lib 't/lib';
use Test::Ravada;
init();
#########################################################################
sub check_empty {
is(Ravada::_check_config( {} ), 1);
is(Ravada::_check_config( undef ), 1);
}
sub check_fail{
is(Ravada::_check_config( {fail => 'yes'} ) , 0);
}
sub check_db {
is(Ravada::_check_config( {
db => {
user => 1
, password => 2
, hostname => 3
}
}) , 1);
is(Ravada::_check_config( {
db => {
user => 1
, password => 2
, foo => 3
}
}) , 0);
}
#########################################################################
clean();
check_empty();
check_fail();
check_db();
clean();
done_testing();
# Testing remote nodes
To test remote nodes you need them created in the host you are testing
with KVM.
Install a Linux and allow ssh password-less then write down the configuration
file: t/etc/remote\_vm\_2.conf.
In this example we have two virtual machines called: ztest-1 and ztest-2:
ztest-1:
vm:
- KVM
- Void
host: 192.168.122.151
public_ip: 192.168.122.250
ztest-2:
vm:
- KVM
- Void
host: 192.168.122.152
public_ip: 192.168.122.251
## Configuration
Each entry has the name of the virtual machine as you can see when you virsh list
in KVM.
- vm is the name of the Virtual Managers type it accepts. At least it should contain
- KVM and Void, that is used to test generic mock virtual machines.
- host is the ip of the virtual machine.
- public\_ip is optional and is used to test nodes with more than one IP.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment