From: Francois Gouget Subject: [1/2] testbot: Don't let the scripts blindly overwrite the VM status. Message-Id: Date: Fri, 25 Jul 2014 11:23:53 +0200 (CEST) This makes it possible for the administrator to step in and mark a VM for maintenance while a script is using it. --- Then the administrator can either let the task using the VM complete, or immediately revert/shutdown the VM thus causing the current task to fail with a boterror (which means it can be restarted later on). This fixes bug 35946. http://bugs.winehq.com/show_bug.cgi?id=35946 testbot/bin/RevertVM.pl | 19 +++++++++++++++---- testbot/bin/WineRunBuild.pl | 21 ++++++++++++--------- testbot/bin/WineRunReconfig.pl | 26 ++++++++++++-------------- testbot/bin/WineRunTask.pl | 29 +++++++++++++++++------------ 4 files changed, 56 insertions(+), 39 deletions(-) diff --git a/testbot/bin/RevertVM.pl b/testbot/bin/RevertVM.pl index 3712c4d..17eb800 100755 --- a/testbot/bin/RevertVM.pl +++ b/testbot/bin/RevertVM.pl @@ -48,11 +48,16 @@ sub FatalError($$) LogMsg $ErrMessage, "\n"; - $VM->Status("offline"); - $VM->ChildPid(undef); - $VM->Save(); - + # Get the up-to-date VM status and update it if nobody else changed it my $VMKey = $VM->GetKey(); + $VM = CreateVMs()->GetItem($VMKey); + if ($VM->Status eq "reverting" or $VM->Status eq "sleeping") + { + $VM->Status("offline"); + $VM->ChildPid(undef); + $VM->Save(); + } + my $VMSnapshot = $VM->IdleSnapshot; open (SENDMAIL, "|/usr/sbin/sendmail -oi -t -odq"); print SENDMAIL <<"EOF"; @@ -110,6 +115,9 @@ if (defined($ErrMessage)) $VM; } +# Get the up-to-date VM status and exit if someone else changed it +$VM = CreateVMs()->GetItem($VMKey); +exit 1 if ($VM->Status ne "reverting"); $VM->Status("sleeping"); ($ErrProperty, $ErrMessage) = $VM->Save(); if (defined($ErrMessage)) @@ -134,6 +142,9 @@ if ($SleepAfterRevert != 0) sleep($SleepAfterRevert); } +# Get the up-to-date VM status and exit if someone else changed it +$VM = CreateVMs()->GetItem($VMKey); +exit 1 if ($VM->Status ne "sleeping"); $VM->Status("idle"); $VM->ChildPid(undef); ($ErrProperty, $ErrMessage) = $VM->Save(); diff --git a/testbot/bin/WineRunBuild.pl b/testbot/bin/WineRunBuild.pl index b07454b..8f1defa 100755 --- a/testbot/bin/WineRunBuild.pl +++ b/testbot/bin/WineRunBuild.pl @@ -39,6 +39,7 @@ sub BEGIN use WineTestBot::Config; use WineTestBot::Jobs; +use WineTestBot::VMs; use WineTestBot::Log; use WineTestBot::Engine::Notify; @@ -69,14 +70,15 @@ sub FatalError($$$$) $Task->Save(); $Job->UpdateStatus(); - my $VM = $Task->VM; + # Get the up-to-date VM status and update it if nobody else changed it + my $VM = CreateVMs()->GetItem($Task->VM->GetKey()); if ($VM->Status eq 'running') { $VM->Status('dirty'); $VM->Save(); + RescheduleJobs(); } - RescheduleJobs(); exit 1; } @@ -326,14 +328,15 @@ $Task->ChildPid(undef); $Task->Ended(time); $Task->Save(); $Job->UpdateStatus(); -$VM->Status('dirty'); -$VM->Save(); - -$Task = undef; -$Step = undef; -$Job = undef; -RescheduleJobs(); +# Get the up-to-date VM status and update it if nobody else changed it +$VM = CreateVMs()->GetItem($VM->GetKey()); +if ($VM->Status eq 'running') +{ + $VM->Status('dirty'); + $VM->Save(); + RescheduleJobs(); +} LogMsg "Task $JobId/$StepNo/$TaskNo completed\n"; exit 0; diff --git a/testbot/bin/WineRunReconfig.pl b/testbot/bin/WineRunReconfig.pl index 555f4e4..c898a52 100755 --- a/testbot/bin/WineRunReconfig.pl +++ b/testbot/bin/WineRunReconfig.pl @@ -39,6 +39,7 @@ sub BEGIN use WineTestBot::Config; use WineTestBot::Jobs; +use WineTestBot::VMs; use WineTestBot::Log; use WineTestBot::Engine::Notify; @@ -69,14 +70,15 @@ sub FatalError($$$$) $Task->Save(); $Job->UpdateStatus(); - my $VM = $Task->VM; + # Get the up-to-date VM status and update it if nobody else changed it + my $VM = CreateVMs()->GetItem($Task->VM->GetKey()); if ($VM->Status eq 'running') { $VM->Status('dirty'); $VM->Save(); + RescheduleJobs(); } - RescheduleJobs(); exit 1; } @@ -272,12 +274,6 @@ if ($NewStatus eq "completed") FatalError "Can't take snapshot: $ErrMessage\n", $FullErrFileName, $Job, $Task; } - - $VM->Status("idle"); -} -else -{ - $VM->Status("dirty"); } $Task->Status($NewStatus); @@ -285,13 +281,15 @@ $Task->ChildPid(undef); $Task->Ended(time); $Task->Save(); $Job->UpdateStatus(); -$VM->Save(); -$Task = undef; -$Step = undef; -$Job = undef; - -RescheduleJobs(); +# Get the up-to-date VM status and update it if nobody else changed it +$VM = CreateVMs()->GetItem($VM->GetKey()); +if ($VM->Status eq 'running') +{ + $VM->Status($NewStatus eq 'completed' ? 'idle' : 'dirty'); + $VM->Save(); + RescheduleJobs(); +} LogMsg "Task $JobId/$StepNo/$TaskNo completed\n"; exit 0; diff --git a/testbot/bin/WineRunTask.pl b/testbot/bin/WineRunTask.pl index 86073e6..353b9b4 100755 --- a/testbot/bin/WineRunTask.pl +++ b/testbot/bin/WineRunTask.pl @@ -38,6 +38,7 @@ sub BEGIN use POSIX qw(:fcntl_h); use WineTestBot::Config; use WineTestBot::Jobs; +use WineTestBot::VMs; use WineTestBot::Log; use WineTestBot::Engine::Notify; @@ -80,11 +81,15 @@ sub FatalError($$$$$) $Task->Save(); $Job->UpdateStatus(); - my $VM = $Task->VM; - $VM->Status('dirty'); - $VM->Save(); + # Get the up-to-date VM status and update it if nobody else changed it + my $VM = CreateVMs()->GetItem($Task->VM->GetKey()); + if ($VM->Status eq 'running') + { + $VM->Status('dirty'); + $VM->Save(); + RescheduleJobs(); + } - RescheduleJobs(); exit 1; } @@ -376,14 +381,14 @@ $Task->Ended(time); $Task->Save(); $Job->UpdateStatus(); -$VM->Status('dirty'); -$VM->Save(); - -$Task = undef; -$Step = undef; -$Job = undef; - -RescheduleJobs(); +# Get the up-to-date VM status and update it if nobody else changed it +$VM = CreateVMs()->GetItem($VM->GetKey()); +if ($VM->Status eq 'running') +{ + $VM->Status('dirty'); + $VM->Save(); + RescheduleJobs(); +} LogMsg "Task $JobId/$StepNo/$TaskNo (" . $VM->Name . ") completed\n"; exit 0; -- 2.0.1