Skip to contentSkip to conversation

Misc standalone wrapper improvements

PATCH Superseded Ian Campbell 2 participants 9 messages Sep 29, 2015

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Misc standalone wrapper improvements

I found these useful for debugging a recent issue.

#1 lore raw

PATCH 1/3 standalone: Add get-job-status to pick status out of standalone.db

The return code of sg-run-job does not reflect the state of the job, which is instead written to the database. For the benefit of running tests in a loop until failure add a command to retrieve the status to stdout.

---
 standalone | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
standalone +30 -2
index 60b6666..0a5d96f 100755
@@ -35,6 +35,11 @@ Operations:
   hosts next time. Otherwise osstest will complain if you change the
   host(s) which a job is running on on successive runs.
 
+* get-job-status [cf] [JOB]
+
+  Prints the status (pass, fail, running, etc) of the given job to
+  stdout.
+
 Options:
 
 -c FILE, --config=FILE        Use FILE as configuration file
@@ -140,8 +145,9 @@ if [ $reuse -eq 0 ]; then
     read
 fi
 
-if [ ! -f standalone.db ] ; then
-    echo "No standalone.db? Run standalone-reset." >&2
+db="standalone.db"
+if [ ! -f $db ] ; then
+    echo "No $db? Run standalone-reset." >&2
     exit 1
 fi
 
@@ -198,6 +204,14 @@ with_logging() {
     fi
 }
 
+job_status() {
+    flight=$1; shift
+    job=$1; shift
+
+    sqlite3 $db \
+        "SELECT status FROM jobs WHERE flight='$flight' AND job='$job'"
+}
+
 # other potential ops:
 # - run standalone reset
 
@@ -303,6 +317,20 @@ case $op in
 	OSSTEST_JOB=$job \
 	    with_logging logs/$flight/$job.$ts.log ./$ts $hosts $@
 	;;
+
+    get-job-status)
+	need_flight;
+
+	if [ $# -ne 1 ] ; then
+	    echo "get-job-status: Need job" >&2
+	    exit 1
+	fi
+
+	job=$1; shift
+
+	job_status $flight $job
+
+	;;
     *)
 	echo "Unknown op $op" ; exit 1 ;;
 esac
Signature · 1 line
2.5.3
#5 lore raw

PATCH 2/3 standalone: Check job status at end of run-job.

In reply to Ian Campbell

Check if the job passed and if not (so status is fail, broken, running etc) then return an error.

This is convenient for scripting.

---
 standalone | 5 +++++
 1 file changed, 5 insertions(+)
standalone +5 -0
index 0a5d96f..e85457d 100755
@@ -299,6 +299,11 @@ case $op in
 	OSSTEST_HOST_REUSE=$reuse \
 	OSSTEST_SIMULATE=$dryrun \
 	    with_logging logs/$flight/$job.log ./sg-run-job $job
+
+	status=`job_status $flight $job`
+	echo "$flight.$job status = $status" >&2
+	if [ "x$status" != xpass ] ; then exit 1; fi
+
 	;;
     run-test)
 	need_flight; need_host
Signature · 1 line
2.5.3
#7 lore raw

PATCH 3/3 standalone: Rotate logs rather than clobbering them

In reply to Ian Campbell

Keep 300, for no better reason than cr-for-branches does.

---
 standalone | 1 +
 1 file changed, 1 insertion(+)
standalone +1 -0
index e85457d..c3ff9e2 100755
@@ -196,6 +196,7 @@ ensure_logs() {
 with_logging() {
     local log=$1; shift
     ensure_logs
+    savelog -c 300 "$log" >/dev/null
     $@ 2>&1 | tee "$log"
     rc=${PIPESTATUS[0]}
     if [ $rc -ne 0 ] ; then
Signature · 1 line
2.5.3
Acked-by on v1 2/3
#6 lore raw

Re: [PATCH OSSTEST 2/3] standalone: Check job status at end of run-job.

In reply to Ian Campbell

Ian Campbell writes ("[PATCH OSSTEST 2/3] standalone: Check job status at end of run-job."):

Quoted 4 lines

Check if the job passed and if not (so status is fail, broken, running etc) then return an error.

This is convenient for scripting.

#2 lore raw

Re: [PATCH OSSTEST 1/3] standalone: Add get-job-status to pick status out of standalone.db

In reply to Ian Campbell

Ian Campbell writes ("[PATCH OSSTEST 1/3] standalone: Add get-job-status to pick status out of standalone.db"):

Quoted 4 lines

The return code of sg-run-job does not reflect the state of the job, which is instead written to the database. For the benefit of running tests in a loop until failure add a command to retrieve the status to stdout.

Maybe this would be better as a cs-* utility, useable on production instances too ?

Ian.

#3 lore raw

Re: [PATCH OSSTEST 1/3] standalone: Add get-job-status to pick status out of standalone.db

In reply to Ian Jackson
Quoted 9 lines · Ian Jackson

Ian Campbell writes ("[PATCH OSSTEST 1/3] standalone: Add get-job-status to pick status out of standalone.db"):

Quoted 4 lines

The return code of sg-run-job does not reflect the state of the job, which is instead written to the database. For the benefit of running tests in a loop until failure add a command to retrieve the status to stdout.

Maybe this would be better as a cs-* utility, useable on production instances too ?

Could do, although actually it turns out that the functionality in patch #2 (i.e. having standalone check the error) was the thing which I really needed for what I was doing (scripting a loop running the job over and over till it failed).

If cs-job-status still seems useful then I can certainly add that. I'd probably keep the convenience wrapper in standalone unless you object.

Ian.

#4 lore raw

Re: [PATCH OSSTEST 1/3] standalone: Add get-job-status to pick status out of standalone.db

Ian Campbell writes ("Re: [PATCH OSSTEST 1/3] standalone: Add get-job-status to pick status out of standalone.db"):

Quoted 2 lines

If cs-job-status still seems useful then I can certainly add that. I'd probably keep the convenience wrapper in standalone unless you object.

Right. Yes, I think cs-job-status would be useful. It could perhaps be a sub-op in cs-adjust-flight.

Ian.