Browse Source

Merge "Should execute 'resolve' before check the values of 'for_each'"

changes/28/202028/1
Jenkins 7 years ago committed by Gerrit Code Review
parent
commit
a16cbefc3e
  1. 7
      heat/engine/hot/functions.py
  2. 16
      heat/tests/test_hot.py

7
heat/engine/hot/functions.py

@ -343,7 +343,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:
@ -377,9 +377,8 @@ class Repeat(function.Function):
for (k, v) in template.items())
def result(self):
for_each = function.resolve(self._for_each)
keys = list(six.iterkeys(for_each))
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)]

16
heat/tests/test_hot.py

@ -628,13 +628,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 = template.Template(hot_kilo_tpl_empty)
tmpl = template.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."""

Loading…
Cancel
Save