From 9f932dffa5c31b689920ad16bbad44d495bf803b Mon Sep 17 00:00:00 2001 From: Georgios Kyratsas Date: Tue, 5 May 2020 09:27:45 +0200 Subject: [PATCH] qa/tasks/cephadm.py: Support bootstrapped clusters Add the possibility of being able to run cephadm.py on clusters that were already bootstrapped by some other task/way so you can deploy the rest of the daemons/services. Signed-off-by: Georgios Kyratsas (cherry picked from commit a002b28bc1aa75e087d850759138763a9a2a3916) --- qa/tasks/cephadm.py | 101 ++++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 42 deletions(-) diff --git a/qa/tasks/cephadm.py b/qa/tasks/cephadm.py index 2c64ca99725ec..9db60ffa2d896 100644 --- a/qa/tasks/cephadm.py +++ b/qa/tasks/cephadm.py @@ -958,36 +958,23 @@ def crush_setup(ctx, config): yield @contextlib.contextmanager -def task(ctx, config): - if config is None: - config = {} - - assert isinstance(config, dict), \ - "task only supports a dictionary for configuration" - - overrides = ctx.config.get('overrides', {}) - teuthology.deep_merge(config, overrides.get('ceph', {})) - log.info('Config: ' + str(config)) - - testdir = teuthology.get_testdir(ctx) +def _bypass(): + yield - # set up cluster context - first_ceph_cluster = False - if not hasattr(ctx, 'daemons'): - first_ceph_cluster = True - if not hasattr(ctx, 'ceph'): - ctx.ceph = {} - ctx.managers = {} - if 'cluster' not in config: - config['cluster'] = 'ceph' +@contextlib.contextmanager +def initialize_config(ctx, config): cluster_name = config['cluster'] - ctx.ceph[cluster_name] = argparse.Namespace() + testdir = teuthology.get_testdir(ctx) ctx.ceph[cluster_name].thrashers = [] # fixme: setup watchdog, ala ceph.py ctx.ceph[cluster_name].roleless = False # see below + first_ceph_cluster = False + if not hasattr(ctx, 'daemons'): + first_ceph_cluster = True + # cephadm mode? if 'cephadm_mode' not in config: config['cephadm_mode'] = 'root' @@ -1002,21 +989,6 @@ def task(ctx, config): ctx.daemons = DaemonGroup( use_cephadm=ctx.cephadm) - # image - ctx.ceph[cluster_name].image = config.get('image') - ref = None - if not ctx.ceph[cluster_name].image: - sha1 = config.get('sha1') - if sha1: - ctx.ceph[cluster_name].image = 'quay.io/ceph-ci/ceph:%s' % sha1 - ref = sha1 - else: - # hmm, fall back to branch? - branch = config.get('branch', 'master') - ref = branch - ctx.ceph[cluster_name].image = 'quay.io/ceph-ci/ceph:%s' % branch - log.info('Cluster image is %s' % ctx.ceph[cluster_name].image) - # uuid fsid = str(uuid.uuid1()) log.info('Cluster fsid is %s' % fsid) @@ -1031,7 +1003,6 @@ def task(ctx, config): if config.get('roleless', False): # mons will be named after hosts - n = len(roles) roles = [] first_mon = None for remote, _ in remotes_and_roles: @@ -1040,7 +1011,7 @@ def task(ctx, config): first_mon = remote.shortname bootstrap_remote = remote log.info('No roles; fabricating mons %s' % roles) - + ctx.ceph[cluster_name].mons = get_mons( roles, ips, cluster_name, mon_bind_msgr2=config.get('mon_bind_msgr2', True), @@ -1071,15 +1042,61 @@ def task(ctx, config): _, _, first_mgr = teuthology.split_role(mgrs[0]) log.info('First mgr is %s' % (first_mgr)) ctx.ceph[cluster_name].first_mgr = first_mgr - + yield + +@contextlib.contextmanager +def task(ctx, config): + if config is None: + config = {} + + assert isinstance(config, dict), \ + "task only supports a dictionary for configuration" + + overrides = ctx.config.get('overrides', {}) + teuthology.deep_merge(config, overrides.get('ceph', {})) + log.info('Config: ' + str(config)) + + testdir = teuthology.get_testdir(ctx) + + # set up cluster context + if not hasattr(ctx, 'ceph'): + ctx.ceph = {} + ctx.managers = {} + if 'cluster' not in config: + config['cluster'] = 'ceph' + cluster_name = config['cluster'] + if cluster_name not in ctx.ceph: + ctx.ceph[cluster_name] = argparse.Namespace() + ctx.ceph[cluster_name].bootstrapped = False + + # image + ctx.ceph[cluster_name].image = config.get('image') + ref = None + if not ctx.ceph[cluster_name].image: + sha1 = config.get('sha1') + if sha1: + ctx.ceph[cluster_name].image = 'quay.io/ceph-ci/ceph:%s' % sha1 + ref = sha1 + else: + # hmm, fall back to branch? + branch = config.get('branch', 'master') + ref = branch + ctx.ceph[cluster_name].image = 'quay.io/ceph-ci/ceph:%s' % branch + log.info('Cluster image is %s' % ctx.ceph[cluster_name].image) + with contextutil.nested( + #if the cluster is already bootstrapped bypass corresponding methods + lambda: _bypass() if (ctx.ceph[cluster_name].bootstrapped)\ + else initialize_config(ctx=ctx, config=config), lambda: ceph_initial(), lambda: normalize_hostnames(ctx=ctx), - lambda: download_cephadm(ctx=ctx, config=config, ref=ref), + lambda: _bypass() if (ctx.ceph[cluster_name].bootstrapped)\ + else download_cephadm(ctx=ctx, config=config, ref=ref), lambda: ceph_log(ctx=ctx, config=config), lambda: ceph_crash(ctx=ctx, config=config), - lambda: ceph_bootstrap(ctx=ctx, config=config), + lambda: _bypass() if (ctx.ceph[cluster_name].bootstrapped)\ + else ceph_bootstrap(ctx=ctx, config=config), lambda: crush_setup(ctx=ctx, config=config), lambda: ceph_mons(ctx=ctx, config=config), lambda: distribute_config_and_admin_keyring(ctx=ctx, config=config), -- 2.39.5