From 7ca6d9db0c87dbd97bbc751cd0936b88b4daf33e Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Tue, 22 Jun 2021 16:42:47 -0600 Subject: [PATCH] cephadm: infer fsid from ceph.conf Fixes: https://tracker.ceph.com/issues/51328 Signed-off-by: Michael Fritch (cherry picked from commit e35271adfcfd64ca19aee58b334eb1aaf3855ef4) --- src/cephadm/cephadm | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 86d5eb1f65ae1..6186d83ac8398 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -1646,13 +1646,19 @@ def infer_fsid(func): """ If we only find a single fsid in /var/lib/ceph/*, use that """ + @infer_config @wraps(func) def _infer_fsid(ctx: CephadmContext): if ctx.fsid: logger.debug('Using specified fsid: %s' % ctx.fsid) return func(ctx) - fsids_set = set() + fsids = set() + + cp = read_config(ctx.config) + if cp.has_option('global', 'fsid'): + fsids.add(cp.get('global', 'fsid')) + daemon_list = list_daemons(ctx, detail=False) for daemon in daemon_list: if not is_fsid(daemon['fsid']): @@ -1660,11 +1666,11 @@ def infer_fsid(func): continue elif 'name' not in ctx or not ctx.name: # ctx.name not specified - fsids_set.add(daemon['fsid']) + fsids.add(daemon['fsid']) elif daemon['name'] == ctx.name: # ctx.name is a match - fsids_set.add(daemon['fsid']) - fsids = sorted(fsids_set) + fsids.add(daemon['fsid']) + fsids = sorted(fsids) if not fsids: # some commands do not always require an fsid @@ -4468,24 +4474,15 @@ def command_run(ctx): ################################## -def fsid_conf_mismatch(ctx): - # type: (CephadmContext) -> bool - (config, _) = get_config_and_keyring(ctx) - if config: - for c in config.split('\n'): - if 'fsid = ' in c.strip(): - if 'fsid = ' + ctx.fsid != c.strip(): - return True - return False - - @infer_fsid @infer_config @infer_image def command_shell(ctx): # type: (CephadmContext) -> int - if fsid_conf_mismatch(ctx): - raise Error('fsid does not match ceph conf') + cp = read_config(ctx.config) + if cp.has_option('global', 'fsid') and \ + cp.get('global', 'fsid') != ctx.fsid: + raise Error('fsid does not match ceph.conf') if ctx.fsid: make_log_dir(ctx, ctx.fsid) -- 2.39.5