Make Fn::GetAtt add a dependency

This will ensure that resources which get attributes from other resources
are not created until the latter resources are available.

An audit of all the templates in the heat-templates repo revealed that in
only one case did this cause a circular reference, and it was the template
that appeared to be incorrect (it has since been fixed).

Change-Id: Ibd51acdda55c24f665c5ca887040f3564d952c0e
This commit is contained in:
Zane Bitter 2013-05-31 12:52:30 +02:00 committed by Steve Baker
parent bc6915260e
commit 4c556ae933
2 changed files with 7 additions and 2 deletions

View File

@ -273,7 +273,10 @@ class Resource(object):
def _add_dependencies(self, deps, head, fragment):
if isinstance(fragment, dict):
for key, value in fragment.items():
if key in ('DependsOn', 'Ref'):
if key in ('DependsOn', 'Ref', 'Fn::GetAtt'):
if key == 'Fn::GetAtt':
value, head = value
try:
target = self.stack.resources[value]
except KeyError:
@ -282,7 +285,7 @@ class Resource(object):
key=head)
if key == 'DependsOn' or target.strict_dependency:
deps += (self, target)
elif key != 'Fn::GetAtt':
else:
self._add_dependencies(deps, key, value)
elif isinstance(fragment, list):
for item in fragment:

View File

@ -156,6 +156,7 @@ class MetadataRefreshTest(HeatTestCase):
instance.Instance.handle_create().AndReturn(cookie)
create_complete = instance.Instance.check_create_complete(cookie)
create_complete.InAnyOrder().AndReturn(True)
scheduler.TaskRunner._sleep(mox.IsA(int)).AndReturn(None)
self.m.StubOutWithMock(instance.Instance, 'FnGetAtt')
return stack
@ -260,6 +261,7 @@ class WaitCondMetadataUpdateTest(HeatTestCase):
scheduler.TaskRunner._sleep(mox.IsA(int)).WithSideEffects(check_empty)
scheduler.TaskRunner._sleep(mox.IsA(int)).WithSideEffects(post_success)
scheduler.TaskRunner._sleep(mox.IsA(int)).AndReturn(None)
self.m.ReplayAll()
self.stack.create()