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
This commit is contained in:
parent
29431cc5b3
commit
c540293cfe
|
@ -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')
|
||||
|
|
|
@ -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}]}
|
||||
|
|
Loading…
Reference in New Issue