From: Steve Baker Date: Wed, 20 Mar 2013 03:52:49 +0000 (+1300) Subject: validate_template returns whole Parameters snippet X-Git-Tag: 2014.1~742 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6975739b1ef133d4fdcab2b29091413c47d40205;p=openstack-build%2Fheat-build.git validate_template returns whole Parameters snippet Currently the engine validate_template returns cfn formatted Parameters from the template, which isn't actually very useful to build a full UI from a validate call. This change returns the original Parameters template snippet and changes the cfn api to reformat to the CFN API legacy format. The Parameters section of the RPC and the REST APIs now return a dictionary containing the parameters as specified in the template. Previously the Parameters section contained a list in the CFN API format. Pseudo parameters are filtered out of the validate results. Change-Id: Iea53dc847ff13f5f479ec3a66bcf141c4ccaeb25 Fixes: bug #1157537 --- diff --git a/heat/api/cfn/v1/stacks.py b/heat/api/cfn/v1/stacks.py index 413e3239..9a171991 100644 --- a/heat/api/cfn/v1/stacks.py +++ b/heat/api/cfn/v1/stacks.py @@ -403,8 +403,23 @@ class StackController(object): return exception.HeatInvalidParameterValueError(detail=msg) logger.info('validate_template') + + def format_validate_parameter(key, value): + """ + Reformat engine output into the AWS "ValidateTemplate" format + """ + + return { + 'ParameterKey': key, + 'DefaultValue': value.get(engine_api.PARAM_DEFAULT, ''), + 'Description': value.get(engine_api.PARAM_DESCRIPTION, ''), + 'NoEcho': value.get(engine_api.PARAM_NO_ECHO, 'false') + } + try: res = self.engine_rpcapi.validate_template(con, template) + res['Parameters'] = [format_validate_parameter(k, v) + for k, v in res['Parameters'].items()] return api_utils.format_response('ValidateTemplate', res) except rpc_common.RemoteError as ex: return exception.map_remote_error(ex) diff --git a/heat/engine/service.py b/heat/engine/service.py index b56cf83a..efd962c1 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -26,6 +26,7 @@ from heat.engine import clients from heat.engine.event import Event from heat.common import exception from heat.common import identifier +from heat.engine import parameters from heat.engine import parser from heat.engine import resource from heat.engine import resources # pyflakes_bypass review 23102 @@ -286,20 +287,14 @@ class EngineService(service.Service): return {'Error': 'Every Resources object must contain a Type member.'} - def describe_param(p): - description = {'NoEcho': p.no_echo() and 'true' or 'false', - 'ParameterKey': p.name, - 'Description': p.description()} - if p.has_default(): - description['DefaultValue'] = p.default() - - return description - - params = parser.Parameters(None, tmpl).map(describe_param) + tmpl_params = parser.Parameters(None, tmpl) + format_validate_parameter = lambda p: dict(p.schema) + is_real_param = lambda p: p.name not in parameters.PSEUDO_PARAMETERS + params = tmpl_params.map(format_validate_parameter, is_real_param) result = { 'Description': template.get('Description', ''), - 'Parameters': params.values(), + 'Parameters': params, } return result diff --git a/heat/rpc/api.py b/heat/rpc/api.py index d1ac2453..b7c9d5e0 100644 --- a/heat/rpc/api.py +++ b/heat/rpc/api.py @@ -127,3 +127,15 @@ WATCH_DATA_KEYS = ( 'watch_name', 'metric_name', 'timestamp', 'namespace', 'data' ) + +VALIDATE_PARAM_KEYS = ( + PARAM_TYPE, PARAM_DEFAULT, PARAM_NO_ECHO, + PARAM_ALLOWED_VALUES, PARAM_ALLOWED_PATTERN, PARAM_MAX_LENGTH, + PARAM_MIN_LENGTH, PARAM_MAX_VALUE, PARAM_MIN_VALUE, + PARAM_DESCRIPTION, PARAM_CONSTRAINT_DESCRIPTION +) = ( + 'Type', 'Default', 'NoEcho', + 'AllowedValues', 'AllowedPattern', 'MaxLength', + 'MinLength', 'MaxValue', 'MinValue', + 'Description', 'ConstraintDescription' +) diff --git a/heat/tests/test_validate.py b/heat/tests/test_validate.py index 5465fe5c..689b828a 100644 --- a/heat/tests/test_validate.py +++ b/heat/tests/test_validate.py @@ -288,3 +288,17 @@ class validateTest(unittest.TestCase): engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertNotEqual(res['Description'], 'Successfully validated') + + def test_validate_parameters(self): + t = template_format.parse(test_template_ref % 'WikiDatabase') + + self.m.StubOutWithMock(instances.Instance, 'nova') + instances.Instance.nova().AndReturn(self.fc) + self.m.ReplayAll() + + engine = service.EngineService('a', 't') + res = dict(engine.validate_template(None, t)) + self.assertEqual(res['Parameters'], {'KeyName': { + 'Type': 'String', + 'Description': 'Name of an existing EC2KeyPair to enable SSH ' + 'access to the instances'}})