From 5c29ae6bd193ae809d2d2bb99d1efc4d36345abf Mon Sep 17 00:00:00 2001 From: John Spray Date: Wed, 20 Aug 2014 12:30:27 +0100 Subject: [PATCH] tasks/ceph: add ceph.stop task So that we can explicitly stop daemons on demand. Useful for MDS tool tests that want the MDS daemons not to be running, is this is more solid and explicit than doing e.g. "ceph mds stop" from within workunits. Signed-off-by: John Spray --- tasks/ceph.py | 53 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/tasks/ceph.py b/tasks/ceph.py index 07eb604ba9a02..02f306a0ffc89 100644 --- a/tasks/ceph.py +++ b/tasks/ceph.py @@ -21,6 +21,7 @@ from teuthology.orchestra.run import CommandFailedError from teuthology.orchestra.daemon import DaemonGroup DEFAULT_CONF_PATH = '/etc/ceph/ceph.conf' +CEPH_ROLE_TYPES = ['mon', 'osd', 'mds', 'rgw'] log = logging.getLogger(__name__) @@ -1049,7 +1050,7 @@ def restart(ctx, config): For example:: tasks: - - ceph.restart: [osd.0, mon.1] + - ceph.restart: [osd.0, mon.1, mds.*] or:: @@ -1064,19 +1065,11 @@ def restart(ctx, config): """ if config is None: config = {} - if isinstance(config, list): - config = { 'daemons': config } - if 'daemons' not in config: - config['daemons'] = [] - type_daemon = ['mon', 'osd', 'mds', 'rgw'] - for d in type_daemon: - type_ = d - for daemon in ctx.daemons.iter_daemons_of_role(type_): - config['daemons'].append(type_ + '.' + daemon.id_) - - assert isinstance(config['daemons'], list) - daemons = dict.fromkeys(config['daemons']) - for i in daemons.keys(): + elif isinstance(config, list): + config = {'daemons': config} + + daemons = ctx.daemons.resolve_role_list(config.get('daemons', None), CEPH_ROLE_TYPES) + for i in daemons: type_ = i.split('.', 1)[0] id_ = i.split('.', 1)[1] ctx.daemons.get_daemon(type_, id_).stop() @@ -1088,6 +1081,38 @@ def restart(ctx, config): wait_for_osds_up(ctx=ctx, config=None) yield + +@contextlib.contextmanager +def stop(ctx, config): + """ + Stop ceph daemons + + For example:: + tasks: + - ceph.stop: [mds.*] + + tasks: + - ceph.stop: [osd.0, osd.2] + + tasks: + - ceph.stop: + daemons: [osd.0, osd.2] + + """ + if config is None: + config = {} + elif isinstance(config, list): + config = {'daemons': config} + + daemons = ctx.daemons.resolve_role_list(config.get('daemons', None), CEPH_ROLE_TYPES) + for i in daemons: + type_ = i.split('.', 1)[0] + id_ = i.split('.', 1)[1] + ctx.daemons.get_daemon(type_, id_).stop() + + yield + + @contextlib.contextmanager def task(ctx, config): """ -- 2.39.5