From: Zane Bitter Date: Fri, 21 Dec 2012 16:25:25 +0000 (+0100) Subject: RPC API: Clean up show_stack results X-Git-Tag: 2014.1~1044 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1e88faa414da77e2726b22ff0b0892e91a5a85d1;p=openstack-build%2Fheat-build.git RPC API: Clean up show_stack results Just return a list, rather than wrapping it in an object. The client API processes can (and do) do whatever wrapping they need. Change-Id: Ibb9955a9c3fc25b88cf3914f2a3ea7cedaf2aa9b Signed-off-by: Zane Bitter --- diff --git a/heat/api/cfn/v1/stacks.py b/heat/api/cfn/v1/stacks.py index 15b630e8..31adeb94 100644 --- a/heat/api/cfn/v1/stacks.py +++ b/heat/api/cfn/v1/stacks.py @@ -214,7 +214,7 @@ class StackController(object): except rpc_common.RemoteError as ex: return exception.map_remote_error(ex) - res = {'Stacks': [format_stack(s) for s in stack_list['stacks']]} + res = {'Stacks': [format_stack(s) for s in stack_list]} return api_utils.format_response('DescribeStacks', res) diff --git a/heat/api/openstack/v1/stacks.py b/heat/api/openstack/v1/stacks.py index 70894f47..ab80f329 100644 --- a/heat/api/openstack/v1/stacks.py +++ b/heat/api/openstack/v1/stacks.py @@ -220,10 +220,10 @@ class StackController(object): except rpc_common.RemoteError as ex: return util.remote_error(ex) - if not stack_list['stacks']: + if not stack_list: raise exc.HTTPInternalServerError() - stack = stack_list['stacks'][0] + stack = stack_list[0] return {'stack': format_stack(req, stack)} diff --git a/heat/engine/service.py b/heat/engine/service.py index b4fb9957..ac864ca1 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -155,7 +155,7 @@ class EngineService(service.Service): stack = parser.Stack.load(context, stack=s) return api.format_stack(stack) - return {'stacks': [format_stack_detail(s) for s in stacks]} + return [format_stack_detail(s) for s in stacks] @request_context def list_stacks(self, context): diff --git a/heat/tests/test_api_cfn_v1.py b/heat/tests/test_api_cfn_v1.py index a2854090..0baef2c7 100644 --- a/heat/tests/test_api_cfn_v1.py +++ b/heat/tests/test_api_cfn_v1.py @@ -159,32 +159,31 @@ class StackControllerTest(unittest.TestCase): # Stub out the RPC call to the engine with a pre-canned response # Note the engine returns a load of keys we don't actually use # so this is a subset of the real response format - engine_resp = {u'stacks': - [{u'stack_identity': - {u'tenant': u't', - u'stack_name': u'wordpress', - u'stack_id': u'6', - u'path': u''}, - u'updated_time': u'2012-07-09T09:13:11Z', - u'parameters': {u'DBUsername': u'admin', - u'LinuxDistribution': u'F17', - u'InstanceType': u'm1.large', - u'DBRootPassword': u'admin', - u'DBPassword': u'admin', - u'DBName': u'wordpress'}, - u'outputs': - [{u'output_key': u'WebsiteURL', - u'description': u'URL for Wordpress wiki', - u'output_value': u'http://10.0.0.8/wordpress'}], - u'stack_status_reason': u'Stack successfully created', - u'creation_time': u'2012-07-09T09:12:45Z', - u'stack_name': u'wordpress', - u'notification_topics': [], - u'stack_status': u'CREATE_COMPLETE', - u'description': u'blah', - u'disable_rollback': True, - u'timeout_mins':60, - u'capabilities':[]}]} + engine_resp = [{u'stack_identity': + {u'tenant': u't', + u'stack_name': u'wordpress', + u'stack_id': u'6', + u'path': u''}, + u'updated_time': u'2012-07-09T09:13:11Z', + u'parameters': {u'DBUsername': u'admin', + u'LinuxDistribution': u'F17', + u'InstanceType': u'm1.large', + u'DBRootPassword': u'admin', + u'DBPassword': u'admin', + u'DBName': u'wordpress'}, + u'outputs': + [{u'output_key': u'WebsiteURL', + u'description': u'URL for Wordpress wiki', + u'output_value': u'http://10.0.0.8/wordpress'}], + u'stack_status_reason': u'Stack successfully created', + u'creation_time': u'2012-07-09T09:12:45Z', + u'stack_name': u'wordpress', + u'notification_topics': [], + u'stack_status': u'CREATE_COMPLETE', + u'description': u'blah', + u'disable_rollback': True, + u'timeout_mins':60, + u'capabilities':[]}] self.m.StubOutWithMock(rpc, 'call') rpc.call(dummy_req.context, self.topic, @@ -247,31 +246,30 @@ class StackControllerTest(unittest.TestCase): # Stub out the RPC call to the engine with a pre-canned response # Note the engine returns a load of keys we don't actually use # so this is a subset of the real response format - engine_resp = {u'stacks': - [{u'stack_identity': {u'tenant': u't', - u'stack_name': u'wordpress', - u'stack_id': u'6', - u'path': u''}, - u'updated_time': u'2012-07-09T09:13:11Z', - u'parameters': {u'DBUsername': u'admin', - u'LinuxDistribution': u'F17', - u'InstanceType': u'm1.large', - u'DBRootPassword': u'admin', - u'DBPassword': u'admin', - u'DBName': u'wordpress'}, - u'outputs': - [{u'output_key': u'WebsiteURL', - u'description': u'URL for Wordpress wiki', - u'output_value': u'http://10.0.0.8/wordpress'}], - u'stack_status_reason': u'Stack successfully created', - u'creation_time': u'2012-07-09T09:12:45Z', - u'stack_name': u'wordpress', - u'notification_topics': [], - u'stack_status': u'CREATE_COMPLETE', - u'description': u'blah', - u'disable_rollback': True, - u'timeout_mins':60, - u'capabilities':[]}]} + engine_resp = [{u'stack_identity': {u'tenant': u't', + u'stack_name': u'wordpress', + u'stack_id': u'6', + u'path': u''}, + u'updated_time': u'2012-07-09T09:13:11Z', + u'parameters': {u'DBUsername': u'admin', + u'LinuxDistribution': u'F17', + u'InstanceType': u'm1.large', + u'DBRootPassword': u'admin', + u'DBPassword': u'admin', + u'DBName': u'wordpress'}, + u'outputs': + [{u'output_key': u'WebsiteURL', + u'description': u'URL for Wordpress wiki', + u'output_value': u'http://10.0.0.8/wordpress'}], + u'stack_status_reason': u'Stack successfully created', + u'creation_time': u'2012-07-09T09:12:45Z', + u'stack_name': u'wordpress', + u'notification_topics': [], + u'stack_status': u'CREATE_COMPLETE', + u'description': u'blah', + u'disable_rollback': True, + u'timeout_mins':60, + u'capabilities':[]}] self.m.StubOutWithMock(rpc, 'call') rpc.call(dummy_req.context, self.topic, diff --git a/heat/tests/test_api_openstack_v1.py b/heat/tests/test_api_openstack_v1.py index d702aced..6c728e5b 100644 --- a/heat/tests/test_api_openstack_v1.py +++ b/heat/tests/test_api_openstack_v1.py @@ -508,25 +508,23 @@ class StackControllerTest(ControllerTest, unittest.TestCase): u'description': u'URL for Wordpress wiki', u'output_value': u'http://10.0.0.8/wordpress'}] - engine_resp = { - u'stacks': [ - { - u'stack_identity': dict(identity), - u'updated_time': u'2012-07-09T09:13:11Z', - u'parameters': parameters, - u'outputs': outputs, - u'stack_status_reason': u'Stack successfully created', - u'creation_time': u'2012-07-09T09:12:45Z', - u'stack_name': identity.stack_name, - u'notification_topics': [], - u'stack_status': u'CREATE_COMPLETE', - u'description': u'blah', - u'disable_rollback': True, - u'timeout_mins':60, - u'capabilities': [], - } - ] - } + engine_resp = [ + { + u'stack_identity': dict(identity), + u'updated_time': u'2012-07-09T09:13:11Z', + u'parameters': parameters, + u'outputs': outputs, + u'stack_status_reason': u'Stack successfully created', + u'creation_time': u'2012-07-09T09:12:45Z', + u'stack_name': identity.stack_name, + u'notification_topics': [], + u'stack_status': u'CREATE_COMPLETE', + u'description': u'blah', + u'disable_rollback': True, + u'timeout_mins':60, + u'capabilities': [], + } + ] self.m.StubOutWithMock(rpc, 'call') rpc.call(req.context, self.topic, {'method': 'show_stack', diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 965c8c38..eb3b5d16 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -500,9 +500,9 @@ class stackServiceTest(unittest.TestCase): def test_stack_describe(self): sl = self.man.show_stack(self.ctx, self.stack_identity) - self.assertEqual(len(sl['stacks']), 1) + self.assertEqual(len(sl), 1) - s = sl['stacks'][0] + s = sl[0] self.assertTrue('creation_time' in s) self.assertTrue('updated_time' in s) self.assertTrue('stack_identity' in s) @@ -518,9 +518,9 @@ class stackServiceTest(unittest.TestCase): def test_stack_describe_all(self): sl = self.man.show_stack(self.ctx, None) - self.assertEqual(len(sl['stacks']), 1) + self.assertEqual(len(sl), 1) - s = sl['stacks'][0] + s = sl[0] self.assertTrue('creation_time' in s) self.assertTrue('updated_time' in s) self.assertTrue('stack_identity' in s) @@ -540,7 +540,7 @@ class stackServiceTest(unittest.TestCase): sl = self.man.show_stack(self.ctx, None) - self.assertEqual(len(sl['stacks']), 0) + self.assertEqual(len(sl), 0) def test_list_resource_types(self): resources = self.man.list_resource_types(self.ctx)