From: John Mulligan Date: Sun, 19 Nov 2023 00:09:29 +0000 (-0500) Subject: cephadm: update _rm_cluster to call terminate_service X-Git-Tag: testing/wip-batrick-testing-20240411.154038~702^2~9 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=0f7a48cc4dc620e388f87a083504664552705758;p=ceph-ci.git cephadm: update _rm_cluster to call terminate_service The terminate_service function was added to encapsulate the act of terminating a systemd service. The rm-deamon handler was updated to use this function previously; this commit updates rm-cluster function(s) to do the same. This needed a bunch of test updates do to how the tests were mocking commands. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 09a373dd27e..7b9ca0fd0ab 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -4282,14 +4282,6 @@ def _rm_cluster(ctx: CephadmContext, keep_logs: bool, zap_osds: bool) -> None: if not ctx.fsid: raise Error('must select the cluster to delete by passing --fsid to proceed') - def disable_systemd_service(unit_name: str) -> None: - call(ctx, ['systemctl', 'stop', unit_name], - verbosity=CallVerbosity.DEBUG) - call(ctx, ['systemctl', 'reset-failed', unit_name], - verbosity=CallVerbosity.DEBUG) - call(ctx, ['systemctl', 'disable', unit_name], - verbosity=CallVerbosity.DEBUG) - logger.info(f'Deleting cluster with fsid: {ctx.fsid}') # stop + disable individual daemon units @@ -4298,11 +4290,11 @@ def _rm_cluster(ctx: CephadmContext, keep_logs: bool, zap_osds: bool) -> None: continue if d['style'] != 'cephadm:v1': continue - disable_systemd_service('ceph-%s@%s' % (ctx.fsid, d['name'])) + terminate_service(ctx, 'ceph-%s@%s' % (ctx.fsid, d['name'])) # cluster units for unit_name in ['ceph-%s.target' % ctx.fsid]: - disable_systemd_service(unit_name) + terminate_service(ctx, unit_name) slice_name = 'system-ceph\\x2d{}.slice'.format(ctx.fsid.replace('-', '\\x2d')) call(ctx, ['systemctl', 'stop', slice_name], @@ -4333,7 +4325,7 @@ def _rm_cluster(ctx: CephadmContext, keep_logs: bool, zap_osds: bool) -> None: # if last cluster on host remove shared files if get_ceph_cluster_count(ctx) == 0: - disable_systemd_service('ceph.target') + terminate_service(ctx, 'ceph.target') # rm shared ceph target files call_throws(ctx, ['rm', '-f', ctx.unit_dir + '/multi-user.target.wants/ceph.target']) diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index 7bca8b9cbf3..9c6caf0092b 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -1345,7 +1345,9 @@ class TestBootstrap(object): ###############################################3 - def test_config(self, cephadm_fs): + def test_config(self, cephadm_fs, funkypatch): + funkypatch.patch('cephadmlib.systemd.call') + conf_file = 'foo' cmd = self._get_cmd( '--mon-ip', '192.168.1.1', @@ -1363,14 +1365,17 @@ class TestBootstrap(object): retval = _cephadm.command_bootstrap(ctx) assert retval == 0 - def test_no_mon_addr(self, cephadm_fs): + def test_no_mon_addr(self, cephadm_fs, funkypatch): + funkypatch.patch('cephadmlib.systemd.call') + cmd = self._get_cmd() with with_cephadm_ctx(cmd) as ctx: msg = r'must specify --mon-ip or --mon-addrv' with pytest.raises(_cephadm.Error, match=msg): _cephadm.command_bootstrap(ctx) - def test_skip_mon_network(self, cephadm_fs): + def test_skip_mon_network(self, cephadm_fs, funkypatch): + funkypatch.patch('cephadmlib.systemd.call') cmd = self._get_cmd('--mon-ip', '192.168.1.1') with with_cephadm_ctx(cmd, list_networks={}) as ctx: @@ -1453,7 +1458,9 @@ class TestBootstrap(object): True, ), ]) - def test_mon_ip(self, mon_ip, list_networks, result, cephadm_fs): + def test_mon_ip(self, mon_ip, list_networks, result, cephadm_fs, funkypatch): + funkypatch.patch('cephadmlib.systemd.call') + cmd = self._get_cmd('--mon-ip', mon_ip) if not result: with with_cephadm_ctx(cmd, list_networks=list_networks) as ctx: @@ -1515,7 +1522,9 @@ class TestBootstrap(object): None, ), ]) - def test_mon_addrv(self, mon_addrv, list_networks, err, cephadm_fs): + def test_mon_addrv(self, mon_addrv, list_networks, err, cephadm_fs, funkypatch): + funkypatch.patch('cephadmlib.systemd.call') + cmd = self._get_cmd('--mon-addrv', mon_addrv) if err: with with_cephadm_ctx(cmd, list_networks=list_networks) as ctx: @@ -1526,7 +1535,9 @@ class TestBootstrap(object): retval = _cephadm.command_bootstrap(ctx) assert retval == 0 - def test_allow_fqdn_hostname(self, cephadm_fs): + def test_allow_fqdn_hostname(self, cephadm_fs, funkypatch): + funkypatch.patch('cephadmlib.systemd.call') + hostname = 'foo.bar' cmd = self._get_cmd( '--mon-ip', '192.168.1.1', @@ -1549,7 +1560,9 @@ class TestBootstrap(object): ('00000000-0000-0000-0000-0000deadbeef', None), ('00000000-0000-0000-0000-0000deadbeez', 'not an fsid'), ]) - def test_fsid(self, fsid, err, cephadm_fs): + def test_fsid(self, fsid, err, cephadm_fs, funkypatch): + funkypatch.patch('cephadmlib.systemd.call') + cmd = self._get_cmd( '--mon-ip', '192.168.1.1', '--skip-mon-network',