]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: validate `--fsid` during bootstrap
authorMichael Fritch <mfritch@suse.com>
Wed, 9 Jun 2021 23:45:03 +0000 (17:45 -0600)
committerSebastian Wagner <sewagner@redhat.com>
Thu, 17 Jun 2021 08:47:01 +0000 (10:47 +0200)
Signed-off-by: Michael Fritch <mfritch@suse.com>
(cherry picked from commit 37ff72ac9ba377abd7115f5fa6db9488fa374645)

src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 47e1199076884f96b96e850bdd754affe94d2619..f2ee97700b82c9a8e01b91767d046b26f6bdcc8c 100755 (executable)
@@ -4002,12 +4002,15 @@ def command_bootstrap(ctx):
 
     # initial vars
     fsid = ctx.fsid or make_fsid()
+    if not is_fsid(fsid):
+        raise Error('not an fsid: %s' % fsid)
+    logger.info('Cluster fsid: %s' % fsid)
+
     hostname = get_hostname()
     if '.' in hostname and not ctx.allow_fqdn_hostname:
         raise Error('hostname is a fully qualified domain name (%s); either fix (e.g., "sudo hostname %s" or similar) or pass --allow-fqdn-hostname' % (hostname, hostname.split('.')[0]))
     mon_id = ctx.mon_id or hostname
     mgr_id = ctx.mgr_id or generate_service_id()
-    logger.info('Cluster fsid: %s' % fsid)
 
     lock = FileLock(ctx, fsid)
     lock.acquire()
index cfe7abb63bf634e7d7fdc85b0217f5c38ce48aba..6b0560f4014b3fa932095cdb57a44925433963d1 100644 (file)
@@ -1137,3 +1137,24 @@ class TestBootstrap(TestCephAdm):
         with with_cephadm_ctx(cmd, hostname=hostname) as ctx:
             retval = cd.command_bootstrap(ctx)
             assert retval == 0
+
+    @pytest.mark.parametrize('fsid, err',
+        [
+            ('', None),
+            ('00000000-0000-0000-0000-0000deadbeef', None),
+            ('00000000-0000-0000-0000-0000deadbeez', 'not an fsid'),
+        ])
+    def test_fsid(self, fsid, err, cephadm_fs):
+        cmd = self._get_cmd(
+            '--mon-ip', '192.168.1.1',
+            '--skip-mon-network',
+            '--fsid', fsid,
+        )
+
+        with with_cephadm_ctx(cmd) as ctx:
+            if err:
+                with pytest.raises(cd.Error, match=err):
+                    cd.command_bootstrap(ctx)
+            else:
+                retval = cd.command_bootstrap(ctx)
+                assert retval == 0