From ead6c56f219822547310b5edd76a30bc69da9f97 Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Wed, 1 Feb 2017 16:34:04 -0800 Subject: [PATCH] Re-enable test_abandoned_not_timer - Re-working old layouts into new ones. - The timer driver was never registered, so do that. - Registering it revealed bugs in it. Fixing those. Change-Id: I0fe6095bd7f5391f4e55d7f0356bfd7de9ad5866 Story: 2000773 Task: 3460 --- tests/base.py | 3 +- .../playbooks/project-bitrot-stable-old.yaml | 2 + .../project-bitrot-stable-older.yaml | 2 + .../layout-idle/playbooks/project-test1.yaml | 2 + .../single-tenant/git/layout-idle/zuul.yaml | 27 ++++++++++ .../playbooks/project-bitrot-stable-old.yaml | 2 + .../project-bitrot-stable-older.yaml | 2 + .../playbooks/project-test1.yaml | 2 + .../git/layout-no-timer/zuul.yaml | 50 +++++++++++++++++++ tests/fixtures/layout-idle.yaml | 12 ----- tests/fixtures/layout-no-timer.yaml | 28 ----------- tests/unit/test_scheduler.py | 15 +++--- zuul/driver/gerrit/gerritconnection.py | 1 + zuul/driver/timer/__init__.py | 6 +-- zuul/launcher/client.py | 4 ++ zuul/lib/connections.py | 2 + 16 files changed, 109 insertions(+), 51 deletions(-) create mode 100644 tests/fixtures/config/single-tenant/git/layout-idle/playbooks/project-bitrot-stable-old.yaml create mode 100644 tests/fixtures/config/single-tenant/git/layout-idle/playbooks/project-bitrot-stable-older.yaml create mode 100644 tests/fixtures/config/single-tenant/git/layout-idle/playbooks/project-test1.yaml create mode 100644 tests/fixtures/config/single-tenant/git/layout-idle/zuul.yaml create mode 100644 tests/fixtures/config/single-tenant/git/layout-no-timer/playbooks/project-bitrot-stable-old.yaml create mode 100644 tests/fixtures/config/single-tenant/git/layout-no-timer/playbooks/project-bitrot-stable-older.yaml create mode 100644 tests/fixtures/config/single-tenant/git/layout-no-timer/playbooks/project-test1.yaml create mode 100644 tests/fixtures/config/single-tenant/git/layout-no-timer/zuul.yaml delete mode 100644 tests/fixtures/layout-idle.yaml delete mode 100644 tests/fixtures/layout-no-timer.yaml diff --git a/tests/base.py b/tests/base.py index 566ceae2cd..d0727d781c 100755 --- a/tests/base.py +++ b/tests/base.py @@ -1758,7 +1758,8 @@ class ZuulTestCase(BaseTestCase): def updateConfigLayout(self, path): root = os.path.join(self.test_root, "config") - os.makedirs(root) + if not os.path.exists(root): + os.makedirs(root) f = tempfile.NamedTemporaryFile(dir=root, delete=False) f.write(""" - tenant: diff --git a/tests/fixtures/config/single-tenant/git/layout-idle/playbooks/project-bitrot-stable-old.yaml b/tests/fixtures/config/single-tenant/git/layout-idle/playbooks/project-bitrot-stable-old.yaml new file mode 100644 index 0000000000..f679dceaef --- /dev/null +++ b/tests/fixtures/config/single-tenant/git/layout-idle/playbooks/project-bitrot-stable-old.yaml @@ -0,0 +1,2 @@ +- hosts: all + tasks: [] diff --git a/tests/fixtures/config/single-tenant/git/layout-idle/playbooks/project-bitrot-stable-older.yaml b/tests/fixtures/config/single-tenant/git/layout-idle/playbooks/project-bitrot-stable-older.yaml new file mode 100644 index 0000000000..f679dceaef --- /dev/null +++ b/tests/fixtures/config/single-tenant/git/layout-idle/playbooks/project-bitrot-stable-older.yaml @@ -0,0 +1,2 @@ +- hosts: all + tasks: [] diff --git a/tests/fixtures/config/single-tenant/git/layout-idle/playbooks/project-test1.yaml b/tests/fixtures/config/single-tenant/git/layout-idle/playbooks/project-test1.yaml new file mode 100644 index 0000000000..f679dceaef --- /dev/null +++ b/tests/fixtures/config/single-tenant/git/layout-idle/playbooks/project-test1.yaml @@ -0,0 +1,2 @@ +- hosts: all + tasks: [] diff --git a/tests/fixtures/config/single-tenant/git/layout-idle/zuul.yaml b/tests/fixtures/config/single-tenant/git/layout-idle/zuul.yaml new file mode 100644 index 0000000000..f71f3e4b8e --- /dev/null +++ b/tests/fixtures/config/single-tenant/git/layout-idle/zuul.yaml @@ -0,0 +1,27 @@ +- pipeline: + name: periodic + manager: independent + source: + gerrit + trigger: + timer: + - time: '* * * * * */1' + +- job: + name: project-bitrot-stable-old + nodes: + - name: static + image: ubuntu-xenial + +- job: + name: project-bitrot-stable-older + nodes: + - name: static + image: ubuntu-trusty + +- project: + name: org/project + periodic: + jobs: + - project-bitrot-stable-old + - project-bitrot-stable-older diff --git a/tests/fixtures/config/single-tenant/git/layout-no-timer/playbooks/project-bitrot-stable-old.yaml b/tests/fixtures/config/single-tenant/git/layout-no-timer/playbooks/project-bitrot-stable-old.yaml new file mode 100644 index 0000000000..f679dceaef --- /dev/null +++ b/tests/fixtures/config/single-tenant/git/layout-no-timer/playbooks/project-bitrot-stable-old.yaml @@ -0,0 +1,2 @@ +- hosts: all + tasks: [] diff --git a/tests/fixtures/config/single-tenant/git/layout-no-timer/playbooks/project-bitrot-stable-older.yaml b/tests/fixtures/config/single-tenant/git/layout-no-timer/playbooks/project-bitrot-stable-older.yaml new file mode 100644 index 0000000000..f679dceaef --- /dev/null +++ b/tests/fixtures/config/single-tenant/git/layout-no-timer/playbooks/project-bitrot-stable-older.yaml @@ -0,0 +1,2 @@ +- hosts: all + tasks: [] diff --git a/tests/fixtures/config/single-tenant/git/layout-no-timer/playbooks/project-test1.yaml b/tests/fixtures/config/single-tenant/git/layout-no-timer/playbooks/project-test1.yaml new file mode 100644 index 0000000000..f679dceaef --- /dev/null +++ b/tests/fixtures/config/single-tenant/git/layout-no-timer/playbooks/project-test1.yaml @@ -0,0 +1,2 @@ +- hosts: all + tasks: [] diff --git a/tests/fixtures/config/single-tenant/git/layout-no-timer/zuul.yaml b/tests/fixtures/config/single-tenant/git/layout-no-timer/zuul.yaml new file mode 100644 index 0000000000..f754e376ac --- /dev/null +++ b/tests/fixtures/config/single-tenant/git/layout-no-timer/zuul.yaml @@ -0,0 +1,50 @@ +- pipeline: + name: check + manager: independent + source: + gerrit + trigger: + gerrit: + - event: patchset-created + success: + gerrit: + verified: 1 + failure: + gerrit: + verified: -1 + +- pipeline: + name: periodic + manager: independent + # Trigger is required, set it to one that is a noop + # during tests that check the timer trigger. + source: + gerrit + trigger: + gerrit: + - event: ref-updated + +- job: + name: project-test1 + +- job: + name: project-bitrot-stable-old + nodes: + - name: static + image: ubuntu-xenial + +- job: + name: project-bitrot-stable-older + nodes: + - name: static + image: ubuntu-trusty + +- project: + name: org/project + check: + jobs: + - project-test1 + periodic: + jobs: + - project-bitrot-stable-old + - project-bitrot-stable-older diff --git a/tests/fixtures/layout-idle.yaml b/tests/fixtures/layout-idle.yaml deleted file mode 100644 index 087078845a..0000000000 --- a/tests/fixtures/layout-idle.yaml +++ /dev/null @@ -1,12 +0,0 @@ -pipelines: - - name: periodic - manager: IndependentPipelineManager - trigger: - timer: - - time: '* * * * * */1' - -projects: - - name: org/project - periodic: - - project-bitrot-stable-old - - project-bitrot-stable-older diff --git a/tests/fixtures/layout-no-timer.yaml b/tests/fixtures/layout-no-timer.yaml deleted file mode 100644 index ca40d13d00..0000000000 --- a/tests/fixtures/layout-no-timer.yaml +++ /dev/null @@ -1,28 +0,0 @@ -pipelines: - - name: check - manager: IndependentPipelineManager - trigger: - gerrit: - - event: patchset-created - success: - gerrit: - verified: 1 - failure: - gerrit: - verified: -1 - - - name: periodic - manager: IndependentPipelineManager - # Trigger is required, set it to one that is a noop - # during tests that check the timer trigger. - trigger: - gerrit: - - event: ref-updated - -projects: - - name: org/project - check: - - project-test1 - periodic: - - project-bitrot-stable-old - - project-bitrot-stable-older diff --git a/tests/unit/test_scheduler.py b/tests/unit/test_scheduler.py index 642669259a..06ec70d0b9 100755 --- a/tests/unit/test_scheduler.py +++ b/tests/unit/test_scheduler.py @@ -1638,27 +1638,28 @@ class TestScheduler(ZuulTestCase): self.assertEqual(A.reported, 0, "Abandoned change should not report") self.assertEqual(B.reported, 1, "Change should report") - @skip("Disabled for early v3 development") def test_abandoned_not_timer(self): "Test that an abandoned change does not cancel timer jobs" self.launch_server.hold_jobs_in_build = True # Start timer trigger - also org/project - self.updateConfigLayout( - 'tests/fixtures/layout-idle.yaml') + self.updateConfigLayout('layout-idle') self.sched.reconfigure(self.config) - self.registerJobs() # The pipeline triggers every second, so we should have seen # several by now. time.sleep(5) self.waitUntilSettled() # Stop queuing timer triggered jobs so that the assertions # below don't race against more jobs being queued. - self.updateConfigLayout( - 'tests/fixtures/layout-no-timer.yaml') + # Must be in same repo, so overwrite config with another one + no_timer_path = os.path.join(self.test_root, 'upstream', + 'layout-no-timer', 'zuul.yaml') + with open(no_timer_path, 'r') as nt: + self.addCommitToRepo('layout-idle', 'Removing timer jobs', + {'zuul.yaml': nt.read()}) + self.sched.reconfigure(self.config) - self.registerJobs() self.assertEqual(len(self.builds), 2, "Two timer jobs") A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') diff --git a/zuul/driver/gerrit/gerritconnection.py b/zuul/driver/gerrit/gerritconnection.py index 627c716fd5..683c8ffcd9 100644 --- a/zuul/driver/gerrit/gerritconnection.py +++ b/zuul/driver/gerrit/gerritconnection.py @@ -282,6 +282,7 @@ class GerritConnection(BaseConnection): change.url = self._getGitwebUrl(project, sha=event.newrev) else: # TODOv3(jeblair): we need to get the project from the event + project = self.getProject(event.project_name) change = NullChange(project) return change diff --git a/zuul/driver/timer/__init__.py b/zuul/driver/timer/__init__.py index b8979c4a6e..a188a26750 100644 --- a/zuul/driver/timer/__init__.py +++ b/zuul/driver/timer/__init__.py @@ -49,7 +49,7 @@ class TimerDriver(Driver, TriggerInterface): def _addJobs(self, tenant): jobs = [] self.tenant_jobs[tenant.name] = jobs - for pipeline in tenant.layout.pipelines: + for pipeline in tenant.layout.pipelines.values(): for ef in pipeline.manager.event_filters: if not isinstance(ef.trigger, timertrigger.TimerTrigger): continue @@ -88,8 +88,8 @@ class TimerDriver(Driver, TriggerInterface): def stop(self): self.apsched.shutdown() - def getTrigger(self, connection_name): - return timertrigger.TimerTrigger(self) + def getTrigger(self, connection_name, config=None): + return timertrigger.TimerTrigger(self, config) def getTriggerSchema(self): return timertrigger.getSchema() diff --git a/zuul/launcher/client.py b/zuul/launcher/client.py index 458aeaf765..5b60506438 100644 --- a/zuul/launcher/client.py +++ b/zuul/launcher/client.py @@ -42,6 +42,10 @@ def make_merger_item(item): oldrev = item.change.oldrev newrev = item.change.newrev branch = item.change.ref + else: + oldrev = None + newrev = None + branch = None connection_name = item.pipeline.source.connection.connection_name project = item.change.project.name diff --git a/zuul/lib/connections.py b/zuul/lib/connections.py index 35b44175a1..0a8be03121 100644 --- a/zuul/lib/connections.py +++ b/zuul/lib/connections.py @@ -17,6 +17,7 @@ import re import zuul.driver.zuul import zuul.driver.gerrit import zuul.driver.smtp +import zuul.driver.timer from zuul.connection import BaseConnection @@ -34,6 +35,7 @@ class ConnectionRegistry(object): self.registerDriver(zuul.driver.zuul.ZuulDriver()) self.registerDriver(zuul.driver.gerrit.GerritDriver()) self.registerDriver(zuul.driver.smtp.SMTPDriver()) + self.registerDriver(zuul.driver.timer.TimerDriver()) def registerDriver(self, driver): if driver.name in self.drivers: