[PATCH] testbot/LibvirtTool: Create the locale snapshots as needed.

Francois Gouget fgouget at codeweavers.com
Wed Sep 25 01:51:57 CDT 2019


A VM may have a lot of locale live snapshots. This removes the need for
manually creating them (or recreating them after restoring the VM from
backup or after a QEmu upgrade).
Sadly the locales must still be manually installed beforehand.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 testbot/bin/LibvirtTool.pl               | 73 +++++++++++++++++++++---
 testbot/{scripts => bin}/SetWinLocale    |  0
 testbot/bin/WineRunReconfig.pl           |  2 +-
 testbot/lib/WineTestBot/LibvirtDomain.pm |  5 +-
 4 files changed, 67 insertions(+), 13 deletions(-)
 rename testbot/{scripts => bin}/SetWinLocale (100%)

diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl
index d1402bc49..936c38608 100755
--- a/testbot/bin/LibvirtTool.pl
+++ b/testbot/bin/LibvirtTool.pl
@@ -365,9 +365,9 @@ sub CheckOff()
   return ChangeStatus("dirty", "off", "done");
 }
 
-sub SetupTestAgentd($$)
+sub SetupTestAgentd($$$)
 {
-  my ($VM, $Booting) = @_;
+  my ($VM, $Booting, $ResetStartCount) = @_;
 
   Debug(Elapsed($Start), " Setting up the $VMKey TestAgent server\n");
   LogMsg "Setting up the $VMKey TestAgent server\n";
@@ -379,6 +379,23 @@ sub SetupTestAgentd($$)
     my $ErrMessage = $TA->GetLastError();
     FatalError("Could not connect to the $VMKey TestAgent: $ErrMessage\n");
   }
+
+  if ($ResetStartCount)
+  {
+    # If SetProperty() is not supported neither is --show-restarts.
+    # So it all works out.
+    $TA->SetProperty("start.count", 0);
+  }
+  else
+  {
+    # Check that TestAgentd is not displaying the "Has Windows rebooted?"
+    # warning.
+    my $Count = $TA->GetProperties("start.count");
+    if (defined $Count and $Count > 1)
+    {
+      FatalError("Cannot take a live snapshot because start.count=$Count > 1");
+    }
+  }
   $TA->Disconnect();
 }
 
@@ -435,9 +452,17 @@ sub Revert()
   $CurrentStatus = "reverting";
   my $DomainSnapshot = $VM->IdleSnapshot;
   my $ExtraTimeout = 0;
-  my $CreateSnapshot;
+  my ($SetLocale, $CreateSnapshot);
 
   my $Domain = $VM->GetDomain();
