]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Archive syslog messages while the test was in progress.
authorTommi Virtanen <tommi.virtanen@dreamhost.com>
Mon, 20 Jun 2011 20:19:08 +0000 (13:19 -0700)
committerTommi Virtanen <tommi.virtanen@dreamhost.com>
Mon, 20 Jun 2011 21:31:41 +0000 (14:31 -0700)
teuthology/misc.py
teuthology/run.py
teuthology/task/internal.py

index 25f77726ada8d3e4135bd043900c055578fd8c9e..59e3f9afb263d5c46a391ef43ac12a51726f2e49 100644 (file)
@@ -197,6 +197,18 @@ def write_file(remote, path, data):
         stdin=data,
         )
 
+def sudo_write_file(remote, path, data):
+    remote.run(
+        args=[
+            'sudo',
+            'python',
+            '-c',
+            'import shutil, sys; shutil.copyfileobj(sys.stdin, file(sys.argv[1], "wb"))',
+            path,
+            ],
+        stdin=data,
+        )
+
 def get_file(remote, path):
     """
     Read a file from remote host into memory.
index c27e4a9b053d3cc2164217c876e9655e99bc8e26..1c0baaaeb898967af101434c36e1c41533c4d2cc 100644 (file)
@@ -97,6 +97,7 @@ def main():
         {'internal.base': None},
         {'internal.archive': None},
         {'internal.coredump': None},
+        {'internal.syslog': None},
         ]
 
     from teuthology.run_tasks import run_tasks
index aa0b71afb645f1a20a97ceab1172cfe0d2e4ac59..23c0e776758d0f26ca4d3b1e16d66acbae73c20c 100644 (file)
@@ -5,6 +5,7 @@ import logging
 import os
 import tarfile
 
+from teuthology import misc as teuthology
 from teuthology import safepath
 from orchestra import run
 
@@ -183,3 +184,95 @@ def coredump(ctx, config):
             if r.stdout.getvalue() != 'OK\n':
                 log.warning('Found coredumps on %s, flagging run as failed', remote)
                 ctx.summary['success'] = False
+
+@contextlib.contextmanager
+def syslog(ctx, config):
+    if ctx.archive is None:
+        # disable this whole feature if we're not going to archive the data anyway
+        yield
+        return
+
+    log.info('Starting syslog monitoring...')
+
+    run.wait(
+        ctx.cluster.run(
+            args=[
+                'mkdir', '-m0755', '--',
+                '/tmp/cephtest/archive/syslog',
+                ],
+            wait=False,
+            )
+        )
+
+    CONF = '/etc/rsyslog.d/80-cephtest.conf'
+    conf_fp = StringIO("""
+kern.* -/tmp/cephtest/archive/syslog/kern.log;RSYSLOG_FileFormat
+*.*;kern.none -/tmp/cephtest/archive/syslog/misc.log;RSYSLOG_FileFormat
+""")
+    try:
+        for rem in ctx.cluster.remotes.iterkeys():
+            teuthology.sudo_write_file(
+                remote=rem,
+                path=CONF,
+                data=conf_fp,
+                )
+            conf_fp.seek(0)
+        run.wait(
+            ctx.cluster.run(
+                args=[
+                    'sudo',
+                    'initctl',
+                    # a mere reload (SIGHUP) doesn't seem to make
+                    # rsyslog open the files
+                    'restart',
+                    'rsyslog',
+                    ],
+                wait=False,
+                ),
+            )
+
+        yield
+    finally:
+        log.info('Shutting down syslog monitoring...')
+
+        run.wait(
+            ctx.cluster.run(
+                args=[
+                    'sudo',
+                    'rm',
+                    '-f',
+                    '--',
+                    CONF,
+                    run.Raw('&&'),
+                    'sudo',
+                    'initctl',
+                    'restart',
+                    'rsyslog',
+                    ],
+                wait=False,
+                ),
+            )
+        # race condition: nothing actually says rsyslog had time to
+        # flush the file fully. oh well.
+
+        log.info('Compressing syslogs...')
+        run.wait(
+            ctx.cluster.run(
+                args=[
+                    'find',
+                    '/tmp/cephtest/archive/syslog',
+                    '-name',
+                    '*.log',
+                    '-print0',
+                    run.Raw('|'),
+                    'xargs',
+                    '-0',
+                    '--no-run-if-empty',
+                    '--',
+                    'bzip2',
+                    '-9',
+                    '--',
+                    ],
+                wait=False,
+                ),
+            )