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 <[email protected]>
---
 qa/qa_utils.py | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/qa/qa_utils.py b/qa/qa_utils.py
index b1d66b2..b8ef546 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,12 @@ 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:
-      _AssertRetCode(rcode, fail, cmdstr, nodename)
-    except:
-      print "Stdout was:\n%s\nStderr was:\n%s\n" % (stdout, stderr)
-      raise
+    _AssertRetCode(rcode, fail, cmdstr, nodename)
+
+  if log_cmd:
+    _PrintCommandOutput(stdout, stderr)
 
   if max_seconds is not None:
     if duration_seconds > max_seconds:
-- 
2.2.0.rc0.207.ga3a616c

Reply via email to