From: Sebastian Wagner Date: Tue, 31 Aug 2021 09:01:11 +0000 (+0200) Subject: mgr/cephadm: Add MonService.post_remove() X-Git-Tag: v17.1.0~925^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=71eaf35aa755735574f8bc53b38fa1bac550792c;p=ceph.git mgr/cephadm: Add MonService.post_remove() We should never remove the mon keyring. Let's move this piece of code into the MonService class Signed-off-by: Sebastian Wagner --- diff --git a/src/pybind/mgr/cephadm/services/cephadmservice.py b/src/pybind/mgr/cephadm/services/cephadmservice.py index 7a7d6b4073a5..17426eb41dbd 100644 --- a/src/pybind/mgr/cephadm/services/cephadmservice.py +++ b/src/pybind/mgr/cephadm/services/cephadmservice.py @@ -483,9 +483,7 @@ class CephService(CephadmService): daemon_id: str = daemon.daemon_id host: str = daemon.hostname - if daemon_id == 'mon': - # do not remove the mon keyring - return + assert daemon.daemon_type != 'mon' entity = self.get_auth_entity(daemon_id, host=host) @@ -586,6 +584,11 @@ class MonService(CephService): 'name': daemon_id, }) + def post_remove(self, daemon: DaemonDescription) -> None: + # Do not remove the mon keyring. + # super().post_remove(daemon) + pass + class MgrService(CephService): TYPE = 'mgr' diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index b0026735058f..951d81f57618 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -841,23 +841,55 @@ spec: with with_daemon(cephadm_module, spec, 'test'): pass + @pytest.mark.parametrize( + "entity,success,spec", + [ + ('mgr.x', True, ServiceSpec( + service_type='mgr', + placement=PlacementSpec(hosts=[HostPlacementSpec('test', '', 'x')], count=1), + unmanaged=True) + ), # noqa: E124 + ('client.rgw.x', True, ServiceSpec( + service_type='rgw', + service_id='id', + placement=PlacementSpec(hosts=[HostPlacementSpec('test', '', 'x')], count=1), + unmanaged=True) + ), # noqa: E124 + ('client.nfs.x', True, ServiceSpec( + service_type='nfs', + service_id='id', + placement=PlacementSpec(hosts=[HostPlacementSpec('test', '', 'x')], count=1), + unmanaged=True) + ), # noqa: E124 + ('mon.', False, ServiceSpec( + service_type='mon', + placement=PlacementSpec(hosts=[HostPlacementSpec('test', '127.0.0.0/24', 'x')], count=1), + unmanaged=True) + ), # noqa: E124 + ] + ) @mock.patch("cephadm.serve.CephadmServe._run_cephadm") - def test_daemon_add_fail(self, _run_cephadm, cephadm_module): + @mock.patch("cephadm.services.nfs.NFSService.run_grace_tool", mock.MagicMock()) + @mock.patch("cephadm.services.nfs.NFSService.purge", mock.MagicMock()) + @mock.patch("cephadm.services.nfs.NFSService.create_rados_config_obj", mock.MagicMock()) + def test_daemon_add_fail(self, _run_cephadm, entity, success, spec, cephadm_module): _run_cephadm.return_value = '{}', '', 0 with with_host(cephadm_module, 'test'): - spec = ServiceSpec( - service_type='mgr', - placement=PlacementSpec(hosts=[HostPlacementSpec('test', '', 'x')], count=1), - unmanaged=True - ) with with_service(cephadm_module, spec): _run_cephadm.side_effect = OrchestratorError('fail') with pytest.raises(OrchestratorError): wait(cephadm_module, cephadm_module.add_daemon(spec)) - cephadm_module.assert_issued_mon_command({ - 'prefix': 'auth rm', - 'entity': 'mgr.x', - }) + if success: + cephadm_module.assert_issued_mon_command({ + 'prefix': 'auth rm', + 'entity': entity, + }) + else: + with pytest.raises(AssertionError): + cephadm_module.assert_issued_mon_command({ + 'prefix': 'auth rm', + 'entity': entity, + }) @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}')) @mock.patch("cephadm.services.nfs.NFSService.run_grace_tool", mock.MagicMock())