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)
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.
"""
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):
fdst.close()
-def copy_file_to(f, dst, host):
+def copy_file_to(f, dst):
"""
Copy file
:param f: file to be copied.
# 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):
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, \
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, \
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)
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)