Prevent null key setting for property
null key is the invalid input when setting property in the openstack components. Prevent null key setting for property in openstackclient. Change-Id: I8ec72664b5393ffef71fffa4bd1cd3c303e86a52 Related-Bug: #1558690
This commit is contained in:
parent
ef4a4f143b
commit
7dbc92b521
@ -33,7 +33,13 @@ class KeyValueAction(argparse.Action):
|
|||||||
|
|
||||||
# Add value if an assignment else remove it
|
# Add value if an assignment else remove it
|
||||||
if '=' in values:
|
if '=' in values:
|
||||||
getattr(namespace, self.dest, {}).update([values.split('=', 1)])
|
values_list = values.split('=', 1)
|
||||||
|
# NOTE(qtang): Prevent null key setting in property
|
||||||
|
if '' == values_list[0]:
|
||||||
|
msg = _("Property key must be specified: %s")
|
||||||
|
raise argparse.ArgumentTypeError(msg % str(values))
|
||||||
|
else:
|
||||||
|
getattr(namespace, self.dest, {}).update([values_list])
|
||||||
else:
|
else:
|
||||||
msg = _("Expected 'key=value' type, but got: %s")
|
msg = _("Expected 'key=value' type, but got: %s")
|
||||||
raise argparse.ArgumentTypeError(msg % str(values))
|
raise argparse.ArgumentTypeError(msg % str(values))
|
||||||
@ -88,7 +94,13 @@ class MultiKeyValueAction(argparse.Action):
|
|||||||
for kv in values.split(','):
|
for kv in values.split(','):
|
||||||
# Add value if an assignment else raise ArgumentTypeError
|
# Add value if an assignment else raise ArgumentTypeError
|
||||||
if '=' in kv:
|
if '=' in kv:
|
||||||
params.update([kv.split('=', 1)])
|
kv_list = kv.split('=', 1)
|
||||||
|
# NOTE(qtang): Prevent null key setting in property
|
||||||
|
if '' == kv_list[0]:
|
||||||
|
msg = _("Each property key must be specified: %s")
|
||||||
|
raise argparse.ArgumentTypeError(msg % str(kv))
|
||||||
|
else:
|
||||||
|
params.update([kv_list])
|
||||||
else:
|
else:
|
||||||
msg = _(
|
msg = _(
|
||||||
"Expected comma separated 'key=value' pairs, but got: %s"
|
"Expected comma separated 'key=value' pairs, but got: %s"
|
||||||
|
@ -49,13 +49,14 @@ class TestKeyValueAction(utils.TestCase):
|
|||||||
self.assertEqual(expect, actual)
|
self.assertEqual(expect, actual)
|
||||||
|
|
||||||
def test_error_values(self):
|
def test_error_values(self):
|
||||||
self.assertRaises(
|
data_list = [
|
||||||
argparse.ArgumentTypeError,
|
['--property', 'red', ],
|
||||||
self.parser.parse_args,
|
['--property', '=', ],
|
||||||
[
|
['--property', '=red', ]
|
||||||
'--property', 'red',
|
]
|
||||||
]
|
for data in data_list:
|
||||||
)
|
self.assertRaises(argparse.ArgumentTypeError,
|
||||||
|
self.parser.parse_args, data)
|
||||||
|
|
||||||
|
|
||||||
class TestMultiKeyValueAction(utils.TestCase):
|
class TestMultiKeyValueAction(utils.TestCase):
|
||||||
@ -115,13 +116,14 @@ class TestMultiKeyValueAction(utils.TestCase):
|
|||||||
self.assertItemsEqual(expect, actual)
|
self.assertItemsEqual(expect, actual)
|
||||||
|
|
||||||
def test_error_values_with_comma(self):
|
def test_error_values_with_comma(self):
|
||||||
self.assertRaises(
|
data_list = [
|
||||||
argparse.ArgumentTypeError,
|
['--test', 'mmm,nnn=zzz', ],
|
||||||
self.parser.parse_args,
|
['--test', 'nnn=zzz,=', ],
|
||||||
[
|
['--test', 'nnn=zzz,=zzz', ]
|
||||||
'--test', 'mmm,nnn=zzz',
|
]
|
||||||
]
|
for data in data_list:
|
||||||
)
|
self.assertRaises(argparse.ArgumentTypeError,
|
||||||
|
self.parser.parse_args, data)
|
||||||
|
|
||||||
def test_error_values_without_comma(self):
|
def test_error_values_without_comma(self):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
|
6
releasenotes/notes/bug-1558690-1528b637f2c0a449.yaml
Normal file
6
releasenotes/notes/bug-1558690-1528b637f2c0a449.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Prevent null key setting for key-value pairs in the ``KeyValueAction``
|
||||||
|
and ``MultiKeyValueAction`` parser actions.
|
||||||
|
[Bug `1558690 <https://bugs.launchpad.net/bugs/1558690>`_]
|
Loading…
Reference in New Issue
Block a user