diff options
author | Jenkins <jenkins@review.openstack.org> | 2017-09-14 10:15:13 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-09-14 10:15:13 +0000 |
commit | 6c3860f4fd617ad567068b96eaaec872ed53c3ed (patch) | |
tree | f1f5ad192febb669e64183aa269e8978d24771b9 | |
parent | 331469b587c7f1a9a4e5396acd5d2fd8504c0758 (diff) | |
parent | 4a089058c54ff4ee887d8504b886ef760f57d1d2 (diff) | |
download | heat-6c3860f4fd617ad567068b96eaaec872ed53c3ed.tar.gz |
Merge "Keep existing stack tags for patch update" into stable/ocata
-rw-r--r-- | heat/engine/service.py | 3 | ||||
-rw-r--r-- | heat/tests/engine/service/test_stack_update.py | 35 | ||||
-rw-r--r-- | heat/tests/utils.py | 6 |
3 files changed, 42 insertions, 2 deletions
diff --git a/heat/engine/service.py b/heat/engine/service.py index ec33573bc..b9500aacc 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 ff63b48b8..f9b50237b 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 |