From 85fe178a95b6f41c93b7ab261f6ae609fde5eb1c Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 26 Jul 2016 13:58:34 -0600 Subject: [PATCH] Instead of StreamHandler, rework copy_file_to() Signed-off-by: Zack Cerza --- teuthology/orchestra/run.py | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/teuthology/orchestra/run.py b/teuthology/orchestra/run.py index c5b1c77fb2..4754cb5ee5 100644 --- a/teuthology/orchestra/run.py +++ b/teuthology/orchestra/run.py @@ -114,16 +114,14 @@ class RemoteProcess(object): # Log the stream host_log = self.logger.getChild(self.hostname) stream_log = host_log.getChild(stream_name) - # If stream_obj is an actual stream, have the logging module write - # to it as well - if stream_obj is not None: - stream_log.addHandler(logging.StreamHandler(stream_obj)) - greenlet = gevent.spawn( - copy_file_to, - getattr(self, stream_name), - stream_log, + self.add_greenlet( + gevent.spawn( + copy_file_to, + getattr(self, stream_name), + stream_log, + stream_obj, + ) ) - self.add_greenlet(greenlet) setattr(self, stream_name, stream_obj) elif self._wait: # FIXME: Is this actually true? @@ -267,20 +265,19 @@ def copy_and_close(src, fdst): fdst.close() -def copy_file_to(f, dst): +def copy_file_to(src, logger, stream=None): """ Copy file - :param f: file to be copied. - :param dst: destination - :param host: original host location + :param src: file to be copied. + :param logger: the logger object + :param stream: an optional file-like object which will receive a copy of + src. """ - if hasattr(dst, 'log'): - # looks like a Logger to me; not using isinstance to make life - # easier for unit tests - handler = copy_to_log - else: - handler = shutil.copyfileobj - return handler(f, dst) + if stream is not None: + shutil.copyfileobj(src, stream) + stream.seek(0) + src = stream + copy_to_log(src, logger) def spawn_asyncresult(fn, *args, **kwargs): -- 2.39.5