]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Move interactive and cfuse into tasks.
authorTommi Virtanen <tommi.virtanen@dreamhost.com>
Thu, 2 Jun 2011 22:04:01 +0000 (15:04 -0700)
committerTommi Virtanen <tommi.virtanen@dreamhost.com>
Thu, 2 Jun 2011 22:04:01 +0000 (15:04 -0700)
dbench.py
requirements.txt
setup.py
teuthology/run_tasks.py [new file with mode: 0644]
teuthology/task/__init__.py [new file with mode: 0644]
teuthology/task/cfuse.py [new file with mode: 0644]
teuthology/task/interactive.py [new file with mode: 0644]
teuthology/task/nop.py [new file with mode: 0644]

index 23721c4625be6ef8b8eec596a23099ee3e98fcf0..2eaaa485774f8ea1702424ac3eb4621c10507e50 100644 (file)
--- a/dbench.py
+++ b/dbench.py
@@ -3,6 +3,7 @@ from orchestra import monkey; monkey.patch_all()
 
 from cStringIO import StringIO
 
+import bunch
 import json
 import logging
 import os
@@ -410,45 +411,6 @@ if __name__ == '__main__':
         remote=mon0_remote,
         )
 
-
-    log.info('Mounting cfuse clients...')
-    cfuse_daemons = {}
-    for idx, roles_for_host in enumerate(ROLES):
-        for id_ in teuthology.roles_of_type(roles_for_host, 'client'):
-            mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
-            run.run(
-                client=connections[idx],
-                args=[
-                    'mkdir',
-                    '--',
-                    mnt,
-                    ],
-                )
-            proc = run.run(
-                client=connections[idx],
-                args=[
-                    '/tmp/cephtest/daemon-helper',
-                    '/tmp/cephtest/binary/usr/local/bin/cfuse',
-                    '-f',
-                    '--name', 'client.{id}'.format(id=id_),
-                    '-c', '/tmp/cephtest/ceph.conf',
-                    # TODO cfuse doesn't understand dash dash '--',
-                    mnt,
-                    ],
-                logger=log.getChild('cfuse.{id}'.format(id=id_)),
-                stdin=run.PIPE,
-                wait=False,
-                )
-            cfuse_daemons[id_] = proc
-    for idx, roles_for_host in enumerate(ROLES):
-        for id_ in teuthology.roles_of_type(roles_for_host, 'client'):
-            mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
-            teuthology.wait_until_fuse_mounted(
-                remote=remotes[idx],
-                fuse=cfuse_daemons[id_],
-                mountpoint=mnt,
-                )
-
     # TODO kclient mount/umount
 
     # TODO rbd
@@ -528,36 +490,17 @@ if __name__ == '__main__':
                 ],
             )
 
-    import code
-    import readline
-    import rlcompleter
-    rlcompleter.__name__ # silence pyflakes
-    readline.parse_and_bind('tab: complete')
-    code.interact(
-        banner='Ceph test interactive mode, press control-D to exit...',
-        # TODO simplify this
-        local=dict(
-            config=config,
-            ROLES=ROLES,
-            connections=connections,
-            cluster=cluster,
-            ),
+    ctx = bunch.Bunch(
+        cluster=cluster,
+        )
+    from teuthology.run_tasks import run_tasks
+    run_tasks(
+        tasks=[
+            {'cfuse': ['client.0']},
+            {'interactive': None},
+            ],
+        ctx=ctx,
         )
-
-    log.info('Unmounting cfuse clients...')
-    for idx, roles_for_host in enumerate(ROLES):
-        for id_ in teuthology.roles_of_type(roles_for_host, 'client'):
-            mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
-            run.run(
-                client=connections[idx],
-                args=[
-                    'fusermount',
-                    '-u',
-                    mnt,
-                    ],
-                )
-    run.wait(cfuse_daemons.itervalues())
-
 
     log.info('Shutting down mds daemons...')
     for id_, proc in mds_daemons.iteritems():
index b418bf8a25fd108921e4406f9281a61b27c3abd8..c44846a98ea101e48a29849d895154e83634e69b 100644 (file)
@@ -1,3 +1,4 @@
 -e git+https://github.com/tv42/orchestra.git#egg=orchestra
 configobj
 PyYAML
+bunch >=1.0.0
index 9eff33d4ded664a64f2da509d986d37ba4bbaf23..a2d408c8f0ce84e390a9285922b6978c1ee3bbbf 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -16,6 +16,7 @@ setup(
         'orchestra',
         'configobj',
         'PyYAML',
+        'bunch >=1.0.0',
         ],
 
     )
diff --git a/teuthology/run_tasks.py b/teuthology/run_tasks.py
new file mode 100644 (file)
index 0000000..8c81845
--- /dev/null
@@ -0,0 +1,47 @@
+import sys
+import logging
+
+log = logging.getLogger(__name__)
+
+def _run_one_task(taskname, **kwargs):
+    parent = __import__('teuthology.task', globals(), locals(), [taskname], 0)
+    mod = getattr(parent, taskname)
+    fn = getattr(mod, 'task')
+    return fn(**kwargs)
+
+def run_tasks(tasks, ctx):
+    stack = []
+    try:
+        for taskdict in tasks:
+            try:
+                ((taskname, config),) = taskdict.iteritems()
+            except ValueError:
+                raise RuntimeError('Invalid task definition: %s' % taskdict)
+            log.info('Running task %s...', taskname)
+            manager = _run_one_task(taskname, ctx=ctx, config=config)
+            if hasattr(manager, '__enter__'):
+                manager.__enter__()
+                stack.append(manager)
+    except:
+        log.exception('Saw exception from tasks')
+    finally:
+        try:
+            exc_info = sys.exc_info()
+            while stack:
+                manager = stack.pop()
+                log.debug('Unwinding manager %s', manager)
+                try:
+                    suppress = manager.__exit__(*exc_info)
+                except:
+                    log.exception('Manager failed: %s', manager)
+                else:
+                    if suppress:
+                        sys.exc_clear()
+                        exc_info = (None, None, None)
+
+            if exc_info != (None, None, None):
+                log.debug('Exception was not quenched, raising %s', exc_info[1])
+                raise exc_info[0], exc_info[1], exc_info[2]
+        finally:
+            # be careful about cyclic references
+            del exc_info
diff --git a/teuthology/task/__init__.py b/teuthology/task/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/teuthology/task/cfuse.py b/teuthology/task/cfuse.py
new file mode 100644 (file)
index 0000000..8017fcf
--- /dev/null
@@ -0,0 +1,78 @@
+import contextlib
+import logging
+import os
+
+from teuthology import misc as teuthology
+from orchestra import run
+
+log = logging.getLogger(__name__)
+
+@contextlib.contextmanager
+def task(ctx, config):
+    log.info('Mounting cfuse clients...')
+    assert isinstance(config, list), \
+        "task fuse automatic configuration not supported yet, list all clients"
+    cfuse_daemons = {}
+
+    for role in config:
+        assert isinstance(role, basestring)
+        PREFIX = 'client.'
+        assert role.startswith(PREFIX)
+        id_ = role[len(PREFIX):]
+        (remote,) = ctx.cluster.only(role).remotes.iterkeys()
+        mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
+        remote.run(
+            args=[
+                'mkdir',
+                '--',
+                mnt,
+                ],
+            )
+        proc = remote.run(
+            args=[
+                '/tmp/cephtest/daemon-helper',
+                '/tmp/cephtest/binary/usr/local/bin/cfuse',
+                '-f',
+                '--name', 'client.{id}'.format(id=id_),
+                '-c', '/tmp/cephtest/ceph.conf',
+                # TODO cfuse doesn't understand dash dash '--',
+                mnt,
+                ],
+            logger=log.getChild('cfuse.{id}'.format(id=id_)),
+            stdin=run.PIPE,
+            wait=False,
+            )
+        cfuse_daemons[id_] = proc
+
+    for role in config:
+        assert isinstance(role, basestring)
+        PREFIX = 'client.'
+        assert role.startswith(PREFIX)
+        id_ = role[len(PREFIX):]
+        (remote,) = ctx.cluster.only(role).remotes.iterkeys()
+        mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
+        teuthology.wait_until_fuse_mounted(
+            remote=remote,
+            fuse=cfuse_daemons[id_],
+            mountpoint=mnt,
+            )
+
+    try:
+        yield
+    finally:
+        log.info('Unmounting cfuse clients...')
+        for role in config:
+            assert isinstance(role, basestring)
+            PREFIX = 'client.'
+            assert role.startswith(PREFIX)
+            id_ = role[len(PREFIX):]
+            (remote,) = ctx.cluster.only(role).remotes.iterkeys()
+            mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
+            remote.run(
+                args=[
+                    'fusermount',
+                    '-u',
+                    mnt,
+                    ],
+                )
+        run.wait(cfuse_daemons.itervalues())
diff --git a/teuthology/task/interactive.py b/teuthology/task/interactive.py
new file mode 100644 (file)
index 0000000..820ef22
--- /dev/null
@@ -0,0 +1,16 @@
+import code
+import readline
+import rlcompleter
+rlcompleter.__name__ # silence pyflakes
+
+readline.parse_and_bind('tab: complete')
+
+def task(ctx, config):
+    code.interact(
+        banner='Ceph test interactive mode, use ctx to interact with the cluster, press control-D to exit...',
+        # TODO simplify this
+        local=dict(
+            ctx=ctx,
+            config=config,
+            ),
+        )
diff --git a/teuthology/task/nop.py b/teuthology/task/nop.py
new file mode 100644 (file)
index 0000000..4739864
--- /dev/null
@@ -0,0 +1,5 @@
+def task(ctx, config):
+    """
+    This task does nothing.
+    """
+    pass