From: Tommi Virtanen Date: Thu, 2 Jun 2011 22:04:01 +0000 (-0700) Subject: Move interactive and cfuse into tasks. X-Git-Tag: 1.1.0~3061 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ce5f0e7121d2cde8682129e44db15ac4c61f18af;p=teuthology.git Move interactive and cfuse into tasks. --- diff --git a/dbench.py b/dbench.py index 23721c462..2eaaa4857 100644 --- 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(): diff --git a/requirements.txt b/requirements.txt index b418bf8a2..c44846a98 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ -e git+https://github.com/tv42/orchestra.git#egg=orchestra configobj PyYAML +bunch >=1.0.0 diff --git a/setup.py b/setup.py index 9eff33d4d..a2d408c8f 100644 --- 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 index 000000000..8c8184535 --- /dev/null +++ b/teuthology/run_tasks.py @@ -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 index 000000000..e69de29bb diff --git a/teuthology/task/cfuse.py b/teuthology/task/cfuse.py new file mode 100644 index 000000000..8017fcf44 --- /dev/null +++ b/teuthology/task/cfuse.py @@ -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 index 000000000..820ef224b --- /dev/null +++ b/teuthology/task/interactive.py @@ -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 index 000000000..473986452 --- /dev/null +++ b/teuthology/task/nop.py @@ -0,0 +1,5 @@ +def task(ctx, config): + """ + This task does nothing. + """ + pass