if ctx.config:
logger.debug('Using specified config: %s' % ctx.config)
return func(ctx)
+
+ def config_path(daemon_type: str, daemon_name: str) -> str:
+ data_dir = get_data_dir(ctx.fsid, ctx.data_dir, daemon_type, daemon_name)
+ return os.path.join(data_dir, 'config')
+
if 'fsid' in ctx and ctx.fsid:
name = ctx.name if 'name' in ctx else None
if not name:
daemon_list = list_daemons(ctx, detail=False)
for daemon in daemon_list:
- if daemon.get('name', '').startswith('mon.') and daemon.get('fsid', '') == ctx.fsid:
+ if (
+ daemon.get('name', '').startswith('mon.')
+ and daemon.get('fsid', '') == ctx.fsid
+ and daemon.get('style', '') == 'cephadm:v1'
+ and os.path.exists(config_path('mon', daemon['name'].split('.', 1)[1]))
+ ):
name = daemon['name']
break
if name:
- ctx.config = f'/var/lib/ceph/{ctx.fsid}/{name}/config'
+ ctx.config = config_path(name.split('.', 1)[0], name.split('.', 1)[1])
if ctx.config:
logger.info('Inferring config %s' % ctx.config)
elif os.path.exists(SHELL_DEFAULT_CONF):
'00000000-0000-0000-0000-0000deadbeef',
None,
None,
- [{'name': 'mon.a', 'fsid': '00000000-0000-0000-0000-0000deadbeef'}],
+ [{'name': 'mon.a', 'fsid': '00000000-0000-0000-0000-0000deadbeef', 'style': 'cephadm:v1'}],
'/var/lib/ceph/00000000-0000-0000-0000-0000deadbeef/mon.a/config',
),
(
'00000000-0000-0000-0000-0000deadbeef',
None,
None,
- [{'name': 'mon.a', 'fsid': 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'}],
+ [{'name': 'mon.a', 'fsid': 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'style': 'cephadm:v1'}],
+ cd.SHELL_DEFAULT_CONF,
+ ),
+ (
+ '00000000-0000-0000-0000-0000deadbeef',
+ None,
+ None,
+ [{'name': 'mon.a', 'fsid': '00000000-0000-0000-0000-0000deadbeef', 'style': 'legacy'}],
cd.SHELL_DEFAULT_CONF,
),
(
'00000000-0000-0000-0000-0000deadbeef',
'/foo/bar.conf',
'mon.a',
- [{'name': 'mon.a'}],
+ [{'name': 'mon.a', 'style': 'cephadm:v1'}],
'/foo/bar.conf',
),
(
),
])
@mock.patch('cephadm.call')
- def test_infer_config(self, _call, fsid, config, name, list_daemons, result, cephadm_fs):
+ @mock.patch('cephadm.logger')
+ def test_infer_config(self, logger, _call, fsid, config, name, list_daemons, result, cephadm_fs):
# build the context
ctx = cd.CephadmContext()
ctx.fsid = fsid
mock_fn.return_value = 0
infer_config = cd.infer_config(mock_fn)
- # mock the shell config
- cephadm_fs.create_file(cd.SHELL_DEFAULT_CONF)
+ # mock the config file
+ cephadm_fs.create_file(result)
# test
with mock.patch('cephadm.list_daemons', return_value=list_daemons):