]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Log stderr and stdout as long as they aren't pipes
authorZack Cerza <zack@redhat.com>
Tue, 19 Jul 2016 16:11:27 +0000 (10:11 -0600)
committerZack Cerza <zack@redhat.com>
Wed, 20 Jul 2016 23:42:48 +0000 (17:42 -0600)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/orchestra/run.py

index 80b3b0727235c4955a0660127438083a925d047a..d146ca6798a124d9a62b13a24288fad56d13c41b 100644 (file)
@@ -102,6 +102,15 @@ class RemoteProcess(object):
 
         status = self._get_exitstatus()
         self.exitstatus = self.returncode = status
+        for stream in ('stdout', 'stderr'):
+            if hasattr(self, stream):
+                stream_obj = getattr(self, stream)
+                # Despite ChannelFile having a seek() method, it raises
+                # "IOError: File does not support seeking."
+                if hasattr(stream_obj, 'seek') and \
+                        not isinstance(stream_obj, ChannelFile):
+                    stream_obj.seek(0)
+
         if self.check_status:
             if status is None:
                 # command either died due to a signal, or the connection
@@ -370,9 +379,13 @@ def run(
 
     g_err = None
     if stderr is not PIPE:
-        if stderr is None:
-            stderr = logger.getChild(name).getChild('stderr')
-        g_err = gevent.spawn(copy_file_to, r.stderr, stderr)
+        # Log stderr
+        stderr_logger = logger.getChild(name).getChild('stderr')
+        # If the stderr arg is a stream, have the logging module write to it as
+        # well
+        if stderr is not None:
+            stderr_logger.addHandler(logging.StreamHandler(stdout))
+        g_err = gevent.spawn(copy_file_to, r.stderr, stderr_logger)
         r.add_greenlet(g_err)
         r.stderr = stderr
     else:
@@ -381,9 +394,13 @@ def run(
 
     g_out = None
     if stdout is not PIPE:
-        if stdout is None:
-            stdout = logger.getChild(name).getChild('stdout')
-        g_out = gevent.spawn(copy_file_to, r.stdout, stdout)
+        # Log stdout
+        stdout_logger = logger.getChild(name).getChild('stdout')
+        # If the stdout arg is a stream, have the logging module write to it as
+        # well
+        if stdout is not None:
+            stdout_logger.addHandler(logging.StreamHandler(stdout))
+        g_out = gevent.spawn(copy_file_to, r.stdout, stdout_logger)
         r.add_greenlet(g_out)
         r.stdout = stdout
     else: