[PATCH] testbot/LibvirtTool: Check the VM state before putting it back online.
Francois Gouget
fgouget at codeweavers.com
Thu Sep 19 08:02:14 CDT 2019
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 at codeweavers.com>
---
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 f15bab70b..dca5a921e 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 d6c07408c..4e1c4ee07 100644
--- a/testbot/lib/WineTestBot/LibvirtDomain.pm
+++ b/testbot/lib/WineTestBot/LibvirtDomain.pm
@@ -365,6 +365,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) = @_;
--
2.20.1
More information about the wine-devel
mailing list