From: Tiago Melo Date: Thu, 19 Mar 2020 12:51:24 +0000 (-0100) Subject: mgr/dashboard: Prevent iSCSI target recreation when editing controls X-Git-Tag: v14.2.10~116^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=920eb09efb594a497fe0404970a035616d792bad;p=ceph.git mgr/dashboard: Prevent iSCSI target recreation when editing controls Also prevents updating target auth, when this was not modified. Fixes: https://tracker.ceph.com/issues/44659 Signed-off-by: Tiago Melo (cherry picked from commit 7d370ce22259a5b6a6c25995a1857d960dc5d27d) --- diff --git a/src/pybind/mgr/dashboard/controllers/iscsi.py b/src/pybind/mgr/dashboard/controllers/iscsi.py index cd4a21bb412e..811d7fafdfd6 100644 --- a/src/pybind/mgr/dashboard/controllers/iscsi.py +++ b/src/pybind/mgr/dashboard/controllers/iscsi.py @@ -300,6 +300,7 @@ class IscsiTarget(RESTController): raise DashboardException(msg='Target IQN already in use', code='target_iqn_already_in_use', component='iscsi') + settings = IscsiClient.instance(gateway_name=gateway).get_settings() new_portal_names = {p['host'] for p in portals} old_portal_names = set(config['targets'][target_iqn]['portals'].keys()) @@ -479,9 +480,12 @@ class IscsiTarget(RESTController): @staticmethod def _target_deletion_required(target, new_target_iqn, new_target_controls): + gateway = get_available_gateway() + settings = IscsiClient.instance(gateway_name=gateway).get_settings() + if target['target_iqn'] != new_target_iqn: return True - if target['target_controls'] != new_target_controls: + if settings['api_version'] < 2 and target['target_controls'] != new_target_controls: return True return False @@ -620,6 +624,13 @@ class IscsiTarget(RESTController): IscsiClient.instance(gateway_name=gateway_name).update_targetacl(target_iqn, targetauth_action) + @staticmethod + def _is_auth_equal(target_auth, auth): + return auth['user'] == target_auth['username'] and \ + auth['password'] == target_auth['password'] and \ + auth['mutual_user'] == target_auth['mutual_username'] and \ + auth['mutual_password'] == target_auth['mutual_password'] + @staticmethod def _create(target_iqn, target_controls, acl_enabled, auth, portals, disks, clients, groups, @@ -647,13 +658,17 @@ class IscsiTarget(RESTController): ip_list) TaskManager.current_task().inc_progress(task_progress_inc) - if acl_enabled: - IscsiTarget._update_targetauth(config, target_iqn, auth, gateway_name) - IscsiTarget._update_targetacl(target_config, target_iqn, acl_enabled, gateway_name) - - else: - IscsiTarget._update_targetacl(target_config, target_iqn, acl_enabled, gateway_name) - IscsiTarget._update_targetauth(config, target_iqn, auth, gateway_name) + if not target_config or \ + acl_enabled != target_config['acl_enabled'] or \ + not IscsiTarget._is_auth_equal(target_config['auth'], auth): + if acl_enabled: + IscsiTarget._update_targetauth(config, target_iqn, auth, gateway_name) + IscsiTarget._update_targetacl(target_config, target_iqn, acl_enabled, + gateway_name) + else: + IscsiTarget._update_targetacl(target_config, target_iqn, acl_enabled, + gateway_name) + IscsiTarget._update_targetauth(config, target_iqn, auth, gateway_name) for disk in disks: pool = disk['pool'] diff --git a/src/pybind/mgr/dashboard/tests/test_iscsi.py b/src/pybind/mgr/dashboard/tests/test_iscsi.py index 38f8386debf7..07ef464f25bf 100644 --- a/src/pybind/mgr/dashboard/tests/test_iscsi.py +++ b/src/pybind/mgr/dashboard/tests/test_iscsi.py @@ -553,6 +553,7 @@ class IscsiClientMock(object): def get_settings(self): return { + "api_version": 2, "backstores": [ "user:rbd" ],