summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrabi <ramishra@redhat.com>2017-06-29 16:11:36 +0530
committerRico Lin <rico.lin@easystack.cn>2017-07-27 01:29:29 +0000
commit4a089058c54ff4ee887d8504b886ef760f57d1d2 (patch)
tree17cfc0fdef88de84bed7cca5878e77d609e48fc1
parent5034bc10afb736eedca0cb4e0503652711008e23 (diff)
downloadheat-4a089058c54ff4ee887d8504b886ef760f57d1d2.tar.gz
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 (cherry picked from commit ed0beb6871b9a64c7a51ea85fd824e7c406343b3)
-rw-r--r--heat/engine/service.py3
-rw-r--r--heat/tests/engine/service/test_stack_update.py35
-rw-r--r--heat/tests/utils.py6
3 files changed, 42 insertions, 2 deletions
diff --git a/heat/engine/service.py b/heat/engine/service.py
index ab47c3777..13896cf32 100644
--- a/heat/engine/service.py
+++ b/heat/engine/service.py
@@ -927,6 +927,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)
diff --git a/heat/tests/engine/service/test_stack_update.py b/heat/tests/engine/service/test_stack_update.py
index c54f149ff..7dac6ba08 100644
--- a/heat/tests/engine/service/test_stack_update.py
+++ b/heat/tests/engine/service/test_stack_update.py
@@ -322,6 +322,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.
diff --git a/heat/tests/utils.py b/heat/tests/utils.py
index acccc73d7..9c9743ea4 100644
--- a/heat/tests/utils.py
+++ b/heat/tests/utils.py
@@ -90,7 +90,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()
@@ -100,7 +101,8 @@ def parse_stack(t, params=None, files=None, stack_name=None,
if stack_name is None:
stack_name = random_name()
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