Convert to oslo strutils.bool_from_string.

The only functional difference here is that the value '2' is now
treated as False instead of True. I suspect that's ok.

Change-Id: I30e75470cb3c312d7f92d389995eb6d845dd2fb0
This commit is contained in:
Michael Still 2013-05-18 21:08:30 +10:00
parent a1d5902117
commit b0325eb772
4 changed files with 5 additions and 26 deletions

View File

@ -25,6 +25,7 @@ from cinder.api import xmlutil
from cinder import exception
from cinder import flags
from cinder.openstack.common import log as logging
from cinder.openstack.common import strutils
from cinder import utils
from cinder import volume
@ -176,7 +177,7 @@ class SnapshotsController(wsgi.Controller):
msg = _("Invalid value '%s' for force. ") % force
raise exception.InvalidParameterValue(err=msg)
if utils.bool_from_str(force):
if strutils.bool_from_string(force):
new_snapshot = self.volume_api.create_snapshot_force(
context,
volume,

View File

@ -25,6 +25,7 @@ from cinder.api import xmlutil
from cinder import exception
from cinder import flags
from cinder.openstack.common import log as logging
from cinder.openstack.common import strutils
from cinder import utils
from cinder import volume
@ -187,7 +188,7 @@ class SnapshotsController(wsgi.Controller):
msg = _("Invalid value '%s' for force. ") % force
raise exception.InvalidParameterValue(err=msg)
if utils.bool_from_str(force):
if strutils.bool_from_string(force):
new_snapshot = self.volume_api.create_snapshot_force(
context,
volume,

View File

@ -29,6 +29,7 @@ import mox
import cinder
from cinder import exception
from cinder import flags
from cinder.openstack.common import strutils
from cinder.openstack.common import timeutils
from cinder import test
from cinder import utils
@ -299,19 +300,6 @@ class GenericUtilsTestCase(test.TestCase):
hostname = "<}\x1fh\x10e\x08l\x02l\x05o\x12!{>"
self.assertEqual("hello", utils.sanitize_hostname(hostname))
def test_bool_from_str(self):
self.assertTrue(utils.bool_from_str('1'))
self.assertTrue(utils.bool_from_str('2'))
self.assertTrue(utils.bool_from_str('-1'))
self.assertTrue(utils.bool_from_str('true'))
self.assertTrue(utils.bool_from_str('True'))
self.assertTrue(utils.bool_from_str('tRuE'))
self.assertFalse(utils.bool_from_str('False'))
self.assertFalse(utils.bool_from_str('false'))
self.assertFalse(utils.bool_from_str('0'))
self.assertFalse(utils.bool_from_str(None))
self.assertFalse(utils.bool_from_str('junk'))
def test_generate_glance_url(self):
generated_url = utils.generate_glance_url()
actual_url = "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port)

View File

@ -815,17 +815,6 @@ def check_isinstance(obj, cls):
return cls() # Ugly PyLint hack
def bool_from_str(val):
"""Convert a string representation of a bool into a bool value"""
if not val:
return False
try:
return True if int(val) else False
except ValueError:
return val.lower() == 'true'
def is_valid_boolstr(val):
"""Check if the provided string is a valid bool string or not. """
val = str(val).lower()