From 32bfbbf10074b49b36447abd2e4f47f9f39d0ea7 Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Tue, 15 Jan 2019 03:34:23 +0900 Subject: [PATCH] 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 --- openstack_dashboard/api/cinder.py | 16 +++++++++++++++- openstack_dashboard/api/microversions.py | 3 ++- openstack_dashboard/test/unit/api/test_cinder.py | 4 +++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/openstack_dashboard/api/cinder.py b/openstack_dashboard/api/cinder.py index 215fcd13e7..d283bff06a 100644 --- a/openstack_dashboard/api/cinder.py +++ b/openstack_dashboard/api/cinder.py @@ -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: diff --git a/openstack_dashboard/api/microversions.py b/openstack_dashboard/api/microversions.py index a1fba3cb48..a1091eabff 100644 --- a/openstack_dashboard/api/microversions.py +++ b/openstack_dashboard/api/microversions.py @@ -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"], } } diff --git a/openstack_dashboard/test/unit/api/test_cinder.py b/openstack_dashboard/test/unit/api/test_cinder.py index be714c5a8d..5805824ed0 100644 --- a/openstack_dashboard/test/unit/api/test_cinder.py +++ b/openstack_dashboard/test/unit/api/test_cinder.py @@ -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):