Translate constraint description in validation

The patch modifies format_validate_parameter to include constraint
description in the CFN compatible output.

Change-Id: I31c6a4dc025a782e8951280e42652b12070476b3
Closes-Bug: #1274994
This commit is contained in:
Thomas Herve
2014-01-31 17:30:12 +01:00
parent 94d03b19b8
commit be74a2d171
2 changed files with 54 additions and 0 deletions

View File

@@ -257,6 +257,8 @@ def format_validate_parameter(param):
if param.has_default():
res[api.PARAM_DEFAULT] = param.default()
constraint_description = []
# build constraints
for c in param.schema.constraints:
if isinstance(c, constr.Length):
@@ -279,4 +281,11 @@ def format_validate_parameter(param):
elif isinstance(c, constr.AllowedPattern):
res[api.PARAM_ALLOWED_PATTERN] = c.pattern
if c.description:
constraint_description.append(c.description)
if constraint_description:
res[api.PARAM_CONSTRAINT_DESCRIPTION] = " ".join(
constraint_description)
return res

View File

@@ -619,6 +619,51 @@ class FormatValidateParameterTest(HeatTestCase):
'NoEcho': 'false'
})
),
('constraint_description_hot',
dict(template=base_template_hot,
param_name='KeyName',
param='''
"KeyName": {
"type": "string",
"description": "Name of SSH key pair",
"constraints": [
{ "length": { "min": 4},
"description": "Big enough" }
]
}
''',
expected={
'Type': 'String',
'Description': 'Name of SSH key pair',
'MinLength': 4,
'ConstraintDescription': 'Big enough',
'NoEcho': 'false'
})
),
('constraint_multiple_descriptions_hot',
dict(template=base_template_hot,
param_name='KeyName',
param='''
"KeyName": {
"type": "string",
"description": "Name of SSH key pair",
"constraints": [
{ "length": { "min": 4},
"description": "Big enough." },
{ "allowed_pattern": "[a-zA-Z0-9]+",
"description": "Only letters." }
]
}
''',
expected={
'Type': 'String',
'Description': 'Name of SSH key pair',
'MinLength': 4,
'AllowedPattern': "[a-zA-Z0-9]+",
'ConstraintDescription': 'Big enough. Only letters.',
'NoEcho': 'false'
})
),
]
def test_format_validate_parameter(self):