diff options
author | ramishra <ramishra@redhat.com> | 2021-04-23 08:36:37 +0530 |
---|---|---|
committer | Rabi Mishra <ramishra@redhat.com> | 2021-04-26 14:50:47 +0000 |
commit | 0833daa3f77dd2267a6068eeafcf9d9af8da1a17 (patch) | |
tree | 824793c58d55a3f4def78c67a8f082ae3b70a9c4 | |
parent | 9181439680347c4f0bddd9a700d45d7dcd6f7969 (diff) | |
download | heat-0833daa3f77dd2267a6068eeafcf9d9af8da1a17.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 cf4eaa0f5..2575264c9 100644 --- a/heat/engine/hot/functions.py +++ b/heat/engine/hot/functions.py @@ -1603,12 +1603,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 6f0a0b495..bd457dd79 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -2366,7 +2366,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) |