summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZane Bitter <zbitter@redhat.com>2018-08-23 19:53:46 -0400
committerRabi Mishra <ramishra@redhat.com>2018-09-03 04:38:45 +0000
commit31148d3690fa7ada9c6e470ca275868a0fe57beb (patch)
tree9a308d4e3470c3bbeb1201dca606094b841cfb96
parent680a51596db8740644710a741962e0676c68cc24 (diff)
downloadheat-31148d3690fa7ada9c6e470ca275868a0fe57beb.tar.gz
Ignore conditions when reparsing ResourceDefinition
In the legacy path we reparse a resource definition to refer to a different StackDefinition when copying a resource definition into the existing template (as the resource is updated) or into the backup stack's template. However, the resources 'condition' may reference conditionals that are not defined in the template it is being copied into (e.g. during a stack update that creates a new condition), and in this case the destination template will become unusable. Since the fact that we care about the resource definition at all indicates that the condition was enabled, just ignore the condition after reparsing. This is consistent with what we do for 'if' macros, which is to resolve the condition part during reparsing. Change-Id: I59a374435f6275badc8124efbd7b7db2e36e2de5 Story: #2003558 Task: 24847 (cherry picked from commit 92101b18e260665718fb9d795c3f6ee2148f8ac5)
-rw-r--r--heat/engine/rsrc_defn.py6
-rw-r--r--heat_integrationtests/functional/test_create_update.py28
2 files changed, 26 insertions, 8 deletions
diff --git a/heat/engine/rsrc_defn.py b/heat/engine/rsrc_defn.py
index 517ebb1d3..6de61c373 100644
--- a/heat/engine/rsrc_defn.py
+++ b/heat/engine/rsrc_defn.py
@@ -187,6 +187,10 @@ class ResourceDefinition(object):
This returns a new resource definition, with all of the functions
parsed in the context of the specified stack and template.
+
+ Any conditions are *not* included - it is assumed that the resource is
+ being interpreted in any context that it should be enabled in that
+ context.
"""
assert not getattr(self, '_frozen', False
), "Cannot re-parse a frozen definition"
@@ -202,7 +206,7 @@ class ResourceDefinition(object):
deletion_policy=reparse_snippet(self._deletion_policy),
update_policy=reparse_snippet(self._update_policy),
external_id=reparse_snippet(self._external_id),
- condition=self._condition)
+ condition=None)
def validate(self):
"""Validate intrinsic functions that appear in the definition."""
diff --git a/heat_integrationtests/functional/test_create_update.py b/heat_integrationtests/functional/test_create_update.py
index cb5779aab..500579731 100644
--- a/heat_integrationtests/functional/test_create_update.py
+++ b/heat_integrationtests/functional/test_create_update.py
@@ -679,7 +679,7 @@ resources:
expected_status='UPDATE_FAILED')
self._stack_delete(stack_identifier)
- def test_stack_update_with_conditions(self):
+ def _test_conditional(self, test3_resource):
"""Update manages new conditions added.
When a new resource is added during updates, the stacks handles the new
@@ -691,12 +691,7 @@ resources:
updated_template = copy.deepcopy(test_template_two_resource)
updated_template['conditions'] = {'cond1': True}
- updated_template['resources']['test3'] = {
- 'type': 'OS::Heat::TestResource',
- 'properties': {
- 'value': {'if': ['cond1', 'val3', 'val4']}
- }
- }
+ updated_template['resources']['test3'] = test3_resource
test2_props = updated_template['resources']['test2']['properties']
test2_props['action_wait_secs'] = {'create': 30}
@@ -716,3 +711,22 @@ resources:
return True
self.assertTrue(test.call_until_true(20, 2, check_resources))
+
+ def test_stack_update_with_if_conditions(self):
+ test3 = {
+ 'type': 'OS::Heat::TestResource',
+ 'properties': {
+ 'value': {'if': ['cond1', 'val3', 'val4']}
+ }
+ }
+ self._test_conditional(test3)
+
+ def test_stack_update_with_conditions(self):
+ test3 = {
+ 'type': 'OS::Heat::TestResource',
+ 'condition': 'cond1',
+ 'properties': {
+ 'value': 'foo',
+ }
+ }
+ self._test_conditional(test3)