The TestBot creates the the missing live snapshots itself so these
options were unused.
Signed-off-by: Francois Gouget <fgouget(a)codeweavers.com>
---
Also they can only be used by running SetWinLocale on the TestBot server
which I cannot do.
---
testbot/bin/SetWinLocale | 327 +++------------------------------------
1 file changed, 21 insertions(+), 306 deletions(-)
diff --git a/testbot/bin/SetWinLocale b/testbot/bin/SetWinLocale
index 1e803c555..d7f795bee 100755
--- a/testbot/bin/SetWinLocale
+++ b/testbot/bin/SetWinLocale
@@ -1,10 +1,9 @@
#!/usr/bin/perl -Tw
# -*- Mode: Perl; perl-indent-level: 2; indent-tabs-mode: nil -*-
#
-# Sets the locale of the specified Windows machine and, optionally,
-# updates or creates a new snapshot of the TestBot VM for it.
+# Sets the locale of the specified Windows machine.
#
-# Copyright 2018 Francois Gouget
+# Copyright 2018, 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
@@ -40,7 +39,6 @@ sub BEGIN
use WineTestBot::Config;
use WineTestBot::Log;
use WineTestBot::TestAgent;
-use WineTestBot::VMs;
use WineTestBot::Utils;
@@ -292,7 +290,6 @@ sub CheckLocale($$)
}
my ($OptHostName, $OptReboot);
-my ($OptVM, $OptRefresh, $OptRefreshAll, $OptAddMissing, $OptAddLocales);
my ($OptDefault, $OptLocale, $OptSystem, $OptMUI, $OptCountry, $OptKeyboard);
while (@ARGV)
{
@@ -301,26 +298,6 @@ while (@ARGV)
{
$Usage = 0;
}
- elsif ($Arg eq "--vm")
- {
- $OptVM = CheckValue($Arg, $OptVM);
- }
- elsif ($Arg eq "--refresh")
- {
- $OptRefresh = 1;
- }
- elsif ($Arg eq "--refresh-all")
- {
- $OptRefreshAll = 1;
- }
- elsif ($Arg eq "--add-missing")
- {
- $OptAddMissing = 1;
- }
- elsif ($Arg eq "--add-locales")
- {
- $OptAddLocales = CheckValue($Arg, $OptAddLocales);
- }
elsif ($Arg eq "--reboot")
{
if (defined $OptReboot and !$OptReboot)
@@ -388,101 +365,22 @@ while (@ARGV)
}
# Check and untaint parameters
-my ($BaseVMName, $VMLocale, %AddLocales, $KeyboardIds, $CountryId);
+my ($KeyboardIds, $CountryId);
if (!defined $Usage)
{
- if (defined $OptVM)
+ if (!defined $OptHostName)
{
- if ($OptRefresh or $OptRefreshAll or $OptAddMissing or
- defined $OptAddLocales)
- {
- if (defined $OptReboot and !$OptReboot)
- {
- Error("--no-reboot is incompatible with --refresh, --refresh-all, --add-missing and --add-locales\n");
- $Usage = 2;
- }
- if (defined $OptDefault or defined $OptLocale or defined $OptMUI or
- defined $OptCountry or defined $OptKeyboard)
- {
- Error("--default, --locale, --mui, --country and --keyboard are incompatible with the VM snapshot options\n");
- $Usage = 2;
- }
-
- # Always reboot Windows before updating a TestBot snapshot
- $OptReboot = 1;
- }
- if ($OptRefresh and
- ($OptRefreshAll or $OptAddMissing or defined $OptAddLocales))
- {
- Error("--refresh is incompatible with --refresh--all, --add-missing and --add-locales\n");
- $Usage = 2;
- }
- if ($OptRefreshAll and $OptAddMissing)
- {
- Error("--refresh-all and --add-missing are mutually incompatible\n");
- $Usage = 2;
- }
- if (defined $OptAddLocales)
- {
- foreach my $Locale (split /:/, $OptAddLocales)
- {
- if ($Locale =~ /^[a-z]{2}_[A-Z]{2}$/)
- {
- $AddLocales{$Locale} = 1;
- }
- else
- {
- Error("'$Locale' is not a valid locale for --add-locales\n");
- $Usage = 2;
- last;
- }
- }
- if (!%AddLocales)
- {
- Error("'$OptAddLocales' does not contain any valid locale\n");
- $Usage = 2;
- }
- }
-
- $BaseVMName = $OptVM;
- if ($BaseVMName =~ s/_([a-z]{2})_([A-Z]{2})$//)
- {
- if ($OptRefreshAll)
- {
- Error("'$OptVM' should not be a locale VM\n");
- $Usage = 2;
- }
- $VMLocale = "$1_$2"; # untaint
- $OptDefault = $VMLocale eq "sr_RS" ? "sr-Latn-CS" : "$1-$2";
- }
- elsif ($OptRefresh)
- {
- Error("'$OptVM' is not a locale VM\n");
- $Usage = 2;
- }
+ Error("you must specify the Windows machine to work on\n");
+ $Usage = 2;
+ }
+ elsif ($OptHostName =~ /^([a-zA-Z0-9.-]+)$/)
+ {
+ $OptHostName = $1; # untaint
}
else
{
- if ($OptRefresh or $OptRefreshAll or $OptAddMissing or
- defined $OptAddLocales)
- {
- Error("--refresh, --refresh-all, --add-missing and --add-locales can only be used with --vm\n");
- $Usage = 2;
- }
- if (!defined $OptHostName)
- {
- Error("you must specify the Windows machine to work on\n");
- $Usage = 2;
- }
- elsif ($OptHostName =~ /^([a-zA-Z0-9.-]+)$/)
- {
- $OptHostName = $1; # untaint
- }
- else
- {
- Error("'$OptHostName' is not a valid hostname\n");
- $Usage = 2;
- }
+ Error("'$OptHostName' is not a valid hostname\n");
+ $Usage = 2;
}
$OptLocale ||= $OptDefault;
@@ -516,9 +414,7 @@ if (!defined $Usage)
}
if (!defined $OptLocale and !defined $OptSystem and !defined $OptMUI and
- !defined $OptKeyboard and !defined $OptCountry and
- !$OptRefresh and !$OptRefreshAll and !$OptAddMissing and
- !defined $OptAddLocales)
+ !defined $OptKeyboard and !defined $OptCountry)
{
Error("you must specify at least one locale to change\n");
$Usage = 2;
@@ -537,21 +433,11 @@ if (defined $Usage)
Error("try '$name0 --help' for more information\n");
exit $Usage;
}
- print "Usage: $name0 [options] --vm NAME --refresh\n";
- print "or $name0 [options] --vm NAME [--refresh-all] [--add-locales LOC1:LOC2:...]\n";
- print "or $name0 [options] [--default LOC] [--locale USR] [--system SYS] [--mui MUI] [--keyboard KBD] [--country CTY] HOSTNAME|--vm NAME\n";
+ print "or $name0 [options] [--default LOC] [--locale USR] [--system SYS] [--mui MUI] [--keyboard KBD] [--country CTY] HOSTNAME\n";
print "\n";
- print "Sets the locale of the specified Windows machine and, optionally, updates or creates a new snapshot ot the TestBot VM for it.\n";
+ print "Sets the locale of the specified Windows machine.\n";
print "\n";
print "Where:\n";
- print " --vm NAME Work on the specified TestBot VM.\n";
- print " --refresh Create or update the TestBot VM's snapshot (and VM if needed).\n";
- print " --refresh-all Refresh the locale VMs derived from the specified base VM.\n";
- print " --add-missing Check the locale VMs derived from the specified base VM and\n";
- print " add any missing corresponding snapshots.\n";
- print " --add-locales LOC1:LOC2:... Create new TestBot VMs derived from the specified\n";
- print " base VM for each of the Unix locale in the colon-sperated\n";
- print " list.\n";
print " HOSTNAME Work on the specified Windows host (must be running TestAgentd).\n";
print " --default LOC Use this Windows locale as the default for the other options.\n";
print " The locale must be in a form suitable for Windows' intl.cpl\n";
@@ -573,160 +459,6 @@ if (defined $Usage)
}
-#
-# Handle the meta options
-#
-
-my $VMs = CreateVMs();
-my $VM = $VMs->GetItem($OptVM);
-if ($VM and $VM->Role eq "deleted")
-{
- FatalError("'$OptVM' is marked for deletion\n");
-}
-
-if ($OptRefreshAll or $OptAddMissing)
-{
- FatalError("could not find the '$OptVM' virtual machine\n") if (!$VM);
-
- my $HasLocaleVMs;
- foreach my $VM (@{$VMs->GetItems()})
- {
- next if ($VM->Role eq "deleted");
- if ($VM->Name =~ /^\Q$OptVM\E_([a-z]{2})_([A-Z]{2})$/)
- {
- $HasLocaleVMs = 1;
- if ($OptRefreshAll or !$VM->GetDomain()->HasSnapshot($VM->IdleSnapshot))
- {
- $AddLocales{"$1_$2"} = 1;
- }
- }
- }
- FatalError("could not find any locale VM for '$OptVM'\n") if (!$HasLocaleVMs);
- if (!%AddLocales)
- {
- Debug(Elapsed($Start), " Nothing to do!\n");
- exit(0);
- }
-}
-
-if (%AddLocales)
-{
- my @Failed;
- my @Cmd = ("$0", ($Debug ? "--debug" : ()), "--refresh", "--vm");
- foreach my $Locale (sort keys %AddLocales)
- {
- if (Run(@Cmd, "${OptVM}_$Locale"))
- {
- push @Failed, $Locale;
- }
- }
- if (@Failed)
- {
- Error("failed to add/refresh the snapshots for the following locales: @Failed\n");
- exit(1);
- }
- exit(0);
-}
-
-
-#
-# Prepare the virtual machine
-#
-
-if ($OptRefresh)
-{
- my $BaseVM = $VMs->GetItem($BaseVMName);
- if (!$BaseVM)
- {
- FatalError("could not find the '$BaseVMName' base virtual machine\n");
- }
-
- if (!$VM)
- {
- if ($BaseVM->Status ne "maintenance")
- {
- FatalError("the base VM is not marked for maintenance\n");
- }
- if ($DryRun)
- {
- Warning("'$OptVM' does not exist. Skipping for dry run.\n");
- exit(0);
- }
-
- # Create the localized VM
- $VM = $VMs->Add();
- $VM->Name($OptVM);
- $VM->SortOrder($BaseVM->SortOrder + 1);
- $VM->Type($BaseVM->Type);
- $VM->Role("extra");
- $VM->Missions($BaseVM->Missions);
- $VM->MissionCaps($BaseVM->MissionCaps);
- # All we need is for one VM to be in maintenance mode to prevent the
- # TestBot from using this hypervisor domain. The base VM is in maintenance
- # mode so that is enough.
- $VM->Status("off");
- $VM->VirtURI($BaseVM->VirtURI);
- $VM->VirtDomain($BaseVM->VirtDomain);
- $VM->IdleSnapshot($BaseVM->IdleSnapshot ."_$VMLocale");
- $VM->Hostname($BaseVM->Hostname);
-
- my $Description = $BaseVM->Description ." ". LocaleName($VMLocale);
- my $PropertyDescriptor = $VMs->GetPropertyDescriptorByName("Description");
- if ($PropertyDescriptor->GetMaxLength() < length($Description))
- {
- Warning("the $OptVM description is too long. Truncating it.\n");
- $Description = substr($Description, 0, $PropertyDescriptor->GetMaxLength());
- }
- $VM->Description($Description);
- $VM->Details($BaseVM->Details);
-
- my ($_ErrKey, $_ErrProperty, $ErrMessage) = $VMs->Save();
- if (defined $ErrMessage)
- {
- FatalError("could not create the localized VM: $ErrMessage\n");
- }
- }
- else
- {
- if ($VM->Status ne "maintenance" and $BaseVM->Status ne "maintenance")
- {
- FatalError("neither $OptVM nor its base VM are marked for maintenance\n");
- }
- if ($VM->Status !~ /^(?:maintenance|off)$/)
- {
- FatalError("'$OptVM' is neither off nor marked for maintenance\n");
- }
- if ($BaseVM->Status !~ /^(?:maintenance|off)$/)
- {
- FatalError("'$BaseVMName' is neither off nor marked for maintenance\n");
- }
-
- }
-
- my $IdleSnapshot = $VM->IdleSnapshot;
- if ($VM->GetDomain()->HasSnapshot($IdleSnapshot))
- {
- Debug(Elapsed($Start), " Deleting the old $IdleSnapshot snapshot\n");
- my $ErrMessage = $DryRun ? undef : $VM->GetDomain()->RemoveSnapshot();
- if (defined $ErrMessage)
- {
- FatalError("could not remove the $IdleSnapshot snapshot: $ErrMessage\n");
- }
- }
-
- Debug(Elapsed($Start), " Reverting the base VM\n");
- if (Run("$::RootDir/bin/LibvirtTool.pl", "--debug", "revert", $BaseVMName))
- {
- # LibvirtTool.pl will have already printed an error message
- exit(1);
- }
-}
-elsif (defined $OptVM and !$VM)
-{
- FatalError("could not find the '$OptVM' virtual machine\n");
-}
-
-
#
# Generate the intl.cpl configuration
#
@@ -782,8 +514,7 @@ push @Config, "</gs:GlobalizationServices>";
# Change the Windows locale using intl.cpl
#
-$OptHostName = $VM->Hostname if ($VM); # For error messages
-my $TA = $VM ? $VM->GetAgent() : TestAgent->new($OptHostName, $AgentPort);
+my $TA = TestAgent->new($OptHostName, $AgentPort);
Debug(Elapsed($Start), " Sending the configuration file\n");
print STDERR join("\n", "locales.xml:", @Config, "") if ($DryRun or $Debug);
@@ -834,6 +565,11 @@ if (!$DryRun)
}
}
+
+#
+# Reboot to finalize the changes
+#
+
if ($OptReboot)
{
Debug(Elapsed($Start), " Rebooting Windows\n");
@@ -847,37 +583,16 @@ if ($OptReboot)
$TA->Run($Cmd, 0);
# Note that we cannot wait for this command since it reboots Windows
}
-}
-
-#
-# Update the virtual machine snapshot
-#
-
-if ($OptRefresh)
-{
# Wait a bit to make sure we don't reconnect before Windows has rebooted.
sleep(30) if (!$DryRun);
- # Allow up to 10 minutes for the shutdown plus reboot.
Debug(Elapsed($Start), " Waiting for Windows to boot\n");
$TA->SetConnectTimeout(undef, undef, $WaitForBoot);
if (!$DryRun and !$TA->Ping())
{
FatalError("could not reconnect to $OptHostName after the reboot: ", $TA->GetLastError(), "\n");
}
-
- # Then wait a good minute after the reboot to make sure all the widgets are
- # up and running.
- Debug(Elapsed($Start), " Letting Windows warm up\n");
- sleep(60) if (!$DryRun);
-
- Debug(Elapsed($Start), " Creating the ", $VM->IdleSnapshot, " snapshot\n");
- my $ErrMessage = $DryRun ? undef : $VM->GetDomain()->CreateSnapshot();
- if (defined $ErrMessage)
- {
- FatalError("could not create the ". $VM->IdleSnapshot ." snapshot: $ErrMessage\n");
- }
}
Debug(Elapsed($Start), " All done!\n");
--
2.30.2