From: Dimitri Savineau Date: Wed, 7 Jul 2021 14:11:41 +0000 (-0400) Subject: mgr/cephadm/iscsi: check if dashboard is enabled X-Git-Tag: v17.1.0~1392^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=1b83aea8b0f5156f3e8bf0c3e33853fb4557f888;p=ceph.git mgr/cephadm/iscsi: check if dashboard is enabled When the mgr dashboard module isn't enabled then the iSCSI service deletion is stuck and the cluster state goes ERR. The `ceph dashboard` commands aren't available when the mgr dashboard module isnt' enabled. Closes: https://tracker.ceph.com/issues/51546 Signed-off-by: Dimitri Savineau --- diff --git a/src/pybind/mgr/cephadm/services/iscsi.py b/src/pybind/mgr/cephadm/services/iscsi.py index c87307e1b7364..a36ad3bca16a6 100644 --- a/src/pybind/mgr/cephadm/services/iscsi.py +++ b/src/pybind/mgr/cephadm/services/iscsi.py @@ -8,7 +8,7 @@ from ipaddress import ip_address, IPv6Address from mgr_module import HandleCommandResult from ceph.deployment.service_spec import IscsiServiceSpec -from orchestrator import DaemonDescription, DaemonDescriptionStatus +from orchestrator import DaemonDescription, DaemonDescriptionStatus, OrchestratorError from .cephadmservice import CephadmDaemonDeploySpec, CephService from .. import utils @@ -150,12 +150,24 @@ class IscsiService(CephService): """ 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, + 'prefix': 'mgr module ls', + 'format': 'json', }) - logger.info(f'{daemon.hostname} removed from iscsi gateways dashboard config') + try: + j = json.loads(out) + except ValueError: + msg = 'Failed to parse mgr module ls: Cannot decode JSON' + logger.exception('%s: \'%s\'' % (msg, out)) + raise OrchestratorError('failed to parse mgr module ls') + + if 'dashboard' in j['enabled_modules']: + # 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 = {} diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 4fc510a4c416c..a02afd143d073 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -889,6 +889,7 @@ spec: placement=ps) unmanaged_spec = ServiceSpec.from_json(spec.to_json()) unmanaged_spec.unmanaged = True + cephadm_module._mon_command_mock_mgr_module_ls = lambda *args: json.dumps({'enabled_modules': []}) with with_service(cephadm_module, unmanaged_spec): c = cephadm_module.add_daemon(spec) @@ -1024,6 +1025,7 @@ spec: @mock.patch("subprocess.run", mock.MagicMock()) def test_apply_save(self, spec: ServiceSpec, meth, cephadm_module: CephadmOrchestrator): with with_host(cephadm_module, 'test'): + cephadm_module._mon_command_mock_mgr_module_ls = lambda *args: json.dumps({'enabled_modules': []}) with with_service(cephadm_module, spec, meth, 'test'): pass