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)
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
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
'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'
+)
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'}})