]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
misc.sh(): Don't capture stderr by default 925/head
authorZack Cerza <zack@redhat.com>
Mon, 8 Aug 2016 19:45:50 +0000 (13:45 -0600)
committerZack Cerza <zack@redhat.com>
Mon, 8 Aug 2016 20:13:05 +0000 (14:13 -0600)
If not capturing it, log it.

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/misc.py
teuthology/test/test_misc.py

index 7fad219c9b3af701eb4ac3c5a3d2f0d22b2949ca..798209424b296ec494854a39fcefeeaeb9329339 100644 (file)
@@ -1331,19 +1331,21 @@ def is_in_dict(searchkey, searchval, d):
         return searchval == val
 
 
-def sh(command, log_limit=1024):
+def sh(command, log_limit=1024, include_stderr=False):
     """
-    Run the shell command and return the output in ascii (stderr and
-    stdout).  If the command fails, raise an exception. The command
-    and its output are logged, on success and on error.
+    Run the shell command and return the output in ascii (stdout and optionally
+    stderr). If the command fails, raise an exception. The command and its
+    output are logged, on success and on error.
     """
     log.debug(":sh: " + command)
     proc = subprocess.Popen(
         args=command,
         stdout=subprocess.PIPE,
-        stderr=subprocess.STDOUT,
+        stderr=subprocess.STDOUT if include_stderr else subprocess.PIPE,
         shell=True,
         bufsize=1)
+    if include_stderr is False:
+        log.debug("stderr: %s", proc.stderr.read())
     lines = []
     truncated = False
     with proc.stdout:
index 464c90488e5e90a627e31ba2ade582f6cfee15ba..e021c4872ead5a7bfaac2f36fe3bb247c7139ebd 100644 (file)
@@ -34,8 +34,9 @@ def test_sh_fail(caplog):
             assert ('replay full' in record.message or
                     'ABC\n' == record.message)
 
+
 def test_sh_progress(caplog):
-    misc.sh("echo AB ; sleep 5 ; /bin/echo C", 2) == "ABC\n"
+    misc.sh("echo AB ; sleep 5 ; /bin/echo C", 2, include_stderr=True) == "ABC\n"
     records = caplog.records()
     assert ':sh: ' in records[0].message
     assert 'AB' == records[1].message
@@ -49,6 +50,7 @@ def test_sh_progress(caplog):
     t2 = datetime.strptime(records[2].asctime.split(',')[0], "%Y-%m-%d %H:%M:%S")
     assert (t2 - t1).total_seconds() > 2
 
+
 def test_wait_until_osds_up():
     ctx = argparse.Namespace()
     remote = FakeRemote()