Commit 55c88023 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

[#547] manage domain started and hibernated elsewhere

The hibernated node gets down, started keeps up
parent fdd94ca5
......@@ -2052,9 +2052,15 @@ sub _cmd_force_shutdown {
my $uid = $request->args('uid');
my $id_domain = $request->args('id_domain');
my $id_vm = $request->defined_arg('id_vm');
my $domain;
$domain = $self->search_domain_by_id($id_domain);
if ($id_vm) {
my $vm = Ravada::VM->open($id_vm);
$domain = $vm->search_domain_by_id($id_domain);
} else {
$domain = $self->search_domain_by_id($id_domain);
}
die "Unknown domain '$id_domain'\n" if !$domain;
my $user = Ravada::Auth::SQL->search_by_id( $uid);
......
......@@ -1368,6 +1368,7 @@ sub _post_shutdown {
my $req = Ravada::Request->force_shutdown_domain(
id_domain => $self->id
,id_vm => $self->_vm->id
, uid => $arg{user}->id
, at => time+$timeout
);
......
......@@ -59,7 +59,7 @@ our %VALID_ARG = (
,remove_domain => $args_manage
,shutdown_domain => { name => 2, id_domain => 2, uid => 1, timeout => 2, at => 2
, id_vm => 2 }
,force_shutdown_domain => { id_domain => 1, uid => 1, at => 2 }
,force_shutdown_domain => { id_domain => 1, uid => 1, at => 2, id_vm => 2 }
,screenshot_domain => { id_domain => 1, filename => 2 }
,copy_screenshot => { id_domain => 1, filename => 2 }
,start_domain => {%$args_manage, remote_ip => 1 }
......
......@@ -433,13 +433,48 @@ sub test_already_started_twice($vm_name, $node) {
eval { $clone2->start(user => user_admin) };
like($@,qr/already running/) if $@;
rvd_back->_process_requests_dont_fork();
rvd_back->_process_all_requests_dont_fork();
for ( 1 .. 10 ) {
last if !$clone->is_active;
last if !$clone_local->is_active;
last if !$clone->is_active
&& !$clone_local->is_active;
sleep 1;
}
rvd_back->_process_all_requests_dont_fork();
is($clone->is_active, 0,"[".$node->type."] expecting remote clone ".$clone->name." down");
is($clone_local->is_active, 0,"[".$node->type."] expecting local clone down");
$clone->remove(user_admin);
$base->remove(user_admin);
}
sub test_already_started_hibernated($vm_name, $node) {
my ($base, $clone) = _create_clone($node);
my $vm = rvd_back->search_vm($vm_name);
is($vm->is_local, 1);
my $clone_local = $vm->search_domain($clone->name);
is($clone_local->_vm->is_local, 1);
start_domain_internal($clone);
hibernate_domain_internal($clone_local);
is($clone->is_active, 1,"expecting clone active on remote");
is($clone_local->is_hibernated, 1, "expecting clone hibernated on local");
my $clone2 = rvd_back->search_domain($clone->name);
eval { $clone2->start(user => user_admin) };
like($@,qr/already running/) if $@;
rvd_back->_process_all_requests_dont_fork();
for ( 1 .. 10 ) {
last if $clone->is_active
&& !$clone_local->is_active
&& !$clone_local->is_hibernated;
sleep 1;
}
rvd_back->_process_requests_dont_fork(1);
rvd_back->_process_all_requests_dont_fork();
is($clone->is_active, 0);
is($clone_local->is_active, 0);
......@@ -448,6 +483,7 @@ sub test_already_started_twice($vm_name, $node) {
$base->remove(user_admin);
}
sub _create_clone($node) {
my $vm =rvd_back->search_vm($node->type);
......@@ -1009,6 +1045,8 @@ SKIP: {
test_already_started_twice($vm_name, $node);
test_already_started_hibernated($vm_name, $node);
test_shutdown($node);
test_domain_ip($vm_name, $node);
......
......@@ -40,6 +40,7 @@ create_domain
clean_remote
start_node shutdown_node remove_node hibernate_node
start_domain_internal shutdown_domain_internal
hibernate_domain_internal
);
our $DEFAULT_CONFIG = "t/etc/ravada.conf";
......@@ -816,6 +817,17 @@ sub remove_node($node) {
ok(!$node2, "Expecting no node ".$node->id);
}
sub hibernate_domain_internal($domain) {
start_domain_internal($domain) if !$domain->is_active;
if ($domain->type eq 'KVM') {
$domain->domain->managed_save();
} elsif ($domain->type eq 'Void') {
$domain->_store(is_hibernated => 1 );
} else {
confess "ERROR: I don't know how to hibernate internal domain of type ".$domain->type;
}
}
sub shutdown_domain_internal($domain) {
if ($domain->type eq 'KVM') {
$domain->domain->destroy();
......
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