Skip reconfig when all project config is excluded

We've noticed that an update to a project that excludes all config will
still trigger a tenant reconfiguration. As this won't have any effect on
the actual tenant configuration we don't submit a reconfiguration event
if the project excludes all config classes.

Since every affected tenant will independently decide if a reconfig is
necessary, this won't cause problems for when a project is part of
multiple tenants.

Change-Id: Ida1a3167bc41397a93db2b2ae876f5e9588caf45
This commit is contained in:
Simon Westphahl 2022-04-04 12:49:06 +02:00
parent 08348143f5
commit feaad6fcdf
3 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,20 @@
- tenant:
name: tenant-one
source:
gerrit:
config-projects:
- common-config
untrusted-projects:
- org/project1
- org/project2:
include: []
- tenant:
name: tenant-two
source:
gerrit:
config-projects:
- common-config
untrusted-projects:
- org/project1
- org/project2

View File

@ -8375,6 +8375,58 @@ class TestPipelineSupersedes(ZuulTestCase):
], ordered=False)
class TestSchedulerExcludeAll(ZuulTestCase):
tenant_config_file = 'config/two-tenant/exclude-all.yaml'
def test_skip_reconfig_exclude_all(self):
"""Test that we don't trigger a reconfiguration for a tenant
when the changed project excludes all config."""
config = textwrap.dedent(
"""
- job:
name: project2-test
parent: test
- project:
check:
jobs:
- project2-test
""")
file_dict = {'zuul.yaml': config}
A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A',
files=file_dict)
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertHistory([
dict(name='project2-test', result='SUCCESS', changes='1,1'),
])
sched = self.scheds.first.sched
tenant_one_layout_state = sched.local_layout_state["tenant-one"]
tenant_two_layout_state = sched.local_layout_state["tenant-two"]
A.setMerged()
self.fake_gerrit.addEvent(A.getChangeMergedEvent())
self.waitUntilSettled()
# We don't expect a reconfiguration for tenant-one as it excludes
# all config of org/project2.
self.assertEqual(sched.local_layout_state["tenant-one"],
tenant_one_layout_state)
# As tenant-two includes the config from org/project2, the merge of
# change A should have triggered a reconfig.
self.assertGreater(sched.local_layout_state["tenant-two"],
tenant_two_layout_state)
B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertHistory([
dict(name='project2-test', result='SUCCESS', changes='1,1'),
dict(name='project2-test', result='SUCCESS', changes='2,1'),
])
class TestReportBuildPage(ZuulTestCase):
tenant_config_file = 'config/build-page/main.yaml'

View File

@ -2178,6 +2178,12 @@ class Scheduler(threading.Thread):
reconfigure_tenant = False
# If all config classes are excluded for this project we don't need
# to trigger a reconfiguration.
tpc = tenant.project_configs.get(project.canonical_name)
if tpc and not tpc.load_classes:
reconfigure_tenant = False
# But if the event is that branch protection status has
# changed, do reconfigure.
if (event.isBranchProtectionChanged()):