From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Wei Liu <wei.liu2@citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
andrew.cooper3@citrix.com
Subject: [XTF PATCH v2] xtf-runner: support two modes for getting output
Date: Thu, 11 Aug 2016 15:14:13 +0100 [thread overview]
Message-ID: <1470924853-17325-1-git-send-email-wei.liu2@citrix.com> (raw)
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 use the console
mode.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v2: delete auto selection mode, squash all patches into one.
---
xtf-runner | 110 +++++++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 89 insertions(+), 21 deletions(-)
diff --git a/xtf-runner b/xtf-runner
index c063699..1150621 100755
--- a/xtf-runner
+++ b/xtf-runner
@@ -425,30 +425,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()
@@ -470,6 +459,52 @@ 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)
+
+ print "Using %s" % fn
+
+ try:
+ logfile = open(fn, "rb")
+ except IOError as e:
+ # Create file if it doesn't exist
+ if e.errno == 2:
+ logfile = open(fn, "ab")
+ logfile.close()
+ logfile = open(fn, "rb")
+ else:
+ raise e
+
+ logfile.seek(0, 2) # Go to end of file
+
+ cmd = ['xl', 'create', '-F', test.cfg_path()]
+ print "Executing '%s'" % (" ".join(cmd), )
+ rc = subproc_call(cmd)
+ if rc:
+ raise RunnerError("Failed to run test")
+
+ lines = logfile.readlines()
+ logfile.close()
+
+ if len(lines) == 0:
+ raise RunnerError("Test output empty")
+
+ print "".join(lines)
+
+ 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 """
@@ -477,12 +512,21 @@ def run_tests(opts):
if not len(tests):
raise RunnerError("No tests to run")
+ if opts.mode == "console":
+ run_test = run_test_console
+ elif opts.mode == "logfile":
+ print "Using logfile mode, please make sure the log \
+files are not rotated!"
+ 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
@@ -519,6 +563,17 @@ def main():
" all tests in the selection, printing a summary of their\n"
" results at the end.\n"
"\n"
+ " To determine how runner should get output from Xen, use\n"
+ " --mode option. The default value is \"console\", which\n"
+ " means using xenconsole program to extract output.\n"
+ " The other supported value is \"logfile\", which\n"
+ " means to get output from log file.\n"
+ "\n"
+ " The \"logfile\" mode requires users to configure\n"
+ " xenconsoled to log guest console output. This mode\n"
+ " is useful for Xen version < 4.8. Also see --logfile-dir\n"
+ " and --logfile-pattern options.\n"
+ "\n"
"Selections:\n"
" A selection is zero or more of any of the following\n"
" parameters: Categories, Environments and Tests.\n"
@@ -596,6 +651,19 @@ def main():
dest = "host", help = "Restrict selection to applicable"
" tests for the current host",
)
+ parser.add_option("-m", "--mode", action = "store",
+ dest = "mode", default = "console", type = "string",
+ help = "Instruct how runner gets its output (see below)")
+ parser.add_option("--logfile-dir", action = "store",
+ dest = "logfile_dir", default = "/var/log/xen/console/",
+ type = "string",
+ help = 'Specify the directory to look for console logs, \
+defaults to "/var/log/xen/console/"')
+ parser.add_option("--logfile-pattern", action = "store",
+ dest = "logfile_pattern", default = "guest-%s.log",
+ type = "string",
+ help = 'Specify the log file name pattern, \
+defaults to "guest-%s.log"')
opts, args = parser.parse_args()
opts.args = args
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next reply other threads:[~2016-08-11 14:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-11 14:14 Wei Liu [this message]
2016-08-11 16:27 ` [XTF PATCH v2] xtf-runner: support two modes for getting output Ian Jackson
2016-08-11 16:50 ` Wei Liu
2016-08-11 17:17 ` Ian Jackson
2016-08-11 17:21 ` Andrew Cooper
2016-08-11 17:23 ` Wei Liu
2016-08-11 17:51 ` Wei Liu
2016-08-11 17:54 ` Andrew Cooper
2016-08-11 18:29 ` Ian Jackson
2016-08-12 9:23 ` Wei Liu
2016-08-12 9:51 ` Ian Jackson
2016-08-12 13:28 ` Wei Liu
2016-08-15 10:58 ` Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1470924853-17325-1-git-send-email-wei.liu2@citrix.com \
--to=wei.liu2@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).