diff options
author | ramishra <ramishra@redhat.com> | 2021-04-23 08:36:37 +0530 |
---|---|---|
committer | Rabi Mishra <ramishra@redhat.com> | 2021-04-24 06:10:15 +0000 |
commit | 7b9ffc5bed4555a8eb26b954d454aa172773417a (patch) | |
tree | be17eb547199cf7fe400720875bccd87a2905c27 | |
parent | 28b78eb971b69616c0a560930c72d75e525d34c9 (diff) | |
download | heat-7b9ffc5bed4555a8eb26b954d454aa172773417a.tar.gz |
Preserve order in list_concat_unique
Also, we should not modify a list when iterating
over it.
Task: 42359
Closes-Bug: #1925373
Change-Id: Iaa2c05b4155d93f44de60b6f98a69450c1512817
(cherry picked from commit a8f8528d1ea1952cf76bd09fd27cbd65a978af65)
-rw-r--r-- | heat/engine/hot/functions.py | 14 | ||||
-rw-r--r-- | heat/tests/test_hot.py | 2 |
2 files changed, 9 insertions, 7 deletions
diff --git a/heat/engine/hot/functions.py b/heat/engine/hot/functions.py index 33b75f4e4..a309392b3 100644 --- a/heat/engine/hot/functions.py +++ b/heat/engine/hot/functions.py @@ -1643,12 +1643,14 @@ class ListConcat(function.Function): for m in args: ret_list.extend(ensure_list(m)) - if self._unique: - for i in ret_list: - while ret_list.count(i) > 1: - del ret_list[ret_list.index(i)] - - return ret_list + if not self._unique: + return ret_list + + unique_list = [] + for item in ret_list: + if item not in unique_list: + unique_list.append(item) + return unique_list class ListConcatUnique(ListConcat): diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py index a0ec62ae8..a4f4c3d32 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -2399,7 +2399,7 @@ resources: self.assertEqual(snippet_resolved, resolved) def test_list_concat_unique(self): - snippet = {'list_concat_unique': [['v1', 'v2'], ['v2', 'v3']]} + snippet = {'list_concat_unique': [['v1', 'v2'], ['v1', 'v3']]} snippet_resolved = ['v1', 'v2', 'v3'] tmpl = template.Template(hot_pike_tpl_empty) resolved = self.resolve(snippet, tmpl) |