]> xenbits.xensource.com Git - people/aperard/osstest.git/commitdiff
sg-run-job: Break out iffail-check
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 15 Jul 2016 14:20:00 +0000 (15:20 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 18 Jul 2016 14:22:21 +0000 (15:22 +0100)
Both spawn-ts and per-host-ts do some processing of `iffail' values:
 * Strip any leading !, which means "run this even if the job
   is being stopped due to error";
 * Turn `.' into `fail'.

The first of these is currently only done by per-host-ts, which checks
ok.  We are going to want to do something more sophisticated when
truncating flights.  So we introduce a new helper.

For now spawn-ts passes 1 for okexpr so its iffail-check always
returns 1 so it doesn't check the return value.

No functional change yet.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
sg-run-job

index 8b2d5e16cd1fc98e26dc70265cea3658b920812c..8c8dff3f8c076178d182cc4c1244cddf47bdabe6 100755 (executable)
@@ -129,6 +129,26 @@ proc repeat-ts {reps testid args} {
      eval [list run-ts . $testid + ts-repeat-test $reps +] $args
 }
 
+proc iffail-check {iffail okexpr iffail_status_var} {
+    # iffail is as passed to spawn-ts, per-host-ts, run-ts, etc.
+    # iffail-check checks for any leading ! (which means "always run")
+    #    if none is present, $okexpr is evaluated
+    # iffail-check sets caller's $iffail_status_var with the actual
+    #    status to use if the step fails (replacing `.' with `fail')
+    # iffail-check then returns 1 if the step should be run
+    #    (either because ! or because $okexpr) or 0 otherwise
+    global ok
+    upvar 1 $iffail_status_var iffail_status
+
+    if {[regexp {^!?\.$} $iffail]} {
+        regsub {\.$} $iffail fail iffail
+    }
+    if {![regsub {^!} $iffail {} iffail_status]} {
+       if {![uplevel 1 [list expr $okexpr]]} { return 0 }
+    }
+    return 1
+}
+
 proc spawn-ts {iffail testid args} {
     global flight c jobinfo reap_details env
 
@@ -139,7 +159,7 @@ proc spawn-ts {iffail testid args} {
         return {}
     }
 
-    if {![string compare . $iffail]} { set iffail fail }
+    iffail-check $iffail 1 iffail_status
 
     set real_args {}
     set adding 1
@@ -173,7 +193,7 @@ proc spawn-ts {iffail testid args} {
     regsub {\(\*\)$} $testid ($stepno) testid
 
     set detstr "$flight.$jobinfo(job) $ts $real_args"
-    set details [list $flight $jobinfo(job) $stepno $detstr $iffail]
+    set details [list $flight $jobinfo(job) $stepno $detstr $iffail_status]
     jobdb::logputs stdout "starting $detstr $testid"
 
     jobdb::spawn-step-commit $flight $jobinfo(job) $stepno $testid
@@ -227,11 +247,8 @@ proc reap-ts {reap} {
 
 proc per-host-ts {iffail ident script args} {
     global ok need_xen_hosts flight jobinfo
-    
-    if {![regsub {^!} $iffail {} iffail]} {
-       if {!$ok} return
-    }
-    if {![string compare . $iffail]} { set iffail fail }
+    if {![iffail-check $iffail {$ok} iffail_status]} return
 
     set awaitl {}
     foreach host $need_xen_hosts {
@@ -254,7 +271,7 @@ proc per-host-ts {iffail ident script args} {
     }
 
     if {$failed} {
-        setstatus $iffail
+        setstatus $iffail_status
     }
 }