Fix early resource property value validation

Currently resource property validation fails if resource it
depends on is not created.

This change skips a property constraint validation if its intrinsic
function resolution does not find the dependant resource.

Change-Id: I2056c89437e8df2a59726b60c3c12f19f713d84d
Partial-Bug: #1317636
This commit is contained in:
Vijendar Komalla 2014-05-22 14:53:43 -05:00
parent 755bdb379b
commit 5022808e9d
2 changed files with 17 additions and 1 deletions

View File

@ -278,7 +278,9 @@ class Property(object):
elif t == Schema.BOOLEAN:
_value = self._get_bool(value)
if validate:
# 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:
self.schema.validate_constraints(_value, self.context)
return _value

View File

@ -1031,6 +1031,20 @@ class PropertiesTest(testtools.TestCase):
err = self.assertRaises(ValueError, props.get, 'foo')
self.assertEqual('foo resolution failed!', str(err))
def test_resolve_returns_none(self):
schema = {'foo': {'Type': 'String', "MinLength": "5"}}
def test_resolver(prop):
return None
props = properties.Properties(schema,
{'foo': 'get_attr: [db, value]'},
test_resolver)
try:
self.assertIsNone(props.validate())
except exception.StackValidationFailed:
self.fail("Constraints should not have been evaluated.")
def test_schema_from_params(self):
params_snippet = {
"DBUsername": {