Skip to content
This repository was archived by the owner on Aug 1, 2019. It is now read-only.

Commit bccdfcf

Browse files
author
James E. Blair
committed
Don't use cached config when deleting files
During dynamic reconfiguration, we treated deleted files the same as files which were not present in the collected file set for the changes in question. This meant that if someone deleted a file from a project-branch, we would end up using the cached data rather than no data. Only use cached data if there is no entry for the project-branch in the files object. If there is an entry, even if it's empty, do not use the cached data. Change-Id: If18bfa12b6c8e9ac5733bfe597f48b90ec49df9e
1 parent 1235f14 commit bccdfcf

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

tests/unit/test_v3.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,52 @@ def test_project_template(self):
949949
self.waitUntilSettled()
950950
self.assertEqual(B.data['status'], 'MERGED')
951951

952+
def test_job_remove_add(self):
953+
# Tests that a job can be removed from one repo and added in another.
954+
# First, remove the current config for project1 since it
955+
# references the job we want to remove.
956+
file_dict = {'.zuul.yaml': None}
957+
A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A',
958+
files=file_dict)
959+
A.setMerged()
960+
self.fake_gerrit.addEvent(A.getChangeMergedEvent())
961+
self.waitUntilSettled()
962+
# Then propose a change to delete the job from one repo...
963+
file_dict = {'.zuul.yaml': None}
964+
B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B',
965+
files=file_dict)
966+
self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
967+
self.waitUntilSettled()
968+
# ...and a second that depends on it that adds it to another repo.
969+
in_repo_conf = textwrap.dedent(
970+
"""
971+
- job:
972+
name: project-test1
973+
974+
- project:
975+
name: org/project1
976+
check:
977+
jobs:
978+
- project-test1
979+
""")
980+
in_repo_playbook = textwrap.dedent(
981+
"""
982+
- hosts: all
983+
tasks: []
984+
""")
985+
file_dict = {'.zuul.yaml': in_repo_conf,
986+
'playbooks/project-test1.yaml': in_repo_playbook}
987+
C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C',
988+
files=file_dict,
989+
parent='refs/changes/1/1/1')
990+
C.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
991+
C.subject, B.data['id'])
992+
self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
993+
self.waitUntilSettled()
994+
self.assertHistory([
995+
dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'),
996+
], ordered=False)
997+
952998
def test_multi_repo(self):
953999
downstream_repo_conf = textwrap.dedent(
9541000
"""

zuul/configloader.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,9 +1632,22 @@ def _loadDynamicProjectData(self, config, project, files, trusted, tenant):
16321632
for branch in branches:
16331633
fns1 = []
16341634
fns2 = []
1635-
files_list = files.connections.get(
1635+
files_entry = files.connections.get(
16361636
project.source.connection.connection_name, {}).get(
1637-
project.name, {}).get(branch, {}).keys()
1637+
project.name, {}).get(branch)
1638+
# If there is no files entry at all for this
1639+
# project-branch, then use the cached config.
1640+
if files_entry is None:
1641+
if trusted:
1642+
incdata = project.unparsed_config
1643+
else:
1644+
incdata = project.unparsed_branch_config.get(branch)
1645+
if incdata:
1646+
config.extend(incdata)
1647+
continue
1648+
# Otherwise, do not use the cached config (even if the
1649+
# files are empty as that likely means they were deleted).
1650+
files_list = files_entry.keys()
16381651
for fn in files_list:
16391652
if fn.startswith("zuul.d/"):
16401653
fns1.append(fn)
@@ -1666,14 +1679,6 @@ def _loadDynamicProjectData(self, config, project, files, trusted, tenant):
16661679

16671680
config.extend(incdata)
16681681

1669-
if not loaded:
1670-
if trusted:
1671-
incdata = project.unparsed_config
1672-
else:
1673-
incdata = project.unparsed_branch_config.get(branch)
1674-
if incdata:
1675-
config.extend(incdata)
1676-
16771682
def createDynamicLayout(self, tenant, files,
16781683
include_config_projects=False,
16791684
scheduler=None, connections=None):

0 commit comments

Comments
 (0)