Add strict Boolean checking

Because of lack of strict boolean checking, the unexpected
'False' value will always be send to server if invalid bool
value is specifed.
For instance:
  the parameter 'is-public' of cinder type-update,
  the parameter 'force' of cinder qos-delete
as so forth.

This patch tries to add a strict checking for them
to prevent invalid bool value.

Change-Id: I896ddbb6ec4760bfd4d721db960138e2df0b86e1
Closes-Bug: #1596418
This commit is contained in:
xiexs 2016-06-27 03:54:21 -04:00
parent 6cadb738b8
commit e5e0a7ee49
3 changed files with 29 additions and 9 deletions
cinderclient

@ -683,6 +683,13 @@ class ShellTest(utils.TestCase):
'--is-public=False')
self.assert_called('POST', '/types', body=expected)
def test_type_create_with_invalid_bool(self):
self.assertRaises(ValueError,
self.run_command,
('type-create test-type-3 '
'--description=test_type-3-desc '
'--is-public=invalid_bool'))
def test_type_update(self):
expected = {'volume_type': {'name': 'test-type-1',
'description': 'test_type-1-desc',
@ -692,6 +699,13 @@ class ShellTest(utils.TestCase):
'--is-public=False 1')
self.assert_called('PUT', '/types/1', body=expected)
def test_type_update_with_invalid_bool(self):
self.assertRaises(ValueError,
self.run_command,
'type-update --name test-type-1 '
'--description=test_type-1-desc '
'--is-public=invalid_bool 1')
def test_type_access_list(self):
self.run_command('type-access-list --volume-type 3')
self.assert_called('GET', '/types/3/os-volume-type-access')

@ -1323,7 +1323,7 @@ def do_qos_show(cs, args):
@utils.service_type('volume')
def do_qos_delete(cs, args):
"""Deletes a specified qos specs."""
force = strutils.bool_from_string(args.force)
force = strutils.bool_from_string(args.force, strict=True)
qos_specs = _find_qos_specs(cs, args.qos_specs)
cs.qos_specs.delete(qos_specs, force)
@ -1477,7 +1477,8 @@ def do_readonly_mode_update(cs, args):
"""Updates volume read-only access-mode flag."""
volume = utils.find_volume(cs, args.volume)
cs.volumes.update_readonly_flag(volume,
strutils.bool_from_string(args.read_only))
strutils.bool_from_string(args.read_only,
strict=True))
@utils.arg('volume', metavar='<volume>', help='ID of the volume to update.')
@ -1490,4 +1491,5 @@ def do_set_bootable(cs, args):
"""Update bootable status of a volume."""
volume = utils.find_volume(cs, args.volume)
cs.volumes.set_bootable(volume,
strutils.bool_from_string(args.bootable))
strutils.bool_from_string(args.bootable,
strict=True))

@ -914,7 +914,7 @@ def do_type_show(cs, args):
@utils.service_type('volumev3')
def do_type_update(cs, args):
"""Updates volume type name, description, and/or is_public."""
is_public = strutils.bool_from_string(args.is_public)
is_public = strutils.bool_from_string(args.is_public, strict=True)
vtype = cs.volume_types.update(args.id, args.name, args.description,
is_public)
_print_volume_type_list([vtype])
@ -940,7 +940,7 @@ def do_extra_specs_list(cs, args):
@utils.service_type('volumev3')
def do_type_create(cs, args):
"""Creates a volume type."""
is_public = strutils.bool_from_string(args.is_public)
is_public = strutils.bool_from_string(args.is_public, strict=True)
vtype = cs.volume_types.create(args.name, args.description, is_public)
_print_volume_type_list([vtype])
@ -1691,7 +1691,8 @@ def do_extend(cs, args):
@utils.service_type('volumev3')
def do_service_list(cs, args):
"""Lists all services. Filter by host and service binary."""
replication = strutils.bool_from_string(args.withreplication)
replication = strutils.bool_from_string(args.withreplication,
strict=True)
result = cs.services.list(host=args.host, binary=args.binary)
columns = ["Binary", "Host", "Zone", "Status", "State", "Updated_at"]
if replication:
@ -2008,7 +2009,8 @@ def do_qos_show(cs, args):
@utils.service_type('volumev3')
def do_qos_delete(cs, args):
"""Deletes a specified qos specs."""
force = strutils.bool_from_string(args.force)
force = strutils.bool_from_string(args.force,
strict=True)
qos_specs = _find_qos_specs(cs, args.qos_specs)
cs.qos_specs.delete(qos_specs, force)
@ -2173,7 +2175,8 @@ def do_readonly_mode_update(cs, args):
"""Updates volume read-only access-mode flag."""
volume = utils.find_volume(cs, args.volume)
cs.volumes.update_readonly_flag(volume,
strutils.bool_from_string(args.read_only))
strutils.bool_from_string(args.read_only,
strict=True))
@utils.arg('volume', metavar='<volume>', help='ID of the volume to update.')
@ -2186,7 +2189,8 @@ def do_set_bootable(cs, args):
"""Update bootable status of a volume."""
volume = utils.find_volume(cs, args.volume)
cs.volumes.set_bootable(volume,
strutils.bool_from_string(args.bootable))
strutils.bool_from_string(args.bootable,
strict=True))
@utils.arg('host',