]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
RPC API: Simplify describe_stack_resources call
authorZane Bitter <zbitter@redhat.com>
Thu, 20 Dec 2012 12:31:14 +0000 (13:31 +0100)
committerZane Bitter <zbitter@redhat.com>
Fri, 21 Dec 2012 18:04:28 +0000 (19:04 +0100)
Remove the part with the physical_resource_id, which can now be done
through the find_physical_resource call.

Change-Id: Idff625014121aaa6ff3697b36fe38facaf54a499
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/api/cfn/v1/stacks.py
heat/engine/service.py
heat/rpc/client.py
heat/tests/test_api_cfn_v1.py
heat/tests/test_engine_service.py
heat/tests/test_rpc_client.py

index 5797805fc11f718c1f8daf54ed92c6eb8a086f6f..fdb3a5e2021b6708bee6d001c7d0e1f55c98930c 100644 (file)
@@ -540,8 +540,7 @@ class StackController(object):
             resources = self.engine_rpcapi.describe_stack_resources(
                 con,
                 stack_identity=identity,
-                physical_resource_id=None,
-                logical_resource_id=req.params.get('LogicalResourceId'))
+                resource_name=req.params.get('LogicalResourceId'))
 
         except rpc_common.RemoteError as ex:
             return exception.map_remote_error(ex)
index 44387daa840ec97fe9bb27d4758fac4765113db2..8823af83e1862e89a20a9955b165c397c4d3e9ba 100644 (file)
@@ -394,25 +394,13 @@ class EngineService(service.Service):
         return dict(resource.identifier())
 
     @request_context
-    def describe_stack_resources(self, context, stack_identity,
-                                 physical_resource_id, logical_resource_id):
-        if stack_identity is not None:
-            s = self._get_stack(context, stack_identity)
-        else:
-            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)
-            s = rs.stack
-
-        if not s:
-            raise AttributeError("The specified stack doesn't exist")
+    def describe_stack_resources(self, context, stack_identity, resource_name):
+        s = self._get_stack(context, stack_identity)
 
         stack = parser.Stack.load(context, stack=s)
 
-        if logical_resource_id is not None:
-            name_match = lambda r: r.name == logical_resource_id
+        if resource_name is not None:
+            name_match = lambda r: r.name == resource_name
         else:
             name_match = lambda r: True
 
index 431abf2fd0ceedff8192fb9e22ee777e1e28faf3..ca2c4f4845e4299581fcfd9e5aac66c10d5e2ca2 100644 (file)
@@ -205,12 +205,10 @@ class EngineClient(heat.openstack.common.rpc.proxy.RpcProxy):
                              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):
+    def describe_stack_resources(self, ctxt, stack_identity, resource_name):
         return self.call(ctxt, self.make_msg('describe_stack_resources',
-                         stack_identity=stack_identity,
-                         physical_resource_id=physical_resource_id,
-                         logical_resource_id=logical_resource_id),
+                                             stack_identity=stack_identity,
+                                             resource_name=resource_name),
                          topic=_engine_topic(self.topic, ctxt, None))
 
     def list_stack_resources(self, ctxt, stack_identity):
index d09023767ca0e72ed06ce1859620eaf522cfad50..4474f538ffb3b9d2af867cb3f3761463dedf3f28 100644 (file)
@@ -983,8 +983,7 @@ class StackControllerTest(unittest.TestCase):
                   'version': self.api_version}, None).AndReturn(identity)
         args = {
             'stack_identity': identity,
-            'physical_resource_id': None,
-            'logical_resource_id': dummy_req.params.get('LogicalResourceId'),
+            'resource_name': dummy_req.params.get('LogicalResourceId'),
         }
         rpc.call(dummy_req.context, self.topic,
                  {'method': 'describe_stack_resources',
@@ -1072,8 +1071,7 @@ class StackControllerTest(unittest.TestCase):
                   'version': self.api_version}, None).AndReturn(identity)
         args = {
             'stack_identity': identity,
-            'physical_resource_id': None,
-            'logical_resource_id': dummy_req.params.get('LogicalResourceId'),
+            'resource_name': dummy_req.params.get('LogicalResourceId'),
         }
         rpc.call(dummy_req.context, self.topic,
                  {'method': 'describe_stack_resources',
index 2853fabf56fdf11b468b019e738eeb5cecb9b5c0..17a35629c52b107e10a03d2356f075e4d41f8564 100644 (file)
@@ -579,7 +579,7 @@ class stackServiceTest(unittest.TestCase):
     def test_stack_resources_describe(self):
         resources = self.man.describe_stack_resources(self.ctx,
                                                       self.stack_identity,
-                                                      None, 'WebServer')
+                                                      'WebServer')
 
         self.assertEqual(len(resources), 1)
         r = resources[0]
@@ -600,7 +600,7 @@ class stackServiceTest(unittest.TestCase):
     def test_stack_resources_describe_no_filter(self):
         resources = self.man.describe_stack_resources(self.ctx,
                                                       self.stack_identity,
-                                                      None, None)
+                                                      None)
 
         self.assertEqual(len(resources), 1)
         r = resources[0]
@@ -608,36 +608,21 @@ class stackServiceTest(unittest.TestCase):
         self.assertEqual(r['logical_resource_id'], 'WebServer')
 
     def test_stack_resources_describe_bad_lookup(self):
-        self.assertRaises(AttributeError,
+        self.assertRaises(TypeError,
                           self.man.describe_stack_resources,
-                          self.ctx, None, None, 'WebServer')
+                          self.ctx, None, 'WebServer')
 
     def test_stack_resources_describe_nonexist_stack(self):
         nonexist = dict(self.stack_identity)
         nonexist['stack_name'] = 'foo'
         self.assertRaises(AttributeError,
                           self.man.describe_stack_resources,
-                          self.ctx, nonexist, None, 'WebServer')
-
-    def test_stack_resources_describe_physid(self):
-        resources = self.man.describe_stack_resources(self.ctx,
-                                                      self.stack_identity,
-                                                      None, None)
-        phys_id = resources[0]['physical_resource_id']
-
-        result = self.man.describe_stack_resources(self.ctx,
-                                                   None, phys_id, None)
-        self.assertEqual(result, resources)
-
-    def test_stack_resources_describe_nonexist_physid(self):
-        self.assertRaises(AttributeError,
-                          self.man.describe_stack_resources,
-                          self.ctx, None, 'foo', 'WebServer')
+                          self.ctx, nonexist, 'WebServer')
 
     def test_find_physical_resource(self):
         resources = self.man.describe_stack_resources(self.ctx,
                                                       self.stack_identity,
-                                                      None, None)
+                                                      None)
         phys_id = resources[0]['physical_resource_id']
 
         result = self.man.find_physical_resource(self.ctx, phys_id)
index 19f646882f799e7333c5342686c669e1b6fbfb7a..3f74b8c783bc6b9209050b8ff1c9f0e798f82a12 100644 (file)
@@ -136,8 +136,7 @@ class EngineRpcAPITestCase(unittest.TestCase):
     def test_describe_stack_resources(self):
         self._test_engine_api('describe_stack_resources', 'call',
                               stack_identity=self.identity,
-                              physical_resource_id=u'404d-a85b-5315293e67de',
-                              logical_resource_id=u'WikiDatabase')
+                              resource_name=u'WikiDatabase')
 
     def test_list_stack_resources(self):
         self._test_engine_api('list_stack_resources', 'call',