From 393e84d30a173e8a001a8c9d877726c37dec6c17 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Wed, 7 Sep 2022 18:55:50 +0200 Subject: [PATCH] md-property-create: add a mandatory "--type" option The "type" property is required when using md-property-create, so there should be a mandatory option for it, as is the case for "name" and "title". Change-Id: I3a118b6f2e375ad60bd4170c5ce0ae284a0c9060 Closes-Bug: #1934626 --- glanceclient/tests/unit/v2/test_shell_v2.py | 8 ++++++-- glanceclient/v2/shell.py | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py index b9ced58..d4af964 100644 --- a/glanceclient/tests/unit/v2/test_shell_v2.py +++ b/glanceclient/tests/unit/v2/test_shell_v2.py @@ -2940,13 +2940,15 @@ class ShellV2Test(testtools.TestCase): args = self._make_args({'namespace': 'MyNamespace', 'name': "MyProperty", 'title': "Title", + 'type': 'boolean', 'schema': '{}'}) with mock.patch.object(self.gc.metadefs_property, 'create') as mocked_create: expect_property = { 'namespace': 'MyNamespace', 'name': 'MyProperty', - 'title': 'Title' + 'title': 'Title', + 'type': 'boolean', } mocked_create.return_value = expect_property @@ -2955,13 +2957,15 @@ class ShellV2Test(testtools.TestCase): mocked_create.assert_called_once_with('MyNamespace', name='MyProperty', - title='Title') + title='Title', + type='boolean') utils.print_dict.assert_called_once_with(expect_property) def test_do_md_property_create_invalid_schema(self): args = self._make_args({'namespace': 'MyNamespace', 'name': "MyProperty", 'title': "Title", + 'type': "boolean", 'schema': 'Invalid'}) self.assertRaises(SystemExit, test_shell.do_md_property_create, self.gc, args) diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index 773c198..54ecdf4 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -1231,6 +1231,8 @@ def do_md_namespace_resource_type_list(gc, args): help=_('Property name displayed to the user.')) @utils.arg('--schema', metavar='', required=True, help=_('Valid JSON schema of a property.')) +@utils.arg('--type', metavar='', required=True, + help=_('Type of the property')) def do_md_property_create(gc, args): """Create a new metadata definitions property inside a namespace.""" try: @@ -1238,7 +1240,7 @@ def do_md_property_create(gc, args): except ValueError: utils.exit('Schema is not a valid JSON object.') else: - fields = {'name': args.name, 'title': args.title} + fields = {'name': args.name, 'title': args.title, 'type': args.type} fields.update(schema) new_property = gc.metadefs_property.create(args.namespace, **fields) utils.print_dict(new_property)