From c540293cfeeae6ff721e7fac59981f40f03bcf19 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Thu, 22 Dec 2016 12:32:55 +0000 Subject: [PATCH] map_replace allow noop colliding replacements We should allow the case where the keys collide, but the replacement is the same as the current key (e.g a noop). This is useful when you want to do a map_replace based on a user parameter, then the default can be to do a noop replace but the user parameter may also be any other (non colliding) value. Change-Id: I8cc5761c219616b4f8c18b3f44c4bf864c5457f1 Closes-Bug: #1652034 --- heat/engine/hot/functions.py | 2 +- heat/tests/test_hot.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/heat/engine/hot/functions.py b/heat/engine/hot/functions.py index f7af96c5f3..97d47f752b 100644 --- a/heat/engine/hot/functions.py +++ b/heat/engine/hot/functions.py @@ -767,7 +767,7 @@ class MapReplace(function.Function): key = repl_keys.get(k) if key is None: key = k - elif key in in_map: + elif key in in_map and key != k: # Keys collide msg = _('key replacement %s collides with ' 'a key in the input map') diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py index 643884166b..cd5f636c36 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -1073,6 +1073,15 @@ class HOTemplateTest(common.HeatTestCase): self.assertEqual({'f1': 'b1', 'F2': 'b2'}, resolved) + def test_map_replace_keys_collide_ok_equal(self): + # It's OK to replace a key with the same value + snippet = {'map_replace': [{'f1': 'b1', 'f2': 'b2'}, + {'keys': {'f2': 'f2'}}]} + tmpl = template.Template(hot_newton_tpl_empty) + resolved = self.resolve(snippet, tmpl) + self.assertEqual({'f1': 'b1', 'f2': 'b2'}, + resolved) + def test_map_replace_none_values(self): snippet = {'map_replace': [{'f1': 'b1', 'f2': 'b2'}, {'values': None}]}