From: Ian Jackson Date: Fri, 15 Jul 2016 14:20:00 +0000 (+0100) Subject: sg-run-job: Break out iffail-check X-Git-Tag: openstack-v11~332 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=83cf7451f4003c26369f399a9138a75fb8da1cb9;p=people%2Faperard%2Fosstest.git sg-run-job: Break out iffail-check 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 --- diff --git a/sg-run-job b/sg-run-job index 8b2d5e16..8c8dff3f 100755 --- a/sg-run-job +++ b/sg-run-job @@ -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 } }