]> 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)
committerMichael Fritch <mfritch@suse.com>
Wed, 28 Jul 2021 13:44:09 +0000 (07:44 -0600)
Signed-off-by: Michael Fritch <mfritch@suse.com>
src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 7d7942ea780318a961541079b10c0abd2abb15a0..a515cb24c5454dd0777d71b0daf3aa3f1f2ea952 100755 (executable)
@@ -1643,6 +1643,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
@@ -1650,7 +1660,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)
 
@@ -1696,7 +1706,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)
@@ -4504,6 +4514,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 d34d3c4b02dfd3ca74e75919a33e7ff993418882..9fe381c12609211a817c5dfb0d0b8f61c53d5e4b 100644 (file)
@@ -1435,6 +1435,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)