Validate maximum limit for integer
If you pass limit value above mysql INT type to quota-class-update api, then it raises 500 internal server error. Passed max_value=db.MAX_INT to validate_integer() method to get appropriate error. Closes-Bug: #1463387 Change-Id: I1075a20ea0142db6c35f1124ba40b23ffef4c2f8
This commit is contained in:
parent
045ee0336b
commit
013e322733
|
@ -84,7 +84,8 @@ class QuotaClassSetsController(wsgi.Controller):
|
|||
bad_keys.append(key)
|
||||
continue
|
||||
try:
|
||||
utils.validate_integer(body['quota_class_set'][key], key)
|
||||
body['quota_class_set'][key] = utils.validate_integer(
|
||||
body['quota_class_set'][key], key, max_value=db.MAX_INT)
|
||||
except exception.InvalidInput as e:
|
||||
raise webob.exc.HTTPBadRequest(
|
||||
explanation=e.format_message())
|
||||
|
@ -93,9 +94,7 @@ class QuotaClassSetsController(wsgi.Controller):
|
|||
msg = _("Bad key(s) %s in quota_set") % ",".join(bad_keys)
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
for key in quota_class_set.keys():
|
||||
value = utils.validate_integer(
|
||||
body['quota_class_set'][key], key)
|
||||
for key, value in quota_class_set.items():
|
||||
try:
|
||||
db.quota_class_update(context, quota_class, key, value)
|
||||
except exception.QuotaClassNotFound:
|
||||
|
|
|
@ -15,12 +15,14 @@
|
|||
import copy
|
||||
|
||||
from nova.api.validation import parameter_types
|
||||
from nova import db
|
||||
|
||||
common_quota = {
|
||||
'type': ['integer', 'string'],
|
||||
'pattern': '^-?[0-9]+$',
|
||||
# -1 is a flag value for unlimited
|
||||
'minimum': -1
|
||||
'minimum': -1,
|
||||
'maximum': db.MAX_INT
|
||||
}
|
||||
|
||||
quota_resources = {
|
||||
|
|
|
@ -128,6 +128,11 @@ class QuotaClassSetsTestV21(test.TestCase):
|
|||
self.assertRaises(self.validation_error, self.controller.update,
|
||||
self.req_admin, 'test_class', body=body)
|
||||
|
||||
def test_quotas_update_with_invalid_integer(self):
|
||||
body = {'quota_class_set': {'instances': 2 ** 31 + 1}}
|
||||
self.assertRaises(self.validation_error, self.controller.update,
|
||||
self.req_admin, 'test_class', body=body)
|
||||
|
||||
def test_quotas_update_with_non_integer(self):
|
||||
body = {'quota_class_set': {'instances': "abc"}}
|
||||
self.assertRaises(self.validation_error, self.controller.update,
|
||||
|
|
Loading…
Reference in New Issue