Module: tools Branch: master Commit: b1653d3e85f37e711be0e5232e81f063c0d8c7df URL: http://source.winehq.org/git/tools.git/?a=commit;h=b1653d3e85f37e711be0e5232...
Author: Francois Gouget fgouget@codeweavers.com Date: Fri Jul 25 11:23:53 2014 +0200
testbot: Don't let the scripts blindly overwrite the VM status.
This makes it possible for the administrator to step in and mark a VM for maintenance while a script is using it.
---
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;