Skip to content

Commit

Permalink
mgr/dashboard: Optimize target edition when a portal is removed
Browse files Browse the repository at this point in the history
Fixes: https://tracker.ceph.com/issues/38794

Signed-off-by: Ricardo Marques <rimarques@suse.com>
  • Loading branch information
ricardoasmarques committed May 10, 2019
1 parent 8107bc6 commit f345fe3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
53 changes: 32 additions & 21 deletions src/pybind/mgr/dashboard/controllers/iscsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,30 +275,37 @@ def _delete(target_iqn, config, task_progress_begin, task_progress_end, new_targ
deleted_groups = []
for group_id in list(target_config['groups'].keys()):
if IscsiTarget._group_deletion_required(target, new_target_iqn, new_target_controls,
new_portals, new_groups, group_id, new_clients,
new_groups, group_id, new_clients,
new_disks):
deleted_groups.append(group_id)
IscsiClient.instance(gateway_name=gateway_name).delete_group(target_iqn,
group_id)
TaskManager.current_task().inc_progress(task_progress_inc)
for client_iqn in list(target_config['clients'].keys()):
if IscsiTarget._client_deletion_required(target, new_target_iqn, new_target_controls,
new_portals, new_clients, client_iqn,
new_clients, client_iqn,
new_groups, deleted_groups):
IscsiClient.instance(gateway_name=gateway_name).delete_client(target_iqn,
client_iqn)
TaskManager.current_task().inc_progress(task_progress_inc)
for image_id in target_config['disks']:
if IscsiTarget._target_lun_deletion_required(target, new_target_iqn,
new_target_controls, new_portals,
new_target_controls,
new_disks, image_id):
IscsiClient.instance(gateway_name=gateway_name).delete_target_lun(target_iqn,
image_id)
pool, image = image_id.split('/', 1)
IscsiClient.instance(gateway_name=gateway_name).delete_disk(pool, image)
TaskManager.current_task().inc_progress(task_progress_inc)
if IscsiTarget._target_deletion_required(target, new_target_iqn, new_target_controls,
new_portals):
old_portals_by_host = IscsiTarget._get_portals_by_host(target['portals'])
new_portals_by_host = IscsiTarget._get_portals_by_host(new_portals)
for old_portal_host, old_portal_ip_list in old_portals_by_host.items():
if IscsiTarget._target_portal_deletion_required(old_portal_host,
old_portal_ip_list,
new_portals_by_host):
IscsiClient.instance(gateway_name=gateway_name).delete_gateway(target_iqn,
old_portal_host)
if IscsiTarget._target_deletion_required(target, new_target_iqn, new_target_controls):
IscsiClient.instance(gateway_name=gateway_name).delete_target(target_iqn)
TaskManager.current_task().set_progress(task_progress_end)
return IscsiClient.instance(gateway_name=gateway_name).get_config()
Expand All @@ -311,10 +318,9 @@ def _get_group(groups, group_id):
return None

@staticmethod
def _group_deletion_required(target, new_target_iqn, new_target_controls, new_portals,
def _group_deletion_required(target, new_target_iqn, new_target_controls,
new_groups, group_id, new_clients, new_disks):
if IscsiTarget._target_deletion_required(target, new_target_iqn, new_target_controls,
new_portals):
if IscsiTarget._target_deletion_required(target, new_target_iqn, new_target_controls):
return True
new_group = IscsiTarget._get_group(new_groups, group_id)
if not new_group:
Expand All @@ -325,14 +331,14 @@ def _group_deletion_required(target, new_target_iqn, new_target_controls, new_po
# Check if any client inside this group has changed
for client_iqn in new_group['members']:
if IscsiTarget._client_deletion_required(target, new_target_iqn, new_target_controls,
new_portals, new_clients, client_iqn,
new_clients, client_iqn,
new_groups, []):
return True
# Check if any disk inside this group has changed
for disk in new_group['disks']:
image_id = '{}/{}'.format(disk['pool'], disk['image'])
if IscsiTarget._target_lun_deletion_required(target, new_target_iqn,
new_target_controls, new_portals,
new_target_controls,
new_disks, image_id):
return True
return False
Expand All @@ -345,10 +351,9 @@ def _get_client(clients, client_iqn):
return None

@staticmethod
def _client_deletion_required(target, new_target_iqn, new_target_controls, new_portals,
def _client_deletion_required(target, new_target_iqn, new_target_controls,
new_clients, client_iqn, new_groups, deleted_groups):
if IscsiTarget._target_deletion_required(target, new_target_iqn, new_target_controls,
new_portals):
if IscsiTarget._target_deletion_required(target, new_target_iqn, new_target_controls):
return True
new_client = deepcopy(IscsiTarget._get_client(new_clients, client_iqn))
if not new_client:
Expand All @@ -374,10 +379,9 @@ def _get_disk(disks, image_id):
return None

@staticmethod
def _target_lun_deletion_required(target, new_target_iqn, new_target_controls, new_portals,
def _target_lun_deletion_required(target, new_target_iqn, new_target_controls,
new_disks, image_id):
if IscsiTarget._target_deletion_required(target, new_target_iqn, new_target_controls,
new_portals):
if IscsiTarget._target_deletion_required(target, new_target_iqn, new_target_controls):
return True
new_disk = IscsiTarget._get_disk(new_disks, image_id)
if not new_disk:
Expand All @@ -388,13 +392,19 @@ def _target_lun_deletion_required(target, new_target_iqn, new_target_controls, n
return False

@staticmethod
def _target_deletion_required(target, new_target_iqn, new_target_controls, new_portals):
def _target_portal_deletion_required(old_portal_host, old_portal_ip_list, new_portals_by_host):
if old_portal_host not in new_portals_by_host:
return True
if sorted(old_portal_ip_list) != sorted(new_portals_by_host[old_portal_host]):
return True
return False

@staticmethod
def _target_deletion_required(target, new_target_iqn, new_target_controls):
if target['target_iqn'] != new_target_iqn:
return True
if target['target_controls'] != new_target_controls:
return True
if target['portals'] != new_portals:
return True
return False

@staticmethod
Expand Down Expand Up @@ -499,11 +509,12 @@ def _create(target_iqn, target_controls, acl_enabled,
if not target_config:
IscsiClient.instance(gateway_name=gateway_name).create_target(target_iqn,
target_controls)
for host, ip_list in portals_by_host.items():
for host, ip_list in portals_by_host.items():
if not target_config or host not in target_config['portals']:
IscsiClient.instance(gateway_name=gateway_name).create_gateway(target_iqn,
host,
ip_list)
TaskManager.current_task().inc_progress(task_progress_inc)
TaskManager.current_task().inc_progress(task_progress_inc)
targetauth_action = ('enable_acl' if acl_enabled else 'disable_acl')
IscsiClient.instance(gateway_name=gateway_name).update_targetauth(target_iqn,
targetauth_action)
Expand Down
5 changes: 5 additions & 0 deletions src/pybind/mgr/dashboard/services/iscsi_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ def create_gateway(self, target_iqn, gateway_name, ip_address, request=None):
def get_gatewayinfo(self, request=None):
return request()

@RestClient.api_delete('/api/gateway/{target_iqn}/{gateway_name}')
def delete_gateway(self, target_iqn, gateway_name, request=None):
logger.debug("iSCSI: Deleting gateway: %s/%s", target_iqn, gateway_name)
return request()

@RestClient.api_put('/api/disk/{pool}/{image}')
def create_disk(self, pool, image, backstore, request=None):
logger.debug("iSCSI[%s] Creating disk: %s/%s", self.gateway_name, pool, image)
Expand Down
6 changes: 6 additions & 0 deletions src/pybind/mgr/dashboard/tests/test_iscsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,12 @@ def create_gateway(self, target_iqn, gateway_name, ip_address):
"portal_ip_address": ip_address[0]
}

def delete_gateway(self, target_iqn, gateway_name):
target_config = self.config['targets'][target_iqn]
portal_config = target_config['portals'][gateway_name]
target_config['ip_list'].remove(portal_config['portal_ip_address'])
target_config['portals'].pop(gateway_name)

def create_disk(self, pool, image, backstore):
image_id = '{}/{}'.format(pool, image)
self.config['disks'][image_id] = {
Expand Down

0 comments on commit f345fe3

Please sign in to comment.