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
This commit is contained in:
Cyril Roelandt 2022-09-07 18:55:50 +02:00
parent f2999ce752
commit 393e84d30a
2 changed files with 9 additions and 3 deletions
glanceclient

@ -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)

@ -1231,6 +1231,8 @@ def do_md_namespace_resource_type_list(gc, args):
help=_('Property name displayed to the user.'))
@utils.arg('--schema', metavar='<SCHEMA>', required=True,
help=_('Valid JSON schema of a property.'))
@utils.arg('--type', metavar='<TYPE>', 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)