]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Handle metadata updates during stack creation
authorZane Bitter <zbitter@redhat.com>
Fri, 31 May 2013 10:52:30 +0000 (12:52 +0200)
committerZane Bitter <zbitter@redhat.com>
Fri, 31 May 2013 10:52:34 +0000 (12:52 +0200)
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
heat/tests/test_metadata_refresh.py

index 3a7cde3cc1516afddcfc81095c29a256cf3d94d5..dd0db0cc53f093d716a1693dcb1e7d13fd050768 100644 (file)
@@ -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
index c985df8128af9b8bc897e3154155077f7e958018..3214debfc94928f267df57d21c4221b9737dd994 100644 (file)
@@ -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'), '{}')