Always return default via template-validate "Default"
Currently we redefine the value of Default when a user value is provided, which means the data returned doesn't match the schema defined in the template. Instead always return the actual default and add a "Value" key that contains the user value, if provided. Change-Id: If4ed0b733d4e61c84167063c36cdcb234b001136 Closes-Bug: #1497310
This commit is contained in:
parent
45140726b4
commit
4ddd4cb2bd
@ -458,8 +458,11 @@ def format_validate_parameter(param):
|
||||
rpc_api.PARAM_LABEL: param.label()
|
||||
}
|
||||
|
||||
if param.has_value():
|
||||
res[rpc_api.PARAM_DEFAULT] = param.value()
|
||||
if param.has_default():
|
||||
res[rpc_api.PARAM_DEFAULT] = param.default()
|
||||
|
||||
if param.user_value:
|
||||
res[rpc_api.PARAM_VALUE] = param.user_value
|
||||
|
||||
constraint_description = []
|
||||
|
||||
|
@ -180,13 +180,13 @@ VALIDATE_PARAM_KEYS = (
|
||||
PARAM_ALLOWED_VALUES, PARAM_ALLOWED_PATTERN, PARAM_MAX_LENGTH,
|
||||
PARAM_MIN_LENGTH, PARAM_MAX_VALUE, PARAM_MIN_VALUE,
|
||||
PARAM_DESCRIPTION, PARAM_CONSTRAINT_DESCRIPTION, PARAM_LABEL,
|
||||
PARAM_CUSTOM_CONSTRAINT
|
||||
PARAM_CUSTOM_CONSTRAINT, PARAM_VALUE
|
||||
) = (
|
||||
'Type', 'Default', 'NoEcho',
|
||||
'AllowedValues', 'AllowedPattern', 'MaxLength',
|
||||
'MinLength', 'MaxValue', 'MinValue',
|
||||
'Description', 'ConstraintDescription', 'Label',
|
||||
'CustomConstraint'
|
||||
'CustomConstraint', 'Value'
|
||||
)
|
||||
|
||||
VALIDATE_PARAM_TYPES = (
|
||||
|
@ -1004,8 +1004,10 @@ class ValidateTest(common.HeatTestCase):
|
||||
env_params = {'net_name': 'betternetname'}
|
||||
engine = service.EngineService('a', 't')
|
||||
res = dict(engine.validate_template(None, t, env_params))
|
||||
self.assertEqual('betternetname',
|
||||
self.assertEqual('defaultnet',
|
||||
res['Parameters']['net_name']['Default'])
|
||||
self.assertEqual('betternetname',
|
||||
res['Parameters']['net_name']['Value'])
|
||||
|
||||
def test_validate_parameters_env_provided(self):
|
||||
t = template_format.parse(test_template_no_default)
|
||||
@ -1013,7 +1015,8 @@ class ValidateTest(common.HeatTestCase):
|
||||
engine = service.EngineService('a', 't')
|
||||
res = dict(engine.validate_template(None, t, env_params))
|
||||
self.assertEqual('betternetname',
|
||||
res['Parameters']['net_name']['Default'])
|
||||
res['Parameters']['net_name']['Value'])
|
||||
self.assertNotIn('Default', res['Parameters']['net_name'])
|
||||
|
||||
def test_validate_hot_empty_parameters_valid(self):
|
||||
t = template_format.parse(
|
||||
|
@ -74,6 +74,20 @@ resources:
|
||||
'Type': 'Number'}}}
|
||||
self.assertEqual(expected, ret)
|
||||
|
||||
def test_template_validate_override_default(self):
|
||||
env = {'parameters': {'aparam': 5}}
|
||||
ret = self.client.stacks.validate(template=self.random_template,
|
||||
environment=env)
|
||||
expected = {'Description': 'the stack description',
|
||||
'Parameters': {
|
||||
'aparam': {'Default': 10,
|
||||
'Value': 5,
|
||||
'Description': 'the param description',
|
||||
'Label': 'aparam',
|
||||
'NoEcho': 'false',
|
||||
'Type': 'Number'}}}
|
||||
self.assertEqual(expected, ret)
|
||||
|
||||
def test_template_validate_basic_required_param(self):
|
||||
tmpl = self.random_template.replace('default: 10', '')
|
||||
ret = self.client.stacks.validate(template=tmpl)
|
||||
|
Loading…
x
Reference in New Issue
Block a user