Keep existing stack tags for patch update

When updating a stack, we overwrite the existing tags.
So if no tags are specified during update, all existing
tags are removed. It would atleast be good to keep the
existing tags when doing a patch update (with `--existing`).

Change-Id: I910fe5237605405791eb6daa81c422bf7fd9eaa1
Closes-Bug: #1701098
This commit is contained in:
rabi 2017-06-29 16:11:36 +05:30
parent 91561ead32
commit ed0beb6871
3 changed files with 42 additions and 2 deletions

View File

@ -942,6 +942,9 @@ class EngineService(service.ServiceBase):
common_params.setdefault(rpc_api.PARAM_DISABLE_ROLLBACK,
current_stack.disable_rollback)
if args.get(rpc_api.PARAM_EXISTING):
common_params.setdefault(rpc_api.STACK_TAGS,
current_stack.tags)
current_kwargs.update(common_params)
updated_stack = parser.Stack(cnxt, stack_name, tmpl,
**current_kwargs)

View File

@ -321,6 +321,41 @@ resources:
tmpl.env.params)
self.assertEqual(stk.identifier(), result)
def test_stack_update_with_tags(self):
"""Test case for updating stack with tags.
Create a stack with tags, then update with/without
rpc_api.PARAM_EXISTING.
"""
stack_name = 'service_update_test_stack_existing_tags'
api_args = {rpc_api.PARAM_TIMEOUT: 60,
rpc_api.PARAM_EXISTING: True}
t = template_format.parse(tools.wp_template)
stk = utils.parse_stack(t, stack_name=stack_name, tags=['tag1'])
stk.set_stack_user_project_id('1234')
self.assertEqual(['tag1'], stk.tags)
self.patchobject(stack.Stack, 'validate')
# update keep old tags
_, _, updated_stack = self.man._prepare_stack_updates(
self.ctx, stk, t, {}, None, None, api_args, None)
self.assertEqual(['tag1'], 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, api_args, None)
self.assertEqual(['tag2'], updated_stack.tags)
# with no PARAM_EXISTING flag and no tags
del api_args[rpc_api.PARAM_EXISTING]
del api_args[rpc_api.STACK_TAGS]
_, _, updated_stack = self.man._prepare_stack_updates(
self.ctx, stk, t, {}, None, None, api_args, None)
self.assertIsNone(updated_stack.tags)
def test_stack_update_existing_registry(self):
# Use a template with existing flag and ensure the
# environment registry is preserved.

View File

@ -91,7 +91,8 @@ def dummy_context(user='test_username', tenant_id='test_tenant_id',
def parse_stack(t, params=None, files=None, stack_name=None,
stack_id=None, timeout_mins=None, cache_data=None):
stack_id=None, timeout_mins=None,
cache_data=None, tags=None):
params = params or {}
files = files or {}
ctx = dummy_context()
@ -104,7 +105,8 @@ def parse_stack(t, params=None, files=None, stack_name=None,
cache_data = {n: node_data.NodeData.from_dict(d)
for n, d in cache_data.items()}
stk = stack.Stack(ctx, stack_name, templ, stack_id=stack_id,
timeout_mins=timeout_mins, cache_data=cache_data)
timeout_mins=timeout_mins,
cache_data=cache_data, tags=tags)
stk.store()
return stk