]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm/iscsi: check if dashboard is enabled 42220/head
authorDimitri Savineau <dsavinea@redhat.com>
Wed, 7 Jul 2021 14:11:41 +0000 (10:11 -0400)
committerDimitri Savineau <dsavinea@redhat.com>
Wed, 14 Jul 2021 14:02:22 +0000 (10:02 -0400)
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 <dsavinea@redhat.com>
src/pybind/mgr/cephadm/services/iscsi.py
src/pybind/mgr/cephadm/tests/test_cephadm.py

index c87307e1b73641e9bfeb57583176a618b98e82fb..a36ad3bca16a6d40c9503ba8a280bcacfe21a038 100644 (file)
@@ -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 = {}
index 4fc510a4c416cf82c3bd1fce47c1ec0cc3f4d2e6..a02afd143d0739046305da588e0296f48e4da287 100644 (file)
@@ -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