From df2e6779bab71da06c00dd78d3732a756ce9c6ad Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Fri, 31 May 2013 12:52:30 +0200 Subject: [PATCH] Handle metadata updates during stack creation Don't try to recalculate the metadata on an instance that hasn't yet been stored in the database. Fixes bug #1185530 Change-Id: I39f2733e2ba4730ea05a4a50962cb30f044ef752 --- heat/engine/service.py | 2 +- heat/tests/test_metadata_refresh.py | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/heat/engine/service.py b/heat/engine/service.py index 3a7cde3c..dd0db0cc 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -499,7 +499,7 @@ class EngineService(service.Service): # resources may refer to WaitCondition Fn::GetAtt Data, which # is updated here. for res in refresh_stack: - if res.name != resource_name: + if res.name != resource_name and res.id is not None: res.metadata_update() return resource.metadata diff --git a/heat/tests/test_metadata_refresh.py b/heat/tests/test_metadata_refresh.py index c985df81..3214debf 100644 --- a/heat/tests/test_metadata_refresh.py +++ b/heat/tests/test_metadata_refresh.py @@ -85,11 +85,11 @@ test_template_waitcondition = ''' "KeyName" : {"Type" : "String", "Default": "mine" }, }, "Resources" : { + "WH" : { + "Type" : "AWS::CloudFormation::WaitConditionHandle" + }, "S1": { "Type": "AWS::EC2::Instance", - "Metadata" : { - "test" : {"Fn::GetAtt": ["WC", "Data"]} - }, "Properties": { "ImageId" : "a", "InstanceType" : "m1.large", @@ -100,9 +100,6 @@ test_template_waitcondition = ''' "\n" ] ] } } }, - "WH" : { - "Type" : "AWS::CloudFormation::WaitConditionHandle" - }, "WC" : { "Type" : "AWS::CloudFormation::WaitCondition", "DependsOn": "S1", @@ -110,6 +107,18 @@ test_template_waitcondition = ''' "Handle" : {"Ref" : "WH"}, "Timeout" : "5" } + }, + "S2": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "test" : {"Fn::GetAtt": ["WC", "Data"]} + }, + "Properties": { + "ImageId" : "a", + "InstanceType" : "m1.large", + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : "#!/bin/bash -v\n" + } } } } @@ -203,9 +212,9 @@ class WaitCondMetadataUpdateTest(HeatTestCase): self.m.StubOutWithMock(instance.Instance, 'handle_create') self.m.StubOutWithMock(instance.Instance, 'check_create_complete') - cookie = object() - instance.Instance.handle_create().AndReturn(cookie) - instance.Instance.check_create_complete(cookie).AndReturn(True) + for cookie in (object(), object()): + instance.Instance.handle_create().AndReturn(cookie) + instance.Instance.check_create_complete(cookie).AndReturn(True) self.m.StubOutWithMock(wc.WaitConditionHandle, 'keystone') wc.WaitConditionHandle.keystone().MultipleTimes().AndReturn(self.fc) @@ -232,7 +241,7 @@ class WaitCondMetadataUpdateTest(HeatTestCase): self.stack = self.create_stack() watch = self.stack['WC'] - inst = self.stack['S1'] + inst = self.stack['S2'] def check_empty(sleep_time): self.assertEqual(watch.FnGetAtt('Data'), '{}') -- 2.45.2