Merge "Fix backward compatibility of compare volume stats"
diff --git a/tempest/api/volume/admin/test_backends_capabilities.py b/tempest/api/volume/admin/test_backends_capabilities.py
index 9a85ed4..e3a8156 100644
--- a/tempest/api/volume/admin/test_backends_capabilities.py
+++ b/tempest/api/volume/admin/test_backends_capabilities.py
@@ -37,6 +37,33 @@
         # Check response schema
         self.admin_capabilities_client.show_backend_capabilities(self.hosts[0])
 
+    @staticmethod
+    def _change_capabilities_storage_protocol(capabilities):
+        """Convert storage_protocol to its canonical version"""
+        # List of storage protocols variants defined in cinder.common.constants
+        # The canonical name for storage protocol comes first in the list
+        VARIANTS = [['iSCSI', 'iscsi'], ['FC', 'fibre_channel', 'fc'],
+                    ['NFS', 'nfs'], ['NVMe-oF', 'NVMeOF', 'nvmeof']]
+
+        capabilities = sorted(list(capabilities))
+
+        # Cinder Bug #1966103: Some drivers were reporting different strings
+        # to represent the same storage protocol. For backward compatibility,
+        # the scheduler can handle the variants, but to standardize this for
+        # operators (who may need to refer to the protocol in volume-type
+        # extra-specs), the get-pools and get-capabilities response was changed
+        # to only report the canonical name for a storage protocol, but these
+        # 2 REST API call swere not changed simultaneously, so we may or may
+        # not get canonical names, so just convert canonical names.
+        for item in range(len(capabilities)):
+            for variants in VARIANTS:
+                if capabilities[item][2] in variants:
+                    capabilities[item] = (capabilities[item][0],
+                                          capabilities[item][1],
+                                          variants[0])
+
+        return capabilities
+
     @decorators.idempotent_id('a9035743-d46a-47c5-9cb7-3c80ea16dea0')
     def test_compare_volume_stats_values(self):
         """Test comparing volume stats values
@@ -47,11 +74,6 @@
                         'volume_backend_name',
                         'storage_protocol')
 
-        # List of storage protocols variants defined in cinder.common.constants
-        # The canonical name for storage protocol comes first in the list
-        VARIANTS = [['iSCSI', 'iscsi'], ['FC', 'fibre_channel', 'fc'],
-                    ['NFS', 'nfs'], ['NVMe-oF', 'NVMeOF', 'nvmeof']]
-
         # Get list backend capabilities using show_pools
         cinder_pools = [
             pool['capabilities'] for pool in
@@ -65,27 +87,9 @@
         ]
 
         # Returns a tuple of VOLUME_STATS values
-        expected_list = sorted(list(map(operator.itemgetter(*VOLUME_STATS),
-                                        cinder_pools)))
-        observed_list = sorted(list(map(operator.itemgetter(*VOLUME_STATS),
-                                        capabilities)))
-
-        # Cinder Bug #1966103: Some drivers were reporting different strings
-        # to represent the same storage protocol. For backward compatibility,
-        # the scheduler can handle the variants, but to standardize this for
-        # operators (who may need to refer to the protocol in volume-type
-        # extra-specs), the get-pools response was changed by I07d74078dbb1
-        # to only report the canonical name for a storage protocol. Thus, the
-        # expected_list (which we got from the get-pools call) will only
-        # contain canonical names, while the observed_list (which we got
-        # from the driver capabilities call) may contain a variant. So before
-        # comparing the lists, we need to look for known variants in the
-        # observed_list elements and replace them with their canonical values
-        for item in range(len(observed_list)):
-            for variants in VARIANTS:
-                if observed_list[item][2] in variants:
-                    observed_list[item] = (observed_list[item][0],
-                                           observed_list[item][1],
-                                           variants[0])
+        expected_list = self._change_capabilities_storage_protocol(
+            map(operator.itemgetter(*VOLUME_STATS), cinder_pools))
+        observed_list = self._change_capabilities_storage_protocol(
+            map(operator.itemgetter(*VOLUME_STATS), capabilities))
 
         self.assertEqual(expected_list, observed_list)