summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlvdongbing <dongbing.lv@kylin-cloud.com>2015-06-29 15:23:43 +0800
committerEthan Lynn <xjunlin@cn.ibm.com>2015-12-21 23:31:19 +0800
commit629caa8bbf256786966e52e0c3382fa2c032737f (patch)
tree56a682a36b96c34e93fd86dfae643a0eced0674f
parent032715014563c689ad294e599cfb9fdd0278a607 (diff)
downloadheat-629caa8bbf256786966e52e0c3382fa2c032737f.tar.gz
Should execute 'resolve' before check the values of 'for_each'
Change-Id: I75f58885a91d11e52ed3737a806b5920774d586c Closes-Bug: #1466748 (cherry picked from commit a7c4b2332f9d1accaa89b51fbc3b09014995983a)
-rw-r--r--heat/engine/hot/functions.py7
-rw-r--r--heat/tests/test_hot.py16
2 files changed, 15 insertions, 8 deletions
diff --git a/heat/engine/hot/functions.py b/heat/engine/hot/functions.py
index e5814230a..2147a5de0 100644
--- a/heat/engine/hot/functions.py
+++ b/heat/engine/hot/functions.py
@@ -300,7 +300,7 @@ class Repeat(function.Function):
self.fn_name)
try:
- for_each = self.args['for_each']
+ for_each = function.resolve(self.args['for_each'])
template = self.args['template']
except (KeyError, TypeError):
example = ('''repeat:
@@ -334,9 +334,8 @@ class Repeat(function.Function):
for (k, v) in template.items())
def result(self):
- for_each = function.resolve(self._for_each)
- keys = for_each.keys()
- lists = [for_each[key] for key in keys]
+ keys = list(six.iterkeys(self._for_each))
+ lists = [self._for_each[key] for key in keys]
template = function.resolve(self._template)
return [self._do_replacement(keys, items, template)
for items in itertools.product(*lists)]
diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py
index 42db882a0..cff124d5c 100644
--- a/heat/tests/test_hot.py
+++ b/heat/tests/test_hot.py
@@ -593,13 +593,21 @@ class HOTemplateTest(common.HeatTestCase):
def test_repeat(self):
"""Test repeat function."""
- snippet = {'repeat': {'template': 'this is %var%',
- 'for_each': {'%var%': ['a', 'b', 'c']}}}
+ hot_tpl = template_format.parse('''
+ heat_template_version: 2015-04-30
+ parameters:
+ param:
+ type: comma_delimited_list
+ default: 'a,b,c'
+ ''')
+ snippet = {'repeat': {'template': 'this is var%',
+ 'for_each': {'var%': {'get_param': 'param'}}}}
snippet_resolved = ['this is a', 'this is b', 'this is c']
- tmpl = parser.Template(hot_kilo_tpl_empty)
+ tmpl = parser.Template(hot_tpl)
+ stack = parser.Stack(utils.dummy_context(), 'test_stack', tmpl)
- self.assertEqual(snippet_resolved, self.resolve(snippet, tmpl))
+ self.assertEqual(snippet_resolved, self.resolve(snippet, tmpl, stack))
def test_repeat_dict_template(self):
"""Test repeat function with a dictionary as a template."""