def _write_custom_conf_files(ctx: CephadmContext, daemon_type: str, daemon_id: str, fsid: str, uid: int, gid: int) -> None:
# mostly making this its own function to make unit testing easier
- if 'config_json' not in ctx or not ctx.config_json:
+ ccfiles = fetch_custom_config_files(ctx)
+ if not ccfiles:
return
- config_json = get_custom_config_files(ctx.config_json)
custom_config_dir = os.path.join(ctx.data_dir, fsid, 'custom_config_files', f'{daemon_type}.{daemon_id}')
if not os.path.exists(custom_config_dir):
makedirs(custom_config_dir, uid, gid, 0o755)
mandatory_keys = ['mount_path', 'content']
- for ccf in config_json['custom_config_files']:
+ for ccf in ccfiles:
if all(k in ccf for k in mandatory_keys):
file_path = os.path.join(custom_config_dir, os.path.basename(ccf['mount_path']))
with write_new(file_path, owner=(uid, gid), encoding='utf-8') as f:
js = _get_config_json(option)
# custom_config_files is a special field that may be in the config
# dict. It is used for mounting custom config files into daemon's containers
- # and should be accessed through the "get_custom_config_files" function.
+ # and should be accessed through the "fetch_custom_config_files" function.
# For get_parm we need to discard it.
js.pop('custom_config_files', None)
return js
-def get_custom_config_files(option: str) -> Dict[str, List[Dict[str, str]]]:
- js = _get_config_json(option)
- res: Dict[str, List[Dict[str, str]]] = {'custom_config_files': []}
- if 'custom_config_files' in js:
- res['custom_config_files'] = js['custom_config_files']
- return res
-
-
def _get_config_json(option: str) -> Dict[str, Any]:
if not option:
return dict()
c.container_args.extend(ctx.extra_container_args)
if 'extra_entrypoint_args' in ctx and ctx.extra_entrypoint_args:
c.args.extend(ctx.extra_entrypoint_args)
- if 'config_json' in ctx and ctx.config_json:
- conf_files = get_custom_config_files(ctx.config_json)
+ ccfiles = fetch_custom_config_files(ctx)
+ if ccfiles:
mandatory_keys = ['mount_path', 'content']
- for conf in conf_files['custom_config_files']:
+ for conf in ccfiles:
if all(k in conf for k in mandatory_keys):
mount_path = conf['mount_path']
file_path = os.path.join(
_cephadm.prepare_dashboard(ctx, 0, 0, lambda _, extra_mounts=None, ___=None : '5', lambda : None)
@mock.patch('cephadm.logger')
- @mock.patch('cephadm.get_custom_config_files')
+ @mock.patch('cephadm.fetch_custom_config_files')
@mock.patch('cephadm.get_container')
def test_get_deployment_container(self, _get_container, _get_config, _logger):
"""
'--something',
]
ctx.data_dir = 'data'
- _get_config.return_value = {'custom_config_files': [
+ _get_config.return_value = [
{
'mount_path': '/etc/testing.str',
'content': 'this\nis\na\nstring',
}
- ]}
+ ]
_get_container.return_value = _cephadm.CephContainer.for_daemon(
ctx,
fsid='9b9d7609-f4d5-4aba-94c8-effa764d96c9',
_cephadm.command_deploy(ctx)
@mock.patch('cephadm.logger')
- @mock.patch('cephadm.get_custom_config_files')
+ @mock.patch('cephadm.fetch_custom_config_files')
def test_write_custom_conf_files(self, _get_config, _logger, cephadm_fs):
"""
test _write_custom_conf_files writes the conf files correctly
ctx = _cephadm.CephadmContext()
ctx.config_json = '-'
ctx.data_dir = _cephadm.DATA_DIR
- _get_config.return_value = {'custom_config_files': [
+ _get_config.return_value = [
{
'mount_path': '/etc/testing.str',
'content': 'this\nis\na\nstring',
{
'mount_path': '/etc/no-content.conf',
},
- ]}
+ ]
_cephadm._write_custom_conf_files(ctx, 'mon', 'host1', 'fsid', 0, 0)
with open(os.path.join(_cephadm.DATA_DIR, 'fsid', 'custom_config_files', 'mon.host1', 'testing.str'), 'r') as f:
assert 'this\nis\na\nstring' == f.read()