From ccef7e2a78ba1fc2f68acbfbed054a3bab9d2547 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Thu, 11 Jan 2018 18:43:16 -0500 Subject: [PATCH] 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 --- heat/engine/properties.py | 2 +- heat/tests/test_properties.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/heat/engine/properties.py b/heat/engine/properties.py index 706e4a8f20..92ace22cca 100644 --- a/heat/engine/properties.py +++ b/heat/engine/properties.py @@ -278,7 +278,7 @@ class Property(object): if isinstance(value, (bool, int)): value = six.text_type(value) else: - raise ValueError(_('Value must be a string')) + raise ValueError(_('Value must be a string; got %r') % value) return value def _get_children(self, child_values, keys=None, validate=False, diff --git a/heat/tests/test_properties.py b/heat/tests/test_properties.py index 3c347cfd6e..f0b6d89ddb 100644 --- a/heat/tests/test_properties.py +++ b/heat/tests/test_properties.py @@ -1687,15 +1687,15 @@ class PropertiesValidationTest(common.HeatTestCase): schema = {'foo': {'Type': 'String'}} props = properties.Properties(schema, {'foo': ['foo', 'bar']}) ex = self.assertRaises(exception.StackValidationFailed, props.validate) - self.assertEqual('Property error: foo: Value must be a string', - six.text_type(ex)) + self.assertIn('Property error: foo: Value must be a string', + six.text_type(ex)) def test_dict_instead_string(self): schema = {'foo': {'Type': 'String'}} props = properties.Properties(schema, {'foo': {'foo': 'bar'}}) ex = self.assertRaises(exception.StackValidationFailed, props.validate) - self.assertEqual('Property error: foo: Value must be a string', - six.text_type(ex)) + self.assertIn('Property error: foo: Value must be a string', + six.text_type(ex)) def test_none_string(self): schema = {'foo': {'Type': 'String'}}