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
This commit is contained in:
srushti 2016-02-26 07:30:46 +00:00
parent 33cd335ee3
commit 807c31dbce
3 changed files with 2 additions and 19 deletions

View File

@ -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,

View File

@ -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.

View File

@ -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 '