Fix backward compatibility of compare volume stats

When we fixed tempest test "test_compare_volume_stats_values" (Change-Id
I04d0eaa1f6dba16bd11052f91a3d1d0967029ea6) to make it work with the
"storage_protocol" canonical names that are returned by Cinder master on
the get-pools call (after Change-Id Change-Id:
I07d74078dbb102490dd722029e32c74cec3aa44c) we made the test non-backward
compatible, because stable releases don't return canonical names.

For example the NFS driver will return value "nfs" in stable releases,
but the test expects it to be "NFS" and thus will fail.

This patch fixes this by converting "storage_protocol" for the result of
both the get-pools and get-capabilities calls.

So we have 3 different cases:

- Current cinder master code --> Should work with current test

- Stable cinder branches with some backends (eg: NFS) --> Fixed by this
  patch

- Future Cinder when get-capabilities returns canonical name (Change-Id
  I8b21fbc2c8ef29689f101f6c397550604662cd8a) --> Works with or without
  this patch.

Closes-Bug: #1979826
Change-Id: I56099463791bb9a0bda18cbf7d315825562042aa
This commit is contained in:
Gorka Eguileor 2022-06-28 12:58:43 +02:00
parent 3857a50f78
commit d30577d07c
1 changed files with 31 additions and 27 deletions

View File

@ -37,6 +37,33 @@ class BackendsCapabilitiesAdminTestsJSON(base.BaseVolumeAdminTest):
# 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 @@ class BackendsCapabilitiesAdminTestsJSON(base.BaseVolumeAdminTest):
'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 @@ class BackendsCapabilitiesAdminTestsJSON(base.BaseVolumeAdminTest):
]
# 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)