]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: validate fsid during cephadm shell command
authorDaniel Pivonka <dpivonka@redhat.com>
Wed, 10 Mar 2021 23:01:35 +0000 (18:01 -0500)
committerSage Weil <sage@newdream.net>
Fri, 26 Mar 2021 12:33:00 +0000 (07:33 -0500)
Signed-off-by: Daniel Pivonka <dpivonka@redhat.com>
(cherry picked from commit 9118b08365b24c3fe26f3dcdc4bf88d8ccbcbce0)

src/cephadm/cephadm

index c6e979acf37cf08d278f7689fd66452f189a9878..2ebda2d8462bd307c11ab8b5afd20cd0f36092e3 100755 (executable)
@@ -2220,14 +2220,20 @@ def get_config_and_keyring(ctx):
         keyring = d.get('keyring')
 
     if 'config' in ctx and ctx.config:
-        with open(ctx.config, 'r') as f:
-            config = f.read()
+        try:
+            with open(ctx.config, 'r') as f:
+                config = f.read()
+        except FileNotFoundError:
+            raise Error('config file: %s does not exist' % ctx.config)
 
     if 'key' in ctx and ctx.key:
         keyring = '[%s]\n\tkey = %s\n' % (ctx.name, ctx.key)
     elif 'keyring' in ctx and ctx.keyring:
-        with open(ctx.keyring, 'r') as f:
-            keyring = f.read()
+        try:
+            with open(ctx.keyring, 'r') as f:
+                keyring = f.read()
+        except FileNotFoundError:
+            raise Error('keyring file: %s does not exist' % ctx.keyring)
 
     return config, keyring
 
@@ -4261,11 +4267,25 @@ def command_run(ctx):
 ##################################
 
 
+def fsid_conf_mismatch(ctx):
+    # type: (CephadmContext) -> bool
+    (config, _) = get_config_and_keyring(ctx)
+    if config:
+        for c in config.split('\n'):
+            if 'fsid = ' in c.strip():
+                if 'fsid = ' + ctx.fsid != c.strip():
+                    return True
+    return False
+
+
 @infer_fsid
 @infer_config
 @infer_image
 def command_shell(ctx):
     # type: (CephadmContext) -> int
+    if fsid_conf_mismatch(ctx):
+        raise Error('fsid does not match ceph conf')
+
     if ctx.fsid:
         make_log_dir(ctx, ctx.fsid)
     if ctx.name: