]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: split-off config work on bootstrap
authorJoao Eduardo Luis <joao@suse.com>
Thu, 31 Dec 2020 01:44:44 +0000 (01:44 +0000)
committerJuan Miguel Olmo Martínez <jolmomar@redhat.com>
Mon, 25 Jan 2021 17:34:45 +0000 (18:34 +0100)
Signed-off-by: Joao Eduardo Luis <joao@suse.com>
(cherry picked from commit b5e9c81321f9195801a794de03d02ec4f9499ba6)

src/cephadm/cephadm

index d564fbf4458e8e5067cd309cab426225ed1ce3ce..8875dd49c95edcacb50f587a6985cc37f6f17d35 100755 (executable)
@@ -3474,6 +3474,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
@@ -3543,22 +3617,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)
@@ -3606,39 +3665,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:
@@ -3647,10 +3675,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)