+  if (!$Domain->HasSnapshot($DomainSnapshot) and
+      $DomainSnapshot =~ s/-([a-z]{2})[_-]([A-Z]{2})$//)
+  {
+    # Add some extra time to set up the VM locale and reboot it
+    $ExtraTimeout += $VMToolTimeout;
+    $SetLocale = "$1-$2";
+    Debug(Elapsed($Start), " $VMKey does not yet have a $DomainSnapshot-$SetLocale snapshot\n");
+  }
   if (!$Domain->HasSnapshot($DomainSnapshot) and $DomainSnapshot =~ s/-live$//)
   {
     # Add some extra time to boot the VM and create the live snapshot
@@ -484,19 +509,49 @@ sub Revert()
   # Mark the VM as sleeping which allows the scheduler to abort the revert in
   # favor of higher priority tasks. But don't allow interruptions in the
   # middle of snapshot creation!
-  if (!$CreateSnapshot)
+  if (!$CreateSnapshot and !$SetLocale)
   {
     return 1 if (ChangeStatus("reverting", "sleeping"));
   }
 
-  # Set up the TestAgent server
-  SetupTestAgentd($VM, $Booting);
+  # Set up the TestAgent server. Note that setting the locale will require a
+  # reboot so reset start.count in that case.
+  SetupTestAgentd($VM, $Booting, $SetLocale);
 
   if ($CreateSnapshot)
   {
-    CreateSnapshot($Domain, $VM->IdleSnapshot);
+    $DomainSnapshot .= "-live";
+    CreateSnapshot($Domain, $DomainSnapshot);
   }
-  else
+
+  # Set up the VM locale
+  if ($SetLocale)
+  {
+    Debug(Elapsed($Start), " Setting up the $SetLocale locale on $VMKey\n");
+    if (system("$BinDir/SetWinLocale", "--vm", $VMKey, "--default", $SetLocale))
+    {
+      FatalError("Could not set the $VMKey locale to $SetLocale\n");
+    }
+
+    Debug(Elapsed($Start), " Wait for the $VMKey locale-setting reboot to complete\n");
+    LogMsg "Wait for the $VMKey locale-setting reboot to complete\n";
+    while (1)
+    {
+      my $TA = $VM->GetAgent();
+      my $Count = $TA->GetProperties("start.count");
+      $TA->Disconnect();
+
+      # SetupTestAgentd() has reset start.count to zero.
+      # It will only change after the reboot.
+      last if (defined $Count and $Count != 0);
+
+      sleep(1);
+    }
+
+    $DomainSnapshot .= "-$SetLocale";
+    CreateSnapshot($Domain, $DomainSnapshot);
+  }
+  elsif (!$CreateSnapshot)
   {
     my $Sleep = ($Booting and $SleepAfterBoot > $SleepAfterRevert) ?
                 $SleepAfterBoot : $SleepAfterRevert;
@@ -505,7 +560,7 @@ sub Revert()
     sleep($Sleep);
   }
 
-  if ($CreateSnapshot)
+  if ($CreateSnapshot or $SetLocale)
   {
     # The activity monitor does not like it when VMs skip the sleeping step
     return 1 if (ChangeStatus("reverting", "sleeping"));
diff --git a/testbot/scripts/SetWinLocale b/testbot/bin/SetWinLocale
similarity index 100%
rename from testbot/scripts/SetWinLocale
rename to testbot/bin/SetWinLocale
diff --git a/testbot/bin/WineRunReconfig.pl b/testbot/bin/WineRunReconfig.pl
index d558654ef..1e0e15371 100755
--- a/testbot/bin/WineRunReconfig.pl
+++ b/testbot/bin/WineRunReconfig.pl
@@ -512,7 +512,7 @@ if ($NewStatus eq 'completed')
   }
 
   Debug(Elapsed($Start), " Recreating the $IdleSnapshot snapshot\n");
-  $ErrMessage = $Domain->CreateSnapshot();
+  $ErrMessage = $Domain->CreateSnapshot($IdleSnapshot);
   if (defined $ErrMessage)
   {
     # Without the snapshot the VM is not usable anymore but FatalError() will
diff --git a/testbot/lib/WineTestBot/LibvirtDomain.pm b/testbot/lib/WineTestBot/LibvirtDomain.pm
index 207dc6d45..68004a551 100644
--- a/testbot/lib/WineTestBot/LibvirtDomain.pm
+++ b/testbot/lib/WineTestBot/LibvirtDomain.pm
@@ -330,14 +330,13 @@ sub RevertToSnapshot($$)
   return (undef, $Reason != Sys::Virt::Domain::STATE_RUNNING_FROM_SNAPSHOT);
 }
 
-sub CreateSnapshot($)
+sub CreateSnapshot($$)
 {
-  my ($self) = @_;
+  my ($self, $SnapshotName) = @_;
 
   my ($ErrMessage, $Domain) = $self->_GetDomain();
   return $ErrMessage if (defined $ErrMessage);
 
-  my $SnapshotName = $self->{VM}->IdleSnapshot;
   # FIXME: XML escaping
   my $Xml = "<domainsnapshot><name>$SnapshotName</name></domainsnapshot>";
   eval { $Domain->create_snapshot($Xml, 0) };
-- 
2.20.1



More information about the wine-devel mailing list