From 2e76bb0716c39850f3394fa6d67b3688bd930eca Mon Sep 17 00:00:00 2001 From: Peter Razumovsky Date: Wed, 21 Oct 2015 16:44:16 +0300 Subject: [PATCH] Add APIs implementation for output functions APIImpact Add new APIs for showing and listing stack outputs. It can be used by heat client and separately for getting stack outputs. implements bp api-call-output Change-Id: Ia24b24f59e2c592801e4e670ba5510f642ecf45c --- etc/heat/policy.json | 2 ++ heat/api/openstack/v1/__init__.py | 15 ++++++++++ heat/api/openstack/v1/stacks.py | 13 +++++++++ heat/engine/service.py | 2 +- heat/rpc/client.py | 12 ++++++++ heat/tests/api/openstack_v1/test_routes.py | 28 +++++++++++++++++++ .../engine/service/test_service_engine.py | 2 +- heat/tests/test_rpc_client.py | 11 ++++++++ 8 files changed, 83 insertions(+), 2 deletions(-) diff --git a/etc/heat/policy.json b/etc/heat/policy.json index 1c8cd02719..1be98e8f76 100644 --- a/etc/heat/policy.json +++ b/etc/heat/policy.json @@ -62,6 +62,8 @@ "stacks:delete_snapshot": "rule:deny_stack_user", "stacks:list_snapshots": "rule:deny_stack_user", "stacks:restore_snapshot": "rule:deny_stack_user", + "stacks:list_outputs": "rule:deny_stack_user", + "stacks:show_output": "rule:deny_stack_user", "software_configs:global_index": "rule:deny_everybody", "software_configs:index": "rule:deny_stack_user", diff --git a/heat/api/openstack/v1/__init__.py b/heat/api/openstack/v1/__init__.py index 2ae7014c4c..8cc68a53d3 100644 --- a/heat/api/openstack/v1/__init__.py +++ b/heat/api/openstack/v1/__init__.py @@ -265,6 +265,21 @@ class API(wsgi.Router): '{snapshot_id}/restore', 'action': 'restore_snapshot', 'method': 'POST' + }, + + # Stack outputs + { + 'name': 'stack_output_list', + 'url': '/stacks/{stack_name}/{stack_id}/outputs', + 'action': 'list_outputs', + 'method': 'GET' + }, + { + 'name': 'stack_output_show', + 'url': '/stacks/{stack_name}/{stack_id}/outputs/' + '{output_key}', + 'action': 'show_output', + 'method': 'GET' } ]) diff --git a/heat/api/openstack/v1/stacks.py b/heat/api/openstack/v1/stacks.py index 36bce5f651..3fb2ce7fab 100644 --- a/heat/api/openstack/v1/stacks.py +++ b/heat/api/openstack/v1/stacks.py @@ -628,6 +628,19 @@ class StackController(object): self.rpc_client.stack_restore(req.context, identity, snapshot_id) raise exc.HTTPAccepted() + @util.identified_stack + def list_outputs(self, req, identity): + return { + 'outputs': self.rpc_client.list_outputs( + req.context, identity) + } + + @util.identified_stack + def show_output(self, req, identity, output_key): + return {'output': self.rpc_client.show_output(req.context, + identity, + output_key)} + class StackSerializer(serializers.JSONResponseSerializer): """Handles serialization of specific controller method responses.""" diff --git a/heat/engine/service.py b/heat/engine/service.py index 55f5f11530..1e88c5fdbb 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -279,7 +279,7 @@ class EngineService(service.Service): by the RPC caller. """ - RPC_API_VERSION = '1.18' + RPC_API_VERSION = '1.19' def __init__(self, host, topic): super(EngineService, self).__init__() diff --git a/heat/rpc/client.py b/heat/rpc/client.py index 1d22412717..55bbf9e39e 100644 --- a/heat/rpc/client.py +++ b/heat/rpc/client.py @@ -37,6 +37,7 @@ class EngineClient(object): 1.16 - Adds version, type_name to list_resource_types() 1.17 - Add files to validate_template 1.18 - Add show_nested to validate_template + 1.19 - Add show_output and list_outputs for returning stack outputs """ BASE_RPC_API_VERSION = '1.0' @@ -686,3 +687,14 @@ class EngineClient(object): def list_services(self, cnxt): return self.call(cnxt, self.make_msg('list_services'), version='1.4') + + def list_outputs(self, cntx, stack_identity): + return self.call(cntx, self.make_msg('list_outputs', + stack_identity=stack_identity), + version='1.19') + + def show_output(self, cntx, stack_identity, output_key): + return self.call(cntx, self.make_msg('show_output', + stack_identity=stack_identity, + output_key=output_key), + version='1.19') diff --git a/heat/tests/api/openstack_v1/test_routes.py b/heat/tests/api/openstack_v1/test_routes.py index a396a5d572..4177f78e0f 100644 --- a/heat/tests/api/openstack_v1/test_routes.py +++ b/heat/tests/api/openstack_v1/test_routes.py @@ -235,6 +235,34 @@ class RoutesTest(common.HeatTestCase): 'snapshot_id': 'cccc' }) + def test_stack_outputs(self): + self.assertRoute( + self.m, + '/aaaa/stacks/teststack/bbbb/outputs', + 'GET', + 'list_outputs', + 'StackController', + { + 'tenant_id': 'aaaa', + 'stack_name': 'teststack', + 'stack_id': 'bbbb' + } + ) + + self.assertRoute( + self.m, + '/aaaa/stacks/teststack/bbbb/outputs/cccc', + 'GET', + 'show_output', + 'StackController', + { + 'tenant_id': 'aaaa', + 'stack_name': 'teststack', + 'stack_id': 'bbbb', + 'output_key': 'cccc' + } + ) + def test_stack_data_template(self): self.assertRoute( self.m, diff --git a/heat/tests/engine/service/test_service_engine.py b/heat/tests/engine/service/test_service_engine.py index 1c703c357f..0487245566 100644 --- a/heat/tests/engine/service/test_service_engine.py +++ b/heat/tests/engine/service/test_service_engine.py @@ -39,7 +39,7 @@ class ServiceEngineTest(common.HeatTestCase): def test_make_sure_rpc_version(self): self.assertEqual( - '1.18', + '1.19', service.EngineService.RPC_API_VERSION, ('RPC version is changed, please update this test to new version ' 'and make sure additional test cases are added for RPC APIs ' diff --git a/heat/tests/test_rpc_client.py b/heat/tests/test_rpc_client.py index ec17aa9c17..14041c410b 100644 --- a/heat/tests/test_rpc_client.py +++ b/heat/tests/test_rpc_client.py @@ -364,3 +364,14 @@ class EngineRpcAPITestCase(common.HeatTestCase): def test_list_services(self): self._test_engine_api('list_services', 'call', version='1.4') + + def test_stack_list_outputs(self): + self._test_engine_api( + 'list_outputs', 'call', stack_identity=self.identity, + version='1.19' + ) + + def test_stack_show_output(self): + self._test_engine_api( + 'show_output', 'call', stack_identity=self.identity, + output_key='test', version='1.19')