From: Ricardo Marques Date: Fri, 29 Mar 2019 09:28:56 +0000 (+0000) Subject: mgr/dashboard: Check if gateway is in use before deletion X-Git-Tag: v14.2.1~39^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ff70c99152d1cf60c4f18aeac8e248e9f82572d9;p=ceph.git mgr/dashboard: Check if gateway is in use before deletion Fixes: https://tracker.ceph.com/issues/39029 Signed-off-by: Ricardo Marques (cherry picked from commit 0e357ca70679a67155e54cd2cf804f1819d23d69) --- diff --git a/src/pybind/mgr/dashboard/services/iscsi_cli.py b/src/pybind/mgr/dashboard/services/iscsi_cli.py index fca1f61b3cc1..d7a0a0139cd9 100644 --- a/src/pybind/mgr/dashboard/services/iscsi_cli.py +++ b/src/pybind/mgr/dashboard/services/iscsi_cli.py @@ -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: diff --git a/src/pybind/mgr/dashboard/services/iscsi_config.py b/src/pybind/mgr/dashboard/services/iscsi_config.py index df6537c0c54c..e4a78f6b626e 100644 --- a/src/pybind/mgr/dashboard/services/iscsi_config.py +++ b/src/pybind/mgr/dashboard/services/iscsi_config.py @@ -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__(