Commit 16e82f0f authored by Francesc Guasch's avatar Francesc Guasch
Browse files

Merge branch 'develop' of https://github.com/UPC/ravada into develop

parents 50c5becb 2f5937dd
......@@ -3,8 +3,18 @@
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.
Install a Linux server with those packages:
- ssh
- qemu-guest-agent
Add a secondary IP in the server to check public ip configuration.
Allow ssh password-less following the documentation for Ravada nodes clustering
https://ravada.readthedocs.io/en/latest/docs/nodes.html?highlight=cluster
Write down a configuration file with the information of the testing virtual machines
in the file: t/etc/remote\_vm.conf.
In this example we have two virtual machines called: ztest-1 and ztest-2:
......@@ -13,13 +23,13 @@ In this example we have two virtual machines called: ztest-1 and ztest-2:
- KVM
- Void
host: 192.168.122.151
public_ip: 192.168.122.250
public_ip: 192.168.122.251
ztest-2:
vm:
- KVM
- Void
host: 192.168.122.152
public_ip: 192.168.122.251
public_ip: 192.168.122.252
## Configuration
......@@ -28,6 +38,6 @@ Each entry has the name of the virtual machine as you can see when you virsh lis
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.
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.
......@@ -59,7 +59,6 @@ create_domain
our $DEFAULT_CONFIG = "t/etc/ravada.conf";
our $FILE_CONFIG_REMOTE = "t/etc/remote_vm.conf";
our $FILE_CONFIG_REMOTE_2 = "t/etc/remote_vm_2.conf";
$Ravada::Front::Domain::Void = "/var/tmp/test/rvd_void/".getpwuid($>);
......@@ -167,7 +166,7 @@ sub create_domain {
, %arg_create
, active => 0
, memory => 256*1024
, disk => 256 * 1024 * 1024
, disk => 1 * 1024 * 1024
);
};
is('',''.$@);
......@@ -267,33 +266,33 @@ sub init($config=undef) {
$Ravada::VM::KVM::VERIFY_ISO = 0;
}
sub remote_config_2() {
return {} if ! -e $FILE_CONFIG_REMOTE_2;
sub _load_remote_config() {
return {} if ! -e $FILE_CONFIG_REMOTE;
my $conf;
eval { $conf = LoadFile($FILE_CONFIG_REMOTE_2) };
is($@,'',"Error in $FILE_CONFIG_REMOTE_2\n".$@) or return;
eval { $conf = LoadFile($FILE_CONFIG_REMOTE) };
is($@,'',"Error in $FILE_CONFIG_REMOTE\n".$@) or return;
lock_hash(%$conf);
return $conf;
}
sub remote_config {
my $vm_name = shift;
return { } if !-e $FILE_CONFIG_REMOTE;
my $conf;
eval { $conf = LoadFile($FILE_CONFIG_REMOTE) };
is($@,'',"Error in $FILE_CONFIG_REMOTE\n".$@) or return;
my $remote_conf = $conf->{$vm_name} or do {
my $conf = _load_remote_config();
my $remote_conf;
for my $node (sort keys %$conf) {
next if !grep /^$vm_name$/, @{$conf->{$node}->{vm}};
$remote_conf = {
name => $node
,host=> $conf->{$node}->{host}
,public_ip => $conf->{$node}->{public_ip}
};
last;
}
if (! $remote_conf) {
diag("SKIPPED: No $vm_name section in $FILE_CONFIG_REMOTE");
return ;
};
for my $field ( qw(host user password security public_ip name)) {
delete $remote_conf->{$field};
}
die "Unknown fields in remote_conf $vm_name, valids are : host user password name\n"
.Dumper($remote_conf) if keys %$remote_conf;
$remote_conf = LoadFile($FILE_CONFIG_REMOTE);
ok($remote_conf->{public_ip} ne $remote_conf->{host},
"Public IP must be different from host at $FILE_CONFIG_REMOTE")
if defined $remote_conf->{public_ip};
......@@ -301,7 +300,7 @@ sub remote_config {
$remote_conf->{public_ip} = '' if !exists $remote_conf->{public_ip};
lock_hash(%$remote_conf);
return $remote_conf->{$vm_name};
return $remote_conf;
}
sub remote_config_nodes {
......@@ -687,6 +686,7 @@ sub clean {
}
_clean_db();
_clean_file_config();
shutdown_nodes();
}
sub _clean_db {
......@@ -705,11 +705,7 @@ sub _clean_db {
}
sub clean_remote {
return if ! -e $FILE_CONFIG_REMOTE;
my $conf;
eval { $conf = LoadFile($FILE_CONFIG_REMOTE) };
return if !$conf;
my $conf = _load_remote_config() or return;
for my $vm_name (keys %$conf) {
my $vm;
eval { $vm = rvd_back->search_vm($vm_name) };
......@@ -977,6 +973,12 @@ sub start_node($node) {
eval { $node->run_command("hwclock","--hctosys") };
is($@,'',"Expecting no error setting clock on ".$node->name." ".($@ or ''));
$node->is_active(1);
for ( 1 .. 60 ) {
my $node2 = Ravada::VM->open(id => $node->id);
last if $node2->is_active(1);
diag("Waiting for node ".$node->name." active ...") if !($_ % 10);
}
}
sub remove_node($node) {
......@@ -1111,7 +1113,7 @@ sub remote_node($vm_name) {
}
sub remote_node_2($vm_name) {
my $remote_config = remote_config_2();
my $remote_config = _load_remote_config();
my @nodes;
for my $name ( sort keys %$remote_config ) {
......@@ -1128,7 +1130,6 @@ sub remote_node_2($vm_name) {
return @nodes;
}
sub _do_remote_node($vm_name, $remote_config) {
my $vm = rvd_back->search_vm($vm_name);
......@@ -1254,11 +1255,15 @@ sub connector {
# this must be in DESTROY because users got removed in END
sub DESTROY {
shutdown_nodes();
remove_old_user() if $CONNECTOR;
remove_old_user_ldap() if $CONNECTOR;
}
sub shutdown_nodes {
for my $node (@NODES) {
shutdown_node($node);
}
remove_old_user() if $CONNECTOR;
remove_old_user_ldap() if $CONNECTOR;
}
sub init_ldap_config($file_config='t/etc/ravada_ldap.conf'
......
......@@ -29,6 +29,7 @@ sub test_disable_node($vm, $node) {
sleep 2;
for (1 .. 10 ) {
last if$clone->is_active;
sleep 1;
}
is($clone->is_active,1,"Expecting clone active") or return;
......@@ -46,25 +47,12 @@ sub test_disable_node($vm, $node) {
is($req->status,'done');
is($req->error,'');
my @reqs = $clone->list_requests();
if (!@reqs) {
my $req2 = Ravada::Request->shutdown_domain(
uid => user_admin->id
,timeout => $timeout
, id_domain => $clone->id
);
rvd_back->_process_requests_dont_fork();
is($req2->status,'done');
is($req2->error,'');
@reqs = $clone->list_requests();
}
for ( 0 .. $timeout + 3 ) {
for ( 0 .. $timeout * 2 ) {
last if !$clone->is_active;
sleep 1;
rvd_back->_process_requests_dont_fork();
}
is($clone->is_active, 0 );
is($clone->is_active, 0,$clone->type." ".$clone->name ) or exit;
if ( $vm->type eq 'KVM' ) {
is($clone->domain->is_active, 0);
} else {
......
......@@ -93,7 +93,7 @@ for my $vm_name ( 'Void', 'KVM') {
my ($node1, $node2) = remote_node_2($vm_name);
if ( !$node1 || !$node2 ) {
diag("Skipped: No remote nodes configured in $Test::Ravada::FILE_CONFIG_REMOTE_2");
diag("Skipped: No remote nodes configured in $Test::Ravada::FILE_CONFIG_REMOTE");
goto NEXT;
}
......
Supports Markdown
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