xtf-runner: support two modes for getting output
PATCH v2 1/1 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 use the console mode.
---
v2: delete auto selection mode, squash all patches into one.
--- xtf-runner | 110 +++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 89 insertions(+), 21 deletions(-)
xtf-runner +89 -21
@@ -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
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Wei Liu writes ("[XTF PATCH v2] xtf-runner: support two modes for getting output"):
Quoted 1 line
We need two modes for getting output:
...
xtf-runner def run_test(test): · line 478
Quoted 9 lines
xtf-runner +9
-0+ 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
This is perverse. Why not just open it O_CREAT|O_RDONLY ? If Python can't do that then unconditionally opening it O_CREAT|O_RDWR would do.
Quoted 1 line
+
logfile.seek(0, 2)# Go to end of file
Does Python not have SEEK_END somewhere ?
xtf-runner def run_test(test): · line 492
Quoted 5 lines
xtf-runner +5
-0+ lines = logfile.readlines() + logfile.close() + + if len(lines) == 0: + raise RunnerError("Test output empty")
I think you are racing with xenconsoled here. How do you know that all the output has arrived ?
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 13 lines · Ian Jackson
Wei Liu writes ("[XTF PATCH v2] xtf-runner: support two modes for getting output"):
Quoted 1 line
We need two modes for getting output:
...
xtf-runner def run_test(test): · line 478
Quoted 9 lines
xtf-runner +9
-0+ 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
Quoted 3 lines
This is perverse. Why not just open it O_CREAT|O_RDONLY ? If Python can't do that then unconditionally opening it O_CREAT|O_RDWR would do.
The open call doesn't accept O_CREAT|O_RDONLY.
Andy my experiment showed that "rb" doesn't create the file.
Quoted 3 lines
Quoted 1 line
+
logfile.seek(0, 2)# Go to end of fileDoes Python not have
SEEK_ENDsomewhere ?
There is one, but that's in os module.
Python official document is using numeric values directly.
Quoted 10 lines
xtf-runner def run_test(test): · line 492
Quoted 6 lines
xtf-runner +5
-0+ lines = logfile.readlines() + logfile.close() + + if len(lines) == 0: + raise RunnerError("Test output empty")I think you are racing with xenconsoled here. How do you know that all the output has arrived ?
Unfortunately there doesn't seem to be a direct way to synchronise between the two.
Maybe the best bet is to watch the tty node for it to go away?
Wei.
Quoted 1 line
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Wei Liu writes ("Re: [XTF PATCH v2] xtf-runner: support two modes for getting output"):
Quoted 5 lines · Ian Jackson
Quoted 2 lines
This is perverse. Why not just open it O_CREAT|O_RDONLY ? If Python can't do that then unconditionally opening it O_CREAT|O_RDWR would do.
The open call doesn't accept O_CREAT|O_RDONLY.
open("t", O_RDONLY|O_CREAT, 0666) = 3
But maybe you mean Python's open doesn't.
Quoted 1 line
Andy my experiment showed that "rb" doesn't create the file.
Yes, it wouldn't. If you want a fopen mode, "a+" may be of some use.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+
logfile.seek(0, 2)# Go to end of fileDoes Python not have
SEEK_ENDsomewhere ?There is one, but that's in os module.
Python official document is using numeric values directly.
Seriously? Fine, whatever.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
xtf-runner +5
-0+ lines = logfile.readlines() + logfile.close() + + if len(lines) == 0: + raise RunnerError("Test output empty")
Quoted 7 lines
Quoted 2 lines
I think you are racing with xenconsoled here. How do you know that all the output has arrived ?
Unfortunately there doesn't seem to be a direct way to synchronise between the two.
Maybe the best bet is to watch the tty node for it to go away?
Does xenconsole write the remaining output to the logfile before deleting the tty node from xenstore ?
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 8 lines · Ian Jackson
Wei Liu writes ("Re: [XTF PATCH v2] xtf-runner: support two modes for getting output"):
Quoted 4 lines · Ian Jackson
Quoted 2 lines
This is perverse. Why not just open it O_CREAT|O_RDONLY ? If Python can't do that then unconditionally opening it O_CREAT|O_RDWR would do.
The open call doesn't accept O_CREAT|O_RDONLY.
open("t", O_RDONLY|O_CREAT, 0666)= 3But maybe you mean Python's open doesn't.
Use os.open() to get a Posix open, the os.fdopen(fd) to get a Python file object for the fd.
Quoted 9 lines
Quoted 2 lines
Andy my experiment showed that "rb" doesn't create the file.
Yes, it wouldn't. If you want a fopen mode, "a+" may be of some use.
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
+
logfile.seek(0, 2)# Go to end of fileDoes Python not have
SEEK_ENDsomewhere ?There is one, but that's in os module.
Python official document is using numeric values directly.Seriously? Fine, whatever.
os.SEEK_END is the proper way of doing this. The documentation is presumably just being lazy.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 17 lines · Andrew Cooper
Quoted 8 lines · Ian Jackson
Wei Liu writes ("Re: [XTF PATCH v2] xtf-runner: support two modes for getting output"):
Quoted 4 lines · Ian Jackson
Quoted 2 lines
This is perverse. Why not just open it O_CREAT|O_RDONLY ? If Python can't do that then unconditionally opening it O_CREAT|O_RDWR would do.
The open call doesn't accept O_CREAT|O_RDONLY.
open("t", O_RDONLY|O_CREAT, 0666)= 3But maybe you mean Python's open doesn't.
Use
os.open()to get a Posix open, theos.fdopen(fd)to get a Python file object for the fd.Quoted 4 lines
Quoted 2 lines
Andy my experiment showed that "rb" doesn't create the file.
Yes, it wouldn't. If you want a fopen mode, "a+" may be of some use.
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
+
logfile.seek(0, 2)# Go to end of fileDoes Python not have
SEEK_ENDsomewhere ?There is one, but that's in os module.
Python official document is using numeric values directly.Seriously? Fine, whatever.
os.SEEK_END is the proper way of doing this. The documentation is presumably just being lazy.
Looks like switching to use os module should work better.
Wei.
Quoted 2 lines
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 33 lines · Ian Jackson
Wei Liu writes ("Re: [XTF PATCH v2] xtf-runner: support two modes for getting output"):
Quoted 5 lines · Ian Jackson
Quoted 2 lines
This is perverse. Why not just open it O_CREAT|O_RDONLY ? If Python can't do that then unconditionally opening it O_CREAT|O_RDWR would do.
The open call doesn't accept O_CREAT|O_RDONLY.
open("t", O_RDONLY|O_CREAT, 0666)= 3But maybe you mean Python's open doesn't.
Quoted 1 line
Andy my experiment showed that "rb" doesn't create the file.
Yes, it wouldn't. If you want a fopen mode, "a+" may be of some use.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+
logfile.seek(0, 2)# Go to end of fileDoes Python not have
SEEK_ENDsomewhere ?There is one, but that's in os module.
Python official document is using numeric values directly.Seriously? Fine, whatever.
Quoted 9 lines
Quoted 8 lines
xtf-runner def run_test(test): · line 492
Quoted 5 lines
xtf-runner +5
-0+ lines = logfile.readlines() + logfile.close() + + if len(lines) == 0: + raise RunnerError("Test output empty")I think you are racing with xenconsoled here. How do you know that all the output has arrived ?
Quoted 8 lines
Quoted 4 lines
Unfortunately there doesn't seem to be a direct way to synchronise between the two.
Maybe the best bet is to watch the tty node for it to go away?
Does xenconsole write the remaining output to the logfile before deleting the tty node from xenstore ?
Unfortunately no, watching tty node in xenstore won't work. In fact, xenconsoled doesn't delete the tty node at all. It's libxl that deletes it AFAICT.
It is sure that xenconsoled will close the tty before closing the file, so stat'ing the actual device node won't work either.
I'm pretty out of idea here.
Wei.
Quoted 1 line
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 33 lines · Wei Liu
Quoted 23 lines · Ian Jackson
Wei Liu writes ("Re: [XTF PATCH v2] xtf-runner: support two modes for getting output"):
Quoted 4 lines · Ian Jackson
Quoted 2 lines
This is perverse. Why not just open it O_CREAT|O_RDONLY ? If Python can't do that then unconditionally opening it O_CREAT|O_RDWR would do.
The open call doesn't accept O_CREAT|O_RDONLY.
open("t", O_RDONLY|O_CREAT, 0666)= 3But maybe you mean Python's open doesn't.
Quoted 1 line
Andy my experiment showed that "rb" doesn't create the file.
Yes, it wouldn't. If you want a fopen mode, "a+" may be of some use.
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
+
logfile.seek(0, 2)# Go to end of fileDoes Python not have
SEEK_ENDsomewhere ?There is one, but that's in os module.
Python official document is using numeric values directly.Seriously? Fine, whatever.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
xtf-runner +5
-0+ lines = logfile.readlines() + logfile.close() + + if len(lines) == 0: + raise RunnerError("Test output empty")Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
I think you are racing with xenconsoled here. How do you know that all the output has arrived ?
Unfortunately there doesn't seem to be a direct way to synchronise between the two.
Maybe the best bet is to watch the tty node for it to go away?
Does xenconsole write the remaining output to the logfile before deleting the tty node from xenstore ?
Quoted 8 lines
Unfortunately no, watching tty node in xenstore won't work. In fact, xenconsoled doesn't delete the tty node at all. It's libxl that deletes it AFAICT.
It is sure that xenconsoled will close the tty before closing the file, so stat'ing the actual device node won't work either.
I'm pretty out of idea here.
Because of XTF's behaviour (waiting for xenconsoled to catch up), you know for certain that once xl create has finished, nothing more will write into the log.
This is a catch 22 situation though, as I specifically want to avoid that behaviour. Perhaps it is acceptable in logfile mode, if we can get xl console mode working without the synchronous delay.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Andrew Cooper writes ("Re: [XTF PATCH v2] xtf-runner: support two modes for getting output"):
Quoted 6 lines · Wei Liu
Quoted 1 line
I'm pretty out of idea here.
Because of XTF's behaviour (waiting for xenconsoled to catch up), you know for certain that once
xl createhas finished, nothing more will write into the log.
You're missing the problem, I think. It's this possible race:
VM prints last output to ring
xenconsoled wakes up from poll
VM calls shutdown
xenstored sends domain death event
xl receives domain death event
xl tears down guest, destroying
all relevant xenstore nodes
xl exits
xtf-runner opens logfile
xtf-runner reads logfile
xtf-runner gets eof on logfile
xenconsoled reads data from ring (which page is now only owned by xenconsoled)
xenconsoled writes final data to logfile
Wei: Maybe you could rely on `xl console' not exiting until xenconsole has written the last data to the logfile ? You say:
Quoted 2 lines
It is sure that xenconsoled will close the tty before closing the file, so stat'ing the actual device node won't work either.
We don't care when xenconsoled closes the logfile. We care about when it last calls write() (with a nonempty buffer).
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 29 lines · Ian Jackson
Andrew Cooper writes ("Re: [XTF PATCH v2] xtf-runner: support two modes for getting output"):
Quoted 6 lines · Wei Liu
Quoted 1 line
I'm pretty out of idea here.
Because of XTF's behaviour (waiting for xenconsoled to catch up), you know for certain that once
xl createhas finished, nothing more will write into the log.You're missing the problem, I think. It's this possible race:
VM prints last output to ring
xenconsoled wakes up from poll
VM calls shutdown
xenstored sends domain death event
xl receives domain death event
xl tears down guest, destroying
all relevant xenstore nodes
xl exits
xtf-runner opens logfile
xtf-runner reads logfile
xtf-runner gets eof on logfilexenconsoled reads data from ring (which page is now only owned by xenconsoled)
xenconsoled writes final data to logfile
Quoted 9 lines
Wei: Maybe you could rely on `xl console' not exiting until xenconsole has written the last data to the logfile ? You say:
Quoted 2 lines
It is sure that xenconsoled will close the tty before closing the file, so stat'ing the actual device node won't work either.
We don't care when xenconsoled closes the logfile. We care about when it last calls
write()(with a nonempty buffer).
In logfile mode, no console client is spawned, because it is not reliable -- that's why we use logfile mode in the first place.
And I would rather just add a bodge (wait 1 or 2 seconds) than to rely on sophisticated hack.
Wei.
Quoted 1 line
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Wei Liu writes ("Re: [XTF PATCH v2] xtf-runner: support two modes for getting output"):
Quoted 8 lines · Ian Jackson
Quoted 2 lines
We don't care when xenconsoled closes the logfile. We care about when it last calls
write()(with a nonempty buffer).In logfile mode, no console client is spawned, because it is not reliable -- that's why we use logfile mode in the first place.
And I would rather just add a bodge (wait 1 or 2 seconds)
That would increase the duration of each test by that 1 or 2 seconds. I suppose you could conclude the logfile is complete if it contains the expected end-of-run message from the vm, and only poll if not.
But, it's worse:
I went to read the xenconsoled source code, and it can handle a domain death event before finishing reading all of the data out of a domain's ring.
Maybe this will be mitigated by XTF's printf waiting for the xenconsoled ring pointer to catch up ?
xenconsoled advances the ring pointer before writing to the logfile, but (assuming there's no overflow), the write will happen before it goes back into the event loop, so it won't be lost.
Quoted 1 line
than to rely on sophisticated hack.
To my mind polling the logfile looking for the final message from the vm is something of a hack.
But indeed I can't see another way to wait for xenconsoled, than going behind libxl's back with something like
* spawn xl create -p -F
* look for the console tty in xenstore
* open the console tty
* unpause
* wait for the console tty to get eof
This is not a logfile mode at all, of course. It probably wouldn't be easily adaptable to other toolstacks (eg XenServer).
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 14 lines · Ian Jackson
Wei Liu writes ("Re: [XTF PATCH v2] xtf-runner: support two modes for getting output"):
Quoted 8 lines · Ian Jackson
Quoted 2 lines
We don't care when xenconsoled closes the logfile. We care about when it last calls
write()(with a nonempty buffer).In logfile mode, no console client is spawned, because it is not reliable -- that's why we use logfile mode in the first place.
And I would rather just add a bodge (wait 1 or 2 seconds)
That would increase the duration of each test by that 1 or 2 seconds. I suppose you could conclude the logfile is complete if it contains the expected end-of-run message from the vm, and only poll if not.
Quoted 9 lines
But, it's worse:
I went to read the xenconsoled source code, and it can handle a domain death event before finishing reading all of the data out of a domain's ring.
Maybe this will be mitigated by XTF's printf waiting for the xenconsoled ring pointer to catch up ?
I think so.
Under normal circumstance (micro VM doesn't crash), we're sure that all output is consumed by xenconsoled before the VM shuts down itself.
Quoted 4 lines
xenconsoled advances the ring pointer before writing to the logfile, but (assuming there's no overflow), the write will happen before it goes back into the event loop, so it won't be lost.
Correct.
Quoted 13 lines
Quoted 1 line
than to rely on sophisticated hack.
To my mind polling the logfile looking for the final message from the vm is something of a hack.
But indeed I can't see another way to wait for xenconsoled, than going behind libxl's back with something like
* spawn xl create -p -F
* look for the console tty in xenstore
* open the console tty
* unpause
* wait for the console tty to get eof
Quoted 3 lines
This is not a logfile mode at all, of course. It probably wouldn't be easily adaptable to other toolstacks (eg XenServer).
Andrew, what is your opinion?
Wei.
Quoted 1 line
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 40 lines · Ian Jackson
Wei Liu writes ("Re: [XTF PATCH v2] xtf-runner: support two modes for getting output"):
Quoted 8 lines · Ian Jackson
Quoted 2 lines
We don't care when xenconsoled closes the logfile. We care about when it last calls
write()(with a nonempty buffer).In logfile mode, no console client is spawned, because it is not reliable -- that's why we use logfile mode in the first place.
And I would rather just add a bodge (wait 1 or 2 seconds)
That would increase the duration of each test by that 1 or 2 seconds. I suppose you could conclude the logfile is complete if it contains the expected end-of-run message from the vm, and only poll if not.
But, it's worse:
I went to read the xenconsoled source code, and it can handle a domain death event before finishing reading all of the data out of a domain's ring.
Maybe this will be mitigated by XTF's printf waiting for the xenconsoled ring pointer to catch up ?
xenconsoled advances the ring pointer before writing to the logfile, but (assuming there's no overflow), the write will happen before it goes back into the event loop, so it won't be lost.
Quoted 1 line
than to rely on sophisticated hack.
To my mind polling the logfile looking for the final message from the vm is something of a hack.
But indeed I can't see another way to wait for xenconsoled, than going behind libxl's back with something like
* spawn xl create -p -F
* look for the console tty in xenstore
* open the console tty
* unpause
* wait for the console tty to get eof
Quoted 3 lines
This is not a logfile mode at all, of course. It probably wouldn't be easily adaptable to other toolstacks (eg XenServer).
It's only empirical, but my experience of running this patch in logfile mode (a few dozen times) hasn't seen a single error due to missing output.
I can go for the polling mode but with a timeout of 1 second. A bit hacky, but hopefully should work good enough.
I want to get something working which I can run in osstest. We can go with something more sophisticated if the above scheme is deemed not suitable for osstest.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel