Do constraint validation for None value property

Should do constraint validation for None value property
when validate if the property has no dependency of any other
Init resource.

Change-Id: Ie22d01de517f25b1f160c84c8c94b8950e528399
Closes-Bug: #1444898
This commit is contained in:
huangtianhua 2015-04-17 14:56:02 +08:00
parent 729aa08f4a
commit 4f0a888316
3 changed files with 22 additions and 5 deletions

View File

@ -332,9 +332,7 @@ class Property(object):
elif t == Schema.BOOLEAN:
_value = self._get_bool(value)
# property value resolves to None if resource it depends on is not
# created. So, if value is None skip constraint validation.
if value is not None and validate:
if validate:
self.schema.validate_constraints(_value, self.context)
return _value
@ -419,6 +417,11 @@ class Properties(collections.Mapping):
message=ex.error_message
)
def _find_deps_any_in_init(self, unresolved_value):
deps = function.dependencies(unresolved_value)
if any(res.action == res.INIT for res in deps):
return True
def _get_property_value(self, key, validate=False):
if key not in self:
raise KeyError(_('Invalid Property %s') % key)
@ -429,8 +432,7 @@ class Properties(collections.Mapping):
try:
unresolved_value = self.data[key]
if validate:
deps = function.dependencies(unresolved_value)
if any(res.action == res.INIT for res in deps):
if self._find_deps_any_in_init(unresolved_value):
validate = False
value = self.resolve(unresolved_value)

View File

@ -1062,6 +1062,9 @@ class PropertiesTest(common.HeatTestCase):
def test_resolver(prop):
return None
self.patchobject(properties.Properties,
'_find_deps_any_in_init').return_value = True
props = properties.Properties(schema,
{'foo': 'get_attr: [db, value]'},
test_resolver)

View File

@ -1683,6 +1683,18 @@ class StackTest(common.HeatTestCase):
self.stack.strict_validate = False
self.assertIsNone(self.stack.validate())
def test_validate_property_getatt(self):
tmpl = {
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {
'R1': {'Type': 'ResourceWithPropsType'},
'R2': {'Type': 'ResourceWithPropsType',
'Properties': {'Foo': {'Fn::GetAtt': ['R1', 'Foo']}}}}
}
self.stack = stack.Stack(self.ctx, 'test_stack',
template.Template(tmpl))
self.assertIsNone(self.stack.validate())
def test_param_validate_value(self):
tmpl = template_format.parse("""
HeatTemplateFormatVersion: '2012-12-12'