From 748391ba2c4647de9a02ca485516fc6033997c98 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Fri, 21 Dec 2012 17:25:26 +0100 Subject: [PATCH] RPC API: Add a separate find_physical_resource call The logic for this is currently mixed up with describe_stack_resources. Change-Id: I14dadfc3ae6cde337dfb1bdee011cb7b32e5e4d9 Signed-off-by: Zane Bitter --- heat/engine/service.py | 19 +++++++++++++++++++ heat/rpc/client.py | 13 +++++++++++++ heat/tests/test_engine_service.py | 18 ++++++++++++++++++ heat/tests/test_rpc_client.py | 4 ++++ 4 files changed, 54 insertions(+) diff --git a/heat/engine/service.py b/heat/engine/service.py index db7178cb..44387daa 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -374,6 +374,25 @@ class EngineService(service.Service): return api.format_stack_resource(stack[resource_name]) + @request_context + def find_physical_resource(self, context, physical_resource_id): + """ + Return an identifier for the resource with the specified physical + resource ID. + arg1 -> RPC context. + arg2 -> The physical resource ID to look up. + """ + rs = db_api.resource_get_by_physical_resource_id(context, + physical_resource_id) + if not rs: + msg = "The specified PhysicalResourceId doesn't exist" + raise AttributeError(msg) + + stack = parser.Stack.load(context, stack=rs.stack) + resource = stack[rs.name] + + return dict(resource.identifier()) + @request_context def describe_stack_resources(self, context, stack_identity, physical_resource_id, logical_resource_id): diff --git a/heat/rpc/client.py b/heat/rpc/client.py index 70852f88..431abf2f 100644 --- a/heat/rpc/client.py +++ b/heat/rpc/client.py @@ -192,6 +192,19 @@ class EngineClient(heat.openstack.common.rpc.proxy.RpcProxy): resource_name=resource_name), topic=_engine_topic(self.topic, ctxt, None)) + def find_physical_resource(self, ctxt, physical_resource_id): + """ + Return an identifier for the resource with the specified physical + resource ID. + :param ctxt RPC context. + :param physcial_resource_id The physical resource ID to look up. + """ + return self.call(ctxt, + self.make_msg( + 'find_physical_resource', + physical_resource_id=physical_resource_id), + topic=_engine_topic(self.topic, ctxt, None)) + def describe_stack_resources(self, ctxt, stack_identity, physical_resource_id, logical_resource_id): return self.call(ctxt, self.make_msg('describe_stack_resources', diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 16e41f5c..2853fabf 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -23,6 +23,7 @@ from heat.common import context from heat.tests.v1_1 import fakes import heat.engine.api as engine_api import heat.db as db_api +from heat.common import identifier from heat.common import template_format from heat.engine import parser from heat.engine import service @@ -633,6 +634,23 @@ class stackServiceTest(unittest.TestCase): self.man.describe_stack_resources, self.ctx, None, 'foo', 'WebServer') + def test_find_physical_resource(self): + resources = self.man.describe_stack_resources(self.ctx, + self.stack_identity, + None, None) + phys_id = resources[0]['physical_resource_id'] + + result = self.man.find_physical_resource(self.ctx, phys_id) + self.assertTrue(isinstance(result, dict)) + resource_identity = identifier.ResourceIdentifier(**result) + self.assertEqual(resource_identity.stack(), self.stack_identity) + self.assertEqual(resource_identity.resource_name, 'WebServer') + + def test_find_physical_resource_nonexist(self): + self.assertRaises(AttributeError, + self.man.find_physical_resource, + self.ctx, 'foo') + def test_stack_resources_list(self): resources = self.man.list_stack_resources(self.ctx, self.stack_identity) diff --git a/heat/tests/test_rpc_client.py b/heat/tests/test_rpc_client.py index e794d8dd..19f64688 100644 --- a/heat/tests/test_rpc_client.py +++ b/heat/tests/test_rpc_client.py @@ -129,6 +129,10 @@ class EngineRpcAPITestCase(unittest.TestCase): stack_identity=self.identity, resource_name='LogicalResourceId') + def test_find_physical_resource(self): + self._test_engine_api('find_physical_resource', 'call', + physical_resource_id=u'404d-a85b-5315293e67de') + def test_describe_stack_resources(self): self._test_engine_api('describe_stack_resources', 'call', stack_identity=self.identity, -- 2.45.2