Include value in string Property type error

When a property value does not match the defined type of the property, we
include the offending value in the error message for all property types
except 'string'. This brings string properties into line with the other
types, for easier debugging.

Change-Id: I34ac7bad414403707f2e8a8f2dfbf804fa9bfaa7
Related-Bug: #1742646
This commit is contained in:
Zane Bitter 2018-01-11 18:43:16 -05:00
parent d3614902dd
commit ccef7e2a78
2 changed files with 5 additions and 5 deletions

View File

@ -278,7 +278,7 @@ class Property(object):
if isinstance(value, (bool, int)): if isinstance(value, (bool, int)):
value = six.text_type(value) value = six.text_type(value)
else: else:
raise ValueError(_('Value must be a string')) raise ValueError(_('Value must be a string; got %r') % value)
return value return value
def _get_children(self, child_values, keys=None, validate=False, def _get_children(self, child_values, keys=None, validate=False,

View File

@ -1687,15 +1687,15 @@ class PropertiesValidationTest(common.HeatTestCase):
schema = {'foo': {'Type': 'String'}} schema = {'foo': {'Type': 'String'}}
props = properties.Properties(schema, {'foo': ['foo', 'bar']}) props = properties.Properties(schema, {'foo': ['foo', 'bar']})
ex = self.assertRaises(exception.StackValidationFailed, props.validate) ex = self.assertRaises(exception.StackValidationFailed, props.validate)
self.assertEqual('Property error: foo: Value must be a string', self.assertIn('Property error: foo: Value must be a string',
six.text_type(ex)) six.text_type(ex))
def test_dict_instead_string(self): def test_dict_instead_string(self):
schema = {'foo': {'Type': 'String'}} schema = {'foo': {'Type': 'String'}}
props = properties.Properties(schema, {'foo': {'foo': 'bar'}}) props = properties.Properties(schema, {'foo': {'foo': 'bar'}})
ex = self.assertRaises(exception.StackValidationFailed, props.validate) ex = self.assertRaises(exception.StackValidationFailed, props.validate)
self.assertEqual('Property error: foo: Value must be a string', self.assertIn('Property error: foo: Value must be a string',
six.text_type(ex)) six.text_type(ex))
def test_none_string(self): def test_none_string(self):
schema = {'foo': {'Type': 'String'}} schema = {'foo': {'Type': 'String'}}