From b5e9c81321f9195801a794de03d02ec4f9499ba6 Mon Sep 17 00:00:00 2001 From: Joao Eduardo Luis Date: Thu, 31 Dec 2020 01:44:44 +0000 Subject: [PATCH] cephadm: split-off config work on bootstrap Signed-off-by: Joao Eduardo Luis --- src/cephadm/cephadm | 130 ++++++++++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 53 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index ef051519026..4d9a8333719 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -3471,6 +3471,80 @@ def prepare_dashboard( password)) +def prepare_bootstrap_config( + ctx: CephadmContext, + fsid: str, mon_addr: str, image: str + +) -> str: + + cp = read_config(ctx.args.config) + if not cp.has_section('global'): + cp.add_section('global') + cp.set('global', 'fsid', fsid) + cp.set('global', 'mon host', mon_addr) + cp.set('global', 'container_image', image) + cpf = StringIO() + cp.write(cpf) + config = cpf.getvalue() + + if ctx.args.registry_json or ctx.args.registry_url: + command_registry_login(ctx) + + if not ctx.args.skip_pull: + _pull_image(ctx, image) + + return config + + +def finish_bootstrap_config( + ctx: CephadmContext, + fsid: str, + config: str, + mon_id: str, mon_dir: str, + mon_network: Optional[str], ipv6: bool, + cli: Callable + +) -> None: + if not ctx.args.no_minimize_config: + logger.info('Assimilating anything we can from ceph.conf...') + cli([ + 'config', 'assimilate-conf', + '-i', '/var/lib/ceph/mon/ceph-%s/config' % mon_id + ], { + mon_dir: '/var/lib/ceph/mon/ceph-%s:z' % mon_id + }) + logger.info('Generating new minimal ceph.conf...') + cli([ + 'config', 'generate-minimal-conf', + '-o', '/var/lib/ceph/mon/ceph-%s/config' % mon_id + ], { + mon_dir: '/var/lib/ceph/mon/ceph-%s:z' % mon_id + }) + # re-read our minimized config + with open(mon_dir + '/config', 'r') as f: + config = f.read() + logger.info('Restarting the monitor...') + call_throws(ctx, [ + 'systemctl', + 'restart', + get_unit_name(fsid, 'mon', mon_id) + ]) + + if mon_network: + logger.info('Setting mon public_network...') + cli(['config', 'set', 'mon', 'public_network', mon_network]) + + if ipv6: + logger.info('Enabling IPv6 (ms_bind_ipv6)') + cli(['config', 'set', 'global', 'ms_bind_ipv6', 'true']) + + + with open(ctx.args.output_config, 'w') as f: + f.write(config) + logger.info('Wrote config to %s' % ctx.args.output_config) + pass + + @default_image def command_bootstrap(ctx): # type: (CephadmContext) -> int @@ -3540,22 +3614,7 @@ def command_bootstrap(ctx): raise Error('Failed to infer CIDR network for mon ip %s; pass ' '--skip-mon-network to configure it later' % base_ip) - # config - cp = read_config(ctx.args.config) - if not cp.has_section('global'): - cp.add_section('global') - cp.set('global', 'fsid', fsid); - cp.set('global', 'mon host', addr_arg) - cp.set('global', 'container_image', ctx.args.image) - cpf = StringIO() - cp.write(cpf) - config = cpf.getvalue() - - if ctx.args.registry_json or ctx.args.registry_url: - command_registry_login(ctx) - - if not ctx.args.skip_pull: - _pull_image(ctx, ctx.args.image) + config = prepare_bootstrap_config(ctx, fsid, addr_arg, ctx.args.image) logger.info('Extracting ceph user uid/gid from container image...') (uid, gid) = extract_uid_gid(ctx) @@ -3603,39 +3662,8 @@ def command_bootstrap(ctx): wait_for_mon(ctx, mon_id, mon_dir, admin_keyring.name, tmp_config.name) - # assimilate and minimize config - if not ctx.args.no_minimize_config: - logger.info('Assimilating anything we can from ceph.conf...') - cli([ - 'config', 'assimilate-conf', - '-i', '/var/lib/ceph/mon/ceph-%s/config' % mon_id - ], { - mon_dir: '/var/lib/ceph/mon/ceph-%s:z' % mon_id - }) - logger.info('Generating new minimal ceph.conf...') - cli([ - 'config', 'generate-minimal-conf', - '-o', '/var/lib/ceph/mon/ceph-%s/config' % mon_id - ], { - mon_dir: '/var/lib/ceph/mon/ceph-%s:z' % mon_id - }) - # re-read our minimized config - with open(mon_dir + '/config', 'r') as f: - config = f.read() - logger.info('Restarting the monitor...') - call_throws(ctx, [ - 'systemctl', - 'restart', - get_unit_name(fsid, 'mon', mon_id) - ]) - - if mon_network: - logger.info('Setting mon public_network...') - cli(['config', 'set', 'mon', 'public_network', mon_network]) - - if ipv6: - logger.info('Enabling IPv6 (ms_bind_ipv6)') - cli(['config', 'set', 'global', 'ms_bind_ipv6', 'true']) + finish_bootstrap_config(ctx, fsid, config, mon_id, mon_dir, + mon_network, ipv6, cli) # output files with open(ctx.args.output_keyring, 'w') as f: @@ -3644,10 +3672,6 @@ def command_bootstrap(ctx): '\tkey = ' + admin_key + '\n') logger.info('Wrote keyring to %s' % ctx.args.output_keyring) - with open(ctx.args.output_config, 'w') as f: - f.write(config) - logger.info('Wrote config to %s' % ctx.args.output_config) - # create mgr create_mgr(ctx, uid, gid, fsid, mgr_id, mgr_key, config, cli) -- 2.39.5