From 576d092b97af41f2e22493e1a2678ab5c948456a Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Fri, 2 Sep 2016 01:59:55 +0000 Subject: [PATCH] Use physical name in event if resource_id is None An event for CREATE_IN_PROGRESS will have a physical_resource_id value of None because the resource hasn't been created yet. Because of this it is not possible to relate a nested stack event with the CREATE_IN_PROGRESS resource event in the parent stack. This change populates Event.physical_resource_id with Resource.physical_resource_name() if Resource.resource_id isn't populated yet. This change will help fix Related-Bug: #1619415 Change-Id: Ib8feb7752bd5736785d142216312bb35629b3601 --- heat/engine/resource.py | 3 ++- heat/tests/test_resource.py | 4 ++++ heat/tests/test_stack_user.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index e7a015fb45..09e118d414 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -1727,8 +1727,9 @@ class Resource(object): def _add_event(self, action, status, reason): """Add a state change event to the database.""" + physical_res_id = self.resource_id or self.physical_resource_name() ev = event.Event(self.context, self.stack, action, status, reason, - self.resource_id, self.properties, + physical_res_id, self.properties, self.name, self.type()) ev.store() diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 500834299c..6e934ed11a 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -3393,6 +3393,7 @@ class ResourceHookTest(common.HeatTestCase): 'GenericResourceType') res = resource.Resource('res', snippet, self.stack) res.id = '1234' + res.uuid = uuid.uuid4() task = scheduler.TaskRunner(res.create) task.start() task.step() @@ -3409,6 +3410,7 @@ class ResourceHookTest(common.HeatTestCase): res = resource.Resource('res', snippet, self.stack) res.id = '1234' res.action = 'CREATE' + res.uuid = uuid.uuid4() self.stack.action = 'DELETE' task = scheduler.TaskRunner(res.delete) task.start() @@ -3425,6 +3427,7 @@ class ResourceHookTest(common.HeatTestCase): 'GenericResourceType') res = resource.Resource('res', snippet, self.stack) res.id = '1234' + res.uuid = uuid.uuid4() task = scheduler.TaskRunner(res.create) task.start() task.step() @@ -3440,6 +3443,7 @@ class ResourceHookTest(common.HeatTestCase): 'GenericResourceType') res = resource.Resource('res', snippet, self.stack) res.id = '1234' + res.uuid = uuid.uuid4() res.action = 'CREATE' self.stack.action = 'DELETE' task = scheduler.TaskRunner(res.delete) diff --git a/heat/tests/test_stack_user.py b/heat/tests/test_stack_user.py index a195618d2b..cbab4f9497 100644 --- a/heat/tests/test_stack_user.py +++ b/heat/tests/test_stack_user.py @@ -60,7 +60,7 @@ class StackUserTest(common.HeatTestCase): rsrc._store() self.m.StubOutWithMock(short_id, 'get_id') - short_id.get_id(rsrc.uuid).AndReturn('aabbcc') + short_id.get_id(rsrc.uuid).MultipleTimes().AndReturn('aabbcc') self.m.StubOutWithMock(fakes.FakeKeystoneClient, 'create_stack_domain_user')