From: Juan Miguel Olmo Martínez Date: Mon, 22 Mar 2021 15:14:03 +0000 (+0100) Subject: mgr/cephadm: Purge iscsi configuration from pool and ceph config X-Git-Tag: v16.2.5~51^2~3^2~18 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ebf73e5ac8eb4c2d09756e9c2a33aea18f181d74;p=ceph.git mgr/cephadm: Purge iscsi configuration from pool and ceph config 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 (cherry picked from commit 1b9e3edcfd1c1a3dd02d6eb14072494f57b086a8) --- diff --git a/src/pybind/mgr/cephadm/services/iscsi.py b/src/pybind/mgr/cephadm/services/iscsi.py index 7737a637422..7445acfcde9 100644 --- a/src/pybind/mgr/cephadm/services/iscsi.py +++ b/src/pybind/mgr/cephadm/services/iscsi.py @@ -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' 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 from {spec.pool}') + + except Exception: + logger.exception(f'failed to purge {service_name}')