From d2ba2b04c1becf85eb8b8a7230b95016cf170383 Mon Sep 17 00:00:00 2001
From: Peter Razumovsky <prazumovsky@mirantis.com>
Date: Mon, 1 Aug 2016 14:13:50 +0300
Subject: [PATCH] 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
---
 heat/engine/hot/functions.py |  4 ++++
 heat/tests/test_hot.py       | 10 ++++++++++
 2 files changed, 14 insertions(+)

diff --git a/heat/engine/hot/functions.py b/heat/engine/hot/functions.py
index 5565b1c1ac..17113e563f 100644
--- a/heat/engine/hot/functions.py
+++ b/heat/engine/hot/functions.py
@@ -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
diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py
index f50b96d8b5..4c7e707b6d 100644
--- a/heat/tests/test_hot.py
+++ b/heat/tests/test_hot.py
@@ -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.