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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user