[tools] testbot: Simplify building a slash-separated Item identifiers.

Francois Gouget fgouget at codeweavers.com
Sun Jun 5 19:59:28 CDT 2022


This also fixes the task id in the GetReportNames() error messages.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 testbot/bin/Janitor.pl           |  2 +-
 testbot/lib/ObjectModel/Item.pm  | 19 +++++++++++++++++++
 testbot/lib/WineTestBot/Steps.pm |  3 +--
 testbot/lib/WineTestBot/Tasks.pm | 13 +++++--------
 4 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/testbot/bin/Janitor.pl b/testbot/bin/Janitor.pl
index ab72ac1b6..af1123aed 100755
--- a/testbot/bin/Janitor.pl
+++ b/testbot/bin/Janitor.pl
@@ -205,7 +205,7 @@ if (%DeletedVMs)
   {
     if (exists $DeletedVMs{$Task->VM->Name})
     {
-      Trace "Keeping the ", $Task->VM->Name, " VM for task ", join("/", @{$Task->GetMasterKey()}), "\n";
+      Trace "Keeping the ", $Task->VM->Name, " VM for task ", $Task->GetSlashKey(), "\n";
       delete $DeletedVMs{$Task->VM->Name};
       last if (!%DeletedVMs);
     }
diff --git a/testbot/lib/ObjectModel/Item.pm b/testbot/lib/ObjectModel/Item.pm
index 0b1da92a2..39c80cc89 100644
--- a/testbot/lib/ObjectModel/Item.pm
+++ b/testbot/lib/ObjectModel/Item.pm
@@ -350,6 +350,25 @@ sub GetMasterKey($)
   return (\@MasterColNames, \@MasterColValues);
 }
 
+=pod
+=over 12
+
+=item C<GetSlashKey()>
+
+Returns a string containing all the slash-separated key components.
+
+This can be used to display the key in the GUI or to build file paths (assuming
+the key components can be trusted).
+
+=back
+=cut
+
+sub GetSlashKey($)
+{
+  my ($self) = @_;
+  return join("/", @{$self->GetMasterKey()}); # drops the column names
+}
+
 sub ResetModified($)
 {
   my ($self) = @_;
diff --git a/testbot/lib/WineTestBot/Steps.pm b/testbot/lib/WineTestBot/Steps.pm
index 860dc4920..cd585e9db 100644
--- a/testbot/lib/WineTestBot/Steps.pm
+++ b/testbot/lib/WineTestBot/Steps.pm
@@ -128,8 +128,7 @@ sub Validate($)
 sub GetDir($)
 {
   my ($self) = @_;
-  my ($JobId, $StepNo) = @{$self->GetMasterKey()};
-  return "$DataDir/jobs/$JobId/$StepNo";
+  return "$DataDir/jobs/". $self->GetSlashKey();
 }
 
 sub CreateDir($)
diff --git a/testbot/lib/WineTestBot/Tasks.pm b/testbot/lib/WineTestBot/Tasks.pm
index 50ce9604a..8c9f89ce8 100644
--- a/testbot/lib/WineTestBot/Tasks.pm
+++ b/testbot/lib/WineTestBot/Tasks.pm
@@ -91,8 +91,7 @@ sub InitializeNew($$)
 sub GetDir($)
 {
   my ($self) = @_;
-  my ($JobId, $StepNo, $TaskNo) = @{$self->GetMasterKey()};
-  return "$DataDir/jobs/$JobId/$StepNo/$TaskNo";
+  return "$DataDir/jobs/". $self->GetSlashKey();
 }
 
 sub CreateDir($)
@@ -118,13 +117,11 @@ sub GetReportNames($)
   return ($ErrMessage, undef, undef) if (defined $ErrMessage);
   if (!@$Missions)
   {
-    my @TaskKey = $self->GetMasterKey();
-    return ("Task @TaskKey has no mission", undef, undef);
+    return ("Task ". $self->GetSlashKey() ." has no mission", undef, undef);
   }
   if (@$Missions > 1)
   {
-    my @TaskKey = $self->GetMasterKey();
-    return ("Task @TaskKey should not have missions for multiple tasks\n", undef);
+    return ("Task ". $self->GetSlashKey() ." should not have missions for multiple tasks\n", undef);
   }
   my $TaskMissions = $Missions->[0];
 
@@ -277,7 +274,6 @@ sub UpdateStatus($$)
   if ($Status eq "running" and
       ($VM->Status ne "running" or !$VM->HasRunningChild()))
   {
-    my ($JobId, $StepNo, $TaskNo) = @{$self->GetMasterKey()};
     my $OldUMask = umask(002);
     my $TaskDir = $self->CreateDir();
     if (open TASKLOG, ">>", "$TaskDir/testbot.log")
@@ -288,7 +284,8 @@ sub UpdateStatus($$)
     umask($OldUMask);
 
     require WineTestBot::Log;
-    WineTestBot::Log::LogMsg("Child process for task $JobId/$StepNo/$TaskNo died unexpectedly\n");
+    WineTestBot::Log::LogMsg("Child process for task ", $self->GetSlashKey(),
+                             " died unexpectedly\n");
 
     # A crash probably indicates a bug in the task script but getting stuck
     # could happen due to network issues. So requeue the task like its script
-- 
2.30.2




More information about the wine-devel mailing list