[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [XTF PATCH 3/3] xtf-runner: support two modes for getting output
We need two modes for getting output: 1. Use console directly with newer (>=4.8) Xen 2. Use log files for older Xen This patch implements both. The default behaviour is to choose mode automatically based on Xen version. User can also explicitly specify which mode to use. Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- xtf-runner | 104 ++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 83 insertions(+), 21 deletions(-) diff --git a/xtf-runner b/xtf-runner index 73a4e0d..2d4d6db 100755 --- a/xtf-runner +++ b/xtf-runner @@ -11,6 +11,8 @@ from optparse import OptionParser from subprocess import Popen, PIPE, call as subproc_call, check_output +from distutils.version import LooseVersion +import time try: import json @@ -438,30 +440,19 @@ def list_tests(opts): for sel in opts.selection: print sel +def run_test_console(opts, test): + """ Run a specific test via xenconsole""" -def run_test(test): - """ Run a specific test """ - - cmd = ['xl', 'create', '-p', test.cfg_path()] - print "Executing '%s'" % (" ".join(cmd), ) - rc = subproc_call(cmd) - if rc: - raise RunnerError("Failed to create VM") - - cmd = ['xl', 'console', test.vm_name()] + cmd = ['xl', 'create', '-Fc', test.cfg_path()] print "Executing '%s'" % (" ".join(cmd), ) - console = Popen(cmd, stdout = PIPE) + guest = Popen(cmd, stdout = PIPE, stderr = PIPE) - cmd = ['xl', 'unpause', test.vm_name()] - print "Executing '%s'" % (" ".join(cmd), ) - rc = subproc_call(cmd) - if rc: - raise RunnerError("Failed to unpause VM") + # stdout is console output, stderr is xl output + stdout, stderr = guest.communicate() - stdout, _ = console.communicate() - - if console.returncode: - raise RunnerError("Failed to obtain VM console") + if guest.returncode: + print stderr + raise RunnerError("Failed to communicate with guest") lines = stdout.splitlines() @@ -483,6 +474,64 @@ def run_test(test): return "ERROR" +def run_test_logfile(opts, test): + """ Run a specific test via grepping log file""" + + fn = opts.logfile_dir + (opts.logfile_pattern % test) + local_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + + # Use time to generate unique stamps + start_stamp = "===== XTF TEST START %s =====" % local_time + end_stamp = "===== XTF TEST END %s =====" % local_time + + print "Using %s" % fn + + f = open(fn, "ab") + f.write(start_stamp + "\n") + f.close() + + cmd = ['xl', 'create', '-F', test.cfg_path()] + print "Executing '%s'" % (" ".join(cmd), ) + rc = subproc_call(cmd) + if rc: + raise RunnerError("Failed to run test") + + f = open(fn, "ab") + f.write(end_stamp + "\n") + f.close() + + f = open(fn, "rb") + output = f.readlines() + f.close() + lines = [] + found = False + for line in output: + if end_stamp in line: + break + if start_stamp in line: + found = True + continue + if not found: + continue + lines.append(line) + + print "".join(lines) + + if len(lines) == 0: + raise RunnerError("Log file output empty") + + test_result = lines[-1] + if not "Test result:" in test_result: + return "ERROR" + + for res in all_results: + + if res in test_result: + return res + + return "ERROR" + + def run_tests(opts): """ Run tests """ @@ -490,12 +539,25 @@ def run_tests(opts): if not len(tests): raise RunnerError("No tests to run") + if opts.mode == "auto": + xen_version = LooseVersion(get_xen_version()) + if xen_version < LooseVersion("4.8"): + run_test = run_test_logfile + else: + run_test = run_test_console + elif opts.mode == "console": + run_test = run_test_console + elif opts.mode == "logfile": + run_test = run_test_logfile + else: + raise RunnerError("Unrecognised mode") + rc = all_results.index('SUCCESS') results = [] for test in tests: - res = run_test(test) + res = run_test(opts, test) res_idx = all_results.index(res) if res_idx > rc: rc = res_idx -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |