Allow tags to be removed with update --existing
When updating a stack using the PATCH method (i.e. passing --existing on the command line), the existing tags are kept unless otherwise specified. However, while it was possible to set a new set of tags on such an update, it was not possible to remove all of the tags because an empty string was treated the same as None or a missing tags key (both of which are treated as no change). When the user explicitly requests an empty tags list (by passing ''), honour that request. Note that while None is treated the same as a missing key, in practice the API never sends us a value of None; the key is never sent to the engine if the user passes null to the API. The input string is split by the API so the engine receives data with the key then the value is always a Python list. Change-Id: I6ae355b0a8af017c7a9145c9483c1ad3f2ac5ca5 Task: 37010
This commit is contained in:
parent
78b7a471c2
commit
2540dfd450
|
@ -60,7 +60,7 @@ def extract_args(params):
|
|||
kwargs[rpc_api.PARAM_ADOPT_STACK_DATA] = adopt_data
|
||||
|
||||
tags = params.get(rpc_api.PARAM_TAGS)
|
||||
if tags:
|
||||
if tags is not None:
|
||||
if not isinstance(tags, list):
|
||||
raise ValueError(_('Invalid tags, not a list: %s') % tags)
|
||||
|
||||
|
|
|
@ -385,11 +385,21 @@ resources:
|
|||
self.ctx, stk, t, {}, None, None, None, api_args, None)
|
||||
self.assertEqual(['tag1'], updated_stack.tags)
|
||||
|
||||
# update clear old tags
|
||||
api_args[rpc_api.STACK_TAGS] = []
|
||||
_, _, updated_stack = self.man._prepare_stack_updates(
|
||||
self.ctx, stk, t, {}, None, None, None, api_args, None)
|
||||
self.assertEqual([], updated_stack.tags)
|
||||
|
||||
# with new tags
|
||||
api_args[rpc_api.STACK_TAGS] = ['tag2']
|
||||
_, _, updated_stack = self.man._prepare_stack_updates(
|
||||
self.ctx, stk, t, {}, None, None, None, api_args, None)
|
||||
self.assertEqual(['tag2'], updated_stack.tags)
|
||||
api_args[rpc_api.STACK_TAGS] = ['tag3']
|
||||
_, _, updated_stack = self.man._prepare_stack_updates(
|
||||
self.ctx, stk, t, {}, None, None, None, api_args, None)
|
||||
self.assertEqual(['tag3'], updated_stack.tags)
|
||||
|
||||
# with no PARAM_EXISTING flag and no tags
|
||||
del api_args[rpc_api.PARAM_EXISTING]
|
||||
|
|
Loading…
Reference in New Issue