diff --git a/openstackclient/common/parseractions.py b/openstackclient/common/parseractions.py index 77798f9024..8f772344e5 100644 --- a/openstackclient/common/parseractions.py +++ b/openstackclient/common/parseractions.py @@ -35,7 +35,9 @@ class KeyValueAction(argparse.Action): if '=' in values: getattr(namespace, self.dest, {}).update([values.split('=', 1)]) else: - getattr(namespace, self.dest, {}).pop(values, None) + msg = _("Expected 'key=value' type, " + "but got: %s") % (str(values)) + raise argparse.ArgumentTypeError(msg) class MultiKeyValueAction(argparse.Action): diff --git a/openstackclient/tests/common/test_parseractions.py b/openstackclient/tests/common/test_parseractions.py index 5c5ca3d321..894b224c46 100644 --- a/openstackclient/tests/common/test_parseractions.py +++ b/openstackclient/tests/common/test_parseractions.py @@ -49,16 +49,13 @@ class TestKeyValueAction(utils.TestCase): self.assertDictEqual(expect, actual) def test_error_values(self): - results = self.parser.parse_args([ - '--property', 'red', - '--property', 'green=100%', - '--property', 'blue', - ]) - - actual = getattr(results, 'property', {}) - # There should be no red or blue - expect = {'green': '100%', 'format': '#rgb'} - self.assertDictEqual(expect, actual) + self.assertRaises( + argparse.ArgumentTypeError, + self.parser.parse_args, + [ + '--property', 'red', + ] + ) class TestMultiKeyValueAction(utils.TestCase): diff --git a/releasenotes/notes/bug-1589935-8a56e6a18d836db9.yaml b/releasenotes/notes/bug-1589935-8a56e6a18d836db9.yaml new file mode 100644 index 0000000000..53c1ea0f0b --- /dev/null +++ b/releasenotes/notes/bug-1589935-8a56e6a18d836db9.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - Raise ``ArgumentTypeError`` if the input arguments do not match the type + ``key=value`` when we set properties. + [Bug `1589935 `_]