From: Michael Still Date: Sat, 18 May 2013 11:08:30 +0000 (+1000) Subject: Convert to oslo strutils.bool_from_string. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=b0325eb77258b63c20e0407e3e4df2d5236209b4;p=openstack-build%2Fcinder-build.git 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 --- diff --git a/cinder/api/v1/snapshots.py b/cinder/api/v1/snapshots.py index 61f8b9718..6dd24e1a7 100644 --- a/cinder/api/v1/snapshots.py +++ b/cinder/api/v1/snapshots.py @@ -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, diff --git a/cinder/api/v2/snapshots.py b/cinder/api/v2/snapshots.py index 28595da0e..5c7dc1f9b 100644 --- a/cinder/api/v2/snapshots.py +++ b/cinder/api/v2/snapshots.py @@ -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, diff --git a/cinder/tests/test_utils.py b/cinder/tests/test_utils.py index c0de09dd4..2e7b08629 100644 --- a/cinder/tests/test_utils.py +++ b/cinder/tests/test_utils.py @@ -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) diff --git a/cinder/utils.py b/cinder/utils.py index dc4e47e90..281dd6586 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -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()