提交 2bc0aa69 编写于 作者: L Lucas Meneghel Rodrigues 提交者: Lucas Meneghel Rodrigues

Merge pull request #162 from lmr/force-fail-ctrl-c

avocado.process: Make processes to fail when interrupted by user
......@@ -146,6 +146,8 @@ class CmdError(Exception):
def __str__(self):
if self.result is not None:
if self.result.interrupted:
return "Command %s interrupted by user (Ctrl+C)" % self.command
if self.result.exit_status is None:
msg = "Command '%s' failed and is not responding to signals"
msg %= self.command
......
......@@ -68,7 +68,7 @@ class VMTestRunner(TestRunner):
:param urls: a string with test URLs.
:return: a dictionary with test results.
"""
avocado_cmd = 'avocado --json run --archive "%s"' % urls
avocado_cmd = 'avocado --json - run --archive "%s"' % urls
stdout = self.result.vm.remote.run(avocado_cmd)
try:
results = json.loads(stdout)
......
......@@ -91,14 +91,18 @@ class CmdResult(object):
self.stdout = stdout
self.stderr = stderr
self.duration = duration
self.interrupted = False
def __repr__(self):
return ("Command: %s\n"
"Exit status: %s\n"
"Duration: %s\n"
"Stdout:\n%s\n"
"Stderr:\n%s\n" % (self.command, self.exit_status,
self.duration, self.stdout, self.stderr))
cmd_rep = ("Command: %s\n"
"Exit status: %s\n"
"Duration: %s\n"
"Stdout:\n%s\n"
"Stderr:\n%s\n" % (self.command, self.exit_status,
self.duration, self.stdout, self.stderr))
if self.interrupted:
cmd_rep += "Command interrupted by user (Ctrl+C)\n"
return cmd_rep
class SubProcess(object):
......@@ -142,7 +146,9 @@ class SubProcess(object):
self.stderr_thread.start()
def signal_handler(signum, frame):
self.result.interrupted = True
self.wait()
signal.signal(signal.SIGINT, signal_handler)
def __str__(self):
......@@ -329,7 +335,8 @@ def run(cmd, timeout=None, verbose=True, ignore_status=False):
"""
sp = SubProcess(cmd=cmd, verbose=verbose)
cmd_result = sp.run(timeout=timeout)
if cmd_result.exit_status != 0 and not ignore_status:
fail_condition = cmd_result.exit_status != 0 or cmd_result.interrupted
if fail_condition and not ignore_status:
raise exceptions.CmdError(cmd, sp.result)
return cmd_result
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册