From: Zane Bitter Date: Thu, 20 Dec 2012 12:31:14 +0000 (+0100) Subject: RPC API: Simplify describe_stack_resources call X-Git-Tag: 2014.1~1037 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=61be8e1ea40ccb2696fba1bf1524d3678bb40f3c;p=openstack-build%2Fheat-build.git RPC API: Simplify describe_stack_resources call 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 --- diff --git a/heat/api/cfn/v1/stacks.py b/heat/api/cfn/v1/stacks.py index 5797805f..fdb3a5e2 100644 --- a/heat/api/cfn/v1/stacks.py +++ b/heat/api/cfn/v1/stacks.py @@ -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) diff --git a/heat/engine/service.py b/heat/engine/service.py index 44387daa..8823af83 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -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 diff --git a/heat/rpc/client.py b/heat/rpc/client.py index 431abf2f..ca2c4f48 100644 --- a/heat/rpc/client.py +++ b/heat/rpc/client.py @@ -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): diff --git a/heat/tests/test_api_cfn_v1.py b/heat/tests/test_api_cfn_v1.py index d0902376..4474f538 100644 --- a/heat/tests/test_api_cfn_v1.py +++ b/heat/tests/test_api_cfn_v1.py @@ -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', diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 2853fabf..17a35629 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -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) diff --git a/heat/tests/test_rpc_client.py b/heat/tests/test_rpc_client.py index 19f64688..3f74b8c7 100644 --- a/heat/tests/test_rpc_client.py +++ b/heat/tests/test_rpc_client.py @@ -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',