]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: update _rm_cluster to call terminate_service
authorJohn Mulligan <jmulligan@redhat.com>
Sun, 19 Nov 2023 00:09:29 +0000 (19:09 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 2 Jan 2024 14:30:21 +0000 (09:30 -0500)
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 <jmulligan@redhat.com>
src/cephadm/cephadm.py
src/cephadm/tests/test_cephadm.py

index 09a373dd27edf6907e69b146d05185257a692dfb..7b9ca0fd0ab650fada8e0d669141bb8f5e254d90 100755 (executable)
@@ -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'])
index 7bca8b9cbf3ca99159c2ea9881e35eff40a12b62..9c6caf0092b7455098ba390c23ff26a65ed4c8e5 100644 (file)
@@ -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',