From aedcfbf17937ecabfcddc167fadea8493cb45fd1 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Wed, 13 Aug 2014 18:15:32 +0100 Subject: [PATCH] Add show_nested parameter to GET v1/stacks API Adds an optional argument which can be used to enable listing of all stacks, including nested stacks blueprint: list-nested Change-Id: I6546ddc549cb3eec769698f5b7ff2a921c2b31d7 --- heat/api/openstack/v1/stacks.py | 9 ++++++++- heat/tests/test_api_openstack_v1.py | 31 +++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/heat/api/openstack/v1/stacks.py b/heat/api/openstack/v1/stacks.py index 29bd22c79..431fbcabc 100644 --- a/heat/api/openstack/v1/stacks.py +++ b/heat/api/openstack/v1/stacks.py @@ -164,6 +164,7 @@ class StackController(object): 'sort_dir': 'single', 'sort_keys': 'multi', 'show_deleted': 'single', + 'show_nested': 'single', } params = util.get_allowed_params(req.params, whitelist) filter_params = util.get_allowed_params(req.params, filter_whitelist) @@ -173,6 +174,11 @@ class StackController(object): params[engine_api.PARAM_SHOW_DELETED] = param_utils.extract_bool( params[engine_api.PARAM_SHOW_DELETED]) show_deleted = params[engine_api.PARAM_SHOW_DELETED] + show_nested = False + if engine_api.PARAM_SHOW_NESTED in params: + params[engine_api.PARAM_SHOW_NESTED] = param_utils.extract_bool( + params[engine_api.PARAM_SHOW_NESTED]) + show_nested = params[engine_api.PARAM_SHOW_NESTED] # get the with_count value, if invalid, raise ValueError with_count = False if req.params.get('with_count'): @@ -195,7 +201,8 @@ class StackController(object): count = self.rpc_client.count_stacks(req.context, filters=filter_params, tenant_safe=tenant_safe, - show_deleted=show_deleted) + show_deleted=show_deleted, + show_nested=show_nested) except AttributeError as exc: LOG.warning(_("Old Engine Version: %s") % exc) diff --git a/heat/tests/test_api_openstack_v1.py b/heat/tests/test_api_openstack_v1.py index bcd778728..fec189bcb 100644 --- a/heat/tests/test_api_openstack_v1.py +++ b/heat/tests/test_api_openstack_v1.py @@ -519,7 +519,7 @@ class StackControllerTest(ControllerTest, HeatTestCase): tenant_safe=True, show_deleted=False) - def test_global_index_show_deleted_True(self, mock_enforce): + def test_global_index_show_deleted_true(self, mock_enforce): rpc_client = self.controller.rpc_client rpc_client.list_stacks = mock.Mock(return_value=[]) rpc_client.count_stacks = mock.Mock() @@ -532,6 +532,32 @@ class StackControllerTest(ControllerTest, HeatTestCase): tenant_safe=True, show_deleted=True) + def test_global_index_show_nested_false(self, mock_enforce): + rpc_client = self.controller.rpc_client + rpc_client.list_stacks = mock.Mock(return_value=[]) + rpc_client.count_stacks = mock.Mock() + + params = {'show_nested': 'False'} + req = self._get('/stacks', params=params) + self.controller.index(req, tenant_id=self.tenant) + rpc_client.list_stacks.assert_called_once_with(mock.ANY, + filters=mock.ANY, + tenant_safe=True, + show_nested=False) + + def test_global_index_show_nested_true(self, mock_enforce): + rpc_client = self.controller.rpc_client + rpc_client.list_stacks = mock.Mock(return_value=[]) + rpc_client.count_stacks = mock.Mock() + + params = {'show_nested': 'True'} + req = self._get('/stacks', params=params) + self.controller.index(req, tenant_id=self.tenant) + rpc_client.list_stacks.assert_called_once_with(mock.ANY, + filters=mock.ANY, + tenant_safe=True, + show_nested=True) + def test_index_show_deleted_True_with_count_True(self, mock_enforce): rpc_client = self.controller.rpc_client rpc_client.list_stacks = mock.Mock(return_value=[]) @@ -549,7 +575,8 @@ class StackControllerTest(ControllerTest, HeatTestCase): rpc_client.count_stacks.assert_called_once_with(mock.ANY, filters=mock.ANY, tenant_safe=True, - show_deleted=True) + show_deleted=True, + show_nested=False) @mock.patch.object(rpc_client.EngineClient, 'call') def test_detail(self, mock_call, mock_enforce):