job continuation error handling fixes
It seems that asking for a continue of a job which has actually completed
results in the following blammo:
JOB ERROR: 1
Traceback (most recent call last):
File "/usr/local/autobench/autotest/bin/job.py", line 569, in runjob
sys.exit(1)
SystemExit: 1
Traceback (most recent call last):
File "bin/autotest", line 51, in ?
job.runjob(args[0], options.cont, options.tag, options.harness)
File "/usr/local/autobench/autotest/bin/job.py", line 604, in runjob
myjob.group_level = 0
AttributeError: 'NoneType' object has no attribute 'group_level'
This seems to be caused by a couple of bugs. The first is that we can
bail out before we have a job. In this case we will attempt to exit(1)
to indicate completion. This will trip an exit exception and the
surrounding try will trigger. Here we have the following construction
which when we have a job will lead to our exiting '1':
except Exception, e:
[...]
if myjob:
[...]
myjob.complete(1)
However as we have yet to instantiate myjob we will drop through to
the end of the exception handler and as its not re-raising anything we
continue on as if there was no error. We then fall into this code
and all hell breaks loose:
myjob.group_level = 0
myjob.record('END GOOD', None, None)
myjob.complete(0)
This patch sorts that out by adding explicit exits to ensure we do not drop
out. It also makes the job completion exit much more obvious by making
a JobComplete exception object along the lines of the existing JobContinue.
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@977 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/bin/job.py b/client/bin/job.py
index cc7112b..23b8305 100755
--- a/client/bin/job.py
+++ b/client/bin/job.py
@@ -566,7 +566,7 @@
# When continuing, the job is complete when there is no
# state file, ensure we don't try and continue.
if cont and not os.path.exists(state):
- sys.exit(1)
+ raise JobComplete("all done")
if cont == False and os.path.exists(state):
os.unlink(state)
@@ -580,6 +580,9 @@
except JobContinue:
sys.exit(5)
+ except JobComplete:
+ sys.exit(1)
+
except JobError, instance:
print "JOB ERROR: " + instance.args[0]
if myjob:
@@ -590,6 +593,8 @@
myjob.record('ABORT', None, command, instance.args[0])
myjob.record('END ABORT', None, None)
myjob.complete(1)
+ else:
+ sys.exit(1)
except Exception, e:
msg = str(e) + '\n' + format_error()
@@ -599,6 +604,8 @@
myjob.record('ABORT', None, None, msg)
myjob.record('END ABORT', None, None)
myjob.complete(1)
+ else:
+ sys.exit(1)
# If we get here, then we assume the job is complete and good.
myjob.group_level = 0