From: srushti Date: Fri, 26 Feb 2016 07:30:46 +0000 (+0000) Subject: Use is_int_like method from oslo_utils X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=807c31dbce5bd4706df9e25f074ca4d099908039;p=openstack-build%2Fcinder-build.git Use is_int_like method from oslo_utils This patch removes is_int_like method from utils.py and replaces it with is_int_like method from oslo_utils.strutils to eliminate duplicate code. TrivialFix Change-Id: Ia81da8b0208bb2a30ab301519cfc714f26480edd --- diff --git a/cinder/tests/unit/test_utils.py b/cinder/tests/unit/test_utils.py index 205411fdb..e4b16722b 100644 --- a/cinder/tests/unit/test_utils.py +++ b/cinder/tests/unit/test_utils.py @@ -90,16 +90,6 @@ class GenericUtilsTestCase(test.TestCase): obj, quiet=False) - def test_is_int_like(self): - self.assertTrue(utils.is_int_like(1)) - self.assertTrue(utils.is_int_like(-1)) - self.assertTrue(utils.is_int_like(0b1)) - self.assertTrue(utils.is_int_like(0o1)) - self.assertTrue(utils.is_int_like(0x1)) - self.assertTrue(utils.is_int_like('1')) - self.assertFalse(utils.is_int_like(1.0)) - self.assertFalse(utils.is_int_like('abc')) - def test_check_exclusive_options(self): utils.check_exclusive_options() utils.check_exclusive_options(something=None, diff --git a/cinder/utils.py b/cinder/utils.py index 289a49eba..3476912a2 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -109,14 +109,6 @@ def as_int(obj, quiet=True): return obj -def is_int_like(val): - """Check if a value looks like an int.""" - try: - return str(int(val)) == str(val) - except Exception: - return False - - def check_exclusive_options(**kwargs): """Checks that only one of the provided options is actually not-none. diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 3d3f9429c..a79bb91c7 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -24,6 +24,7 @@ import functools from oslo_config import cfg from oslo_log import log as logging from oslo_utils import excutils +from oslo_utils import strutils from oslo_utils import timeutils from oslo_utils import uuidutils import six @@ -223,7 +224,7 @@ class API(base.Base): # of the size value. BUT there is a possibility that somebody # could call the API directly so the is_int_like check # handles both cases (string representation of true float or int). - if size and (not utils.is_int_like(size) or int(size) <= 0): + if size and (not strutils.is_int_like(size) or int(size) <= 0): msg = _('Invalid volume size provided for create request: %s ' '(size argument must be an integer (or string ' 'representation of an integer) and greater '