summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-15 06:39:40 +0000
committerGerrit Code Review <review@openstack.org>2017-06-15 06:39:40 +0000
commit1c4b725b8529a176847517a3aa9ed0582fa4098f (patch)
tree62630ba5e295fb209e3fac33e72fda486869e23d
parentc52fdbb7d68bb0814843f3fec9b2d966239bab40 (diff)
parent40ea8371378b64dd042ee6e749718e940105ba2c (diff)
Merge "Ignore dependency errors with conditions" into stable/newton
-rw-r--r--heat/engine/rsrc_defn.py9
-rw-r--r--heat/tests/test_hot.py19
-rw-r--r--heat/tests/test_rsrc_defn.py15
3 files changed, 39 insertions, 4 deletions
diff --git a/heat/engine/rsrc_defn.py b/heat/engine/rsrc_defn.py
index 4efff2f..4cb5a82 100644
--- a/heat/engine/rsrc_defn.py
+++ b/heat/engine/rsrc_defn.py
@@ -208,6 +208,10 @@ class ResourceDefinitionCore(object):
208 208
209 def get_resource(res_name): 209 def get_resource(res_name):
210 if res_name not in stack: 210 if res_name not in stack:
211 if res_name in stack.t.get(stack.t.RESOURCES):
212 # The resource is conditionally defined, allow dependencies
213 # on it
214 return
211 raise exception.InvalidTemplateReference(resource=res_name, 215 raise exception.InvalidTemplateReference(resource=res_name,
212 key=self.name) 216 key=self.name)
213 return stack[res_name] 217 return stack[res_name]
@@ -231,8 +235,9 @@ class ResourceDefinitionCore(object):
231 ) 235 )
232 return itertools.chain() 236 return itertools.chain()
233 237
234 return itertools.chain((get_resource(dep) for dep in explicit_depends), 238 return itertools.chain(
235 prop_deps, metadata_deps) 239 filter(None, (get_resource(dep) for dep in explicit_depends)),
240 prop_deps, metadata_deps)
236 241
237 def properties(self, schema, context=None): 242 def properties(self, schema, context=None):
238 """Return a Properties object representing the resource properties. 243 """Return a Properties object representing the resource properties.
diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py
index 422cbcd..30a9fc5 100644
--- a/heat/tests/test_hot.py
+++ b/heat/tests/test_hot.py
@@ -1665,6 +1665,25 @@ conditions:
1665 1665
1666 self.assertEqual(hot_tpl['resources'], empty.t['resources']) 1666 self.assertEqual(hot_tpl['resources'], empty.t['resources'])
1667 1667
1668 def test_depends_condition(self):
1669 hot_tpl = template_format.parse('''
1670 heat_template_version: 2016-10-14
1671 resources:
1672 one:
1673 type: OS::Heat::None
1674 two:
1675 type: OS::Heat::None
1676 condition: False
1677 three:
1678 type: OS::Heat::None
1679 depends_on: two
1680 ''')
1681
1682 tmpl = template.Template(hot_tpl)
1683 stack = parser.Stack(utils.dummy_context(), 'test_stack', tmpl)
1684 stack.validate()
1685 self.assertEqual({'one', 'three'}, set(stack.resources))
1686
1668 1687
1669class HotStackTest(common.HeatTestCase): 1688class HotStackTest(common.HeatTestCase):
1670 """Test stack function when stack was created from HOT template.""" 1689 """Test stack function when stack was created from HOT template."""
diff --git a/heat/tests/test_rsrc_defn.py b/heat/tests/test_rsrc_defn.py
index e5bb2b4..ee995ea 100644
--- a/heat/tests/test_rsrc_defn.py
+++ b/heat/tests/test_rsrc_defn.py
@@ -35,6 +35,16 @@ resources:
35 type: OS::Heat::TestResource 35 type: OS::Heat::TestResource
36''' 36'''
37 37
38TEMPLATE_WITH_INVALID_EXPLICIT_DEPEND = '''
39heat_template_version: 2016-10-14
40resources:
41 test1:
42 type: OS::Heat::TestResource
43 test3:
44 type: OS::Heat::TestResource
45 depends_on: test2
46'''
47
38 48
39class ResourceDefinitionTest(common.HeatTestCase): 49class ResourceDefinitionTest(common.HeatTestCase):
40 50
@@ -105,8 +115,9 @@ class ResourceDefinitionTest(common.HeatTestCase):
105 self.assertEqual([], list(rsrc.t.dependencies(stack))) 115 self.assertEqual([], list(rsrc.t.dependencies(stack)))
106 116
107 def test_dependencies_explicit_invalid(self): 117 def test_dependencies_explicit_invalid(self):
108 rd = rsrc_defn.ResourceDefinition('rsrc', 'SomeType', depends=['baz']) 118 t = template_format.parse(TEMPLATE_WITH_INVALID_EXPLICIT_DEPEND)
109 stack = {'foo': 'FOO', 'bar': 'BAR'} 119 stack = utils.parse_stack(t)
120 rd = stack.t.resource_definitions(stack)['test3']
110 self.assertRaises(exception.InvalidTemplateReference, 121 self.assertRaises(exception.InvalidTemplateReference,
111 lambda: list(rd.dependencies(stack))) 122 lambda: list(rd.dependencies(stack)))
112 123