Merge "Check immutable and update_allowed conflict in schema validation"
This commit is contained in:
commit
6450a13a96
@ -71,6 +71,17 @@ class Schema(constr.Schema):
|
|||||||
# validate structural correctness of schema itself
|
# validate structural correctness of schema itself
|
||||||
self.validate()
|
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
|
@classmethod
|
||||||
def from_legacy(cls, schema_dict):
|
def from_legacy(cls, schema_dict):
|
||||||
"""Return a Property Schema object from a legacy schema dictionary."""
|
"""Return a Property Schema object from a legacy schema dictionary."""
|
||||||
@ -366,16 +377,6 @@ class Properties(collections.Mapping):
|
|||||||
raise exception.StackValidationFailed(message=msg)
|
raise exception.StackValidationFailed(message=msg)
|
||||||
|
|
||||||
for (key, prop) in self.props.items():
|
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:
|
if with_value:
|
||||||
try:
|
try:
|
||||||
self._get_property_value(key,
|
self._get_property_value(key,
|
||||||
|
@ -1899,9 +1899,8 @@ class PropertiesValidationTest(common.HeatTestCase):
|
|||||||
self.assertEqual({}, props)
|
self.assertEqual({}, props)
|
||||||
|
|
||||||
def test_update_allowed_and_immutable_contradict(self):
|
def test_update_allowed_and_immutable_contradict(self):
|
||||||
schema = {'foo': properties.Schema(
|
self.assertRaises(exception.InvalidSchemaError,
|
||||||
properties.Schema.STRING,
|
properties.Schema,
|
||||||
update_allowed=True,
|
properties.Schema.STRING,
|
||||||
immutable=True)}
|
update_allowed=True,
|
||||||
props = properties.Properties(schema, {})
|
immutable=True)
|
||||||
self.assertRaises(exception.InvalidSchemaError, props.validate)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user