diff --git a/tests/fixtures/config/timer-two-tenant/git/common-config/playbooks/run.yaml b/tests/fixtures/config/timer-two-tenant/git/common-config/playbooks/run.yaml new file mode 100644 index 0000000000..f679dceaef --- /dev/null +++ b/tests/fixtures/config/timer-two-tenant/git/common-config/playbooks/run.yaml @@ -0,0 +1,2 @@ +- hosts: all + tasks: [] diff --git a/tests/fixtures/config/timer-two-tenant/git/common-config/zuul.yaml b/tests/fixtures/config/timer-two-tenant/git/common-config/zuul.yaml new file mode 100644 index 0000000000..4d2f06be3e --- /dev/null +++ b/tests/fixtures/config/timer-two-tenant/git/common-config/zuul.yaml @@ -0,0 +1,14 @@ +- pipeline: + name: periodic + manager: independent + trigger: + timer: + - time: '* * * * * */1' + +- job: + name: base + parent: null + run: playbooks/run.yaml + +- job: + name: test-job diff --git a/tests/fixtures/config/timer-two-tenant/git/org_project1/README b/tests/fixtures/config/timer-two-tenant/git/org_project1/README new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/tests/fixtures/config/timer-two-tenant/git/org_project1/README @@ -0,0 +1 @@ +test diff --git a/tests/fixtures/config/timer-two-tenant/git/org_project1/zuul.yaml b/tests/fixtures/config/timer-two-tenant/git/org_project1/zuul.yaml new file mode 100644 index 0000000000..f9584c40c6 --- /dev/null +++ b/tests/fixtures/config/timer-two-tenant/git/org_project1/zuul.yaml @@ -0,0 +1,4 @@ +- project: + periodic: + jobs: + - test-job diff --git a/tests/fixtures/config/timer-two-tenant/git/org_project2/README b/tests/fixtures/config/timer-two-tenant/git/org_project2/README new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/tests/fixtures/config/timer-two-tenant/git/org_project2/README @@ -0,0 +1 @@ +test diff --git a/tests/fixtures/config/timer-two-tenant/git/org_project2/zuul.yaml b/tests/fixtures/config/timer-two-tenant/git/org_project2/zuul.yaml new file mode 100644 index 0000000000..f9584c40c6 --- /dev/null +++ b/tests/fixtures/config/timer-two-tenant/git/org_project2/zuul.yaml @@ -0,0 +1,4 @@ +- project: + periodic: + jobs: + - test-job diff --git a/tests/fixtures/config/timer-two-tenant/main.yaml b/tests/fixtures/config/timer-two-tenant/main.yaml new file mode 100644 index 0000000000..06150aabc1 --- /dev/null +++ b/tests/fixtures/config/timer-two-tenant/main.yaml @@ -0,0 +1,21 @@ +- 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: + include: [] + - org/project2 diff --git a/tests/unit/test_timer_driver.py b/tests/unit/test_timer_driver.py new file mode 100644 index 0000000000..227ec676d7 --- /dev/null +++ b/tests/unit/test_timer_driver.py @@ -0,0 +1,43 @@ +# Copyright 2021 Acme Gating, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tests.base import ZuulTestCase, iterate_timeout + + +class TestTimerTwoTenants(ZuulTestCase): + tenant_config_file = 'config/timer-two-tenant/main.yaml' + + def test_timer_two_tenants(self): + # The pipeline triggers every second. Wait until we have 4 + # jobs (2 from each tenant). + for _ in iterate_timeout(60, 'jobs started'): + if len(self.history) >= 4: + break + + tenant_one_projects = set() + tenant_two_projects = set() + for h in self.history: + if h.parameters['zuul']['tenant'] == 'tenant-one': + tenant_one_projects.add((h.parameters['items'][0]['project'])) + if h.parameters['zuul']['tenant'] == 'tenant-two': + tenant_two_projects.add((h.parameters['items'][0]['project'])) + + # Verify that the right job ran in the right tenant + self.assertEqual(tenant_one_projects, {'org/project1'}) + self.assertEqual(tenant_two_projects, {'org/project2'}) + + # Stop running timer jobs so the assertions don't race. + self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') + self.scheds.execute(lambda app: app.sched.reconfigure(app.config)) + self.waitUntilSettled() diff --git a/zuul/driver/gerrit/gerritconnection.py b/zuul/driver/gerrit/gerritconnection.py index 6d55299750..ef0b9c39fb 100644 --- a/zuul/driver/gerrit/gerritconnection.py +++ b/zuul/driver/gerrit/gerritconnection.py @@ -779,7 +779,7 @@ class GerritConnection(ZKChangeCacheMixin, BaseConnection): def _getTag(self, event): tag = event.ref[len('refs/tags/'):] - key = ChangeKey(self.connection_name, None, + key = ChangeKey(self.connection_name, event.project_name, 'Tag', tag, event.newrev) change = self._change_cache.get(key) if change: @@ -798,7 +798,7 @@ class GerritConnection(ZKChangeCacheMixin, BaseConnection): return change def _getBranch(self, event, branch, ref): - key = ChangeKey(self.connection_name, None, + key = ChangeKey(self.connection_name, event.project_name, 'Branch', branch, event.newrev) change = self._change_cache.get(key) if change: @@ -817,7 +817,7 @@ class GerritConnection(ZKChangeCacheMixin, BaseConnection): return change def _getRef(self, event): - key = ChangeKey(self.connection_name, None, + key = ChangeKey(self.connection_name, event.project_name, 'Ref', event.ref, event.newrev) change = self._change_cache.get(key) if change: