]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Check if gateway is in use before deletion 27457/head
authorRicardo Marques <rimarques@suse.com>
Fri, 29 Mar 2019 09:28:56 +0000 (09:28 +0000)
committerRicardo Marques <rimarques@suse.com>
Tue, 9 Apr 2019 09:44:18 +0000 (10:44 +0100)
Fixes: https://tracker.ceph.com/issues/39029
Signed-off-by: Ricardo Marques <rimarques@suse.com>
(cherry picked from commit 0e357ca70679a67155e54cd2cf804f1819d23d69)

src/pybind/mgr/dashboard/services/iscsi_cli.py
src/pybind/mgr/dashboard/services/iscsi_config.py

index fca1f61b3cc14db1a24a176f935bad97ba016bfb..d7a0a0139cd9a612c37c47b223254d11992c29b6 100644 (file)
@@ -8,7 +8,7 @@ from mgr_module import CLIReadCommand, CLIWriteCommand
 
 from .iscsi_client import IscsiClient
 from .iscsi_config import IscsiGatewaysConfig, IscsiGatewayAlreadyExists, InvalidServiceUrl, \
-    ManagedByOrchestratorException, IscsiGatewayDoesNotExist
+    ManagedByOrchestratorException, IscsiGatewayDoesNotExist, IscsiGatewayInUse
 from ..rest_client import RequestException
 
 
@@ -41,8 +41,16 @@ def add_iscsi_gateway(_, service_url):
                  'Remove iSCSI gateway configuration')
 def remove_iscsi_gateway(_, name):
     try:
+        try:
+            iscsi_config = IscsiClient.instance(gateway_name=name).get_config()
+            if name in iscsi_config['gateways']:
+                raise IscsiGatewayInUse(name)
+        except RequestException:
+            pass
         IscsiGatewaysConfig.remove_gateway(name)
         return 0, 'Success', ''
+    except IscsiGatewayInUse as ex:
+        return -errno.EBUSY, '', str(ex)
     except IscsiGatewayDoesNotExist as ex:
         return -errno.ENOENT, '', str(ex)
     except ManagedByOrchestratorException as ex:
index df6537c0c54c1a43ecb33187a9528028790c3195..e4a78f6b626ef6f6eb57061bb1871ab2942ca669 100644 (file)
@@ -24,6 +24,12 @@ class IscsiGatewayDoesNotExist(Exception):
             "iSCSI gateway '{}' does not exist".format(hostname))
 
 
+class IscsiGatewayInUse(Exception):
+    def __init__(self, hostname):
+        super(IscsiGatewayInUse, self).__init__(
+            "iSCSI gateway '{}' is in use".format(hostname))
+
+
 class InvalidServiceUrl(Exception):
     def __init__(self, service_url):
         super(InvalidServiceUrl, self).__init__(