From 5022808e9d2904ae061e6ad584d3215792ff7c39 Mon Sep 17 00:00:00 2001 From: Vijendar Komalla Date: Thu, 22 May 2014 14:53:43 -0500 Subject: [PATCH] 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 --- heat/engine/properties.py | 4 +++- heat/tests/test_properties.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/heat/engine/properties.py b/heat/engine/properties.py index 185d79900e..a80e4e5487 100644 --- a/heat/engine/properties.py +++ b/heat/engine/properties.py @@ -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 diff --git a/heat/tests/test_properties.py b/heat/tests/test_properties.py index b20c71de98..c6fb3931ca 100644 --- a/heat/tests/test_properties.py +++ b/heat/tests/test_properties.py @@ -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": {