]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
console: add console task
authorSage Weil <sage@inktank.com>
Mon, 1 Oct 2012 04:08:41 +0000 (21:08 -0700)
committerSage Weil <sage@inktank.com>
Mon, 1 Oct 2012 04:08:41 +0000 (21:08 -0700)
Log the sol console of every target to a file in the archive dir.

teuthology/task/console.py [new file with mode: 0644]

diff --git a/teuthology/task/console.py b/teuthology/task/console.py
new file mode 100644 (file)
index 0000000..01b0ef1
--- /dev/null
@@ -0,0 +1,64 @@
+import contextlib
+import logging
+import os
+import re
+import subprocess
+
+from teuthology import misc as teuthology
+from ..orchestra import run
+
+log = logging.getLogger(__name__)
+
+@contextlib.contextmanager
+def task(ctx, config):
+    if config is None:
+        config = {}
+        for _, roles_for_host in ctx.cluster.remotes.iteritems():
+            config[roles_for_host[0]] = {}
+    assert isinstance(config, dict)
+
+    log.info('Console config is %s', config)
+
+    procs = {}
+    if ctx.archive is not None:
+        path = os.path.join(ctx.archive, 'console')
+        os.makedirs(path)
+
+        for role in config.iterkeys():
+            # figure out ipmi host
+            (rem, ) = ctx.cluster.only(role).remotes.keys()
+            log.info(' role %s remote %s', role, rem)
+            match = re.search('@((plana|burnupi)\d\d)\.', rem.name);
+            if match:
+                host = match.group(1) + '.ipmi.sepia.ceph.com'
+                htype = match.group(2)
+                log.info('Attaching to console on %s', host)
+                subprocess.call([
+                        'ipmitool',
+                        '-I', 'lanplus',
+                        '-U', htype + 'temp',
+                        '-P', htype + 'temp',
+                        '-H', host,
+                        'sol', 'deactivate'
+                        ])
+                procs[rem] = subprocess.Popen(
+                    args=[
+                        'ipmitool',
+                        '-I', 'lanplus',
+                        '-U', htype + 'temp',
+                        '-P', htype + 'temp',
+                        '-H', host,
+                        'sol', 'activate'
+                        ],
+                    stdout=open(os.path.join(path, host), 'w'),
+                    stderr=open(os.devnull, 'w'),
+                    stdin=subprocess.PIPE,
+                    )
+        
+    try:
+        yield
+    finally:
+        for rem, proc in procs.iteritems():
+            log.info('Terminating %s console', rem.name)
+            proc.stdin.write('~.\n')
+            proc.wait()