From: Josh Durgin Date: Thu, 24 Mar 2016 02:31:48 +0000 (-0700) Subject: tasks/workunit: work with roles that include cluster X-Git-Tag: v11.1.1~58^2^2~212^2~25 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1b2087231d36bc05db247cccbe2d217cde771fad;p=ceph.git tasks/workunit: work with roles that include cluster Signed-off-by: Josh Durgin --- diff --git a/tasks/workunit.py b/tasks/workunit.py index 86bcdb5b9f64..847b56f0e171 100644 --- a/tasks/workunit.py +++ b/tasks/workunit.py @@ -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') ]