replace dict.update by a dict merge in zuul_return
This fixes an issue when using zuul_return several times. zuul_return module takes a dictionary as a parameter with one root key: 'zuul' Using dict.update with two identical keys will cause dict key overriding When using zuul_return in child and parent playbooks, the parent zuul_return value overwrites the child zuul_return value Change-Id: I6308020d2af0670eb5c598a3daf0ef51066651f6
This commit is contained in:
parent
ed99392ac1
commit
81e34256af
6
tests/fixtures/config/data-return/git/common-config/playbooks/several-zuul-return-child.yaml
vendored
Normal file
6
tests/fixtures/config/data-return/git/common-config/playbooks/several-zuul-return-child.yaml
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
- hosts: localhost
|
||||||
|
tasks:
|
||||||
|
- zuul_return:
|
||||||
|
data:
|
||||||
|
zuul:
|
||||||
|
child_jobs: []
|
|
@ -0,0 +1,6 @@
|
||||||
|
- hosts: localhost
|
||||||
|
tasks:
|
||||||
|
- zuul_return:
|
||||||
|
data:
|
||||||
|
zuul:
|
||||||
|
log_url: http://example.com/test/log/url/
|
|
@ -41,6 +41,15 @@
|
||||||
name: child
|
name: child
|
||||||
run: playbooks/child.yaml
|
run: playbooks/child.yaml
|
||||||
|
|
||||||
|
- job:
|
||||||
|
name: several-zuul-return-parent
|
||||||
|
post-run: playbooks/several-zuul-return-parent-post.yaml
|
||||||
|
|
||||||
|
- job:
|
||||||
|
name: several-zuul-return-child
|
||||||
|
parent: several-zuul-return-parent
|
||||||
|
run: playbooks/several-zuul-return-child.yaml
|
||||||
|
|
||||||
- project:
|
- project:
|
||||||
name: org/project
|
name: org/project
|
||||||
check:
|
check:
|
||||||
|
@ -84,3 +93,12 @@
|
||||||
- child:
|
- child:
|
||||||
dependencies:
|
dependencies:
|
||||||
- data-return-skip-all
|
- data-return-skip-all
|
||||||
|
|
||||||
|
- project:
|
||||||
|
name: org/project4
|
||||||
|
check:
|
||||||
|
jobs:
|
||||||
|
- several-zuul-return-child
|
||||||
|
- data-return:
|
||||||
|
dependencies:
|
||||||
|
- several-zuul-return-child
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
test
|
|
@ -9,3 +9,4 @@
|
||||||
- org/project1
|
- org/project1
|
||||||
- org/project2
|
- org/project2
|
||||||
- org/project3
|
- org/project3
|
||||||
|
- org/project4
|
||||||
|
|
|
@ -3084,6 +3084,20 @@ class TestDataReturn(AnsibleZuulTestCase):
|
||||||
self.assertIn('data-return : SKIPPED', A.messages[-1])
|
self.assertIn('data-return : SKIPPED', A.messages[-1])
|
||||||
self.assertIn('Build succeeded', A.messages[-1])
|
self.assertIn('Build succeeded', A.messages[-1])
|
||||||
|
|
||||||
|
def test_several_zuul_return(self):
|
||||||
|
A = self.fake_gerrit.addFakeChange('org/project4', 'master', 'A')
|
||||||
|
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
|
||||||
|
self.waitUntilSettled()
|
||||||
|
self.assertHistory([
|
||||||
|
dict(name='several-zuul-return-child', result='SUCCESS',
|
||||||
|
changes='1,1'),
|
||||||
|
])
|
||||||
|
self.assertIn(
|
||||||
|
'- several-zuul-return-child http://example.com/test/log/url/',
|
||||||
|
A.messages[-1])
|
||||||
|
self.assertIn('data-return : SKIPPED', A.messages[-1])
|
||||||
|
self.assertIn('Build succeeded', A.messages[-1])
|
||||||
|
|
||||||
|
|
||||||
class TestDiskAccounting(AnsibleZuulTestCase):
|
class TestDiskAccounting(AnsibleZuulTestCase):
|
||||||
config_file = 'zuul-disk-accounting.conf'
|
config_file = 'zuul-disk-accounting.conf'
|
||||||
|
|
|
@ -20,6 +20,22 @@ import json
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
|
def merge_dict(dict_a, dict_b):
|
||||||
|
"""
|
||||||
|
Add dict_a into dict_b
|
||||||
|
Merge values if possible else dict_a value replace dict_b value
|
||||||
|
"""
|
||||||
|
for key in dict_a:
|
||||||
|
if key in dict_b:
|
||||||
|
if isinstance(dict_a[key], dict) and isinstance(dict_b[key], dict):
|
||||||
|
merge_dict(dict_a[key], dict_b[key])
|
||||||
|
else:
|
||||||
|
dict_b[key] = dict_a[key]
|
||||||
|
else:
|
||||||
|
dict_b[key] = dict_a[key]
|
||||||
|
return dict_b
|
||||||
|
|
||||||
|
|
||||||
def set_value(path, new_data, new_file):
|
def set_value(path, new_data, new_file):
|
||||||
workdir = os.path.dirname(path)
|
workdir = os.path.dirname(path)
|
||||||
data = None
|
data = None
|
||||||
|
@ -33,9 +49,9 @@ def set_value(path, new_data, new_file):
|
||||||
|
|
||||||
if new_file:
|
if new_file:
|
||||||
with open(new_file, 'r') as f:
|
with open(new_file, 'r') as f:
|
||||||
data.update(json.load(f))
|
merge_dict(json.load(f), data)
|
||||||
if new_data:
|
if new_data:
|
||||||
data.update(new_data)
|
merge_dict(new_data, data)
|
||||||
|
|
||||||
(f, tmp_path) = tempfile.mkstemp(dir=workdir)
|
(f, tmp_path) = tempfile.mkstemp(dir=workdir)
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue