Module: tools Branch: master Commit: de68e426859f08ccc0906adc9ee1c5ba5fea7fd4 URL: https://source.winehq.org/git/tools.git/?a=commit;h=de68e426859f08ccc0906adc...
Author: Francois Gouget fgouget@codeweavers.com Date: Thu Sep 19 15:02:14 2019 +0200
testbot/LibvirtTool: Check the VM state before putting it back online.
Normally GetSnapshotName() returns undef when the domain is busy reverting. But that's an undocumented feature and the the VM may end up in a state where GetSnapshotName() returns undef despite the VM being usable (e.g. powered off after a failed revert). So check the Libvirt domain state instead.
Signed-off-by: Francois Gouget fgouget@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
testbot/bin/LibvirtTool.pl | 46 ++++++++++---------------------- testbot/lib/WineTestBot/LibvirtDomain.pm | 21 +++++++++++++++ 2 files changed, 35 insertions(+), 32 deletions(-)
diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl index f15bab7..dca5a92 100755 --- a/testbot/bin/LibvirtTool.pl +++ b/testbot/bin/LibvirtTool.pl @@ -282,42 +282,24 @@ sub Monitor() return 0; }
- my ($ErrMessage, $SnapshotName) = $VM->GetDomain()->GetSnapshotName(); - if (defined $ErrMessage) - { - Error "$ErrMessage\n"; - } - else + my $IsReady = $VM->GetDomain()->IsReady(); + if ($IsReady and $VM->GetDomain()->IsPoweredOn()) { - my $IsPoweredOn; - if (!defined $SnapshotName) - { - Debug("$VMKey has no snapshot (reverting?)\n"); - $IsPoweredOn = undef; - } - elsif (!defined $SnapshotName or $SnapshotName ne $VM->IdleSnapshot) - { - $IsPoweredOn = 0; - } - else - { - $IsPoweredOn = $VM->GetDomain()->IsPoweredOn(); - if ($IsPoweredOn) - { - $ErrMessage = $VM->GetDomain()->PowerOff(); - Error "$ErrMessage\n" if (defined $ErrMessage); - $IsPoweredOn = undef; - } - } - if (defined $IsPoweredOn) + my $ErrMessage = $VM->GetDomain()->PowerOff(); + if (defined $ErrMessage) { - return 1 if (ChangeStatus("offline", "off", "done")); - NotifyAdministrator("The $VMKey VM is working again", - "The $VMKey VM started working again after ". - PrettyElapsed($Start) ."."); - return 0; + Error "$ErrMessage\n"; + $IsReady = undef; } } + if ($IsReady) + { + return 1 if (ChangeStatus("offline", "off", "done")); + NotifyAdministrator("The $VMKey VM is working again", + "The $VMKey VM started working again after ". + PrettyElapsed($Start) ."."); + return 0; + }
Debug(Elapsed($Start), " $VMKey is still unreachable\n"); sleep(60); diff --git a/testbot/lib/WineTestBot/LibvirtDomain.pm b/testbot/lib/WineTestBot/LibvirtDomain.pm index 8d9b9df..f0a8c69 100644 --- a/testbot/lib/WineTestBot/LibvirtDomain.pm +++ b/testbot/lib/WineTestBot/LibvirtDomain.pm @@ -363,6 +363,27 @@ sub IsPoweredOn($) return ($State == Sys::Virt::Domain::STATE_RUNNING); }
+sub IsReady($) +{ + my ($self) = @_; + + my ($ErrMessage, $Domain) = $self->_GetDomain(); + if (defined $ErrMessage) + { + $@ = $ErrMessage; + return undef; + } + + my ($State, $_Reason); + eval { ($State, $_Reason) = $Domain->get_state() }; + return $self->_Reset(undef) if ($@); + return ($State == Sys::Virt::Domain::STATE_RUNNING or + $State == Sys::Virt::Domain::STATE_SHUTOFF or + $State == Sys::Virt::Domain::STATE_CRASHED or + $State == Sys::Virt::Domain::STATE_PMSUSPENDED + ); +} + sub _GetStateName($) { my ($State) = @_;