From 011a8e8f7e7b6efd89840155dab83726df23ff2b Mon Sep 17 00:00:00 2001 From: Hrvoje Ribicic Date: Tue, 17 Mar 2015 20:13:20 +0000 Subject: [PATCH] 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: Hrvoje Ribicic Reviewed-by: Klaus Aehlig --- qa/qa_utils.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/qa/qa_utils.py b/qa/qa_utils.py index b1d66b297..c1a6d2205 100644 --- a/qa/qa_utils.py +++ b/qa/qa_utils.py @@ -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: -- GitLab