Use method validate_integer from oslo.utils

We added method validate_integer in oslo.utils 3.33.0 [1].
so we can simply the method validate_integer in Cinder.

Depends-On: I741875eba329b762789a7c7c910a6c46beeff3fa

[1] https://review.openstack.org/#/c/508401/

Change-Id: I950316ac0924acd692b2410993f3c240ce319d6f
This commit is contained in:
ChangBo Guo(gcb) 2017-12-18 11:39:00 +08:00
parent 0c97ab11de
commit c0951aac0a
2 changed files with 6 additions and 16 deletions

View File

@ -558,7 +558,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
def test_update_key_size_non_integer(self):
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)
def test_update_item_invalid_body(self):

View File

@ -1038,21 +1038,11 @@ def validate_integer(value, name, min_value=None, max_value=None):
:param max_length: the max_length of the integer
:returns: integer
"""
if not strutils.is_int_like(value):
raise webob.exc.HTTPBadRequest(explanation=(
_('%s must be an integer.') % name))
value = int(value)
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
try:
value = strutils.validate_integer(value, name, min_value, max_value)
return value
except ValueError as e:
raise webob.exc.HTTPBadRequest(explanation=six.text_type(e))
def validate_dictionary_string_length(specs):