Update ValueError message

The strings in oslo_utils.strutils.TRUE_STRINGS and
oslo_utils.strutils.FALSE_STRINGS can coverted to bool
by os_utils.bool_from_string.

Change-Id: Id7b2b44b86a8df29286937f04312bbf0d67525ca
Signed-off-by: pengdake <19921207pq@gmail.com>
This commit is contained in:
pengdake 2018-01-13 16:36:40 +08:00
parent 03c69ad8d2
commit 65f52390f6
2 changed files with 20 additions and 17 deletions

View File

@ -195,9 +195,8 @@ class ContainersController(base.Controller):
container_dict['interactive'] = strutils.bool_from_string(
container_dict.get('interactive', False), strict=True)
except ValueError:
msg = _('Valid run or interactive value is ''true'', '
'"false", True, False, "True" and "False"')
raise exception.InvalidValue(msg)
raise exception.InvalidValue(_('Valid run or interactive values '
'are: true, false, True, False'))
auto_remove = container_dict.pop('auto_remove', None)
if auto_remove is not None:
@ -208,8 +207,8 @@ class ContainersController(base.Controller):
container_dict['auto_remove'] = strutils.bool_from_string(
auto_remove, strict=True)
except ValueError:
msg = _('Auto_remove value are true or false')
raise exception.InvalidValue(msg)
raise exception.InvalidValue(_('Auto_remove values are: '
'true, false, True, False'))
else:
raise exception.InvalidParamInVersion(param='auto_remove',
req_version=req_version,
@ -494,14 +493,16 @@ class ContainersController(base.Controller):
try:
force = strutils.bool_from_string(force, strict=True)
except ValueError:
msg = _('Valid force values are true, false, 0, 1, yes and no')
raise exception.InvalidValue(msg)
bools = ', '.join(strutils.TRUE_STRINGS + strutils.FALSE_STRINGS)
raise exception.InvalidValue(_('Valid force values are: %s')
% bools)
stop = kwargs.pop('stop', False)
try:
stop = strutils.bool_from_string(stop, strict=True)
except ValueError:
msg = _('Valid stop values are true, false, 0, 1, yes and no')
raise exception.InvalidValue(msg)
bools = ', '.join(strutils.TRUE_STRINGS + strutils.FALSE_STRINGS)
raise exception.InvalidValue(_('Valid stop values are: %s')
% bools)
compute_api = pecan.request.compute_api
if not force and not stop:
utils.validate_container_state(container, 'delete')
@ -648,9 +649,10 @@ class ContainersController(base.Controller):
stderr = strutils.bool_from_string(stderr, strict=True)
timestamps = strutils.bool_from_string(timestamps, strict=True)
except ValueError:
msg = _('Valid stdout, stderr and timestamps values are ''true'', '
'"false", True, False, 0 and 1, yes and no')
raise exception.InvalidValue(msg)
bools = ', '.join(strutils.TRUE_STRINGS + strutils.FALSE_STRINGS)
raise exception.InvalidValue(_('Valid stdout, stderr and '
'timestamps values are: %s')
% bools)
LOG.debug('Calling compute.container_logs with %s', container.uuid)
context = pecan.request.context
compute_api = pecan.request.compute_api
@ -676,8 +678,9 @@ class ContainersController(base.Controller):
run = strutils.bool_from_string(run, strict=True)
interactive = strutils.bool_from_string(interactive, strict=True)
except ValueError:
msg = _('Valid run values are true, false, 0, 1, yes and no')
raise exception.InvalidValue(msg)
bools = ', '.join(strutils.TRUE_STRINGS + strutils.FALSE_STRINGS)
raise exception.InvalidValue(_('Valid run or interactive '
'values are: %s') % bools)
LOG.debug('Calling compute.container_exec with %(uuid)s command '
'%(command)s',
{'uuid': container.uuid, 'command': kwargs['command']})

View File

@ -145,9 +145,9 @@ class ImagesController(base.Controller):
try:
exact_match = strutils.bool_from_string(exact_match, strict=True)
except ValueError:
msg = _("Valid exact_match values are true,"
" false, 0, 1, yes and no")
raise exception.InvalidValue(msg)
bools = ', '.join(strutils.TRUE_STRINGS + strutils.FALSE_STRINGS)
raise exception.InvalidValue(_('Valid exact_match values are: %s')
% bools)
# Valiadtion accepts 'None' so need to convert it to None
if image_driver:
image_driver = api_utils.string_or_none(image_driver)