]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Express hostnames as child logger names
authorZack Cerza <zack@cerza.org>
Fri, 9 May 2014 17:55:42 +0000 (12:55 -0500)
committerZack Cerza <zack@cerza.org>
Sat, 10 May 2014 14:10:22 +0000 (09:10 -0500)
Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/orchestra/run.py
teuthology/orchestra/test/test_run.py

index 7ff637c0fb3e9cd2f1b5ff2a6d1e8f6eaa922a97..2fd8f250332492a9b40dd7b38b245d9292a23367 100644 (file)
@@ -89,7 +89,7 @@ def execute(client, args, name=None):
         host = name
     else:
         (host, port) = client.get_transport().getpeername()
-    log.info('Running [{h}]: {cmd!r}'.format(h=host, cmd=cmd))
+    log.getChild(host).info(u"Running: {cmd!r}".format(cmd=cmd))
 
     (in_, out, err) = client.exec_command(cmd)
 
@@ -124,7 +124,7 @@ def execute(client, args, name=None):
     return r
 
 
-def copy_to_log(f, logger, host, loglevel=logging.INFO):
+def copy_to_log(f, logger, loglevel=logging.INFO):
     """
     Interface to older xreadlines api.
     """
@@ -138,7 +138,7 @@ def copy_to_log(f, logger, host, loglevel=logging.INFO):
         line = line.rstrip()
         # Second part of work-around for http://tracker.ceph.com/issues/8313
         line = unicode(line, 'utf-8', 'replace').encode('utf-8')
-        logger.log(loglevel, '[' + host + ']: ' + line)
+        logger.log(loglevel, line)
 
 
 def copy_and_close(src, fdst):
@@ -152,7 +152,7 @@ def copy_and_close(src, fdst):
     fdst.close()
 
 
-def copy_file_to(f, dst, host):
+def copy_file_to(f, dst):
     """
     Copy file
     :param f: file to be copied.
@@ -163,10 +163,9 @@ def copy_file_to(f, dst, host):
         # looks like a Logger to me; not using isinstance to make life
         # easier for unit tests
         handler = copy_to_log
-        return handler(f, dst, host)
     else:
         handler = shutil.copyfileobj
-        return handler(f, dst)
+    return handler(f, dst)
 
 
 class CommandFailedError(Exception):
@@ -332,8 +331,8 @@ def run(
     g_err = None
     if stderr is not PIPE:
         if stderr is None:
-            stderr = logger.getChild('err')
-        g_err = gevent.spawn(copy_file_to, r.stderr, stderr, name)
+            stderr = logger.getChild(name).getChild('err')
+        g_err = gevent.spawn(copy_file_to, r.stderr, stderr)
         r.stderr = stderr
     else:
         assert not wait, \
@@ -342,8 +341,8 @@ def run(
     g_out = None
     if stdout is not PIPE:
         if stdout is None:
-            stdout = logger.getChild('out')
-        g_out = gevent.spawn(copy_file_to, r.stdout, stdout, name)
+            stdout = logger.getChild(name).getChild('out')
+        g_out = gevent.spawn(copy_file_to, r.stdout, stdout)
         r.stdout = stdout
     else:
         assert not wait, \
index 96cee4417a3fff70f05b41cead54866a30db0024..534ebc280ace80a579eb5bea02994e95c7885b38 100644 (file)
@@ -29,13 +29,15 @@ class TestRun(object):
         out.expects('xreadlines').with_args().returns(['foo', 'bar'])
         err.expects('xreadlines').with_args().returns(['bad'])
         logger = fudge.Fake('logger')
+        log_host = fudge.Fake('log_host')
+        logger.expects('getChild').with_args('HOST').returns(log_host)
         log_err = fudge.Fake('log_err')
-        logger.expects('getChild').with_args('err').returns(log_err)
-        log_err.expects('log').with_args(logging.INFO, '[HOST]: bad')
+        log_host.expects('getChild').with_args('err').returns(log_err)
+        log_err.expects('log').with_args(logging.INFO, 'bad')
         log_out = fudge.Fake('log_out')
-        logger.expects('getChild').with_args('out').returns(log_out)
-        log_out.expects('log').with_args(logging.INFO, '[HOST]: foo')
-        log_out.expects('log').with_args(logging.INFO, '[HOST]: bar')
+        log_host.expects('getChild').with_args('out').returns(log_out)
+        log_out.expects('log').with_args(logging.INFO, 'foo')
+        log_out.expects('log').with_args(logging.INFO, 'bar')
         channel = fudge.Fake('channel')
         out.has_attr(channel=channel)
         channel.expects('recv_exit_status').with_args().returns(0)
@@ -68,9 +70,11 @@ class TestRun(object):
         out.expects('read').with_args().returns('')
         err.expects('xreadlines').with_args().returns(['bad'])
         logger = fudge.Fake('logger')
+        log_host = fudge.Fake('log_host')
+        logger.expects('getChild').with_args('HOST').returns(log_host)
         log_err = fudge.Fake('log_err')
-        logger.expects('getChild').with_args('err').returns(log_err)
-        log_err.expects('log').with_args(logging.INFO, '[HOST]: bad')
+        log_host.expects('getChild').with_args('err').returns(log_err)
+        log_err.expects('log').with_args(logging.INFO, 'bad')
         channel = fudge.Fake('channel')
         out.has_attr(channel=channel)
         channel.expects('recv_exit_status').with_args().returns(0)