From 0e357ca70679a67155e54cd2cf804f1819d23d69 Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Fri, 29 Mar 2019 09:28:56 +0000 Subject: [PATCH] mgr/dashboard: Check if gateway is in use before deletion Fixes: https://tracker.ceph.com/issues/39029 Signed-off-by: Ricardo Marques --- src/pybind/mgr/dashboard/services/iscsi_cli.py | 10 +++++++++- src/pybind/mgr/dashboard/services/iscsi_config.py | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/dashboard/services/iscsi_cli.py b/src/pybind/mgr/dashboard/services/iscsi_cli.py index fca1f61b3cc..d7a0a0139cd 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 df6537c0c54..e4a78f6b626 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__( -- 2.39.5