This simplifies getting a connection to the TestAgent server with elevated privileges.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/LibvirtTool.pl | 60 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 28 deletions(-)
diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl index b186e19c39..51ed8e73e8 100755 --- a/testbot/bin/LibvirtTool.pl +++ b/testbot/bin/LibvirtTool.pl @@ -257,6 +257,28 @@ sub ChangeStatus($$;$) return 0; }
+=pod +=over 12 + +=item C<GetPrivilegedTA()> + +Returns a connection to a TestAgent server with elevated privileges. + +If the server running on the regular port does not have elevated privileges +this assumes that the one on the alternate port will. It is up to the caller +to report an error if that's not the case. + +=back +=cut + +sub GetPrivilegedTA($) +{ + my ($TA) = @_; + + # Use SetTime() to detect if privileged operations are allowed. + return $TA->SetTime() ? $TA : $VM->GetAgent(1); +} + sub ShutDown() { my $Domain = $VM->GetDomain(); @@ -270,30 +292,15 @@ sub ShutDown() Debug(Elapsed($Start), " Performing a clean shutdown of $VMKey $CurrentSnapshot\n"); LogMsg "Performing a clean shutdown of $VMKey $CurrentSnapshot\n";
- # Use SetTime() to detect if privileged operations are allowed. - my $TA = $VM->GetAgent(); - if (!$TA->SetTime()) - { - # Not a fatal error. Try the next port in case the VM runs a privileged - # TestAgentd daemon there. - $TA->Disconnect(); - $TA = $VM->GetAgent(1); - if (!$TA->SetTime()) - { - Error "Unable to get a privileged TestAgent: ". $TA->GetLastError() ."\n"; - $TA->Disconnect(); - return 0; - } - } - my $Success = 1; my $Cmd = $VM->Type =~ /^win(?:32|64)$/ ? ["shutdown.exe", "/p", "/d", "00:00"] : ["/sbin/shutdown", "--poweroff", "now"]; Debug(Elapsed($Start), " Running @$Cmd\n"); - if (!$TA->Run($Cmd, 0)) + my $PTA = GetPrivilegedTA($VM->GetAgent()); + if (!$PTA->Run($Cmd, 0)) { - Error "Could not run @$Cmd: ". $TA->GetLastError() ."\n"; + Error "Could not run @$Cmd: ". $PTA->GetLastError() ."\n"; $Success = 0; } else @@ -311,7 +318,8 @@ sub ShutDown() sleep(1); } } - $TA->Disconnect(); + $PTA->Disconnect(); + Debug(Elapsed($Start), " Successfully shut down $VMKey\n"); LogMsg "Successfully shut down $VMKey\n"; return $Success; @@ -496,16 +504,11 @@ sub SetupTestAgentd($$$$) # This is needed not only for the tests (date is important when checking # HTTPS certificates), but also for the build (if the time moves forward # during the build some ccache versions will return a compilation error). - if (!$TA->SetTime()) + my $PTA = GetPrivilegedTA($TA); + FatalError("Cannot set the VM system time\n") if (!$PTA); + if (!$PTA->SetTime()) { - # Not a fatal error. Try the next port in case the VM runs a privileged - # TestAgentd daemon there. - my $PrivilegedTA = $VM->GetAgent(1); - if (!$PrivilegedTA->SetTime()) - { - FatalError("Unable to set the VM system time: ". $PrivilegedTA->GetLastError() ."\n"); - } - $PrivilegedTA->Disconnect(); + FatalError("Setting the VM system time failed: ". $PTA->GetLastError() ."\n"); }
if ($Booting and $VM->Type eq "wine") @@ -543,6 +546,7 @@ sub SetupTestAgentd($$$$) FatalError("The VM has been rebooted too many times: start.count=$Count > 1"); } } + $PTA->Disconnect(); $TA->Disconnect(); }