Commit 011a8e8f authored by Hrvoje Ribicic's avatar Hrvoje Ribicic

Always preserve QA command output

A previous patch suppressed command output if the command succeded,
which reduces the amount of information we have in the QA, especially
warnings or the like. This patch restores the output, while still
ignoring the use cases in which we really do not care whether the
command succeeds or not.
Signed-off-by: default avatarHrvoje Ribicic <riba@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent cf0ec9cb
......@@ -150,6 +150,25 @@ def _AssertRetCode(rcode, fail, cmdstr, nodename):
(cmdstr, nodename, rcode))
def _PrintCommandOutput(stdout, stderr):
"""Prints the output of commands, minimizing wasted space.
@type stdout: string
@type stderr: string
"""
if stdout:
stdout_clean = stdout.rstrip('\n')
if stderr:
print "Stdout was:\n%s" % stdout_clean
else:
print stdout_clean
if stderr:
print "Stderr was:"
print >> sys.stderr, stderr.rstrip('\n')
def AssertCommand(cmd, fail=False, node=None, log_cmd=True, max_seconds=None):
"""Checks that a remote command succeeds.
......@@ -186,12 +205,13 @@ def AssertCommand(cmd, fail=False, node=None, log_cmd=True, max_seconds=None):
stdout, stderr = popen.communicate()
rcode = popen.returncode
duration_seconds = TimedeltaToTotalSeconds(datetime.datetime.now() - start)
if fail is not None:
try:
try:
if fail is not None:
_AssertRetCode(rcode, fail, cmdstr, nodename)
except:
print "Stdout was:\n%s\nStderr was:\n%s\n" % (stdout, stderr)
raise
finally:
if log_cmd:
_PrintCommandOutput(stdout, stderr)
if max_seconds is not None:
if duration_seconds > max_seconds:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment