diff --git a/cinder/api/contrib/quotas.py b/cinder/api/contrib/quotas.py index f29f93f74ff..7f117696944 100644 --- a/cinder/api/contrib/quotas.py +++ b/cinder/api/contrib/quotas.py @@ -212,7 +212,7 @@ class QuotaSetsController(wsgi.Controller): # Get the optional argument 'skip_validation' from body, # if skip_validation is False, then validate existing resource. skip_flag = body.get('skip_validation', True) - if not utils.is_valid_boolstr(skip_flag): + if not strutils.is_valid_boolstr(skip_flag): msg = _("Invalid value '%s' for skip_validation.") % skip_flag raise exception.InvalidParameterValue(err=msg) skip_flag = strutils.bool_from_string(skip_flag) diff --git a/cinder/api/contrib/types_manage.py b/cinder/api/contrib/types_manage.py index f9d55a7d784..843df33b5a5 100644 --- a/cinder/api/contrib/types_manage.py +++ b/cinder/api/contrib/types_manage.py @@ -18,6 +18,8 @@ import six import webob +from oslo_utils import strutils + from cinder.api import extensions from cinder.api.openstack import wsgi from cinder.api.views import types as views_types @@ -72,7 +74,7 @@ class VolumeTypesManageController(wsgi.Controller): utils.check_string_length(description, 'Type description', min_length=0, max_length=255) - if not utils.is_valid_boolstr(is_public): + if not strutils.is_valid_boolstr(is_public): msg = _("Invalid value '%s' for is_public. Accepted values: " "True or False.") % is_public raise webob.exc.HTTPBadRequest(explanation=msg) @@ -124,7 +126,7 @@ class VolumeTypesManageController(wsgi.Controller): "a combination thereof.") raise webob.exc.HTTPBadRequest(explanation=msg) - if is_public is not None and not utils.is_valid_boolstr(is_public): + if is_public is not None and not strutils.is_valid_boolstr(is_public): msg = _("Invalid value '%s' for is_public. Accepted values: " "True or False.") % is_public raise webob.exc.HTTPBadRequest(explanation=msg) diff --git a/cinder/api/v1/snapshots.py b/cinder/api/v1/snapshots.py index b09dc90576c..c75af2a440c 100644 --- a/cinder/api/v1/snapshots.py +++ b/cinder/api/v1/snapshots.py @@ -142,7 +142,7 @@ class SnapshotsController(wsgi.Controller): msg = _LI("Create snapshot from volume %s") LOG.info(msg, volume_id) - if not utils.is_valid_boolstr(force): + if not strutils.is_valid_boolstr(force): msg = _("Invalid value '%s' for force. ") % force raise exception.InvalidParameterValue(err=msg) diff --git a/cinder/api/v3/group_types.py b/cinder/api/v3/group_types.py index dd6d3be5f4d..e916abe8554 100644 --- a/cinder/api/v3/group_types.py +++ b/cinder/api/v3/group_types.py @@ -124,7 +124,7 @@ class GroupTypesController(wsgi.Controller): "a combination thereof.") raise webob.exc.HTTPBadRequest(explanation=msg) - if is_public is not None and not utils.is_valid_boolstr(is_public): + if is_public is not None and not strutils.is_valid_boolstr(is_public): msg = _("Invalid value '%s' for is_public. Accepted values: " "True or False.") % is_public raise webob.exc.HTTPBadRequest(explanation=msg) diff --git a/cinder/backup/api.py b/cinder/backup/api.py index e227edb5658..9c7fc30980b 100644 --- a/cinder/backup/api.py +++ b/cinder/backup/api.py @@ -39,7 +39,6 @@ from cinder.objects import fields import cinder.policy from cinder import quota from cinder import quota_utils -from cinder import utils import cinder.volume from cinder.volume import utils as volume_utils @@ -123,7 +122,7 @@ class API(base.Base): search_opts = search_opts or {} all_tenants = search_opts.pop('all_tenants', '0') - if not utils.is_valid_boolstr(all_tenants): + if not strutils.is_valid_boolstr(all_tenants): msg = _("all_tenants must be a boolean, got '%s'.") % all_tenants raise exception.InvalidParameterValue(err=msg) diff --git a/cinder/tests/unit/test_utils.py b/cinder/tests/unit/test_utils.py index 57816f3e568..166f405cc1d 100644 --- a/cinder/tests/unit/test_utils.py +++ b/cinder/tests/unit/test_utils.py @@ -130,20 +130,6 @@ class GenericUtilsTestCase(test.TestCase): hostname = "<}\x1fh\x10e\x08l\x02l\x05o\x12!{>" self.assertEqual("hello", utils.sanitize_hostname(hostname)) - def test_is_valid_boolstr(self): - self.assertTrue(utils.is_valid_boolstr(True)) - self.assertTrue(utils.is_valid_boolstr('trUe')) - self.assertTrue(utils.is_valid_boolstr(False)) - self.assertTrue(utils.is_valid_boolstr('faLse')) - self.assertTrue(utils.is_valid_boolstr('yeS')) - self.assertTrue(utils.is_valid_boolstr('nO')) - self.assertTrue(utils.is_valid_boolstr('y')) - self.assertTrue(utils.is_valid_boolstr('N')) - self.assertTrue(utils.is_valid_boolstr(1)) - self.assertTrue(utils.is_valid_boolstr('1')) - self.assertTrue(utils.is_valid_boolstr(0)) - self.assertTrue(utils.is_valid_boolstr('0')) - @mock.patch('os.path.join', side_effect=lambda x, y: '/'.join((x, y))) def test_make_dev_path(self, mock_join): self.assertEqual('/dev/xvda', utils.make_dev_path('xvda')) diff --git a/cinder/utils.py b/cinder/utils.py index e26a7ac3b96..59ce3b2b8a5 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -268,12 +268,6 @@ def last_completed_audit_period(unit=None): return (begin, end) -def is_valid_boolstr(val): - """Check if the provided string is a valid bool string or not.""" - val = str(val).lower() - return val in ('true', 'false', 'yes', 'no', 'y', 'n', '1', '0') - - def is_none_string(val): """Check if a string represents a None value.""" if not isinstance(val, six.string_types): @@ -600,7 +594,7 @@ def _get_disk_of_partition(devpath, st=None): def get_bool_param(param_string, params): param = params.get(param_string, False) - if not is_valid_boolstr(param): + if not strutils.is_valid_boolstr(param): msg = _('Value %(param)s for %(param_string)s is not a ' 'boolean.') % {'param': param, 'param_string': param_string} raise exception.InvalidParameterValue(err=msg)