From c8fbeed7bff6364f270051ceac0eee440e07eeff Mon Sep 17 00:00:00 2001 From: Francesc Guasch Date: Mon, 14 Oct 2024 12:27:34 +0200 Subject: [PATCH 1/3] test: backup autostart issue #2097 --- t/vm/backup.t | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/t/vm/backup.t b/t/vm/backup.t index f323b7c0e..81d989b87 100644 --- a/t/vm/backup.t +++ b/t/vm/backup.t @@ -83,6 +83,43 @@ sub backup_different_id_vm($vm) { $sth->execute($vm2->id, $id_vm_old); } +sub backup_auto_start($vm) { + my $domain = create_domain_v2(vm => $vm, swap => 1, data => 1 + ); + _remove_iso($domain); + + my $req = Ravada::Request->domain_autostart( + uid => user_admin->id + ,id_domain => $domain->id + ); + wait_request(); + + is($domain->autostart,1); + + $domain->backup(); + my ($backup) = $domain->list_backups(); + + my $name = $domain->name; + my $id = $domain->id; + $domain->remove(user_admin); + + rvd_back->restore_backup($backup->{file},0); + + my $domain_f = Ravada::Front::Domain->open($id); + is($domain_f->_data('autostart'),1); + + my $domain2 = rvd_back->search_domain($name); + ok($domain2); + is($domain2->autostart,1); + is($domain2->_data('autostart'),1); + if ($vm->type eq 'KVM') { + is($domain->domain->get_autostart(),1); + } + $domain2->remove(user_admin); + exit; + +} + sub backup($vm,$remove_user=undef) { my $user = create_user(); user_admin->make_admin($user->id); @@ -364,6 +401,8 @@ for my $vm_name ( vm_names() ) { diag($msg) if !$vm; skip $msg,10 if !$vm; + backup_auto_start($vm); + backup_clone_and_base($vm); backup_clone_base_different($vm); From 9f2bfd33c8fb05ceb4e0032ba4134bb0604cbbc9 Mon Sep 17 00:00:00 2001 From: Francesc Guasch Date: Mon, 14 Oct 2024 14:48:21 +0200 Subject: [PATCH 2/3] fix: set internal autostart issue #2097 --- lib/Ravada/Domain.pm | 3 +++ t/vm/backup.t | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Ravada/Domain.pm b/lib/Ravada/Domain.pm index 7a79095ce..e9d321b55 100644 --- a/lib/Ravada/Domain.pm +++ b/lib/Ravada/Domain.pm @@ -7830,6 +7830,9 @@ sub restore_backup($self, $backup, $interactive, $rvd_back=undef) { if($self->_data('is_base')) { $self->_set_base_vm_db($self->_vm->id,1); } + if($data->{autostart}) { + $self->autostart(1, Ravada::Utils::user_daemon()); + } return $self; } diff --git a/t/vm/backup.t b/t/vm/backup.t index 81d989b87..a6a701920 100644 --- a/t/vm/backup.t +++ b/t/vm/backup.t @@ -113,10 +113,11 @@ sub backup_auto_start($vm) { is($domain2->autostart,1); is($domain2->_data('autostart'),1); if ($vm->type eq 'KVM') { - is($domain->domain->get_autostart(),1); + is($domain2->domain->get_autostart(),1); } + is($domain2->_internal_autostart(),1); + $domain2->remove(user_admin); - exit; } From 0e8b0aad19c5f170fdea0d42e8528fde3e799c29 Mon Sep 17 00:00:00 2001 From: Francesc Guasch Date: Mon, 14 Oct 2024 15:18:34 +0200 Subject: [PATCH 3/3] wip: properly refresh auto start from internal --- lib/Ravada.pm | 4 ++++ t/vm/a10_autostart.t | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lib/Ravada.pm b/lib/Ravada.pm index 3fe67ec8e..0eb31805f 100644 --- a/lib/Ravada.pm +++ b/lib/Ravada.pm @@ -5758,6 +5758,10 @@ sub _cmd_refresh_machine($self, $request) { if $is_active && $domain->ip && $domain->list_ports; $domain->_unlock_host_devices() if !$is_active; + + if ($domain->autostart() ne $domain->_data('autostart')) { + $domain->_data('autostart' => $domain->autostart()); + } } sub _cmd_refresh_machine_ports($self, $request) { diff --git a/t/vm/a10_autostart.t b/t/vm/a10_autostart.t index 92db07f65..4c696dbaf 100644 --- a/t/vm/a10_autostart.t +++ b/t/vm/a10_autostart.t @@ -18,6 +18,39 @@ init( ); ####################################################################### +sub test_refresh($vm_name) { + my $domain = create_domain($vm_name); + is($domain->autostart,0,"[$vm_name] Expecting autostart=0 on domain ".$domain->name); + is($domain->is_active,0); + + $domain->_internal_autostart(1); + my $req = Ravada::Request->refresh_machine( + uid => user_admin->id + ,id_domain => $domain->id + ); + wait_request(); + is($req->error,''); + + my $domain2 = Ravada::Domain->open($domain->id); + is($domain2->_data('autostart'),1); + is($domain2->autostart,1); + + $domain->_internal_autostart(0); + + my $req2 = Ravada::Request->refresh_machine( + uid => user_admin->id + ,id_domain => $domain->id + ,_force => 1 + ); + wait_request(); + is($req2->error,''); + + my $domain3 = Ravada::Domain->open($domain->id); + is($domain3->_data('autostart'),0); + is($domain3->autostart,0); + + $domain3->remove(user_admin); +} sub test_autostart($vm_name) { my $domain = create_domain($vm_name); is($domain->autostart,0,"[$vm_name] Expecting autostart=0 on domain ".$domain->name); @@ -148,6 +181,8 @@ for my $vm_name ( vm_names() ) { diag($msg) if !$vm; skip $msg,10 if !$vm; + test_refresh($vm_name); + test_autostart($vm_name); test_autostart_base($vm_name); test_autostart_prepare_base($vm_name);