diff options
author | Zuul <zuul@review.opendev.org> | 2022-04-08 02:37:36 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2022-04-08 02:37:36 +0000 |
commit | 8d98ab7bf4d7118479de59a7d5b26a14d1a436f5 (patch) | |
tree | 7fb2eb4e22cbadaefdd9b13dfdb4ed60020c885e | |
parent | a8c8844a8f376be079898526654e9bedeafd4abf (diff) | |
parent | feaad6fcdf16e52c956daffea10852039beb494a (diff) | |
download | zuul-8d98ab7bf4d7118479de59a7d5b26a14d1a436f5.tar.gz |
Merge "Skip reconfig when all project config is excluded"
-rw-r--r-- | tests/fixtures/config/two-tenant/exclude-all.yaml | 20 | ||||
-rw-r--r-- | tests/unit/test_scheduler.py | 52 | ||||
-rw-r--r-- | zuul/scheduler.py | 6 |
3 files changed, 78 insertions, 0 deletions
diff --git a/tests/fixtures/config/two-tenant/exclude-all.yaml b/tests/fixtures/config/two-tenant/exclude-all.yaml new file mode 100644 index 000000000..60938c366 --- /dev/null +++ b/tests/fixtures/config/two-tenant/exclude-all.yaml @@ -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 diff --git a/tests/unit/test_scheduler.py b/tests/unit/test_scheduler.py index c596028de..3cb2507c4 100644 --- a/tests/unit/test_scheduler.py +++ b/tests/unit/test_scheduler.py @@ -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' diff --git a/zuul/scheduler.py b/zuul/scheduler.py index efc7711a2..04b6b0f45 100644 --- a/zuul/scheduler.py +++ b/zuul/scheduler.py @@ -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()): |