blob: 0cd259a4d5f7e9aadd998d0f124fcd25814456e1 [file] [log] [blame]
James E. Blairc494d542014-08-06 09:23:52 -07001#!/usr/bin/env python
2
3# Copyright 2014 Hewlett-Packard Development Company, L.P.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17import logging
James E. Blairc494d542014-08-06 09:23:52 -070018
19from tests.base import ZuulTestCase
20
21logging.basicConfig(level=logging.DEBUG,
22 format='%(asctime)s %(name)-32s '
23 '%(levelname)-8s %(message)s')
24
25
26class TestZuulTrigger(ZuulTestCase):
27 """Test Zuul Trigger"""
28
James E. Blair509cada2015-12-08 16:31:16 -080029 def setUp(self):
30 self.skip("Disabled for early v3 development")
31
James E. Blairc494d542014-08-06 09:23:52 -070032 def test_zuul_trigger_parent_change_enqueued(self):
33 "Test Zuul trigger event: parent-change-enqueued"
34 self.config.set('zuul', 'layout_config',
35 'tests/fixtures/layout-zuultrigger-enqueued.yaml')
36 self.sched.reconfigure(self.config)
37 self.registerJobs()
38
39 # This test has the following three changes:
40 # B1 -> A; B2 -> A
41 # When A is enqueued in the gate, B1 and B2 should both attempt
42 # to be enqueued in both pipelines. B1 should end up in check
43 # and B2 in gate because of differing pipeline requirements.
44 self.worker.hold_jobs_in_build = True
45 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
46 B1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'B1')
47 B2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'B2')
48 A.addApproval('CRVW', 2)
49 B1.addApproval('CRVW', 2)
50 B2.addApproval('CRVW', 2)
Joshua Hesketh29d99b72014-08-19 16:27:42 +100051 A.addApproval('VRFY', 1) # required by gate
52 B1.addApproval('VRFY', -1) # should go to check
53 B2.addApproval('VRFY', 1) # should go to gate
James E. Blairc494d542014-08-06 09:23:52 -070054 B1.addApproval('APRV', 1)
55 B2.addApproval('APRV', 1)
56 B1.setDependsOn(A, 1)
57 B2.setDependsOn(A, 1)
58 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
59 # Jobs are being held in build to make sure that 3,1 has time
60 # to enqueue behind 1,1 so that the test is more
61 # deterministic.
62 self.waitUntilSettled()
63 self.worker.hold_jobs_in_build = False
64 self.worker.release()
65 self.waitUntilSettled()
66
67 self.assertEqual(len(self.history), 3)
68 for job in self.history:
69 if job.changes == '1,1':
70 self.assertEqual(job.name, 'project-gate')
James E. Blairbfb8e042014-12-30 17:01:44 -080071 elif job.changes == '1,1 2,1':
James E. Blairc494d542014-08-06 09:23:52 -070072 self.assertEqual(job.name, 'project-check')
73 elif job.changes == '1,1 3,1':
74 self.assertEqual(job.name, 'project-gate')
75 else:
76 raise Exception("Unknown job")
77
78 def test_zuul_trigger_project_change_merged(self):
79 "Test Zuul trigger event: project-change-merged"
80 self.config.set('zuul', 'layout_config',
81 'tests/fixtures/layout-zuultrigger-merged.yaml')
82 self.sched.reconfigure(self.config)
83 self.registerJobs()
84
85 # This test has the following three changes:
86 # A, B, C; B conflicts with A, but C does not.
87 # When A is merged, B and C should be checked for conflicts,
88 # and B should receive a -1.
James E. Blairc0acb552014-08-16 08:17:02 -070089 # D and E are used to repeat the test in the second part, but
90 # are defined here to that they end up in the trigger cache.
James E. Blairc494d542014-08-06 09:23:52 -070091 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
92 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
93 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blairc0acb552014-08-16 08:17:02 -070094 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
95 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
James E. Blairc494d542014-08-06 09:23:52 -070096 A.addPatchset(['conflict'])
97 B.addPatchset(['conflict'])
James E. Blairc0acb552014-08-16 08:17:02 -070098 D.addPatchset(['conflict2'])
99 E.addPatchset(['conflict2'])
James E. Blairc494d542014-08-06 09:23:52 -0700100 A.addApproval('CRVW', 2)
101 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
102 self.waitUntilSettled()
103
104 self.assertEqual(len(self.history), 1)
105 self.assertEqual(self.history[0].name, 'project-gate')
106 self.assertEqual(A.reported, 2)
107 self.assertEqual(B.reported, 1)
108 self.assertEqual(C.reported, 0)
James E. Blairc0acb552014-08-16 08:17:02 -0700109 self.assertEqual(D.reported, 0)
110 self.assertEqual(E.reported, 0)
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000111 self.assertEqual(
112 B.messages[0],
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +0000113 "Merge Failed.\n\nThis change or one of its cross-repo "
114 "dependencies was unable to be automatically merged with the "
115 "current state of its repository. Please rebase the change and "
116 "upload a new patchset.")
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000117
James E. Blair96698e22015-04-02 07:48:21 -0700118 self.assertTrue("project:org/project status:open" in
119 self.fake_gerrit.queries)
James E. Blairc0acb552014-08-16 08:17:02 -0700120
121 # Reconfigure and run the test again. This is a regression
122 # check to make sure that we don't end up with a stale trigger
123 # cache that has references to projects from the old
124 # configuration.
125 self.sched.reconfigure(self.config)
126
127 D.addApproval('CRVW', 2)
128 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
129 self.waitUntilSettled()
130
131 self.assertEqual(len(self.history), 2)
132 self.assertEqual(self.history[1].name, 'project-gate')
133 self.assertEqual(A.reported, 2)
134 self.assertEqual(B.reported, 1)
135 self.assertEqual(C.reported, 0)
136 self.assertEqual(D.reported, 2)
137 self.assertEqual(E.reported, 1)
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000138 self.assertEqual(
139 E.messages[0],
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +0000140 "Merge Failed.\n\nThis change or one of its cross-repo "
141 "dependencies was unable to be automatically merged with the "
142 "current state of its repository. Please rebase the change and "
143 "upload a new patchset.")
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000144 self.assertEqual(self.fake_gerrit.queries[1],
145 "project:org/project status:open")