]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tasks/workunit: work with roles that include cluster
authorJosh Durgin <jdurgin@redhat.com>
Thu, 24 Mar 2016 02:31:48 +0000 (19:31 -0700)
committerJosh Durgin <jdurgin@redhat.com>
Fri, 20 May 2016 18:08:53 +0000 (11:08 -0700)
Signed-off-by: Josh Durgin <jdurgin@redhat.com>
(cherry picked from commit 1b2087231d36bc05db247cccbe2d217cde771fad)

tasks/workunit.py

index 86bcdb5b9f6456e73c59d1f338328cdbb784e95b..847b56f0e171a8429bcdf40cd5b05133b1ccabff 100644 (file)
@@ -5,6 +5,8 @@ import logging
 import pipes
 import os
 
+from util import get_remote_for_role
+
 from teuthology import misc
 from teuthology.config import config as teuth_config
 from teuthology.orchestra.run import CommandFailedError
@@ -13,8 +15,6 @@ from teuthology.orchestra import run
 
 log = logging.getLogger(__name__)
 
-CLIENT_PREFIX = 'client.'
-
 
 def task(ctx, config):
     """
@@ -59,6 +59,15 @@ def task(ctx, config):
               BAZ: quux
             timeout: 3h
 
+    This task supports roles that include a ceph cluster, e.g.::
+
+        tasks:
+        - ceph:
+        - workunit:
+            clients:
+              backup.client.0: [foo]
+              client.1: [bar] # cluster is implicitly 'ceph'
+
     :param ctx: Context
     :param config: Configuration
     """
@@ -94,7 +103,7 @@ def task(ctx, config):
         if role == "all":
             continue
 
-        assert role.startswith(CLIENT_PREFIX)
+        assert 'client' in role
         created_mnt_dir = _make_scratch_dir(ctx, role, config.get('subdir'))
         created_mountpoint[role] = created_mnt_dir
 
@@ -116,6 +125,20 @@ def task(ctx, config):
                               config.get('subdir'), timeout=timeout)
 
 
+def _client_mountpoint(ctx, cluster, id_):
+    """
+    Returns the path to the expected mountpoint for workunits running
+    on some kind of filesystem.
+    """
+    # for compatibility with tasks like ceph-fuse that aren't cluster-aware yet,
+    # only include the cluster name in the dir if the cluster is not 'ceph'
+    if cluster == 'ceph':
+        dir_ = 'mnt.{0}'.format(id_)
+    else:
+        dir_ = 'mnt.{0}.{1}'.format(cluster, id_)
+    return os.path.join(misc.get_testdir(ctx), dir_)
+
+
 def _delete_dir(ctx, role, created_mountpoint):
     """
     Delete file used by this role, and delete the directory that this
@@ -124,11 +147,9 @@ def _delete_dir(ctx, role, created_mountpoint):
     :param ctx: Context
     :param role: "role.#" where # is used for the role id.
     """
-    testdir = misc.get_testdir(ctx)
-    id_ = role[len(CLIENT_PREFIX):]
-    (remote,) = ctx.cluster.only(role).remotes.iterkeys()
-    mnt = os.path.join(testdir, 'mnt.{id}'.format(id=id_))
-    # Is there any reason why this is not: join(mnt, role) ?
+    cluster, _, id_ = misc.split_role(role)
+    remote = get_remote_for_role(ctx, role)
+    mnt = _client_mountpoint(ctx, cluster, id_)
     client = os.path.join(mnt, 'client.{id}'.format(id=id_))
 
     # Remove the directory inside the mount where the workunit ran
@@ -165,11 +186,10 @@ def _make_scratch_dir(ctx, role, subdir):
     :param subdir: use this subdir (False if not used)
     """
     created_mountpoint = False
-    id_ = role[len(CLIENT_PREFIX):]
-    log.debug("getting remote for {id} role {role_}".format(id=id_, role_=role))
-    (remote,) = ctx.cluster.only(role).remotes.iterkeys()
+    cluster, _, id_ = misc.split_role(role)
+    remote = get_remote_for_role(ctx, role)
     dir_owner = remote.user
-    mnt = os.path.join(misc.get_testdir(ctx), 'mnt.{id}'.format(id=id_))
+    mnt = _client_mountpoint(ctx, cluster, id_)
     # if neither kclient nor ceph-fuse are required for a workunit,
     # mnt may not exist. Stat and create the directory if it doesn't.
     try:
@@ -237,26 +257,24 @@ def _spawn_on_all_clients(ctx, refspec, tests, env, subdir, timeout=None):
 
     See run_tests() for parameter documentation.
     """
-    client_generator = misc.all_roles_of_type(ctx.cluster, 'client')
-    client_remotes = list()
-
+    is_client = misc.is_type('client')
+    client_remotes = {}
     created_mountpoint = {}
-    for client in client_generator:
-        (client_remote,) = ctx.cluster.only('client.{id}'.format(id=client)).remotes.iterkeys()
-        client_remotes.append((client_remote, 'client.{id}'.format(id=client)))
-        created_mountpoint[client] = _make_scratch_dir(ctx, "client.{id}".format(id=client), subdir)
+    for remote, roles_for_host in ctx.cluster.remotes.items():
+        for role in roles_for_host:
+            if is_client(role):
+                client_remotes[role] = remote
+                created_mountpoint[role] = _make_scratch_dir(ctx, role, subdir)
 
     for unit in tests:
         with parallel() as p:
-            for remote, role in client_remotes:
+            for role, remote in client_remotes.items():
                 p.spawn(_run_tests, ctx, refspec, role, [unit], env, subdir,
                         timeout=timeout)
 
     # cleanup the generated client directories
-    client_generator = misc.all_roles_of_type(ctx.cluster, 'client')
-    for client in client_generator:
-        _delete_dir(ctx, 'client.{id}'.format(id=client), created_mountpoint[client])
-
+    for role, _ in client_remotes.items():
+        _delete_dir(ctx, role, created_mountpoint[role])
 
 def _run_tests(ctx, refspec, role, tests, env, subdir=None, timeout=None):
     """
@@ -278,10 +296,10 @@ def _run_tests(ctx, refspec, role, tests, env, subdir=None, timeout=None):
     """
     testdir = misc.get_testdir(ctx)
     assert isinstance(role, basestring)
-    assert role.startswith(CLIENT_PREFIX)
-    id_ = role[len(CLIENT_PREFIX):]
-    (remote,) = ctx.cluster.only(role).remotes.iterkeys()
-    mnt = os.path.join(testdir, 'mnt.{id}'.format(id=id_))
+    cluster, type_, id_ = misc.split_role(role)
+    assert type_ == 'client'
+    remote = get_remote_for_role(ctx, role)
+    mnt = _client_mountpoint(ctx, cluster, id_)
     # subdir so we can remove and recreate this a lot without sudo
     if subdir is None:
         scratch_tmp = os.path.join(mnt, 'client.{id}'.format(id=id_), 'tmp')
@@ -359,6 +377,7 @@ def _run_tests(ctx, refspec, role, tests, env, subdir=None, timeout=None):
                     run.Raw('CEPH_CLI_TEST_DUP_COMMAND=1'),
                     run.Raw('CEPH_REF={ref}'.format(ref=refspec)),
                     run.Raw('TESTDIR="{tdir}"'.format(tdir=testdir)),
+                    run.Raw('CEPH_ARGS="--cluster {0}"'.format(cluster)),
                     run.Raw('CEPH_ID="{id}"'.format(id=id_)),
                     run.Raw('PATH=$PATH:/usr/sbin')
                 ]