Fix bypass list length check when all values are None

The patch https://review.openstack.org/#/c/527001/ bypassed the None
list but did not consider the case where all the for_each lists are
getting their values from attributes and therefore are None.

This patch set fix it by also skipping the check if all the values
are None -- as len(value_lens) would be 0 in that case.

Closes-bug: #1732934
Change-Id: Iba574bbd3877f9ca1ca755c384b3ddb47aec711c
This commit is contained in:
Luis Tomas Bolivar 2018-01-03 16:08:46 +01:00
parent 5aa603bb2b
commit bd8df9a8b9
2 changed files with 12 additions and 2 deletions

View File

@ -956,7 +956,7 @@ class Repeat(function.Function):
self._valid_arg(value)
values.append(value)
value_lens.append(len(value))
if not self._nested_loop:
if not self._nested_loop and value_lens:
if len(set(value_lens)) != 1:
raise ValueError(_('For %s, the length of for_each values '
'should be equal if no nested '

View File

@ -1109,7 +1109,17 @@ class HOTemplateTest(common.HeatTestCase):
snippet = {'map_merge': {'repeat': {
'template': {'ROLE': 'ROLE', 'NAME': 'NAME'},
'for_each': {'ROLE': None, 'NAME': ['n1', 'n2']},
'permutations': None}}}
'permutations': False}}}
tmpl = template.Template(hot_mitaka_tpl_empty)
resolved = self.resolve(snippet, tmpl)
self.assertEqual({}, resolved)
def test_merge_containing_repeat_multi_list_no_nested_loop_all_none(self):
snippet = {'map_merge': {'repeat': {
'template': {'ROLE': 'ROLE', 'NAME': 'NAME'},
'for_each': {'ROLE': None, 'NAME': None},
'permutations': False}}}
tmpl = template.Template(hot_mitaka_tpl_empty)
resolved = self.resolve(snippet, tmpl)