Add new detail kwarg to show_quota_set to QuotasClient.
Currently, quotas_client.QuotasClient doesn't support the
'os-quota-sets/{tenant_id}/detail' endpoint [0] but is supported
by Nova [1].
Nova uses the policy 'os_compute_api:os-quota-sets:detail'
for the endpoint ending with /detail and
'os_compute_api:os-quota-sets:show' without the /detail uri [2].
This is needed by Patrole for complete test coverage for Nova.
This patch adds the kwarg to show_quota_set which calls the '/detail'
endpoint, if True. Also updated quotas schema with
get_quota_set_details, because each property in the response body
is of type object, not integer [1].
[0] https://github.com/openstack/tempest/blob/master/tempest/lib/services/compute/quotas_client.py
[1] https://developer.openstack.org/api-ref/compute/?expanded=show-the-detail-of-quota-detail#show-the-detail-of-quota
[2] https://github.com/openstack/nova/blob/master/nova/policies/quota_sets.py
Change-Id: I9a65411c6bf65bf20842719bffe46c7fa7db82eb
Closes-Bug: #1662593
diff --git a/releasenotes/notes/add-quota-sets-detail-kwarg-74b72183295b3ce7.yaml b/releasenotes/notes/add-quota-sets-detail-kwarg-74b72183295b3ce7.yaml
new file mode 100644
index 0000000..06f4fcd
--- /dev/null
+++ b/releasenotes/notes/add-quota-sets-detail-kwarg-74b72183295b3ce7.yaml
@@ -0,0 +1,6 @@
+---
+features:
+ - |
+ Interface show_quota_set of compute quotas_client has been extended to include the
+ argument "detail", which allows for detailed quota set information for a project to be
+ retrieved, if set to True.
diff --git a/tempest/api/compute/test_quotas.py b/tempest/api/compute/test_quotas.py
index 0ad2df8..9d83ee1 100644
--- a/tempest/api/compute/test_quotas.py
+++ b/tempest/api/compute/test_quotas.py
@@ -62,8 +62,8 @@
self.assertIn(quota, quota_set.keys())
# get the quota set using user id
- quota_set = self.client.show_quota_set(self.tenant_id,
- self.user_id)['quota_set']
+ quota_set = self.client.show_quota_set(
+ self.tenant_id, user_id=self.user_id)['quota_set']
self.assertEqual(quota_set['id'], self.tenant_id)
for quota in expected_quota_set:
self.assertIn(quota, quota_set.keys())
diff --git a/tempest/lib/api_schema/response/compute/v2_1/quotas.py b/tempest/lib/api_schema/response/compute/v2_1/quotas.py
index 7953983..44f5bdf 100644
--- a/tempest/lib/api_schema/response/compute/v2_1/quotas.py
+++ b/tempest/lib/api_schema/response/compute/v2_1/quotas.py
@@ -60,6 +60,124 @@
get_quota_set['response_body']['properties']['quota_set']['required'].extend([
'id'])
+get_quota_set_details = copy.deepcopy(get_quota_set)
+get_quota_set_details['response_body']['properties']['quota_set'][
+ 'properties'] = {
+ 'id': {'type': 'string'},
+ 'instances': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'cores': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'ram': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'floating_ips': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'fixed_ips': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'metadata_items': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'key_pairs': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'security_groups': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'security_group_rules': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'server_group_members': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'server_groups': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'injected_files': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'injected_file_content_bytes': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ },
+ 'injected_file_path_bytes': {
+ 'type': 'object',
+ 'properties': {
+ 'reserved': {'type': 'integer'},
+ 'limit': {'type': 'integer'},
+ 'in_use': {'type': 'integer'}
+ }
+ }
+}
+
delete_quota = {
'status_code': [202]
}
diff --git a/tempest/lib/services/compute/quotas_client.py b/tempest/lib/services/compute/quotas_client.py
index a2b0397..3839c74 100644
--- a/tempest/lib/services/compute/quotas_client.py
+++ b/tempest/lib/services/compute/quotas_client.py
@@ -14,6 +14,7 @@
# under the License.
from oslo_serialization import jsonutils as json
+from six.moves.urllib import parse as urllib
from tempest.lib.api_schema.response.compute.v2_1 import quotas as schema
from tempest.lib.common import rest_client
@@ -22,15 +23,29 @@
class QuotasClient(base_compute_client.BaseComputeClient):
- def show_quota_set(self, tenant_id, user_id=None):
- """List the quota set for a tenant."""
+ def show_quota_set(self, tenant_id, user_id=None, detail=False):
+ """List the quota set for a tenant.
+ For a full list of available parameters, please refer to the official
+ API reference:
+ http://developer.openstack.org/api-ref-compute-v2.1.html/#show-a-quota
+ http://developer.openstack.org/api-ref-compute-v2.1.html/#show-the-detail-of-quota
+ """
+
+ params = {}
url = 'os-quota-sets/%s' % tenant_id
+ if detail:
+ url += '/detail'
if user_id:
- url += '?user_id=%s' % user_id
+ params.update({'user_id': user_id})
+ if params:
+ url += '?%s' % urllib.urlencode(params)
resp, body = self.get(url)
body = json.loads(body)
- self.validate_response(schema.get_quota_set, resp, body)
+ if detail:
+ self.validate_response(schema.get_quota_set_details, resp, body)
+ else:
+ self.validate_response(schema.get_quota_set, resp, body)
return rest_client.ResponseBody(resp, body)
def show_default_quota_set(self, tenant_id):
diff --git a/tempest/tests/lib/services/compute/test_quotas_client.py b/tempest/tests/lib/services/compute/test_quotas_client.py
index 4c49e8d..bbb8eb7 100644
--- a/tempest/tests/lib/services/compute/test_quotas_client.py
+++ b/tempest/tests/lib/services/compute/test_quotas_client.py
@@ -49,22 +49,35 @@
self.client = quotas_client.QuotasClient(
fake_auth, 'compute', 'regionOne')
- def _test_show_quota_set(self, bytes_body=False, user_id=None):
+ def _get_quota_set(self, detail):
+ if not detail:
+ return self.FAKE_QUOTA_SET
+ fake_quota_set = {"quota_set": {}}
+ for key, val in self.FAKE_QUOTA_SET['quota_set'].items():
+ fake_quota_set['quota_set'][key] = \
+ {'limit': val, 'reserved': 0, 'in_use': 0}
+ fake_quota_set['quota_set']['id'] = "8421f7be61064f50b680465c07f334af"
+ return fake_quota_set
+
+ def _test_show_quota_set(self, bytes_body=False, detail=False,
+ user_id=None):
if user_id:
self.check_service_client_function(
self.client.show_quota_set,
'tempest.lib.common.rest_client.RestClient.get',
- self.FAKE_QUOTA_SET,
+ self._get_quota_set(detail),
to_utf=bytes_body,
tenant_id=self.project_id,
+ detail=detail,
user_id=user_id)
else:
self.check_service_client_function(
self.client.show_quota_set,
'tempest.lib.common.rest_client.RestClient.get',
- self.FAKE_QUOTA_SET,
+ self._get_quota_set(detail),
to_utf=bytes_body,
- tenant_id=self.project_id)
+ tenant_id=self.project_id,
+ detail=detail)
def test_show_quota_set_with_str_body(self):
self._test_show_quota_set()
@@ -78,6 +91,9 @@
def test_show_quota_set_for_user_with_bytes_body(self):
self._test_show_quota_set(bytes_body=True, user_id=self.fake_user_id)
+ def test_show_quota_set_with_details(self):
+ self._test_show_quota_set(detail=True)
+
def _test_show_default_quota_set(self, bytes_body=False):
self.check_service_client_function(
self.client.show_default_quota_set,