From e45109b6457a1025b7f5cb3fe1f5cf3d96dfeb48 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Wed, 7 Sep 2011 16:54:24 -0700 Subject: [PATCH] rbd: allow specifying all clients --- teuthology/task/rbd.py | 53 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/teuthology/task/rbd.py b/teuthology/task/rbd.py index ed8062ea7d..aeed5b13a9 100644 --- a/teuthology/task/rbd.py +++ b/teuthology/task/rbd.py @@ -340,18 +340,36 @@ def mount(ctx, config): ] ) +def _normalize_config(cluster, config): + """ + Returns a configuration that can be used by rbd subtasks. + + This is either a list of clients or a dict mapping clients + to image options. "all" is converted to individual clients. + """ + assert isinstance(config, list) or isinstance(config, dict), \ + "task rbd only supports a list or dict for configuration" + if isinstance(config, list) or 'all' not in config: + return config + norm_config = {} + assert len(config) == 1, \ + "rbd config cannot have 'all' and specific clients listed" + for client in teuthology.all_roles_of_type(cluster, 'client'): + norm_config['client.{id}'.format(id=client)] = config['all'] + return norm_config + @contextlib.contextmanager def task(ctx, config): """ Create and mount an rbd image. - For example:: + For example, you can specify which clients to run on:: tasks: - ceph: - rbd: [client.0, client.1] - Different image options:: + There are a few image options:: tasks: - ceph: @@ -361,23 +379,38 @@ def task(ctx, config): image_name: foo image_size: 2048 fs_type: xfs + + To use default options on all clients:: + + tasks: + - ceph: + - rbd: + all: + + To create 20GiB images and format them with xfs on all clients:: + + tasks: + - ceph: + - rbd: + all: + image_size: 20480 + fs_type: xfs """ - assert isinstance(config, list) or isinstance(config, dict), \ - "task rbd only supports a list or dict for configuration" - if isinstance(config, dict): + norm_config = _normalize_config(ctx.cluster, config) + if isinstance(norm_config, dict): role_images = {} - for role, properties in config.iteritems(): + for role, properties in norm_config.iteritems(): if properties is None: properties = {} role_images[role] = properties.get('image_name') else: - role_images = config + role_images = norm_config with contextutil.nested( - lambda: create_image(ctx=ctx, config=config), - lambda: modprobe(ctx=ctx, config=config), + lambda: create_image(ctx=ctx, config=norm_config), + lambda: modprobe(ctx=ctx, config=norm_config), lambda: dev_create(ctx=ctx, config=role_images), - lambda: mkfs(ctx=ctx, config=config), + lambda: mkfs(ctx=ctx, config=norm_config), lambda: mount(ctx=ctx, config=role_images), ): yield -- 2.39.5