Francois Gouget : testbot/LibvirtTool: Clean up the snapshot name parsing.
Alexandre Julliard
julliard at winehq.org
Tue Feb 15 15:55:38 CST 2022
Module: tools
Branch: master
Commit: c960a95f6025538a9979b56cca652dc7a612615f
URL: https://source.winehq.org/git/tools.git/?a=commit;h=c960a95f6025538a9979b56cca652dc7a612615f
Author: Francois Gouget <fgouget at codeweavers.com>
Date: Tue Feb 15 05:03:22 2022 +0100
testbot/LibvirtTool: Clean up the snapshot name parsing.
This also makes it easier to extend it and pass all the configuration
around.
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
testbot/bin/LibvirtTool.pl | 95 +++++++++++++++++++++++++++-------------------
1 file changed, 56 insertions(+), 39 deletions(-)
diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl
index 3b2794f..d51699f 100755
--- a/testbot/bin/LibvirtTool.pl
+++ b/testbot/bin/LibvirtTool.pl
@@ -6,7 +6,7 @@
# network trouble, and thus are best performed in a separate process.
#
# Copyright 2009 Ge van Geldorp
-# Copyright 2012-2019 Francois Gouget
+# Copyright 2012-2021 Francois Gouget
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -564,6 +564,27 @@ sub SetupTestAgentd($$$)
$TA->Disconnect();
}
+sub GetSnapshotConfig($)
+{
+ my ($Config) = @_;
+
+ while (1)
+ {
+ if ($Config->{base} =~ s/-([a-z]{2}-[A-Z]{2})$//)
+ {
+ $Config->{locale} = $1;
+ }
+ elsif ($Config->{base} =~ s/-(live)$//)
+ {
+ $Config->{$1} = 1;
+ }
+ else
+ {
+ last;
+ }
+ }
+}
+
sub CreateSnapshot($$)
{
my ($Domain, $SnapshotName) = @_;
@@ -591,35 +612,32 @@ sub Revert()
return 1;
}
$CurrentStatus = "reverting";
- my $DomainSnapshot = $VM->IdleSnapshot;
- my $ExtraTimeout = 0;
- my ($SetLocale, $CreateSnapshot);
+ my $Config = { base => $VM->IdleSnapshot };
my $Domain = $VM->GetDomain();
- if (($VM->Type eq "win32" or $VM->Type eq "win64") and
- !$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";
- $CreateSnapshot = 1;
- 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
- $ExtraTimeout += $WaitForBoot + $VMToolTimeout / 2;
- $CreateSnapshot = 1;
- Debug(Elapsed($Start), " $VMKey does not yet have a $DomainSnapshot-live snapshot\n");
- }
- if (!$Domain->HasSnapshot($DomainSnapshot))
- {
- FatalError("Could not find $VMKey\'s $DomainSnapshot snapshot\n");
- }
- if ($ExtraTimeout)
+ if (!$Domain->HasSnapshot($Config->{base}))
{
+ $Config->{create} = 1;
+ GetSnapshotConfig($Config);
+ if ($Config->{locale} and $VM->Type !~ /^win(?:32|64)$/)
+ {
+ FatalError("Creating locale snapshots ($Config->{locale}) is not supported for ". $VM->Type ." VMs ($VMKey)\n");
+ }
+ if (!$Config->{live})
+ {
+ FatalError("Only live snapshots can be created ($VMKey)\n");
+ }
+ if (!$Domain->HasSnapshot($Config->{base}))
+ {
+ FatalError("Could not find $VMKey\'s $Config->{base} snapshot\n");
+ }
+
+ # Extend the deadline to have time to set up the VM and (re)boot it.
+ # Add $WaitForBoot even if no reboot is needed in the end.
+ my $ExtraTimeout = $WaitForBoot + $VMToolTimeout;
Debug(Elapsed($Start), " Extending the $VMKey revert deadline by ${ExtraTimeout}s\n");
+ # ChildDeadline is undefined if the VM (or another sharing the same
+ # hypervisor domain) is in maintenance mode.
my $Deadline = $VM->ChildDeadline || (time() + $VMToolTimeout);
$VM->ChildDeadline($Deadline + $ExtraTimeout);
$VM->Save();
@@ -631,8 +649,8 @@ sub Revert()
sleep(1) if (ShutDownIfOffSnapshot() == 2);
# Revert the VM (and power it on if necessary)
- Debug(Elapsed($Start), " Reverting $VMKey to $DomainSnapshot\n");
- my ($ErrMessage, $Booting) = $Domain->RevertToSnapshot($DomainSnapshot);
+ Debug(Elapsed($Start), " Reverting $VMKey to $Config->{base}\n");
+ my ($ErrMessage, $Booting) = $Domain->RevertToSnapshot($Config->{base});
if (defined $ErrMessage)
{
# Libvirt/QEmu is buggy and cannot revert a running VM from one hardware
@@ -645,40 +663,39 @@ sub Revert()
FatalError("Could not power off $VMKey: $ErrMessage\n");
}
- Debug(Elapsed($Start), " Reverting $VMKey to $DomainSnapshot... again\n");
- ($ErrMessage, $Booting) = $Domain->RevertToSnapshot($DomainSnapshot);
+ Debug(Elapsed($Start), " Reverting $VMKey to $Config->{base}... again\n");
+ ($ErrMessage, $Booting) = $Domain->RevertToSnapshot($Config->{base});
}
if (defined $ErrMessage)
{
- FatalError("Could not revert $VMKey to $DomainSnapshot: $ErrMessage\n");
+ FatalError("Could not revert $VMKey to $Config->{base}: $ErrMessage\n");
}
# 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 (!$Config->{create})
{
return 1 if (ChangeStatus("reverting", "sleeping"));
}
# Set up the TestAgent server. Note that setting the locale will require a
# reboot so reset start.count in that case.
- SetupTestAgentd($Booting, ($CreateSnapshot or $SetLocale), $SetLocale);
+ SetupTestAgentd($Booting, $Config->{create}, $Config->{locale});
# Set up the VM locale
- if ($SetLocale)
+ if ($Config->{locale})
{
- Debug(Elapsed($Start), " Setting up the $SetLocale locale on $VMKey\n");
- my @Cmd = ("$BinDir/SetWinLocale", $VM->Hostname, "--default", $SetLocale);
+ Debug(Elapsed($Start), " Setting up the $Config->{locale} locale on $VMKey\n");
+ my @Cmd = ("$BinDir/SetWinLocale", $VM->Hostname, "--default", $Config->{locale});
push @Cmd, "--debug" if ($Debug);
if (system(@Cmd))
{
- FatalError("Could not set the $VMKey locale to $SetLocale\n");
+ FatalError("Could not set the $VMKey locale to $Config->{locale}\n");
}
- $Booting = 1;
}
- if ($CreateSnapshot)
+ if ($Config->{create})
{
CreateSnapshot($Domain, $VM->IdleSnapshot);
More information about the wine-cvs
mailing list