From 1359887fd86384f71767a2c999784ea02954a57c Mon Sep 17 00:00:00 2001 From: Oleksii Chuprykov Date: Mon, 20 Jun 2016 15:26:37 +0300 Subject: [PATCH] Check immutable and update_allowed conflict in schema validation This doesn't check any user input, but checks the validity of the schema itself, so better to do it during schema validation. Note, that now heat engine doesn't start in the case of invalid schema. Change-Id: Iec5ca304eae780f8c028f7eb59cc7ee8710043a1 --- heat/engine/properties.py | 21 +++++++++++---------- heat/tests/test_properties.py | 11 +++++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/heat/engine/properties.py b/heat/engine/properties.py index c91c950dd1..12075fb597 100644 --- a/heat/engine/properties.py +++ b/heat/engine/properties.py @@ -71,6 +71,17 @@ class Schema(constr.Schema): # validate structural correctness of schema itself self.validate() + def validate(self, context=None): + super(Schema, self).validate() + # check that update_allowed and immutable + # do not contradict each other + if self.update_allowed and self.immutable: + msg = _("Options %(ua)s and %(im)s " + "cannot both be True") % { + 'ua': UPDATE_ALLOWED, + 'im': IMMUTABLE} + raise exception.InvalidSchemaError(message=msg) + @classmethod def from_legacy(cls, schema_dict): """Return a Property Schema object from a legacy schema dictionary.""" @@ -365,16 +376,6 @@ class Properties(collections.Mapping): raise exception.StackValidationFailed(message=msg) for (key, prop) in self.props.items(): - # check that update_allowed and immutable - # do not contradict each other - if prop.update_allowed() and prop.immutable(): - msg = _("Property %(prop)s: %(ua)s and %(im)s " - "cannot both be True") % { - 'prop': key, - 'ua': prop.schema.UPDATE_ALLOWED, - 'im': prop.schema.IMMUTABLE} - raise exception.InvalidSchemaError(message=msg) - if with_value: try: self._get_property_value(key, validate=True) diff --git a/heat/tests/test_properties.py b/heat/tests/test_properties.py index 47e6fe446b..8380a00a6d 100644 --- a/heat/tests/test_properties.py +++ b/heat/tests/test_properties.py @@ -1899,9 +1899,8 @@ class PropertiesValidationTest(common.HeatTestCase): self.assertEqual({}, props) def test_update_allowed_and_immutable_contradict(self): - schema = {'foo': properties.Schema( - properties.Schema.STRING, - update_allowed=True, - immutable=True)} - props = properties.Properties(schema, {}) - self.assertRaises(exception.InvalidSchemaError, props.validate) + self.assertRaises(exception.InvalidSchemaError, + properties.Schema, + properties.Schema.STRING, + update_allowed=True, + immutable=True)