]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: validate fsid during shell command
authorMichael Fritch <mfritch@suse.com>
Mon, 26 Jul 2021 22:58:54 +0000 (16:58 -0600)
committerSebastian Wagner <sewagner@redhat.com>
Tue, 10 Aug 2021 14:32:16 +0000 (16:32 +0200)
Signed-off-by: Michael Fritch <mfritch@suse.com>
(cherry picked from commit 25febfd9e081eaa275faa786102d59522ddba405)

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

index 48b94acf58c4f52c96e0127a895f6c5a9766dfda..5f0fa84eb56dcb246d31ae12a1ce5e8211360173 100755 (executable)
@@ -1642,6 +1642,16 @@ def is_fsid(s):
     return True
 
 
+def validate_fsid(func):
+    @wraps(func)
+    def _validate_fsid(ctx: CephadmContext):
+        if 'fsid' in ctx and ctx.fsid:
+            if not is_fsid(ctx.fsid):
+                raise Error('not an fsid: %s' % ctx.fsid)
+        return func(ctx)
+    return _validate_fsid
+
+
 def infer_fsid(func):
     """
     If we only find a single fsid in /var/lib/ceph/*, use that
@@ -1649,7 +1659,7 @@ def infer_fsid(func):
     @infer_config
     @wraps(func)
     def _infer_fsid(ctx: CephadmContext):
-        if ctx.fsid:
+        if 'fsid' in ctx and ctx.fsid:
             logger.debug('Using specified fsid: %s' % ctx.fsid)
             return func(ctx)
 
@@ -1695,7 +1705,7 @@ def infer_config(func):
         if ctx.config:
             logger.debug('Using specified config: %s' % ctx.config)
             return func(ctx)
-        if ctx.fsid:
+        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)
@@ -4474,6 +4484,7 @@ def command_run(ctx):
 @infer_fsid
 @infer_config
 @infer_image
+@validate_fsid
 def command_shell(ctx):
     # type: (CephadmContext) -> int
     cp = read_config(ctx.config)
index 37e276c207a05fa3ccffc96c72b99ca1bb92daf9..6993214ac072b30f0cf4590f47ba110d9fb03bbd 100644 (file)
@@ -1415,6 +1415,14 @@ class TestShell(object):
             assert retval == 0
             assert ctx.fsid == fsid
 
+        cmd = ['shell', '--fsid', '00000000-0000-0000-0000-0000deadbeez']
+        with with_cephadm_ctx(cmd) as ctx:
+            err = 'not an fsid'
+            with pytest.raises(cd.Error, match=err):
+                retval = cd.command_shell(ctx)
+                assert retval == 1
+                assert ctx.fsid == None
+
         s = get_ceph_conf(fsid=fsid)
         f = cephadm_fs.create_file('ceph.conf', contents=s)