]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Prevent iSCSI target recreation when editing controls 34551/head
authorTiago Melo <tmelo@suse.com>
Thu, 19 Mar 2020 12:51:24 +0000 (11:51 -0100)
committerTiago Melo <tmelo@suse.com>
Wed, 15 Apr 2020 21:34:38 +0000 (21:34 +0000)
Also prevents updating target auth, when this was not modified.

Fixes: https://tracker.ceph.com/issues/44659
Signed-off-by: Tiago Melo <tmelo@suse.com>
(cherry picked from commit 7d370ce22259a5b6a6c25995a1857d960dc5d27d)

src/pybind/mgr/dashboard/controllers/iscsi.py
src/pybind/mgr/dashboard/tests/test_iscsi.py

index cd4a21bb412ee891db420387bdbe9790fd015de1..811d7fafdfd6f8abb928c0d662843917c2b0ec0f 100644 (file)
@@ -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']
index 38f8386debf7da8d9fc7c4f7c9a4d79cfadfde8f..07ef464f25bf4ef8df532e3780823e4e97851335 100644 (file)
@@ -553,6 +553,7 @@ class IscsiClientMock(object):
 
     def get_settings(self):
         return {
+            "api_version": 2,
             "backstores": [
                 "user:rbd"
             ],