From 466e9983d0c855b03b64227c607fdd7125f3ae8c Mon Sep 17 00:00:00 2001 From: Tomas Sedovic Date: Thu, 12 Jul 2012 18:04:54 +0200 Subject: [PATCH] Don't require user params on template validation Fixes #161 Change-Id: Ia7e1a83043f8d175e320bfd52aa64cb6f62ead90 Signed-off-by: Tomas Sedovic --- heat/engine/manager.py | 34 +++++++++++++++++++++------------- heat/tests/test_validate.py | 4 ++-- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/heat/engine/manager.py b/heat/engine/manager.py index b6872c3273..a39d4223e9 100644 --- a/heat/engine/manager.py +++ b/heat/engine/manager.py @@ -131,7 +131,6 @@ class EngineManager(manager.Manager): arg3 -> Template of stack you want to create. arg4 -> Params passed from API. """ - auth.authenticate(context) logger.info('validate_template') @@ -139,20 +138,29 @@ class EngineManager(manager.Manager): msg = _("No Template provided.") return webob.exc.HTTPBadRequest(explanation=msg) - stack_name = 'validate' - try: - tmpl = parser.Template(template) - user_params = parser.Parameters(stack_name, tmpl, params) - s = parser.Stack(context, stack_name, tmpl, user_params) - except KeyError as ex: - res = ('A Fn::FindInMap operation referenced ' - 'a non-existent map [%s]' % str(ex)) + tmpl = parser.Template(template) + resources = template.get('Resources', []) - result = {'Description': 'Malformed Query Response [%s]' % (res), - 'Parameters': []} - else: - result = s.validate() + if not resources: + return {'Error': 'At least one Resources member must be defined.'} + for res in resources.values(): + if not res.get('Type'): + return {'Error': + 'Every Resources object must contain a Type member.'} + + parameters = [] + for param_key, param in template.get('Parameters', {}).items(): + parameters.append({ + 'NoEcho': param.get('NoEcho', 'false'), + 'ParameterKey': param_key, + 'Description': param.get('Description', '') + }) + + result = { + 'Description': template.get('Description', ''), + 'Parameters': parameters, + } return {'ValidateTemplateResult': result} def get_template(self, context, stack_name, params): diff --git a/heat/tests/test_validate.py b/heat/tests/test_validate.py index 7dea58218f..975e508244 100644 --- a/heat/tests/test_validate.py +++ b/heat/tests/test_validate.py @@ -269,7 +269,7 @@ class validateTest(unittest.TestCase): res = dict(manager. validate_template(None, t, params)['ValidateTemplateResult']) print 'res %s' % res - self.assertEqual(res['Description'], 'Successfully validated') + self.assertEqual(res['Description'], 'test.') def test_validate_ref_invalid(self): t = json.loads(test_template_ref % 'WikiDatabasez') @@ -301,7 +301,7 @@ class validateTest(unittest.TestCase): manager = managers.EngineManager() res = dict(manager. validate_template(None, t, params)['ValidateTemplateResult']) - self.assertEqual(res['Description'], 'Successfully validated') + self.assertEqual(res['Description'], 'test.') def test_validate_findinmap_invalid(self): t = json.loads(test_template_findinmap_invalid)