Commit 5a9f4bf7 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

refactor(test): polish the remote node tests

issue #1069
parent 88401769
......@@ -17,7 +17,6 @@ use_ok('Ravada');
init();
my $USER = create_user("foo","bar");
my $REMOTE_CONFIG;
##########################################################
sub test_node_renamed {
......@@ -59,27 +58,14 @@ sub test_node_renamed {
}
sub test_node {
my $vm_name = shift;
die "Error: missing host in remote config\n ".Dumper($REMOTE_CONFIG)
if !$REMOTE_CONFIG->{host};
sub test_node($vm_name,$node) {
my $vm = rvd_back->search_vm($vm_name);
my $node;
my @list_nodes0 = rvd_front->list_vms;
eval { $node = $vm->new(%{$REMOTE_CONFIG}) };
ok(!$@,"Expecting no error connecting to $vm_name at ".Dumper($REMOTE_CONFIG).", got :'"
.($@ or '')."'") or return;
ok($node) or return;
is($node->type,$vm->type) or return;
is($node->host,$REMOTE_CONFIG->{host});
is($node->name,$REMOTE_CONFIG->{name}) or return;
eval { $node->ping };
is($@,'',"[$vm_name] ping ".$node->name);
......@@ -115,15 +101,14 @@ sub test_node {
my @list_nodes = $vm->list_nodes();
is(scalar @list_nodes, 2,"[$vm_name] Expecting nodes") or return;
ok(ref($list_nodes[0])) or exit;
ok(ref($list_nodes[1])) or exit;
my ($node_remote) = grep { $_->name eq $REMOTE_CONFIG->{name}} @list_nodes;
ok($node_remote, "[$vm_name] Expecting node $REMOTE_CONFIG->{name} in back->list_nodes")
or return;
my ($node_remote) = grep { !$_->is_local } @list_nodes;
ok($node_remote->{type} eq $vm_name);
my @list_nodes2 = rvd_front->list_vms;
($node_remote) = grep { $_->{name} eq $REMOTE_CONFIG->{name}} @list_nodes2;
ok($node_remote, "[$vm_name] Expecting node $REMOTE_CONFIG->{name} in front->list_vms")
or return;
($node_remote) = grep { !$_->{is_local} } @list_nodes2;
ok($node_remote->{type} eq $vm_name);
return $node;
}
......@@ -192,12 +177,8 @@ sub test_domain {
my $local_ip = $node->ip;
$local_ip = $REMOTE_CONFIG->{public_ip}
if $REMOTE_CONFIG->{public_ip};
like($clone->display(user_admin),qr($local_ip));
diag("SKIPPED: Add public_ip to remote_vm.conf to test nodes with 2 IPs")
if !exists $REMOTE_CONFIG->{public_ip};
my ($local_port) = $clone->display(user_admin) =~ m{:(\d+)};
test_iptables($node, $remote_ip, $local_ip, $local_port) if $remote_ip;
return $clone;
......@@ -1159,24 +1140,20 @@ eval { $vm = rvd_back->search_vm($vm_name) };
SKIP: {
my $msg = "SKIPPED: $vm_name virtual manager not found ".($@ or '');
$REMOTE_CONFIG = remote_config($vm_name);
if (!keys %$REMOTE_CONFIG) {
my $msg = "skipped, missing the remote configuration for $vm_name in the file "
.$Test::Ravada::FILE_CONFIG_REMOTE;
diag($msg);
skip($msg,10);
}
my $node;
if ($vm && $>) {
$msg = "SKIPPED: Test must run as root";
$vm = undef;
} else {
$node = remote_node($vm_name);
$node = test_node($vm_name, $node);
$vm = undef if !$node;
}
diag($msg) if !$vm;
skip($msg,10) if !$vm;
diag("Testing remote node in $vm_name");
my $node = test_node($vm_name) or next;
ok($node->vm,"[$vm_name] expecting a VM inside the node") or do {
remove_node($node);
......
......@@ -113,6 +113,12 @@ sub test_prepare_base {
is($domain->is_active(),0);
$domain->is_public(1);
my @files_target = $domain->list_files_base_target();
for (@files_target) {
ok($_->[0]) or exit;
ok($_->[1],"No target in $_->[0]") or exit;
}
my $front_domains = rvd_front->list_domains();
my ($dom_front) = grep { $_->{name} eq $domain->name }
@$front_domains;
......
......@@ -25,8 +25,8 @@ sub test_rebase($vm) {
is(scalar($base->clones),2);
my @reqs = $base->rebase(user_admin, $clone1);
rvd_back->_process_requests_dont_fork(1);
for my $req (@reqs) {
rvd_back->_process_requests_dont_fork();
is($req->status, 'done' ) or exit;
is($req->error, '') or exit;
}
......@@ -69,3 +69,5 @@ for my $vm_name ( vm_names() ) {
}
clean();
done_testing();
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