]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Make cfuse and kclient default to all clients.
authorTommi Virtanen <tommi.virtanen@dreamhost.com>
Thu, 16 Jun 2011 23:07:59 +0000 (16:07 -0700)
committerTommi Virtanen <tommi.virtanen@dreamhost.com>
Thu, 16 Jun 2011 23:09:50 +0000 (16:09 -0700)
teuthology/misc.py
teuthology/task/cfuse.py
teuthology/task/kclient.py

index d5288eece8e853af7c2cd9c15959ccc12074539f..5b8fc26472f96f48704e3f8271d3ea16461299f0 100644 (file)
@@ -122,6 +122,15 @@ def roles_of_type(roles_for_host, type_):
         id_ = name[len(prefix):]
         yield id_
 
+def all_roles_of_type(cluster, type_):
+    prefix = '{type}.'.format(type=type_)
+    for _, roles_for_host in cluster.remotes.iteritems():
+        for name in roles_for_host:
+            if not name.startswith(prefix):
+                continue
+            id_ = name[len(prefix):]
+            yield id_
+
 def is_type(type_):
     """
     Returns a matcher function for whether role is of type given.
index 31553378b75d696d684103c63953de3fbd68b1ff..23e2636903392b1c33687904ca2a43c4b1b25c18 100644 (file)
@@ -7,31 +7,52 @@ from orchestra import run
 
 log = logging.getLogger(__name__)
 
+def get_clients(ctx, roles):
+    for role in roles:
+        assert isinstance(role, basestring)
+        PREFIX = 'client.'
+        assert role.startswith(PREFIX)
+        id_ = role[len(PREFIX):]
+        (remote,) = ctx.cluster.only(role).remotes.iterkeys()
+        yield (id_, remote)
+
+
 @contextlib.contextmanager
 def task(ctx, config):
     """
     Mount/unmount a ``cfuse`` client.
 
-    The config is expected to be a list of clients to do this
-    operation on. This lets you e.g. set up one client with ``cfuse``
-    and another with ``kclient``.
+    The config is optional and defaults to mounting on all clients. If
+    a config is given, it is expected to be a list of clients to do
+    this operation on. This lets you e.g. set up one client with
+    ``cfuse`` and another with ``kclient``.
+
+    Example that mounts all clients::
+
+        tasks:
+        - ceph:
+        - cfuse:
+        - interactive:
+
+    Example that uses both ``kclient` and ``cfuse``::
 
         tasks:
         - ceph:
         - cfuse: [client.0]
+        - kclient: [client.1]
         - interactive:
     """
     log.info('Mounting cfuse clients...')
-    assert isinstance(config, list), \
-        "task fuse automatic configuration not supported yet, list all clients"
+    assert config is None or isinstance(config, list), \
+        "task cfuse got invalid config"
     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()
+    if config is None:
+        config = ['client.{id}'.format(id=id_)
+                  for id_ in teuthology.all_roles_of_type(ctx.cluster, 'client')]
+    clients = list(get_clients(ctx=ctx, roles=config))
+
+    for id_, remote in clients:
         mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
         remote.run(
             args=[
@@ -59,12 +80,7 @@ def task(ctx, config):
             )
         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()
+    for id_, remote in clients:
         mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
         teuthology.wait_until_fuse_mounted(
             remote=remote,
@@ -76,12 +92,7 @@ def task(ctx, config):
         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()
+        for id_, remote in clients:
             mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
             remote.run(
                 args=[
@@ -92,12 +103,7 @@ def task(ctx, config):
                 )
         run.wait(cfuse_daemons.itervalues())
 
-        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()
+        for id_, remote in clients:
             mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
             remote.run(
                 args=[
index 2039899d8e4c9991f081ad5cbe7dacce8770e2b9..70158ac087986318bba04329f54c4da7a1ded372 100644 (file)
@@ -6,14 +6,25 @@ from teuthology import misc as teuthology
 
 log = logging.getLogger(__name__)
 
+def get_clients(ctx, roles):
+    for role in roles:
+        assert isinstance(role, basestring)
+        PREFIX = 'client.'
+        assert role.startswith(PREFIX)
+        id_ = role[len(PREFIX):]
+        (remote,) = ctx.cluster.only(role).remotes.iterkeys()
+        yield (id_, remote)
+
+
 @contextlib.contextmanager
 def task(ctx, config):
     """
     Mount/unmount a ``kernel`` client.
 
-    The config is expected to be a list of clients to do this
-    operation on. This lets you e.g. set up one client with ``cfuse``
-    and another with ``kclient``.
+    The config is optional and defaults to mounting on all clients. If
+    a config is given, it is expected to be a list of clients to do
+    this operation on. This lets you e.g. set up one client with
+    ``cfuse`` and another with ``kclient``.
 
         tasks:
         - ceph:
@@ -22,23 +33,23 @@ def task(ctx, config):
         - interactive:
     """
     log.info('Mounting kernel clients...')
-    assert isinstance(config, list), \
-        "task kclient automatic configuration not supported yet, list all clients"
+    assert config is None or isinstance(config, list), \
+        "task kclient got invalid config"
 
-    for role in config:
-        log.debug('Mounting client {role}...'.format(role=role))
-        assert isinstance(role, basestring)
-        PREFIX = 'client.'
-        assert role.startswith(PREFIX)
-        id_ = role[len(PREFIX):]
-        (remote,) = ctx.cluster.only(role).remotes.iterkeys()
+    if config is None:
+        config = ['client.{id}'.format(id=id_)
+                  for id_ in teuthology.all_roles_of_type(ctx.cluster, 'client')]
+    clients = list(get_clients(ctx=ctx, roles=config))
+
+    for id_, remote in clients:
+        log.debug('Mounting client client.{id}...'.format(id=id_))
         remotes_and_roles = ctx.cluster.remotes.items()
         roles = [roles for (remote, roles) in remotes_and_roles]
         ips = [host for (host, port) in (remote.ssh.get_transport().getpeername() for (remote, roles) in remotes_and_roles)]
         mons = teuthology.get_mons(roles, ips).values()
         mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
-        secret = '/tmp/cephtest/data/{role}.secret'.format(role=role)
-        teuthology.write_secret_file(remote, role, secret)
+        secret = '/tmp/cephtest/data/client.{id}.secret'.format(id=id_)
+        teuthology.write_secret_file(remote, 'client.{id}'.format(id=id_), secret)
 
         remote.run(
             args=[
@@ -67,13 +78,8 @@ def task(ctx, config):
         yield
     finally:
         log.info('Unmounting kernel clients...')
-        for role in config:
-            log.debug('Unmounting client {role}...'.format(role=role))
-            assert isinstance(role, basestring)
-            PREFIX = 'client.'
-            assert role.startswith(PREFIX)
-            id_ = role[len(PREFIX):]
-            (remote,) = ctx.cluster.only(role).remotes.iterkeys()
+        for id_, remote in clients:
+            log.debug('Unmounting client client.{id}...'.format(id=id_))
             mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
             remote.run(
                 args=[