From bc93c561697c19c08c8f4b5239198600d9b9a1d5 Mon Sep 17 00:00:00 2001 From: Francesc Guasch Date: Thu, 21 May 2020 10:51:55 +0200 Subject: [PATCH] Fix locked in admin machines (#1336) fix(frontend): update domain status after request add test in 30_hardware.t issue #1333 --- lib/Ravada.pm | 14 ++++++++++++++ t/request/30_hardware.t | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/Ravada.pm b/lib/Ravada.pm index 6a4a26ac1..fa37cdaad 100644 --- a/lib/Ravada.pm +++ b/lib/Ravada.pm @@ -2565,6 +2565,20 @@ sub _do_execute_command { if $request->status() ne 'done' && $request->status() !~ /^retry/i; } + $self->_set_domain_changed($request) if $request->status eq 'done'; +} + +sub _set_domain_changed($self, $request) { + my $id_domain = $request->id_domain; + if (!defined $id_domain) { + $id_domain = $request->defined_arg('id_domain'); + } + return if !defined $id_domain; + + my $sth = $CONNECTOR->dbh->prepare("UPDATE domains set date_changed=CURRENT_TIMESTAMP" + ." WHERE id=? "); + $sth->execute($id_domain); + } sub _cmd_manage_pools($self, $request) { diff --git a/t/request/30_hardware.t b/t/request/30_hardware.t index 9ad9be3bc..c47452970 100644 --- a/t/request/30_hardware.t +++ b/t/request/30_hardware.t @@ -29,6 +29,8 @@ my %CREATE_ARGS = ( ,Void => { id_owner => $USER->id } ); +my $TEST_TIMESTAMP = 0; + ######################################################################## sub create_args { my $backend = shift; @@ -68,6 +70,9 @@ sub test_add_hardware_request_drivers { sub test_add_hardware_request($vm, $domain, $hardware, $data={}) { confess if !ref($data) || ref($data) ne 'HASH'; + + my $date_changed = $domain->_data('date_changed'); + my @list_hardware1 = $domain->get_controller($hardware); my $numero = scalar(@list_hardware1)+1; while ($hardware eq 'usb' && $numero > 4) { @@ -87,6 +92,7 @@ sub test_add_hardware_request($vm, $domain, $hardware, $data={}) { is($@,'') or return; $USER->unread_messages(); ok($req, 'Request'); + sleep 1 if !$TEST_TIMESTAMP; rvd_back->_process_all_requests_dont_fork(); is($req->status(),'done'); is($req->error(),'') or exit; @@ -117,6 +123,9 @@ sub test_add_hardware_request($vm, $domain, $hardware, $data={}) { } elsif($hardware eq 'disk') { like($new_hardware->{file},qr(\.iso$)) or die Dumper($info->{hardware}->{$hardware}); } + if (!$TEST_TIMESTAMP++) { + isnt($domain->_data('date_changed'), $date_changed); + } } sub test_add_cdrom($domain) { @@ -639,6 +648,7 @@ for my $vm_name ( qw(Void KVM )) { ok(!$domain_b->is_active); } + ok($TEST_TIMESTAMP); } end();