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
This commit is contained in:
Steve Baker 2013-03-20 16:52:49 +13:00
parent 84ba8f8ef9
commit 6975739b1e
4 changed files with 47 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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