Fix "{}" is not a list error for json parameter type

If json paramter `default` of nested stack is set to
[], it resets it to {} and nested resource validations
fail. This patch fixes it by allowing empty list to
passthrough.

Change-Id: I153e9a94566679c01d6ca21713233e3140769ded
Closes-Bug: #1486778
This commit is contained in:
Rabi Mishra
2015-08-20 21:14:36 +05:30
parent 25f6c6d12f
commit c77fc2d83d
2 changed files with 22 additions and 1 deletions

View File

@@ -277,7 +277,7 @@ class Property(object):
def _get_map(self, value, validate=False):
if value is None:
value = self.has_default() and self.default() or {}
value = self.default() if self.has_default() else {}
if not isinstance(value, collections.Mapping):
# This is to handle passing Lists via Json parameters exposed
# via a provider resource, in particular lists-of-dicts which

View File

@@ -898,6 +898,27 @@ class PropertyTest(common.HeatTestCase):
self.assertRaises(exception.StackValidationFailed,
p.get_value, ['1', '2', '3'], True)
def test_map_list_default(self):
schema = {'Type': 'Map',
'Default': ['foo', 'bar']}
p = properties.Property(schema)
p.schema.allow_conversion = True
self.assertEqual(jsonutils.dumps(['foo', 'bar']),
p.get_value(None))
def test_map_list_default_empty(self):
schema = {'Type': 'Map',
'Default': []}
p = properties.Property(schema)
p.schema.allow_conversion = True
self.assertEqual(jsonutils.dumps([]), p.get_value(None))
def test_map_list_no_default(self):
schema = {'Type': 'Map'}
p = properties.Property(schema)
p.schema.allow_conversion = True
self.assertEqual({}, p.get_value(None))
def test_map_string(self):
p = properties.Property({'Type': 'Map'})
self.assertRaises(TypeError, p.get_value, 'foo')