Francois Gouget : testbot/LibvirtTool: Add support for creating adm snapshots.

Alexandre Julliard julliard at winehq.org
Thu Feb 24 15:28:30 CST 2022


Module: tools
Branch: master
Commit: 712ba348088535efc69b0e7c28642eba1cd16c3b
URL:    https://source.winehq.org/git/tools.git/?a=commit;h=712ba348088535efc69b0e7c28642eba1cd16c3b

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Thu Feb 24 19:02:08 2022 +0100

testbot/LibvirtTool: Add support for creating adm snapshots.

This adds a task to run TestAgentd without elevated privileges and
modifies the original task so it does not interfere.
Note that schtasks.exe asks for a password so use the Powershell APIs
instead.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 testbot/bin/LibvirtTool.pl  |  19 ++++++-
 testbot/bin/LibvirtTool.ps1 | 119 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 137 insertions(+), 1 deletion(-)

diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl
index ff834ef..bd676f0 100755
--- a/testbot/bin/LibvirtTool.pl
+++ b/testbot/bin/LibvirtTool.pl
@@ -610,7 +610,7 @@ sub GetSnapshotConfig($)
     {
       $Config->{locale} ||= $1; # take only the last match
     }
-    elsif ($Config->{base} =~ s/-(live|off|tsign|u8)$//)
+    elsif ($Config->{base} =~ s/-(adm|live|off|tsign|u8)$//)
     {
       $Config->{$1} = 1;
     }
@@ -693,6 +693,23 @@ sub CreateSnapshot($$$$)
       }
     }
 
+    if ($Config->{adm})
+    {
+      # Takes effect after the next reboot
+      my $PS1 = "$0.ps1";
+      $PS1 =~ s/\.pl//;
+      if (!$TA->SendFile($PS1, "$Name0.ps1", 0))
+      {
+        FatalError("Could not send '$Name0.ps1'\n");
+      }
+      if (RunAndWait($PTA, ["powershell.exe", "-ExecutionPolicy", "ByPass",
+                            "-File", "$Name0.ps1", "admin", $AgentPort]))
+      {
+        FatalError("Could not set up the TestAgentd tasks on $VMKey\n");
+      }
+      $PTA->Rm("$Name0.ps1");
+    }
+
     $Reboot = 1;
   }
 
diff --git a/testbot/bin/LibvirtTool.ps1 b/testbot/bin/LibvirtTool.ps1
new file mode 100644
index 0000000..e2b2d12
--- /dev/null
+++ b/testbot/bin/LibvirtTool.ps1
@@ -0,0 +1,119 @@
+# Shows or sets up the TestAgentd tasks
+#
+# Copyright 2022 Francois Gouget
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+
+$Name0 = (Get-Item $MyInvocation.InvocationName).Basename
+
+
+#
+# Show the existing tasks
+#
+
+function ShowTask($Name)
+{
+  $Task = Get-ScheduledTask -TaskName $Name -ErrorAction SilentlyContinue
+  if ($Task -ne $null)
+  {
+    Write-Output "$Name.User=$($Task.Principal.UserId)"
+    Write-Output "$Name.RunLevel=$($Task.Principal.RunLevel)"
+    Write-Output "$Name.Execute=$($Task.Actions.Execute)"
+    Write-Output "$Name.Arguments=$($Task.Actions.Arguments)"
+    Write-Output "$Name.WorkingDirectory=$($Task.Actions.WorkingDirectory)"
+    Write-Output "$Name.NotOnBatteries=$($Task.Settings.DisallowStartIfOnBatteries)"
+  }
+  else
+  {
+    Write-Output "$Name=<no such task>"
+  }
+}
+
+function ShowTasks()
+{
+  ShowTask "TestAgentd"
+  ShowTask "TestAgentdAdm"
+  exit 0
+}
+
+
+#
+# Sets up split tasks
+#
+
+function SetupAdminTasks($Argv)
+{
+  $Port = [int]$Argv[1]
+  $Task = Get-ScheduledTask -TaskName TestAgentd -ErrorAction SilentlyContinue
+  if ($Task -eq $null)
+  {
+    echo "$Name0:error: the TestAgentd task does not exist!"
+    exit 1
+  }
+  $WorkDir = $Task.Actions.WorkingDirectory
+  if ($WorkDir -eq $null)
+  {
+    $WorkDir = Split-Path $Task.Actions.Execute
+  }
+
+  # Modify the 'elevated privileges' server to start on the alternate port
+  $HighPort = $Port + 1
+  $Action = New-ScheduledTaskAction -Execute $Task.Actions.Execute -Argument "--detach --set-time-only $HighPort" -WorkingDirectory $WorkDir
+  Set-ScheduledTask -TaskName TestAgentd -Action $Action
+
+  # Add a 'regular privileges' server on the regular port
+  $Action = New-ScheduledTaskAction -Execute $Task.Actions.Execute -Argument "--detach --show-restarts $Port" -WorkingDirectory $WorkDir
+  $AdmTask = Get-ScheduledTask -TaskName TestAgentdAdm -ErrorAction SilentlyContinue
+  if ($AdmTask -eq $null)
+  {
+    Register-ScheduledTask -TaskName TestAgentdAdm -Action $Action -Trigger $Task.Triggers -Settings $Task.Settings
+  }
+  else
+  {
+    Set-ScheduledTask -TaskName TestAgentdAdm -Action $Action
+  }
+  exit 0
+}
+
+
+#
+# Main
+#
+
+function ShowUsage()
+{
+  Write-Output "Usage: $Name0 show"
+  Write-Output "or     $Name0 admin PORT"
+  Write-Output ""
+  Write-Output "Shows or modifies the Windows locales."
+  Write-Output ""
+  Write-Output "Where:"
+  Write-Output "  show       Shows the existing TestAgentd tasks."
+  Write-Output "  admin      Sets up a separate not-elevated-privileges task."
+  Write-Output "  PORT       Specifies the port TestAgentd should listen on."
+  Write-Output "  -?         Shows this help message."
+}
+
+$Action = $args[0]
+if ($Action -eq "show") { ShowTasks }
+if ($Action -eq "admin") { SetupAdminTasks $args }
+$Rc = 0
+if ($Action -and $Action -ne "-?" -and $Action -ne "-h" -and $Action -ne "help")
+{
+  echo "$Name0:error: unknown action $Action"
+  $Rc = 2
+}
+ShowUsage
+exit $Rc




More information about the wine-cvs mailing list