Merge "Use method is_valid_boolstr from oslo_utils"

This commit is contained in:
Jenkins 2016-12-16 04:59:38 +00:00 committed by Gerrit Code Review
commit 67c4c96a6a
7 changed files with 9 additions and 28 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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