From 3e1aa3ad9b5f9c5ab1953f572160bc293ef86f51 Mon Sep 17 00:00:00 2001 From: Jay Dobies Date: Thu, 10 Sep 2015 14:51:08 -0400 Subject: Ability to specify show_nested for template validation This is the client-side change to support Idb51c983fc07e49d371b8ccb3cea6f7e92f99903 Change-Id: I83744bd552bcb5cee183336bec97ab616bd82a91 Implements-blueprint: nested-validation Closes-Bug: #1495695 --- heatclient/tests/unit/test_shell.py | 3 ++- heatclient/tests/unit/test_stacks.py | 42 ++++++++++++++++++++++++++++++++++++ heatclient/v1/shell.py | 7 +++++- heatclient/v1/stacks.py | 6 +++++- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/heatclient/tests/unit/test_shell.py b/heatclient/tests/unit/test_shell.py index 67a5f20..0d50d83 100644 --- a/heatclient/tests/unit/test_shell.py +++ b/heatclient/tests/unit/test_shell.py @@ -3824,7 +3824,8 @@ class ShellTestConfig(ShellBase): six.StringIO('the config script')) http.SessionClient.request( - '/validate', 'POST', data=validate_template).AndReturn(http_resp) + '/validate', 'POST', + data=validate_template).AndReturn(http_resp) http.SessionClient.request( '/software_configs', 'POST', data=create_dict).AndReturn(http_resp) diff --git a/heatclient/tests/unit/test_stacks.py b/heatclient/tests/unit/test_stacks.py index 12ebdc0..9bb89e5 100644 --- a/heatclient/tests/unit/test_stacks.py +++ b/heatclient/tests/unit/test_stacks.py @@ -314,3 +314,45 @@ class StackManagerPaginationTest(testtools.TestCase): results[0].stack_name) self.assertEqual('stack_%s' % (self.offset + last_result), results[-1].stack_name) + + +class StackManagerValidateTest(testtools.TestCase): + + def setUp(self): + super(StackManagerValidateTest, self).setUp() + + self.mock_response = mock.MagicMock() + self.mock_response.json.return_value = {'result': 'fake_response'} + self.mock_response.headers = {'content-type': 'application/json'} + + self.mock_client = mock.MagicMock() + self.mock_client.post.return_value = self.mock_response + + self.manager = stacks.StackManager(self.mock_client) + + def test_validate_show_nested(self): + # Test + result = self.manager.validate(**{'show_nested': True}) + + # Verify + self.assertEqual(self.mock_response.json.return_value, result) + self.mock_client.post.assert_called_once_with( + '/validate?show_nested=True', data={}) + + def test_validate_show_nested_false(self): + # Test + result = self.manager.validate(**{'show_nested': False}) + + # Verify + self.assertEqual(self.mock_response.json.return_value, result) + self.mock_client.post.assert_called_once_with( + '/validate', data={}) + + def test_validate_show_nested_default(self): + # Test + result = self.manager.validate() + + # Verify + self.assertEqual(self.mock_response.json.return_value, result) + self.mock_client.post.assert_called_once_with( + '/validate', data={}) diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index 583b4b4..b358a88 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -741,6 +741,8 @@ def do_template_show(hc, args): action='append') @utils.arg('-o', '--template-object', metavar='', help=_('URL to retrieve template object (e.g. from swift).')) +@utils.arg('-n', '--show-nested', default=False, action="store_true", + help=_('Resolve parameters from nested templates as well.')) def do_template_validate(hc, args): '''Validate a template with parameters.''' @@ -755,9 +757,12 @@ def do_template_validate(hc, args): fields = { 'template': template, 'files': dict(list(tpl_files.items()) + list(env_files.items())), - 'environment': env + 'environment': env, } + if args.show_nested: + fields['show_nested'] = args.show_nested + validation = hc.stacks.validate(**fields) print(jsonutils.dumps(validation, indent=2, ensure_ascii=False)) diff --git a/heatclient/v1/stacks.py b/heatclient/v1/stacks.py index a728fdf..7ce25e0 100644 --- a/heatclient/v1/stacks.py +++ b/heatclient/v1/stacks.py @@ -227,7 +227,11 @@ class StackManager(base.BaseManager): def validate(self, **kwargs): """Validate a stack template.""" - resp = self.client.post('/validate', data=kwargs) + url = '/validate' + if kwargs.pop('show_nested', False): + url += '?show_nested=True' + + resp = self.client.post(url, data=kwargs) body = utils.get_response_body(resp) return body -- cgit v1.2.1