]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
RPC API: Add a separate find_physical_resource call
authorZane Bitter <zbitter@redhat.com>
Fri, 21 Dec 2012 16:25:26 +0000 (17:25 +0100)
committerZane Bitter <zbitter@redhat.com>
Fri, 21 Dec 2012 18:03:13 +0000 (19:03 +0100)
The logic for this is currently mixed up with describe_stack_resources.

Change-Id: I14dadfc3ae6cde337dfb1bdee011cb7b32e5e4d9
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/engine/service.py
heat/rpc/client.py
heat/tests/test_engine_service.py
heat/tests/test_rpc_client.py

index db7178cb7b8d603e506f9dd2a3ba6f6b8b745de8..44387daa840ec97fe9bb27d4758fac4765113db2 100644 (file)
@@ -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):
index 70852f88887f8fceaede30010076671baf4b444a..431abf2fd0ceedff8192fb9e22ee777e1e28faf3 100644 (file)
@@ -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',
index 16e41f5c376b11716ebe40f5a46c081d39ef7653..2853fabf56fdf11b468b019e738eeb5cecb9b5c0 100644 (file)
@@ -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)
index e794d8dd326520ec1d5eb7240492d964befa58b9..19f646882f799e7333c5342686c669e1b6fbfb7a 100644 (file)
@@ -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,