Beaker tests call a lot of shell scripts to report statuses and logs to the beaker server. In order to control where the data goes and how it gets there, redirect everything to autotest for processing. This is done by adding a cheap hack to the bootstrap command and creating stub scripts.
The beaker tests now call the stub scripts, which call the autotest bootstrap command, which takes the data and reformats it for delivery to the destination. I attached the scripts I am using as examples of usage cases. I am trying to work out a solution where this can be one shell script sourced from an environment. Its a little ugly but works around some of the beaker quirks. Signed-off-by: Don Zickus <[email protected]> --- client/harness_beaker.py | 78 +++++++++++++++++++++++++++++++++++++++++++++ client/rhts-reboot | 4 ++ client/rhts-report-result | 7 ++++ client/rhts-submit-log | 6 +++ client/rhts_submit_log | 6 +++ 5 files changed, 101 insertions(+), 0 deletions(-) create mode 100755 client/rhts-reboot create mode 100755 client/rhts-report-result create mode 100755 client/rhts-submit-log create mode 100755 client/rhts_submit_log diff --git a/client/harness_beaker.py b/client/harness_beaker.py index 7b15178..12dec25 100644 --- a/client/harness_beaker.py +++ b/client/harness_beaker.py @@ -70,6 +70,9 @@ class harness_beaker(harness.harness): self.offline = False self.cmd = None + #handle legacy rhts scripts called from inside tests + os.environ['PATH'] = "%s:%s" % ('/var/cache/autotest', os.environ['PATH']) + if harness_args: log.info('harness_args: %s' % harness_args) os.environ['AUTOTEST_HARNESS_ARGS'] = harness_args @@ -108,15 +111,90 @@ class harness_beaker(harness.harness): if not is_bootstrap: self.offline = True + elif a[:8] == 'quickcmd': + if len(a) < 8 or a[8] != '=': + raise error.HarnessError("Bad use of 'quickcmd'") + self.cmd = a[9:] + else: raise error.HarnessError("Unknown beaker harness arg: %s" % a) + def parse_quickcmd(self, args): + #hack allow tests to quickly submit feedback through harness + + if not args: + return + + if 'BEAKER_TASK_ID' not in os.environ: + raise error.HarnessError("No BEAKER_TASK_ID set") + task_id = os.environ['BEAKER_TASK_ID'] + + #Commands are from tests and should be reported as results + cmd,q_args = args.split(':') + if cmd == 'submit_log': + try: + #rhts_submit_log has as args: -S -T -l + #we just care about -l + f = None + arg_list = q_args.split(' ') + while arg_list: + arg = arg_list.pop(0) + if arg == '-l': + f = arg_list.pop(0) + break + if not f: + raise + self.bkr_proxy.task_upload_file(task_id, f) + except Exception: + log.critical('ERROR: Failed to process quick cmd %s' % cmd) + + elif cmd == 'submit_result': + def init_args(testname='Need/a/testname/here', status="None", logfile=None, score="0"): + return testname, status, logfile, score + + try: + #report_result has TESNAME STATUS LOGFILE SCORE + arg_list = q_args.split(' ') + testname, status, logfile, score = init_args(*arg_list) + + resultid = self.bkr_proxy.task_result(task_id, status, + testname, score, '') + + if (logfile and os.path.isfile(logfile) and + os.path.getsize(logfile) != 0): + self.bkr_proxy.result_upload_file(task_id, resultid, logfile) + + #save the dmesg file + dfile = '/tmp/beaker.dmesg' + utils.system('dmesg -c > %s' % dfile) + if os.path.getsize(dfile) != 0: + self.bkr_proxy.result_upload_file(task_id, resultid, dfile) + #os.remove(dfile) + + except Exception: + log.critical('ERROR: Failed to process quick cmd %s' % cmd) + + elif cmd == 'reboot': + #we are in a stub job. Can't use self.job.reboot() :-( + utils.system("sync; sync; reboot") + self.run_pause() + raise error.JobContinue("more to come") + + else: + raise error.HarnessError("Bad sub-quickcmd: %s" % cmd) + def bootstrap(self, fetchdir): '''How to kickstart autotest when you have no control file? You download the beaker XML, convert it to a control file and pass it back to autotest. Much like bootstrapping.. :-) ''' + #hack to sneakily pass results back to beaker without running + #autotest. Need to avoid calling get_recipe below + if self.cmd: + self.parse_quickcmd(self.cmd) + return None + recipe = self.init_recipe_from_beaker() #remove stale file diff --git a/client/rhts-reboot b/client/rhts-reboot new file mode 100755 index 0000000..1af2031 --- /dev/null +++ b/client/rhts-reboot @@ -0,0 +1,4 @@ +#!/bin/sh + +autotest -P quickcmd="reboot:" bootstrap + diff --git a/client/rhts-report-result b/client/rhts-report-result new file mode 100755 index 0000000..8ef43b5 --- /dev/null +++ b/client/rhts-report-result @@ -0,0 +1,7 @@ +#!/bin/sh + +args="$@" +echo "$env" +test -n "$AUTOTEST_HARNESS_ARGS" && extra=",$AUTOTEST_HARNESS_ARGS" +autotest --verbose -P quickcmd="submit_result:$args$extra" bootstrap + diff --git a/client/rhts-submit-log b/client/rhts-submit-log new file mode 100755 index 0000000..215caa0 --- /dev/null +++ b/client/rhts-submit-log @@ -0,0 +1,6 @@ +#!/bin/sh + +args="$@" +test -n "$AUTOTEST_HARNESS_ARGS" && extra=",$AUTOTEST_HARNESS_ARGS" +autotest --verbose -P quickcmd="submit_log:$args$extra" bootstrap + diff --git a/client/rhts_submit_log b/client/rhts_submit_log new file mode 100755 index 0000000..215caa0 --- /dev/null +++ b/client/rhts_submit_log @@ -0,0 +1,6 @@ +#!/bin/sh + +args="$@" +test -n "$AUTOTEST_HARNESS_ARGS" && extra=",$AUTOTEST_HARNESS_ARGS" +autotest --verbose -P quickcmd="submit_log:$args$extra" bootstrap + -- 1.7.1 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
