[PATCH 3/4] testbot: Replace poweroff with checkoff in the Engine's Cleanup().

Francois Gouget fgouget at codeweavers.com
Tue Feb 27 18:55:41 CST 2018


checkoff verifies that the hypervisor domain state matches that of the
current VM instance before powering it off.
If the state does not match then the VM is just marked off.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 testbot/bin/Engine.pl          |  8 ++++----
 testbot/bin/LibvirtTool.pl     | 28 ++++++++++++++++++++++++++--
 testbot/lib/WineTestBot/VMs.pm | 20 ++++++++++++++++++++
 3 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/testbot/bin/Engine.pl b/testbot/bin/Engine.pl
index 2e62c660c..a03fa06b9 100755
--- a/testbot/bin/Engine.pl
+++ b/testbot/bin/Engine.pl
@@ -206,8 +206,8 @@ sub Cleanup($;$$)
       {
         # The VM should not have a process.
         $VM->KillChild();
-        $VM->RunPowerOff();
-        $VM->RecordStatus($Records, "dirty poweroff (unexpected process)");
+        $VM->RunCheckOff();
+        $VM->RecordStatus($Records, "dirty off check (unexpected process)");
       }
       elsif ($Starting)
       {
@@ -228,8 +228,8 @@ sub Cleanup($;$$)
         # Power off the VM, even if its status is already off.
         # This is the simplest way to resync the VM status field.
         # Also powering off a powered off VM will detect offline VMs.
-        $VM->RunPowerOff();
-        $VM->RecordStatus($Records, "dirty poweroff");
+        $VM->RunCheckOff();
+        $VM->RecordStatus($Records, "dirty off check");
       }
     }
     # $KillVMs is normally used on shutdown so don't start a process that
diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl
index 0293baeb7..76ea70713 100755
--- a/testbot/bin/LibvirtTool.pl
+++ b/testbot/bin/LibvirtTool.pl
@@ -104,7 +104,7 @@ while (@ARGV)
   {
     $LogOnly = 1;
   }
-  elsif ($Arg =~ /^(?:checkidle|monitor|poweroff|revert)$/)
+  elsif ($Arg =~ /^(?:checkidle|checkoff|monitor|poweroff|revert)$/)
   {
     $Action = $Arg;
   }
@@ -163,7 +163,7 @@ if (!defined $Usage)
 }
 if (defined $Usage)
 {
-  print "Usage: $Name0 [--debug] [--log-only] [--help] (checkidle|monitor|poweroff|revert) VMName\n";
+  print "Usage: $Name0 [--debug] [--log-only] [--help] (checkidle|checkoff|monitor|poweroff|revert) VMName\n";
   exit $Usage;
 }
 
@@ -344,6 +344,26 @@ sub CheckIdle()
   return ChangeStatus("dirty", $NewStatus, "done");
 }
 
+sub CheckOff()
+{
+  $CurrentStatus = "dirty";
+  my $IsPoweredOn = $VM->GetDomain()->IsPoweredOn();
+  return ChangeStatus("dirty", "offline", "done") if (!defined $IsPoweredOn);
+
+  if ($IsPoweredOn)
+  {
+    my ($ErrMessage, $SnapshotName) = $VM->GetDomain()->GetSnapshotName();
+    FatalError("$ErrMessage\n") if (defined $ErrMessage);
+    if ($SnapshotName eq $VM->IdleSnapshot)
+    {
+      my $ErrMessage = $VM->GetDomain()->PowerOff();
+      FatalError("$ErrMessage\n") if (defined $ErrMessage);
+    }
+  }
+
+  return ChangeStatus("dirty", "off", "done");
+}
+
 sub Revert()
 {
   my $VM = CreateVMs()->GetItem($VMKey);
@@ -405,6 +425,10 @@ if ($Action eq "checkidle")
 {
   $Rc = CheckIdle();
 }
+elsif ($Action eq "checkoff")
+{
+  $Rc = CheckOff();
+}
 elsif ($Action eq "monitor")
 {
   $Rc = Monitor();
diff --git a/testbot/lib/WineTestBot/VMs.pm b/testbot/lib/WineTestBot/VMs.pm
index f09863996..afc7af985 100644
--- a/testbot/lib/WineTestBot/VMs.pm
+++ b/testbot/lib/WineTestBot/VMs.pm
@@ -451,6 +451,26 @@ sub RunCheckIdle($)
 =pod
 =over 12
 
+=item C<RunCheckOff()>
+
+If the hypervisor domain state matches that of this VM instance, power if off.
+If not the VM is simply marked as off. While this is happening the VM status
+is set to dirty so the job scheduler does not try to use it.
+
+This operation can take a long time so it is performed in a separate process.
+
+=back
+=cut
+
+sub RunCheckOff($)
+{
+  my ($self) = @_;
+  return $self->_RunVMTool("dirty", ["--log-only", "checkoff", $self->GetKey()]);
+}
+
+=pod
+=over 12
+
 =item C<RunMonitor()>
 
 Monitors an offline VM to detect when it becomes accessible again.
-- 
2.16.1




More information about the wine-devel mailing list