From 248d87801188cfcc464f8f1b4503cf3d2be18b28 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Thu, 22 Nov 2012 11:06:57 +0100 Subject: [PATCH] Add a method for querying a resource's type Change-Id: Ie07a01668c5958494631806ffc0748f659eb8a1b Signed-off-by: Zane Bitter --- heat/engine/resources/resource.py | 11 ++++++----- heat/tests/test_resource.py | 5 +++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/heat/engine/resources/resource.py b/heat/engine/resources/resource.py index bd91540e..45031299 100644 --- a/heat/engine/resources/resource.py +++ b/heat/engine/resources/resource.py @@ -132,6 +132,9 @@ class Resource(object): return result return not result + def type(self): + return self.t['Type'] + def identifier(self): '''Return an identifier for this resource''' return identifier.ResourceIdentifier(resource_name=self.name, @@ -335,7 +338,7 @@ class Resource(object): 'resource_status': new_state, 'name': new_state, 'resource_status_reason': reason, - 'resource_type': self.t['Type'], + 'resource_type': self.type(), 'resource_properties': dict(self.properties)} try: db_api.event_create(self.context, ev) @@ -399,9 +402,7 @@ class GenericResource(Resource): properties_schema = {} def handle_create(self): - logger.warning('Creating generic resource (Type "%s")' % - self.t['Type']) + logger.warning('Creating generic resource (Type "%s")' % self.type()) def handle_update(self): - logger.warning('Updating generic resource (Type "%s")' % - self.t['Type']) + logger.warning('Updating generic resource (Type "%s")' % self.type()) diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 200ff12f..c1f94b79 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -49,6 +49,11 @@ class ResourceTest(unittest.TestCase): res.state_set('blarg', 'wibble') self.assertEqual(res.state_description, 'wibble') + def test_type(self): + tmpl = {'Type': 'Foo'} + res = resource.GenericResource('test_resource', tmpl, self.stack) + self.assertEqual(res.type(), 'Foo') + def test_created_time(self): tmpl = {'Type': 'Foo'} res = resource.GenericResource('test_res_new', tmpl, self.stack) -- 2.45.2