Merge "Add an optional parameter --append"
This commit is contained in:
commit
63bb03a145
@ -3142,7 +3142,8 @@ class ShellV2Test(testtools.TestCase):
|
||||
def test_do_md_tag_create_multiple(self):
|
||||
args = self._make_args({'namespace': 'MyNamespace',
|
||||
'delim': ',',
|
||||
'names': 'MyTag1, MyTag2'})
|
||||
'names': 'MyTag1, MyTag2',
|
||||
'append': False})
|
||||
with mock.patch.object(
|
||||
self.gc.metadefs_tag, 'create_multiple') as mocked_create_tags:
|
||||
expect_tags = [{'tags': [{'name': 'MyTag1'}, {'name': 'MyTag2'}]}]
|
||||
@ -3152,7 +3153,28 @@ class ShellV2Test(testtools.TestCase):
|
||||
test_shell.do_md_tag_create_multiple(self.gc, args)
|
||||
|
||||
mocked_create_tags.assert_called_once_with(
|
||||
'MyNamespace', tags=['MyTag1', 'MyTag2'])
|
||||
'MyNamespace', tags=['MyTag1', 'MyTag2'], append=False)
|
||||
utils.print_list.assert_called_once_with(
|
||||
expect_tags,
|
||||
['name'],
|
||||
field_settings={
|
||||
'description': {'align': 'l', 'max_width': 50}})
|
||||
|
||||
def test_do_md_tag_create_multiple_with_append(self):
|
||||
args = self._make_args({'namespace': 'MyNamespace',
|
||||
'delim': ',',
|
||||
'names': 'MyTag1, MyTag2',
|
||||
'append': True})
|
||||
with mock.patch.object(
|
||||
self.gc.metadefs_tag, 'create_multiple') as mocked_create_tags:
|
||||
expect_tags = [{'tags': [{'name': 'MyTag1'}, {'name': 'MyTag2'}]}]
|
||||
|
||||
mocked_create_tags.return_value = expect_tags
|
||||
|
||||
test_shell.do_md_tag_create_multiple(self.gc, args)
|
||||
|
||||
mocked_create_tags.assert_called_once_with(
|
||||
'MyNamespace', tags=['MyTag1', 'MyTag2'], append=True)
|
||||
utils.print_list.assert_called_once_with(
|
||||
expect_tags,
|
||||
['name'],
|
||||
|
@ -490,9 +490,8 @@ class TagController(object):
|
||||
"""Create the list of tags.
|
||||
|
||||
:param namespace: Name of a namespace to which the Tags belong.
|
||||
:param kwargs: list of tags.
|
||||
:param kwargs: list of tags, optional parameter append.
|
||||
"""
|
||||
|
||||
tag_names = kwargs.pop('tags', [])
|
||||
md_tag_list = []
|
||||
|
||||
@ -502,11 +501,15 @@ class TagController(object):
|
||||
except (warlock.InvalidOperation) as e:
|
||||
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||
tags = {'tags': md_tag_list}
|
||||
headers = {}
|
||||
|
||||
url = '/v2/metadefs/namespaces/%(namespace)s/tags' % {
|
||||
'namespace': namespace}
|
||||
'namespace': namespace}
|
||||
|
||||
resp, body = self.http_client.post(url, data=tags)
|
||||
append = kwargs.pop('append', False)
|
||||
if append:
|
||||
headers['X-Openstack-Append'] = True
|
||||
resp, body = self.http_client.post(url, headers=headers, data=tags)
|
||||
body.pop('self', None)
|
||||
for tag in body['tags']:
|
||||
yield self.model(tag), resp
|
||||
|
@ -1396,10 +1396,12 @@ def do_md_tag_create(gc, args):
|
||||
@utils.arg('--delim', metavar='<DELIM>', required=False,
|
||||
help=_('The delimiter used to separate the names'
|
||||
' (if none is provided then the default is a comma).'))
|
||||
@utils.arg('--append', default=False, action='store_true', required=False,
|
||||
help=_('Append the new tags to the existing ones instead of'
|
||||
'overwriting them'))
|
||||
def do_md_tag_create_multiple(gc, args):
|
||||
"""Create new metadata definitions tags inside a namespace."""
|
||||
delim = args.delim or ','
|
||||
|
||||
tags = []
|
||||
names_list = args.names.split(delim)
|
||||
for name in names_list:
|
||||
@ -1411,7 +1413,7 @@ def do_md_tag_create_multiple(gc, args):
|
||||
utils.exit('Please supply at least one tag name. For example: '
|
||||
'--names Tag1')
|
||||
|
||||
fields = {'tags': tags}
|
||||
fields = {'tags': tags, 'append': args.append}
|
||||
new_tags = gc.metadefs_tag.create_multiple(args.namespace, **fields)
|
||||
columns = ['name']
|
||||
column_settings = {
|
||||
|
Loading…
Reference in New Issue
Block a user