From d9198d8668055fdc9e5c3c58668a6aeeda61df4a Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Wed, 14 Jul 2021 14:43:00 -0600 Subject: [PATCH] cephadm: `ceph-volume` should raise fsid mismatch raise an fsid mismatch error when passed differing fsids via `--fsid` and `--config`: ``` self = , cephadm_fs = def test_fsid(self, cephadm_fs): cv_cmd = ['--', 'inventory', '--format', 'json'] fsid = '00000000-0000-0000-0000-0000deadbeef' cmd = ['ceph-volume', '--fsid', fsid] + cv_cmd with with_cephadm_ctx(cmd) as ctx: cd.command_ceph_volume(ctx) assert ctx.fsid == fsid s = get_ceph_conf(fsid=fsid) f = cephadm_fs.create_file('ceph.conf', contents=s) cmd = ['ceph-volume', '--fsid', fsid, '--config', f.path] + cv_cmd with with_cephadm_ctx(cmd) as ctx: cd.command_ceph_volume(ctx) assert ctx.fsid == fsid cmd = ['ceph-volume', '--fsid', '10000000-0000-0000-0000-0000deadbeef', '--config', f.path] + cv_cmd with with_cephadm_ctx(cmd) as ctx: err = 'fsid does not match ceph.conf' with pytest.raises(cd.Error, match=err): cd.command_ceph_volume(ctx) > assert ctx.fsid == None E AssertionError: assert '10000000-0000-0000-0000-0000deadbeef' == None E + where '10000000-0000-0000-0000-0000deadbeef' = .fsid ``` Signed-off-by: Michael Fritch --- src/cephadm/cephadm | 5 +++++ src/cephadm/tests/test_cephadm.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 8b03505d3cb..7d7942ea780 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -4625,6 +4625,11 @@ def command_enter(ctx): @infer_image def command_ceph_volume(ctx): # type: (CephadmContext) -> None + cp = read_config(ctx.config) + if cp.has_option('global', 'fsid') and \ + cp.get('global', 'fsid') != ctx.fsid: + raise Error('fsid does not match ceph.conf') + if ctx.fsid: make_log_dir(ctx, ctx.fsid) diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index ae9e9ad955d..d34d3c4b02d 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -1545,6 +1545,13 @@ class TestCephVolume(object): cd.command_ceph_volume(ctx) assert ctx.fsid == fsid + cmd = self._get_cmd('--fsid', '10000000-0000-0000-0000-0000deadbeef', '--config', f.path) + with with_cephadm_ctx(cmd) as ctx: + err = 'fsid does not match ceph.conf' + with pytest.raises(cd.Error, match=err): + cd.command_ceph_volume(ctx) + assert ctx.fsid == None + def test_config(self, cephadm_fs): cmd = self._get_cmd('--config', 'foo') with with_cephadm_ctx(cmd) as ctx: