Merge "Ability to specify show_nested for template validation"

This commit is contained in:
Jenkins
2015-09-16 07:43:15 +00:00
committed by Gerrit Code Review
4 changed files with 55 additions and 3 deletions

View File

@@ -3883,7 +3883,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)

View File

@@ -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={})

View File

@@ -782,6 +782,8 @@ def do_template_show(hc, args):
action='append')
@utils.arg('-o', '--template-object', metavar='<URL>',
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.'''
@@ -796,9 +798,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))

View File

@@ -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