Fix str_split function when string is None

Currently str_split raises error, when function take string to split as
NoneType object (e.g. get_attr value during validation). Fix such
behaviour to allow resources with str_split in properties pass
validation.

Change-Id: Iabd8ebb90a38253434e7c29005654c9a6abb3196
Closes-bug: #1608482
This commit is contained in:
Peter Razumovsky 2016-08-01 14:13:50 +03:00
parent bf22f11240
commit d2ba2b04c1
2 changed files with 14 additions and 0 deletions

View File

@ -765,6 +765,10 @@ class StrSplit(function.Function):
except (AttributeError, IndexError):
raise ValueError(_('Incorrect arguments to "%(fn_name)s" '
'should be: %(example)s') % self.fmt_data)
if str_to_split is None:
return None
split_list = str_to_split.split(delim)
# Optionally allow an index to be specified

View File

@ -1291,6 +1291,16 @@ class HOTemplateTest(common.HeatTestCase):
self.assertIn('Incorrect arguments to \"str_split\"',
six.text_type(exc))
def test_str_split_none_string_to_split(self):
tmpl = template.Template(hot_liberty_tpl_empty)
snippet = {'str_split': ['.', None]}
self.assertIsNone(self.resolve(snippet, tmpl))
def test_str_split_none_delim(self):
tmpl = template.Template(hot_liberty_tpl_empty)
snippet = {'str_split': [None, 'check']}
self.assertEqual(['check'], self.resolve(snippet, tmpl))
def test_prevent_parameters_access(self):
"""Check parameters section inaccessible using the template as a dict.