From: Adam King Date: Thu, 4 Apr 2024 18:11:11 +0000 (-0400) Subject: mgr/cephadm: make client-keyring deploying ceph.conf optional X-Git-Tag: testing/wip-batrick-testing-20240411.154038~27^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=0dab95eb4fffb493edc3e542a6613bdb5332a670;p=ceph-ci.git mgr/cephadm: make client-keyring deploying ceph.conf optional There are cases where users would like to manage their own ceph.conf but still have cephadm deploy the client keyrings, so this is being added to facilitate that. Fixes: https://tracker.ceph.com/issues/65335 Signed-off-by: Adam King --- diff --git a/src/pybind/mgr/cephadm/inventory.py b/src/pybind/mgr/cephadm/inventory.py index 966ffc0461c..cbaff8a5b00 100644 --- a/src/pybind/mgr/cephadm/inventory.py +++ b/src/pybind/mgr/cephadm/inventory.py @@ -406,12 +406,14 @@ class ClientKeyringSpec(object): mode: Optional[int] = None, uid: Optional[int] = None, gid: Optional[int] = None, + include_ceph_conf: bool = True, ) -> None: self.entity = entity self.placement = placement self.mode = mode or 0o600 self.uid = uid or 0 self.gid = gid or 0 + self.include_ceph_conf = include_ceph_conf def validate(self) -> None: pass @@ -423,6 +425,7 @@ class ClientKeyringSpec(object): 'mode': self.mode, 'uid': self.uid, 'gid': self.gid, + 'include_ceph_conf': self.include_ceph_conf, } @property diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index b93cb7f3096..4e77653f1d5 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1521,7 +1521,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, output = to_format(self.keys.keys.values(), format, many=True, cls=ClientKeyringSpec) else: table = PrettyTable( - ['ENTITY', 'PLACEMENT', 'MODE', 'OWNER', 'PATH'], + ['ENTITY', 'PLACEMENT', 'MODE', 'OWNER', 'PATH', 'INCLUDE_CEPH_CONF'], border=False) table.align = 'l' table.left_padding_width = 0 @@ -1532,6 +1532,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, utils.file_mode_to_str(ks.mode), f'{ks.uid}:{ks.gid}', ks.path, + ks.include_ceph_conf )) output = table.get_string() return HandleCommandResult(stdout=output) @@ -1543,6 +1544,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, placement: str, owner: Optional[str] = None, mode: Optional[str] = None, + no_ceph_conf: bool = False, ) -> HandleCommandResult: """ Add or update client keyring under cephadm management @@ -1565,7 +1567,14 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, else: imode = 0o600 pspec = PlacementSpec.from_string(placement) - ks = ClientKeyringSpec(entity, pspec, mode=imode, uid=uid, gid=gid) + ks = ClientKeyringSpec( + entity, + pspec, + mode=imode, + uid=uid, + gid=gid, + include_ceph_conf=(not no_ceph_conf) + ) self.keys.update(ks) self._kick_serve_loop() return HandleCommandResult() diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index b7e75f8abf6..4ef588ccea3 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -1232,8 +1232,9 @@ class CephadmServe: if host not in client_files: client_files[host] = {} ceph_conf = (0o644, 0, 0, bytes(config), str(config_digest)) - client_files[host]['/etc/ceph/ceph.conf'] = ceph_conf - client_files[host][f'{cluster_cfg_dir}/ceph.conf'] = ceph_conf + if ks.include_ceph_conf: + client_files[host]['/etc/ceph/ceph.conf'] = ceph_conf + client_files[host][f'{cluster_cfg_dir}/ceph.conf'] = ceph_conf client_key = (ks.mode, ks.uid, ks.gid, keyring.encode('utf-8'), digest) client_files[host][ks.path] = client_key client_files[host][f'{cluster_cfg_dir}/{os.path.basename(ks.path)}'] = client_key diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 2477de13e00..5882e78cf50 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -2111,6 +2111,21 @@ class TestCephadm(object): CephadmServe(cephadm_module)._write_client_files({}, 'host2') CephadmServe(cephadm_module)._write_client_files({}, 'host3') + @mock.patch('cephadm.CephadmOrchestrator.mon_command') + @mock.patch("cephadm.inventory.HostCache.get_host_client_files") + def test_dont_write_etc_ceph_client_files_when_turned_off(self, _get_client_files, _mon_command, cephadm_module): + cephadm_module.keys.update(ClientKeyringSpec('keyring1', PlacementSpec(label='keyring1'), include_ceph_conf=False)) + cephadm_module.inventory.add_host(HostSpec('host1', '1.2.3.1', labels=['keyring1'])) + cephadm_module.cache.update_host_daemons('host1', {}) + + _mon_command.return_value = (0, 'my-keyring', '') + + client_files = CephadmServe(cephadm_module)._calc_client_files() + + assert 'host1' in client_files + assert '/etc/ceph/ceph.keyring1.keyring' in client_files['host1'] + assert '/etc/ceph/ceph.conf' not in client_files['host1'] + def test_etc_ceph_init(self): with with_cephadm_module({'manage_etc_ceph_ceph_conf': True}) as m: assert m.manage_etc_ceph_ceph_conf is True