Merge "Implement query param schema for quota set APIs"

This commit is contained in:
Zuul 2017-11-23 17:05:26 +00:00 committed by Gerrit Code Review
commit d022afd222
3 changed files with 54 additions and 0 deletions

View File

@ -95,6 +95,7 @@ class QuotaSetsController(wsgi.Controller):
def show(self, req, id):
return self._show(req, id, FILTERED_QUOTAS)
@validation.query_schema(quota_sets.query_schema)
def _show(self, req, id, filtered_quotas):
context = req.environ['nova.context']
context.can(qs_policies.POLICY_ROOT % 'show', {'project_id': id})
@ -116,6 +117,7 @@ class QuotaSetsController(wsgi.Controller):
def detail(self, req, id):
return self._detail(req, id, FILTERED_QUOTAS)
@validation.query_schema(quota_sets.query_schema)
def _detail(self, req, id, filtered_quotas):
context = req.environ['nova.context']
context.can(qs_policies.POLICY_ROOT % 'detail', {'project_id': id})
@ -139,6 +141,7 @@ class QuotaSetsController(wsgi.Controller):
def update(self, req, id, body):
return self._update(req, id, body, FILTERED_QUOTAS)
@validation.query_schema(quota_sets.query_schema)
def _update(self, req, id, body, filtered_quotas):
context = req.environ['nova.context']
context.can(qs_policies.POLICY_ROOT % 'update', {'project_id': id})
@ -220,6 +223,7 @@ class QuotaSetsController(wsgi.Controller):
# +microversions because the resource quota-set has been deleted completely
# when returning a response.
@extensions.expected_errors(())
@validation.query_schema(quota_sets.query_schema)
@wsgi.response(202)
def delete(self, req, id):
context = req.environ['nova.context']

View File

@ -68,3 +68,15 @@ update = {
update_v236 = copy.deepcopy(update)
update_v236['properties']['quota_set']['properties'] = update_quota_set_v236
query_schema = {
'type': 'object',
'properties': {
'user_id': parameter_types.multi_params({'type': 'string'})
},
# NOTE(gmann): This is kept True to keep backward compatibility.
# As of now Schema validation stripped out the additional parameters and
# does not raise 400. In the future, we may block the additional parameters
# by bump in Microversion.
'additionalProperties': True
}

View File

@ -295,6 +295,44 @@ class QuotaSetsTestV21(BaseQuotaSetsTest):
self.controller.update(self._get_http_request(),
1234, body={'quota_set': {'networks': 1}})
def test_duplicate_quota_filter(self):
query_string = 'user_id=1&user_id=2'
req = fakes.HTTPRequest.blank('', query_string=query_string)
self.controller.show(req, 1234)
self.controller.update(req, 1234, body={'quota_set': {}})
self.controller.detail(req, 1234)
self.controller.delete(req, 1234)
def test_quota_filter_negative_int_as_string(self):
req = fakes.HTTPRequest.blank('', query_string='user_id=-1')
self.controller.show(req, 1234)
self.controller.update(req, 1234, body={'quota_set': {}})
self.controller.detail(req, 1234)
self.controller.delete(req, 1234)
def test_quota_filter_int_as_string(self):
req = fakes.HTTPRequest.blank('', query_string='user_id=123')
self.controller.show(req, 1234)
self.controller.update(req, 1234, body={'quota_set': {}})
self.controller.detail(req, 1234)
self.controller.delete(req, 1234)
def test_unknown_quota_filter(self):
query_string = 'unknown_filter=abc'
req = fakes.HTTPRequest.blank('', query_string=query_string)
self.controller.show(req, 1234)
self.controller.update(req, 1234, body={'quota_set': {}})
self.controller.detail(req, 1234)
self.controller.delete(req, 1234)
def test_quota_additional_filter(self):
query_string = 'user_id=1&additional_filter=2'
req = fakes.HTTPRequest.blank('', query_string=query_string)
self.controller.show(req, 1234)
self.controller.update(req, 1234, body={'quota_set': {}})
self.controller.detail(req, 1234)
self.controller.delete(req, 1234)
class ExtendedQuotasTestV21(BaseQuotaSetsTest):
plugin = quotas_v21