Merge "Use method validate_integer from oslo.utils"
This commit is contained in:
commit
6dd3776723
@ -558,7 +558,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
|
|||||||
|
|
||||||
def test_update_key_size_non_integer(self):
|
def test_update_key_size_non_integer(self):
|
||||||
update_body = {"encryption": {'key_size': 'abc'}}
|
update_body = {"encryption": {'key_size': 'abc'}}
|
||||||
msg = 'key_size must be an integer.'
|
msg = 'key_size must be an integer'
|
||||||
self._encryption_update_bad_body(update_body, msg)
|
self._encryption_update_bad_body(update_body, msg)
|
||||||
|
|
||||||
def test_update_item_invalid_body(self):
|
def test_update_item_invalid_body(self):
|
||||||
|
@ -1038,21 +1038,11 @@ def validate_integer(value, name, min_value=None, max_value=None):
|
|||||||
:param max_length: the max_length of the integer
|
:param max_length: the max_length of the integer
|
||||||
:returns: integer
|
:returns: integer
|
||||||
"""
|
"""
|
||||||
if not strutils.is_int_like(value):
|
try:
|
||||||
raise webob.exc.HTTPBadRequest(explanation=(
|
value = strutils.validate_integer(value, name, min_value, max_value)
|
||||||
_('%s must be an integer.') % name))
|
return value
|
||||||
value = int(value)
|
except ValueError as e:
|
||||||
|
raise webob.exc.HTTPBadRequest(explanation=six.text_type(e))
|
||||||
if min_value is not None and value < min_value:
|
|
||||||
raise webob.exc.HTTPBadRequest(
|
|
||||||
explanation=(_('%(value_name)s must be >= %(min_value)d') %
|
|
||||||
{'value_name': name, 'min_value': min_value}))
|
|
||||||
if max_value is not None and value > max_value:
|
|
||||||
raise webob.exc.HTTPBadRequest(
|
|
||||||
explanation=(_('%(value_name)s must be <= %(max_value)d') %
|
|
||||||
{'value_name': name, 'max_value': max_value}))
|
|
||||||
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
def validate_dictionary_string_length(specs):
|
def validate_dictionary_string_length(specs):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user