summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngus Salkeld <asalkeld@redhat.com>2013-10-14 13:00:13 +1100
committerSteve Baker <sbaker@redhat.com>2014-01-27 16:34:14 +1300
commit6fa3c8fa50b3570dff8da425250c4d3166fdc138 (patch)
tree7a06547e774f5d0e9120e4f1e8040d1f6a1432af
parente483b38ec107d53ca4134382f4ac0d69d5962ef6 (diff)
downloadheat-6fa3c8fa50b3570dff8da425250c4d3166fdc138.tar.gz
Allow DependsOn to accept a list
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html Change-Id: I8187d8a0395cc96d9727aa812d57f281e69c516d Closes-bug: #1235496
-rw-r--r--heat/engine/resource.py26
-rw-r--r--heat/tests/test_parser.py21
2 files changed, 37 insertions, 10 deletions
diff --git a/heat/engine/resource.py b/heat/engine/resource.py
index 1141b008c..4fd11801d 100644
--- a/heat/engine/resource.py
+++ b/heat/engine/resource.py
@@ -284,16 +284,22 @@ class Resource(object):
if key in ('DependsOn', 'Ref', 'Fn::GetAtt', 'get_attr',
'get_resource'):
if key in ('Fn::GetAtt', 'get_attr'):
- value, att = value
-
- try:
- target = self.stack.resources[value]
- except KeyError:
- raise exception.InvalidTemplateReference(
- resource=value,
- key=path)
- if key == 'DependsOn' or target.strict_dependency:
- deps += (self, target)
+ res_name, att = value
+ res_list = [res_name]
+ elif key == 'DependsOn' and isinstance(value, list):
+ res_list = value
+ else:
+ res_list = [value]
+
+ for res in res_list:
+ try:
+ target = self.stack[res]
+ except KeyError:
+ raise exception.InvalidTemplateReference(
+ resource=res,
+ key=path)
+ if key == 'DependsOn' or target.strict_dependency:
+ deps += (self, target)
else:
self._add_dependencies(deps, '%s.%s' % (path, key), value)
elif isinstance(fragment, list):
diff --git a/heat/tests/test_parser.py b/heat/tests/test_parser.py
index 5b9789042..9ac90f9ff 100644
--- a/heat/tests/test_parser.py
+++ b/heat/tests/test_parser.py
@@ -1798,6 +1798,27 @@ class StackTest(HeatTestCase):
self.assertIn(r, required_by)
@utils.stack_delete_after
+ def test_resource_multi_required_by(self):
+ tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'},
+ 'BResource': {'Type': 'GenericResourceType'},
+ 'CResource': {'Type': 'GenericResourceType'},
+ 'DResource': {'Type': 'GenericResourceType',
+ 'DependsOn': ['AResource',
+ 'BResource',
+ 'CResource']}}}
+
+ self.stack = parser.Stack(self.ctx, 'depends_test_stack',
+ template.Template(tmpl))
+ self.stack.store()
+ self.stack.create()
+ self.assertEqual(self.stack.state,
+ (parser.Stack.CREATE, parser.Stack.COMPLETE))
+
+ for r in ['AResource', 'BResource', 'CResource']:
+ self.assertEqual(['DResource'],
+ self.stack[r].required_by())
+
+ @utils.stack_delete_after
def test_store_saves_owner(self):
"""
The owner_id attribute of Store is saved to the database when stored.