From 0dfb31efe815c9688ebdcad861f38db51472d23a Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Tue, 5 Mar 2013 18:08:59 +0000 Subject: [PATCH] heat engine : allow Properties validation failure events Currently if properties.validate() fails causing the resource to go to CREATE_FAILED state, we get an error when creating the event, because the bad properties are evaluated in the event constructor. Instead create a dummy Error property with the error string for the event. ref bug 1146529 Change-Id: I12f11de617d796d65c67a5ddb6d74c86adf67b5d --- heat/engine/event.py | 5 ++++- heat/tests/test_event.py | 20 +++++++++++++++++--- heat/tests/test_parser.py | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/heat/engine/event.py b/heat/engine/event.py index cb49aea3..3017a4f2 100644 --- a/heat/engine/event.py +++ b/heat/engine/event.py @@ -39,7 +39,10 @@ class Event(object): self.new_state = new_state self.reason = reason self.physical_resource_id = physical_resource_id - self.resource_properties = dict(resource_properties) + try: + self.resource_properties = dict(resource_properties) + except ValueError as ex: + self.resource_properties = {'Error': str(ex)} self.timestamp = timestamp self.id = id diff --git a/heat/tests/test_event.py b/heat/tests/test_event.py index c57c76a7..cd50cdfa 100644 --- a/heat/tests/test_event.py +++ b/heat/tests/test_event.py @@ -31,6 +31,7 @@ tmpl = { 'Resources': { 'EventTestResource': { 'Type': 'GenericResourceType', + 'Properties': {'foo': True} } } } @@ -51,6 +52,10 @@ class EventTest(unittest.TestCase): self.m.ReplayAll() + # patch in a dummy property schema for GenericResource + dummy_schema = {'foo': {'Type': 'Boolean', 'Required': True}} + generic_rsrc.GenericResource.properties_schema = dummy_schema + resource._register_class('GenericResourceType', generic_rsrc.GenericResource) @@ -70,7 +75,7 @@ class EventTest(unittest.TestCase): e = event.Event(self.ctx, self.stack, self.resource, 'TEST_IN_PROGRESS', 'Testing', - 'wibble', {'foo': 'bar'}) + 'wibble', self.resource.properties) e.store() self.assertNotEqual(e.id, None) @@ -84,12 +89,12 @@ class EventTest(unittest.TestCase): self.assertEqual(loaded_e.new_state, 'TEST_IN_PROGRESS') self.assertEqual(loaded_e.reason, 'Testing') self.assertNotEqual(loaded_e.timestamp, None) - self.assertEqual(loaded_e.resource_properties, {'foo': 'bar'}) + self.assertEqual(loaded_e.resource_properties, {'foo': True}) def test_identifier(self): e = event.Event(self.ctx, self.stack, self.resource, 'TEST_IN_PROGRESS', 'Testing', - 'wibble', {'foo': 'bar'}) + 'wibble', self.resource.properties) eid = e.store() expected_identifier = { @@ -99,3 +104,12 @@ class EventTest(unittest.TestCase): 'path': '/resources/EventTestResource/events/%s' % str(eid) } self.assertEqual(e.identifier(), expected_identifier) + + def test_badprop(self): + tmpl = {'Type': 'GenericResourceType', 'Properties': {'foo': 'abc'}} + rname = 'bad_resource' + res = generic_rsrc.GenericResource(rname, tmpl, self.stack) + e = event.Event(self.ctx, self.stack, res, + 'TEST_IN_PROGRESS', 'Testing', + 'wibble', res.properties) + self.assertTrue('Error' in e.resource_properties) diff --git a/heat/tests/test_parser.py b/heat/tests/test_parser.py index 2f06ca5b..cf560713 100644 --- a/heat/tests/test_parser.py +++ b/heat/tests/test_parser.py @@ -305,6 +305,7 @@ class StackTest(unittest.TestCase): self.ctx.username = self.username self.ctx.tenant_id = 'test_tenant' + generic_rsrc.GenericResource.properties_schema = {} resource._register_class('GenericResourceType', generic_rsrc.GenericResource) -- 2.45.2