Merge "Add new detail kwarg to show_quota_set to QuotasClient."

This commit is contained in:
Jenkins
2017-03-14 07:36:05 +00:00
committed by Gerrit Code Review
5 changed files with 165 additions and 10 deletions

View File

@@ -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.

View File

@@ -62,8 +62,8 @@ class QuotasTestJSON(base.BaseV2ComputeTest):
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())

View File

@@ -60,6 +60,124 @@ get_quota_set['response_body']['properties']['quota_set']['properties'][
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]
}

View File

@@ -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 @@ from tempest.lib.services.compute import base_compute_client
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):

View File

@@ -49,22 +49,35 @@ class TestQuotasClient(base.BaseServiceTest):
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 @@ class TestQuotasClient(base.BaseServiceTest):
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,