Use correct cinder API version for tenant_absolute_limits

To verify resource usages when updating project quotas,
project_id query parameter needs to be supported in
tenant_absolute_limits in the cinder API.

This is supported in 3.39 or later in the cinder API.
API vesions shipped with released versions (pike, queens and
rocky) are selected as verified versions.

Change-Id: If5fc190988cf173387da2b66be23db9134310692
Closes-Bug: #1810309
This commit is contained in:
Akihiro Motoki 2019-01-15 03:34:23 +09:00
parent df897988d1
commit 32bfbbf100
3 changed files with 20 additions and 3 deletions

View File

@ -986,10 +986,24 @@ def qos_specs_list(request):
return [QosSpecs(s) for s in qos_spec_list(request)]
def _cinderclient_with_limits_project_id_query(request):
version = get_microversion(request, ['limits_project_id_query'])
if version is None:
cinder_microversions = microversions.MICROVERSION_FEATURES['cinder']
LOG.warning('Insufficient microversion for GET limits with '
'project_id query. One of the following API micro '
'version is required: %s',
cinder_microversions['limits_project_id_query'])
else:
version = version.get_string()
return cinderclient(request, version=version)
@profiler.trace
@memoized
def tenant_absolute_limits(request, tenant_id=None):
limits = cinderclient(request).limits.get(tenant_id=tenant_id).absolute
_cinderclient = _cinderclient_with_limits_project_id_query(request)
limits = _cinderclient.limits.get(tenant_id=tenant_id).absolute
limits_dict = {}
for limit in limits:
if limit.value < 0:

View File

@ -39,7 +39,8 @@ MICROVERSION_FEATURES = {
"cinder": {
"groups": ["3.27", "3.43", "3.48"],
"consistency_groups": ["2.0", "3.10"],
"message_list": ["3.5", "3.29"]
"message_list": ["3.5", "3.29"],
"limits_project_id_query": ["3.43", "3.50", "3.55"],
}
}

View File

@ -394,7 +394,8 @@ class CinderApiTests(test.APIMockTestCase):
qos_associations_mock.assert_called_once_with(qos_specs_only_one[0].id)
self.assertEqual(associate_spec, qos_specs_only_one[0].name)
@mock.patch.object(api.cinder, 'cinderclient')
@mock.patch.object(api.cinder,
'_cinderclient_with_limits_project_id_query')
def test_absolute_limits_with_negative_values(self, mock_cinderclient):
values = {"maxTotalVolumes": -1, "totalVolumesUsed": -1}
expected_results = {"maxTotalVolumes": float("inf"),
@ -421,6 +422,7 @@ class CinderApiTests(test.APIMockTestCase):
self.assertEqual(expected_results[key], ret_val[key])
mock_limit.assert_called_once()
mock_cinderclient.assert_called_once_with(self.request)
@mock.patch.object(api.cinder, 'cinderclient')
def test_pool_list(self, mock_cinderclient):