testbot: PowerOff() should not return an error if a VM is already off.

Francois Gouget fgouget at codeweavers.com
Tue Dec 17 04:00:48 CST 2013


VMs may be put in unexpected states when an administrator manually reconfigures them. So, even though we normally don't call PowerOff() on powered off VMs, robustness dictates this change.
Also ensure that if an error does occur the error message contains the VM name.
This fixes various 'Scheduling problem in HandleXxx' error reports.
---
 testbot/bin/RevertVM.pl        | 13 +++++--------
 testbot/lib/WineTestBot/VMs.pm | 20 +++++++++++++++-----
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/testbot/bin/RevertVM.pl b/testbot/bin/RevertVM.pl
index 5f98191..2ce3be1 100755
--- a/testbot/bin/RevertVM.pl
+++ b/testbot/bin/RevertVM.pl
@@ -97,15 +97,12 @@ if (defined($ErrMessage))
   FatalError "Can't change status for VM $VMKey: $ErrMessage", $VM;
 }
 
-if ($VM->IsPoweredOn())
+# Some QEmu/KVM versions are buggy and cannot revert a running VM
+$ErrMessage = $VM->PowerOff(1);
+if (defined $ErrMessage)
 {
-  # Some QEmu/KVM versions are buggy and cannot revert a running VM
-  $ErrMessage = $VM->PowerOff(1);
-  if (defined $ErrMessage)
-  {
-    LogMsg "Could not shut down $VMKey: $ErrMessage\n";
-    LogMsg "Trying the revert anyway\n";
-  }
+  LogMsg "$ErrMessage\n";
+  LogMsg "Trying the revert anyway\n";
 }
 
 $ErrMessage = $VM->RevertToSnapshot($VM->IdleSnapshot);
diff --git a/testbot/lib/WineTestBot/VMs.pm b/testbot/lib/WineTestBot/VMs.pm
index 7c403cd..d4267e0 100644
--- a/testbot/lib/WineTestBot/VMs.pm
+++ b/testbot/lib/WineTestBot/VMs.pm
@@ -375,11 +375,21 @@ sub PowerOff($$)
   my ($ErrMessage, $Domain) = $self->_GetDomain();
   return $ErrMessage if (defined $ErrMessage);
 
-  eval { $Domain->destroy() };
-  return $@->message() if ($@);
-
-  return $self->UpdateStatus($Domain) if (!$NoStatus);
-  return undef;
+  if ($self->IsPoweredOn())
+  {
+    eval { $Domain->destroy() };
+    if ($@)
+    {
+      $ErrMessage = $@->message();
+    }
+    elsif ($self->IsPoweredOn())
+    {
+      $ErrMessage = "The VM is still active";
+    }
+  }
+  $ErrMessage ||= $self->UpdateStatus($Domain) if (!$NoStatus);
+  return undef if (!defined $ErrMessage);
+  return join("", "Could not power off ", $self->Name, ": ", $ErrMessage);
 }
 
 sub GetAgent($)
-- 
1.8.5.1




More information about the wine-patches mailing list