]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: Purge iscsi configuration from pool and ceph config
authorJuan Miguel Olmo Martínez <jolmomar@redhat.com>
Mon, 22 Mar 2021 15:14:03 +0000 (16:14 +0100)
committerSage Weil <sage@newdream.net>
Fri, 7 May 2021 12:38:15 +0000 (07:38 -0500)
Remove gateway.conf from iscsi pool when service is removed
Remove iscsi ceph config keys
Remove iscsi dashboard gateways config from dashboard

fixes: https://tracker.ceph.com/issues/48930

Signed-off-by: Juan Miguel Olmo Martínez <jolmomar@redhat.com>
(cherry picked from commit 1b9e3edcfd1c1a3dd02d6eb14072494f57b086a8)

src/pybind/mgr/cephadm/services/iscsi.py

index 7737a637422ff89a0a3377674b2b1769879509f7..7445acfcde97c8ee8a18dd3290315c5528f439a1 100644 (file)
@@ -1,6 +1,7 @@
 import errno
 import json
 import logging
+import subprocess
 from typing import List, cast, Optional
 from ipaddress import ip_address, IPv6Address
 
@@ -142,3 +143,56 @@ class IscsiService(CephService):
         names = [f'{self.TYPE}.{d_id}' for d_id in daemon_ids]
         warn_message = f'It is presumed safe to stop {names}'
         return HandleCommandResult(0, warn_message, '')
+
+    def post_remove(self, daemon: DaemonDescription) -> None:
+        """
+        Called after the daemon is removed.
+        """
+        logger.debug(f'Post remove daemon {self.TYPE}.{daemon.daemon_id}')
+
+        # remove config for dashboard iscsi gateways
+        ret, out, err = self.mgr.check_mon_command({
+            'prefix': 'dashboard iscsi-gateway-rm',
+            'name': daemon.hostname,
+        })
+        logger.info(f'{daemon.hostname} removed from iscsi gateways dashboard config')
+
+        # needed to know if we have ssl stuff for iscsi in ceph config
+        iscsi_config_dict = {}
+        ret, iscsi_config, err = self.mgr.check_mon_command({
+            'prefix': 'config-key dump',
+            'key': 'iscsi',
+        })
+        if iscsi_config:
+            iscsi_config_dict = json.loads(iscsi_config)
+
+        # remove iscsi cert and key from ceph config
+        for iscsi_key, value in iscsi_config_dict.items():
+            if f'iscsi/client.{daemon.name()}/' in iscsi_key:
+                ret, out, err = self.mgr.check_mon_command({
+                    'prefix': 'config-key rm',
+                    'key': iscsi_key,
+                })
+                logger.info(f'{iscsi_key} removed from ceph config')
+
+    def purge(self, service_name: str) -> None:
+        """Removes configuration
+        """
+        spec = cast(IscsiServiceSpec, self.mgr.spec_store[service_name].spec)
+        try:
+            # remove service configuration from the pool
+            try:
+                subprocess.run(['rados',
+                                '-k', str(self.mgr.get_ceph_option('keyring')),
+                                '-n', f'mgr.{self.mgr.get_mgr_id()}',
+                                '-p', cast(str, spec.pool),
+                                'rm',
+                                'gateway.conf'])
+                logger.info(f'<gateway.conf> removed from {spec.pool}')
+            except subprocess.CalledProcessError as ex:
+                logger.error(f'Error executing <<{ex.cmd}>>: {ex.output}')
+            except subprocess.TimeoutExpired:
+                logger.error(f'timeout (5s) trying to remove <gateway.conf> from {spec.pool}')
+
+        except Exception:
+            logger.exception(f'failed to purge {service_name}')