blob: a77990ced77f570644cfc2b48ad7e9d04a44ec22 [file] [log] [blame]
James E. Blairb0fcae42012-07-17 11:12:10 -07001#!/usr/bin/env python
2
3# Copyright 2012 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
James E. Blairb0fcae42012-07-17 11:12:10 -070017import json
Monty Taylorbc758832013-06-17 17:22:42 -040018import logging
19import os
James E. Blairb0fcae42012-07-17 11:12:10 -070020import re
James E. Blair4886cc12012-07-18 15:39:41 -070021import shutil
Monty Taylorbc758832013-06-17 17:22:42 -040022import time
Maru Newby3fe5f852015-01-13 04:22:14 +000023import yaml
James E. Blairec056492016-07-22 09:45:56 -070024from unittest import skip
Monty Taylorbc758832013-06-17 17:22:42 -040025
James E. Blair4886cc12012-07-18 15:39:41 -070026import git
Morgan Fainberg293f7f82016-05-30 14:01:22 -070027from six.moves import urllib
Monty Taylorbc758832013-06-17 17:22:42 -040028import testtools
James E. Blairb0fcae42012-07-17 11:12:10 -070029
Maru Newby3fe5f852015-01-13 04:22:14 +000030import zuul.change_matcher
James E. Blairb0fcae42012-07-17 11:12:10 -070031import zuul.scheduler
James E. Blairad28e912013-11-27 10:43:22 -080032import zuul.rpcclient
Joshua Hesketh1879cf72013-08-19 14:13:15 +100033import zuul.reporter.gerrit
Joshua Hesketh5fea8672013-08-19 17:32:01 +100034import zuul.reporter.smtp
Paul Belanger9bba4902016-11-02 16:07:33 -040035import zuul.model
James E. Blairb0fcae42012-07-17 11:12:10 -070036
Maru Newby3fe5f852015-01-13 04:22:14 +000037from tests.base import (
Maru Newby3fe5f852015-01-13 04:22:14 +000038 ZuulTestCase,
39 repack_repo,
40)
James E. Blairb0fcae42012-07-17 11:12:10 -070041
James E. Blair1f4c2bb2013-04-26 08:40:46 -070042logging.basicConfig(level=logging.DEBUG,
43 format='%(asctime)s %(name)-32s '
44 '%(levelname)-8s %(message)s')
James E. Blairb0fcae42012-07-17 11:12:10 -070045
46
Clark Boylanb640e052014-04-03 16:41:46 -070047class TestScheduler(ZuulTestCase):
James E. Blair552b54f2016-07-22 13:55:32 -070048 tenant_config_file = 'config/single-tenant/main.yaml'
Antoine Mussobd86a312014-01-08 14:51:33 +010049
James E. Blairb0fcae42012-07-17 11:12:10 -070050 def test_jobs_launched(self):
51 "Test that jobs are launched and a change is merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -070052
James E. Blairb0fcae42012-07-17 11:12:10 -070053 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -070054 A.addApproval('code-review', 2)
55 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairb0fcae42012-07-17 11:12:10 -070056 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -040057 self.assertEqual(self.getJobFromHistory('project-merge').result,
58 'SUCCESS')
59 self.assertEqual(self.getJobFromHistory('project-test1').result,
60 'SUCCESS')
61 self.assertEqual(self.getJobFromHistory('project-test2').result,
62 'SUCCESS')
63 self.assertEqual(A.data['status'], 'MERGED')
64 self.assertEqual(A.reported, 2)
James E. Blair34776ee2016-08-25 13:53:54 -070065 self.assertEqual(self.getJobFromHistory('project-test1').node,
66 'image1')
James E. Blairb0fcae42012-07-17 11:12:10 -070067
James E. Blair552b54f2016-07-22 13:55:32 -070068 # TODOv3(jeblair): we may want to report stats by tenant (also?).
James E. Blair66eeebf2013-07-27 17:44:32 -070069 self.assertReportedStat('gerrit.event.comment-added', value='1|c')
70 self.assertReportedStat('zuul.pipeline.gate.current_changes',
71 value='1|g')
72 self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',
73 kind='ms')
74 self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',
75 value='1|c')
76 self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms')
77 self.assertReportedStat('zuul.pipeline.gate.total_changes',
78 value='1|c')
James E. Blair412e5582013-04-22 15:50:12 -070079 self.assertReportedStat(
James E. Blair66eeebf2013-07-27 17:44:32 -070080 'zuul.pipeline.gate.org.project.resident_time', kind='ms')
James E. Blair412e5582013-04-22 15:50:12 -070081 self.assertReportedStat(
James E. Blair66eeebf2013-07-27 17:44:32 -070082 'zuul.pipeline.gate.org.project.total_changes', value='1|c')
James E. Blair412e5582013-04-22 15:50:12 -070083
James E. Blair5821bd92015-09-16 08:48:15 -070084 for build in self.builds:
85 self.assertEqual(build.parameters['ZUUL_VOTING'], '1')
86
James E. Blair3cb10702013-08-24 08:56:03 -070087 def test_initial_pipeline_gauges(self):
88 "Test that each pipeline reported its length on start"
James E. Blair7da51b72016-07-25 15:29:43 -070089 self.assertReportedStat('zuul.pipeline.gate.current_changes',
90 value='0|g')
91 self.assertReportedStat('zuul.pipeline.check.current_changes',
92 value='0|g')
James E. Blair3cb10702013-08-24 08:56:03 -070093
James E. Blair34776ee2016-08-25 13:53:54 -070094 def test_job_branch(self):
95 "Test the correct variant of a job runs on a branch"
96 self.create_branch('org/project', 'stable')
97 A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A')
98 A.addApproval('code-review', 2)
99 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
100 self.waitUntilSettled()
101 self.assertEqual(self.getJobFromHistory('project-test1').result,
102 'SUCCESS')
103 self.assertEqual(self.getJobFromHistory('project-test2').result,
104 'SUCCESS')
105 self.assertEqual(A.data['status'], 'MERGED')
106 self.assertEqual(A.reported, 2,
107 "A should report start and success")
108 self.assertIn('gate', A.messages[1],
109 "A should transit gate")
110 self.assertEqual(self.getJobFromHistory('project-test1').node,
111 'image2')
112
James E. Blairb0fcae42012-07-17 11:12:10 -0700113 def test_parallel_changes(self):
114 "Test that changes are tested in parallel and merged in series"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700115
James E. Blair791b5392016-08-03 11:25:56 -0700116 self.launch_server.hold_jobs_in_build = True
James E. Blairb0fcae42012-07-17 11:12:10 -0700117 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
118 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
119 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700120 A.addApproval('code-review', 2)
121 B.addApproval('code-review', 2)
122 C.addApproval('code-review', 2)
James E. Blairb0fcae42012-07-17 11:12:10 -0700123
James E. Blair8b5408c2016-08-08 15:37:46 -0700124 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
125 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
126 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairb0fcae42012-07-17 11:12:10 -0700127
128 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400129 self.assertEqual(len(self.builds), 1)
130 self.assertEqual(self.builds[0].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700131 self.assertTrue(self.builds[0].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700132
James E. Blair791b5392016-08-03 11:25:56 -0700133 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700134 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400135 self.assertEqual(len(self.builds), 3)
136 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700137 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400138 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700139 self.assertTrue(self.builds[1].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400140 self.assertEqual(self.builds[2].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700141 self.assertTrue(self.builds[2].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700142
James E. Blair791b5392016-08-03 11:25:56 -0700143 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700144 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400145 self.assertEqual(len(self.builds), 5)
146 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700147 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400148 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700149 self.assertTrue(self.builds[1].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700150
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400151 self.assertEqual(self.builds[2].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700152 self.assertTrue(self.builds[2].hasChanges(A, B))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400153 self.assertEqual(self.builds[3].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700154 self.assertTrue(self.builds[3].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700155
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400156 self.assertEqual(self.builds[4].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700157 self.assertTrue(self.builds[4].hasChanges(A, B, C))
James E. Blairb0fcae42012-07-17 11:12:10 -0700158
James E. Blair791b5392016-08-03 11:25:56 -0700159 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700160 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400161 self.assertEqual(len(self.builds), 6)
162 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700163 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400164 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700165 self.assertTrue(self.builds[1].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700166
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400167 self.assertEqual(self.builds[2].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700168 self.assertTrue(self.builds[2].hasChanges(A, B))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400169 self.assertEqual(self.builds[3].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700170 self.assertTrue(self.builds[3].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700171
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400172 self.assertEqual(self.builds[4].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700173 self.assertTrue(self.builds[4].hasChanges(A, B, C))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400174 self.assertEqual(self.builds[5].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700175 self.assertTrue(self.builds[5].hasChanges(A, B, C))
James E. Blairb0fcae42012-07-17 11:12:10 -0700176
James E. Blair791b5392016-08-03 11:25:56 -0700177 self.launch_server.hold_jobs_in_build = False
178 self.launch_server.release()
James E. Blairb0fcae42012-07-17 11:12:10 -0700179 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400180 self.assertEqual(len(self.builds), 0)
James E. Blairb0fcae42012-07-17 11:12:10 -0700181
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400182 self.assertEqual(len(self.history), 9)
183 self.assertEqual(A.data['status'], 'MERGED')
184 self.assertEqual(B.data['status'], 'MERGED')
185 self.assertEqual(C.data['status'], 'MERGED')
186 self.assertEqual(A.reported, 2)
187 self.assertEqual(B.reported, 2)
188 self.assertEqual(C.reported, 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700189
190 def test_failed_changes(self):
191 "Test that a change behind a failed change is retested"
James E. Blair08d19992016-08-10 15:25:31 -0700192 self.launch_server.hold_jobs_in_build = True
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700193
James E. Blairb02a3bb2012-07-30 17:49:55 -0700194 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
195 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -0700196 A.addApproval('code-review', 2)
197 B.addApproval('code-review', 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700198
James E. Blair08d19992016-08-10 15:25:31 -0700199 self.launch_server.failJob('project-test1', A)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700200
James E. Blair8b5408c2016-08-08 15:37:46 -0700201 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
202 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700203 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700204 self.assertBuilds([dict(name='project-merge', changes='1,1')])
James E. Blaire2819012013-06-28 17:17:26 -0400205
James E. Blair08d19992016-08-10 15:25:31 -0700206 self.launch_server.release('.*-merge')
James E. Blaire2819012013-06-28 17:17:26 -0400207 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700208 # A/project-merge is complete
209 self.assertBuilds([
210 dict(name='project-test1', changes='1,1'),
211 dict(name='project-test2', changes='1,1'),
212 dict(name='project-merge', changes='1,1 2,1'),
213 ])
James E. Blaire2819012013-06-28 17:17:26 -0400214
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700215 self.launch_server.release('.*-merge')
James E. Blaire2819012013-06-28 17:17:26 -0400216 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700217 # A/project-merge is complete
218 # B/project-merge is complete
219 self.assertBuilds([
220 dict(name='project-test1', changes='1,1'),
221 dict(name='project-test2', changes='1,1'),
222 dict(name='project-test1', changes='1,1 2,1'),
223 dict(name='project-test2', changes='1,1 2,1'),
224 ])
225
226 # Release project-test1 for A which will fail. This will
227 # abort both running B jobs and relaunch project-merge for B.
228 self.builds[0].release()
229 self.waitUntilSettled()
230
231 self.orderedRelease()
232 self.assertHistory([
233 dict(name='project-merge', result='SUCCESS', changes='1,1'),
234 dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'),
235 dict(name='project-test1', result='FAILURE', changes='1,1'),
236 dict(name='project-test1', result='ABORTED', changes='1,1 2,1'),
237 dict(name='project-test2', result='ABORTED', changes='1,1 2,1'),
238 dict(name='project-test2', result='SUCCESS', changes='1,1'),
239 dict(name='project-merge', result='SUCCESS', changes='2,1'),
240 dict(name='project-test1', result='SUCCESS', changes='2,1'),
241 dict(name='project-test2', result='SUCCESS', changes='2,1'),
James E. Blairb536ecc2016-08-31 10:11:42 -0700242 ], ordered=False)
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700243
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400244 self.assertEqual(A.data['status'], 'NEW')
245 self.assertEqual(B.data['status'], 'MERGED')
246 self.assertEqual(A.reported, 2)
247 self.assertEqual(B.reported, 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700248
249 def test_independent_queues(self):
250 "Test that changes end up in the right queues"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700251
James E. Blair08d19992016-08-10 15:25:31 -0700252 self.launch_server.hold_jobs_in_build = True
Zhongyue Luo5d556072012-09-21 02:00:47 +0900253 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700254 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
255 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700256 A.addApproval('code-review', 2)
257 B.addApproval('code-review', 2)
258 C.addApproval('code-review', 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700259
James E. Blair8b5408c2016-08-08 15:37:46 -0700260 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
261 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
262 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700263
James E. Blairb02a3bb2012-07-30 17:49:55 -0700264 self.waitUntilSettled()
265
266 # There should be one merge job at the head of each queue running
James E. Blair5f0d49e2016-08-19 09:36:50 -0700267 self.assertBuilds([
268 dict(name='project-merge', changes='1,1'),
269 dict(name='project-merge', changes='2,1'),
270 ])
James E. Blairb02a3bb2012-07-30 17:49:55 -0700271
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700272 # Release the current merge builds
James E. Blair5f0d49e2016-08-19 09:36:50 -0700273 self.builds[0].release()
274 self.waitUntilSettled()
275 self.builds[0].release()
James E. Blairb02a3bb2012-07-30 17:49:55 -0700276 self.waitUntilSettled()
277 # Release the merge job for project2 which is behind project1
James E. Blair08d19992016-08-10 15:25:31 -0700278 self.launch_server.release('.*-merge')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700279 self.waitUntilSettled()
280
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700281 # All the test builds should be running:
James E. Blair5f0d49e2016-08-19 09:36:50 -0700282 self.assertBuilds([
283 dict(name='project-test1', changes='1,1'),
284 dict(name='project-test2', changes='1,1'),
285 dict(name='project-test1', changes='2,1'),
286 dict(name='project-test2', changes='2,1'),
287 dict(name='project-test1', changes='2,1 3,1'),
288 dict(name='project-test2', changes='2,1 3,1'),
289 ])
James E. Blairb02a3bb2012-07-30 17:49:55 -0700290
James E. Blair5f0d49e2016-08-19 09:36:50 -0700291 self.orderedRelease()
292 self.assertHistory([
293 dict(name='project-merge', result='SUCCESS', changes='1,1'),
294 dict(name='project-merge', result='SUCCESS', changes='2,1'),
295 dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'),
296 dict(name='project-test1', result='SUCCESS', changes='1,1'),
297 dict(name='project-test2', result='SUCCESS', changes='1,1'),
298 dict(name='project-test1', result='SUCCESS', changes='2,1'),
299 dict(name='project-test2', result='SUCCESS', changes='2,1'),
300 dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'),
301 dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'),
302 ])
James E. Blairb02a3bb2012-07-30 17:49:55 -0700303
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400304 self.assertEqual(A.data['status'], 'MERGED')
305 self.assertEqual(B.data['status'], 'MERGED')
306 self.assertEqual(C.data['status'], 'MERGED')
307 self.assertEqual(A.reported, 2)
308 self.assertEqual(B.reported, 2)
309 self.assertEqual(C.reported, 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700310
311 def test_failed_change_at_head(self):
312 "Test that if a change at the head fails, jobs behind it are canceled"
James E. Blaird466dc42012-07-31 10:42:56 -0700313
James E. Blair08d19992016-08-10 15:25:31 -0700314 self.launch_server.hold_jobs_in_build = True
James E. Blaird466dc42012-07-31 10:42:56 -0700315 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
316 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
317 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700318 A.addApproval('code-review', 2)
319 B.addApproval('code-review', 2)
320 C.addApproval('code-review', 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700321
James E. Blair08d19992016-08-10 15:25:31 -0700322 self.launch_server.failJob('project-test1', A)
James E. Blaird466dc42012-07-31 10:42:56 -0700323
James E. Blair8b5408c2016-08-08 15:37:46 -0700324 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
325 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
326 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blaird466dc42012-07-31 10:42:56 -0700327
328 self.waitUntilSettled()
James E. Blaird466dc42012-07-31 10:42:56 -0700329
James E. Blairb536ecc2016-08-31 10:11:42 -0700330 self.assertBuilds([
331 dict(name='project-merge', changes='1,1'),
332 ])
James E. Blaird466dc42012-07-31 10:42:56 -0700333
James E. Blair08d19992016-08-10 15:25:31 -0700334 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700335 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700336 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700337 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700338 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700339 self.waitUntilSettled()
340
James E. Blairb536ecc2016-08-31 10:11:42 -0700341 self.assertBuilds([
342 dict(name='project-test1', changes='1,1'),
343 dict(name='project-test2', changes='1,1'),
344 dict(name='project-test1', changes='1,1 2,1'),
345 dict(name='project-test2', changes='1,1 2,1'),
346 dict(name='project-test1', changes='1,1 2,1 3,1'),
347 dict(name='project-test2', changes='1,1 2,1 3,1'),
348 ])
James E. Blaird466dc42012-07-31 10:42:56 -0700349
Monty Taylor6bef8ef2013-06-02 08:17:12 -0400350 self.release(self.builds[0])
James E. Blaird466dc42012-07-31 10:42:56 -0700351 self.waitUntilSettled()
352
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400353 # project-test2, project-merge for B
James E. Blairb536ecc2016-08-31 10:11:42 -0700354 self.assertBuilds([
355 dict(name='project-test2', changes='1,1'),
356 dict(name='project-merge', changes='2,1'),
357 ])
358 # Unordered history comparison because the aborts can finish
359 # in any order.
360 self.assertHistory([
361 dict(name='project-merge', result='SUCCESS',
362 changes='1,1'),
363 dict(name='project-merge', result='SUCCESS',
364 changes='1,1 2,1'),
365 dict(name='project-merge', result='SUCCESS',
366 changes='1,1 2,1 3,1'),
367 dict(name='project-test1', result='FAILURE',
368 changes='1,1'),
369 dict(name='project-test1', result='ABORTED',
370 changes='1,1 2,1'),
371 dict(name='project-test2', result='ABORTED',
372 changes='1,1 2,1'),
373 dict(name='project-test1', result='ABORTED',
374 changes='1,1 2,1 3,1'),
375 dict(name='project-test2', result='ABORTED',
376 changes='1,1 2,1 3,1'),
377 ], ordered=False)
James E. Blaird466dc42012-07-31 10:42:56 -0700378
James E. Blairb536ecc2016-08-31 10:11:42 -0700379 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700380 self.waitUntilSettled()
James E. Blairb536ecc2016-08-31 10:11:42 -0700381 self.launch_server.release('.*-merge')
382 self.waitUntilSettled()
383 self.orderedRelease()
James E. Blaird466dc42012-07-31 10:42:56 -0700384
James E. Blairb536ecc2016-08-31 10:11:42 -0700385 self.assertBuilds([])
386 self.assertHistory([
387 dict(name='project-merge', result='SUCCESS',
388 changes='1,1'),
389 dict(name='project-merge', result='SUCCESS',
390 changes='1,1 2,1'),
391 dict(name='project-merge', result='SUCCESS',
392 changes='1,1 2,1 3,1'),
393 dict(name='project-test1', result='FAILURE',
394 changes='1,1'),
395 dict(name='project-test1', result='ABORTED',
396 changes='1,1 2,1'),
397 dict(name='project-test2', result='ABORTED',
398 changes='1,1 2,1'),
399 dict(name='project-test1', result='ABORTED',
400 changes='1,1 2,1 3,1'),
401 dict(name='project-test2', result='ABORTED',
402 changes='1,1 2,1 3,1'),
403 dict(name='project-merge', result='SUCCESS',
404 changes='2,1'),
405 dict(name='project-merge', result='SUCCESS',
406 changes='2,1 3,1'),
407 dict(name='project-test2', result='SUCCESS',
408 changes='1,1'),
409 dict(name='project-test1', result='SUCCESS',
410 changes='2,1'),
411 dict(name='project-test2', result='SUCCESS',
412 changes='2,1'),
413 dict(name='project-test1', result='SUCCESS',
414 changes='2,1 3,1'),
415 dict(name='project-test2', result='SUCCESS',
416 changes='2,1 3,1'),
417 ], ordered=False)
418
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400419 self.assertEqual(A.data['status'], 'NEW')
420 self.assertEqual(B.data['status'], 'MERGED')
421 self.assertEqual(C.data['status'], 'MERGED')
422 self.assertEqual(A.reported, 2)
423 self.assertEqual(B.reported, 2)
424 self.assertEqual(C.reported, 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700425
James E. Blair0aac4872013-08-23 14:02:38 -0700426 def test_failed_change_in_middle(self):
427 "Test a failed change in the middle of the queue"
428
James E. Blair08d19992016-08-10 15:25:31 -0700429 self.launch_server.hold_jobs_in_build = True
James E. Blair0aac4872013-08-23 14:02:38 -0700430 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
431 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
432 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700433 A.addApproval('code-review', 2)
434 B.addApproval('code-review', 2)
435 C.addApproval('code-review', 2)
James E. Blair0aac4872013-08-23 14:02:38 -0700436
James E. Blair08d19992016-08-10 15:25:31 -0700437 self.launch_server.failJob('project-test1', B)
James E. Blair0aac4872013-08-23 14:02:38 -0700438
James E. Blair8b5408c2016-08-08 15:37:46 -0700439 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
440 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
441 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair0aac4872013-08-23 14:02:38 -0700442
443 self.waitUntilSettled()
444
James E. Blair08d19992016-08-10 15:25:31 -0700445 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700446 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700447 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700448 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700449 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700450 self.waitUntilSettled()
451
452 self.assertEqual(len(self.builds), 6)
453 self.assertEqual(self.builds[0].name, 'project-test1')
454 self.assertEqual(self.builds[1].name, 'project-test2')
455 self.assertEqual(self.builds[2].name, 'project-test1')
456 self.assertEqual(self.builds[3].name, 'project-test2')
457 self.assertEqual(self.builds[4].name, 'project-test1')
458 self.assertEqual(self.builds[5].name, 'project-test2')
459
460 self.release(self.builds[2])
461 self.waitUntilSettled()
462
James E. Blair972e3c72013-08-29 12:04:55 -0700463 # project-test1 and project-test2 for A
464 # project-test2 for B
465 # project-merge for C (without B)
466 self.assertEqual(len(self.builds), 4)
James E. Blair0aac4872013-08-23 14:02:38 -0700467 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2)
468
James E. Blair08d19992016-08-10 15:25:31 -0700469 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -0700470 self.waitUntilSettled()
471
472 # project-test1 and project-test2 for A
473 # project-test2 for B
474 # project-test1 and project-test2 for C
475 self.assertEqual(len(self.builds), 5)
476
Paul Belanger2e2a0492016-10-30 18:33:37 -0400477 tenant = self.sched.abide.tenants.get('tenant-one')
478 items = tenant.layout.pipelines['gate'].getAllItems()
James E. Blair0aac4872013-08-23 14:02:38 -0700479 builds = items[0].current_build_set.getBuilds()
480 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
481 self.assertEqual(self.countJobResults(builds, None), 2)
482 builds = items[1].current_build_set.getBuilds()
483 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
484 self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1)
485 self.assertEqual(self.countJobResults(builds, None), 1)
486 builds = items[2].current_build_set.getBuilds()
487 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
James E. Blair972e3c72013-08-29 12:04:55 -0700488 self.assertEqual(self.countJobResults(builds, None), 2)
James E. Blair0aac4872013-08-23 14:02:38 -0700489
James E. Blair08d19992016-08-10 15:25:31 -0700490 self.launch_server.hold_jobs_in_build = False
491 self.launch_server.release()
James E. Blair0aac4872013-08-23 14:02:38 -0700492 self.waitUntilSettled()
493
494 self.assertEqual(len(self.builds), 0)
495 self.assertEqual(len(self.history), 12)
496 self.assertEqual(A.data['status'], 'MERGED')
497 self.assertEqual(B.data['status'], 'NEW')
498 self.assertEqual(C.data['status'], 'MERGED')
499 self.assertEqual(A.reported, 2)
500 self.assertEqual(B.reported, 2)
501 self.assertEqual(C.reported, 2)
502
James E. Blairec056492016-07-22 09:45:56 -0700503 @skip("Disabled for early v3 development")
James E. Blaird466dc42012-07-31 10:42:56 -0700504 def test_failed_change_at_head_with_queue(self):
505 "Test that if a change at the head fails, queued jobs are canceled"
James E. Blaird466dc42012-07-31 10:42:56 -0700506
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700507 self.gearman_server.hold_jobs_in_queue = True
James E. Blaird466dc42012-07-31 10:42:56 -0700508 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
509 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
510 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700511 A.addApproval('code-review', 2)
512 B.addApproval('code-review', 2)
513 C.addApproval('code-review', 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700514
James E. Blair08d19992016-08-10 15:25:31 -0700515 self.launch_server.failJob('project-test1', A)
James E. Blaird466dc42012-07-31 10:42:56 -0700516
James E. Blair8b5408c2016-08-08 15:37:46 -0700517 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
518 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
519 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blaird466dc42012-07-31 10:42:56 -0700520
521 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700522 queue = self.gearman_server.getQueue()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400523 self.assertEqual(len(self.builds), 0)
524 self.assertEqual(len(queue), 1)
525 self.assertEqual(queue[0].name, 'build:project-merge')
526 self.assertTrue(self.job_has_changes(queue[0], A))
James E. Blaird466dc42012-07-31 10:42:56 -0700527
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700528 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700529 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700530 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700531 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700532 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700533 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700534 queue = self.gearman_server.getQueue()
James E. Blaird466dc42012-07-31 10:42:56 -0700535
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400536 self.assertEqual(len(self.builds), 0)
537 self.assertEqual(len(queue), 6)
538 self.assertEqual(queue[0].name, 'build:project-test1')
539 self.assertEqual(queue[1].name, 'build:project-test2')
540 self.assertEqual(queue[2].name, 'build:project-test1')
541 self.assertEqual(queue[3].name, 'build:project-test2')
542 self.assertEqual(queue[4].name, 'build:project-test1')
543 self.assertEqual(queue[5].name, 'build:project-test2')
James E. Blaird466dc42012-07-31 10:42:56 -0700544
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700545 self.release(queue[0])
James E. Blaird466dc42012-07-31 10:42:56 -0700546 self.waitUntilSettled()
547
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400548 self.assertEqual(len(self.builds), 0)
James E. Blair701c5b42013-06-06 09:34:59 -0700549 queue = self.gearman_server.getQueue()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400550 self.assertEqual(len(queue), 2) # project-test2, project-merge for B
551 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0)
James E. Blaird466dc42012-07-31 10:42:56 -0700552
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700553 self.gearman_server.hold_jobs_in_queue = False
554 self.gearman_server.release()
James E. Blaird466dc42012-07-31 10:42:56 -0700555 self.waitUntilSettled()
556
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400557 self.assertEqual(len(self.builds), 0)
558 self.assertEqual(len(self.history), 11)
559 self.assertEqual(A.data['status'], 'NEW')
560 self.assertEqual(B.data['status'], 'MERGED')
561 self.assertEqual(C.data['status'], 'MERGED')
562 self.assertEqual(A.reported, 2)
563 self.assertEqual(B.reported, 2)
564 self.assertEqual(C.reported, 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700565
James E. Blairec056492016-07-22 09:45:56 -0700566 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700567 def _test_time_database(self, iteration):
James E. Blair08d19992016-08-10 15:25:31 -0700568 self.launch_server.hold_jobs_in_build = True
James E. Blairce8a2132016-05-19 15:21:52 -0700569 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -0700570 A.addApproval('code-review', 2)
571 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairce8a2132016-05-19 15:21:52 -0700572 self.waitUntilSettled()
573 time.sleep(2)
574
575 data = json.loads(self.sched.formatStatusJSON())
576 found_job = None
577 for pipeline in data['pipelines']:
578 if pipeline['name'] != 'gate':
579 continue
580 for queue in pipeline['change_queues']:
581 for head in queue['heads']:
582 for item in head:
583 for job in item['jobs']:
584 if job['name'] == 'project-merge':
585 found_job = job
586 break
587
588 self.assertIsNotNone(found_job)
589 if iteration == 1:
590 self.assertIsNotNone(found_job['estimated_time'])
591 self.assertIsNone(found_job['remaining_time'])
592 else:
593 self.assertIsNotNone(found_job['estimated_time'])
594 self.assertTrue(found_job['estimated_time'] >= 2)
595 self.assertIsNotNone(found_job['remaining_time'])
596
James E. Blair08d19992016-08-10 15:25:31 -0700597 self.launch_server.hold_jobs_in_build = False
598 self.launch_server.release()
James E. Blairce8a2132016-05-19 15:21:52 -0700599 self.waitUntilSettled()
600
James E. Blairec056492016-07-22 09:45:56 -0700601 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700602 def test_time_database(self):
603 "Test the time database"
604
605 self._test_time_database(1)
606 self._test_time_database(2)
607
James E. Blairec056492016-07-22 09:45:56 -0700608 @skip("Disabled for early v3 development")
James E. Blairfef71632013-09-23 11:15:47 -0700609 def test_two_failed_changes_at_head(self):
610 "Test that changes are reparented correctly if 2 fail at head"
611
James E. Blair08d19992016-08-10 15:25:31 -0700612 self.launch_server.hold_jobs_in_build = True
James E. Blairfef71632013-09-23 11:15:47 -0700613 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
614 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
615 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700616 A.addApproval('code-review', 2)
617 B.addApproval('code-review', 2)
618 C.addApproval('code-review', 2)
James E. Blairfef71632013-09-23 11:15:47 -0700619
James E. Blair08d19992016-08-10 15:25:31 -0700620 self.launch_server.failJob('project-test1', A)
621 self.launch_server.failJob('project-test1', B)
James E. Blairfef71632013-09-23 11:15:47 -0700622
James E. Blair8b5408c2016-08-08 15:37:46 -0700623 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
624 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
625 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairfef71632013-09-23 11:15:47 -0700626 self.waitUntilSettled()
627
James E. Blair08d19992016-08-10 15:25:31 -0700628 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700629 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700630 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700631 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700632 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700633 self.waitUntilSettled()
634
635 self.assertEqual(len(self.builds), 6)
636 self.assertEqual(self.builds[0].name, 'project-test1')
637 self.assertEqual(self.builds[1].name, 'project-test2')
638 self.assertEqual(self.builds[2].name, 'project-test1')
639 self.assertEqual(self.builds[3].name, 'project-test2')
640 self.assertEqual(self.builds[4].name, 'project-test1')
641 self.assertEqual(self.builds[5].name, 'project-test2')
642
643 self.assertTrue(self.job_has_changes(self.builds[0], A))
644 self.assertTrue(self.job_has_changes(self.builds[2], A))
645 self.assertTrue(self.job_has_changes(self.builds[2], B))
646 self.assertTrue(self.job_has_changes(self.builds[4], A))
647 self.assertTrue(self.job_has_changes(self.builds[4], B))
648 self.assertTrue(self.job_has_changes(self.builds[4], C))
649
650 # Fail change B first
651 self.release(self.builds[2])
652 self.waitUntilSettled()
653
654 # restart of C after B failure
James E. Blair08d19992016-08-10 15:25:31 -0700655 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700656 self.waitUntilSettled()
657
658 self.assertEqual(len(self.builds), 5)
659 self.assertEqual(self.builds[0].name, 'project-test1')
660 self.assertEqual(self.builds[1].name, 'project-test2')
661 self.assertEqual(self.builds[2].name, 'project-test2')
662 self.assertEqual(self.builds[3].name, 'project-test1')
663 self.assertEqual(self.builds[4].name, 'project-test2')
664
665 self.assertTrue(self.job_has_changes(self.builds[1], A))
666 self.assertTrue(self.job_has_changes(self.builds[2], A))
667 self.assertTrue(self.job_has_changes(self.builds[2], B))
668 self.assertTrue(self.job_has_changes(self.builds[4], A))
669 self.assertFalse(self.job_has_changes(self.builds[4], B))
670 self.assertTrue(self.job_has_changes(self.builds[4], C))
671
672 # Finish running all passing jobs for change A
673 self.release(self.builds[1])
674 self.waitUntilSettled()
675 # Fail and report change A
676 self.release(self.builds[0])
677 self.waitUntilSettled()
678
679 # restart of B,C after A failure
James E. Blair08d19992016-08-10 15:25:31 -0700680 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700681 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700682 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700683 self.waitUntilSettled()
684
685 self.assertEqual(len(self.builds), 4)
686 self.assertEqual(self.builds[0].name, 'project-test1') # B
687 self.assertEqual(self.builds[1].name, 'project-test2') # B
688 self.assertEqual(self.builds[2].name, 'project-test1') # C
689 self.assertEqual(self.builds[3].name, 'project-test2') # C
690
691 self.assertFalse(self.job_has_changes(self.builds[1], A))
692 self.assertTrue(self.job_has_changes(self.builds[1], B))
693 self.assertFalse(self.job_has_changes(self.builds[1], C))
694
695 self.assertFalse(self.job_has_changes(self.builds[2], A))
696 # After A failed and B and C restarted, B should be back in
697 # C's tests because it has not failed yet.
698 self.assertTrue(self.job_has_changes(self.builds[2], B))
699 self.assertTrue(self.job_has_changes(self.builds[2], C))
700
James E. Blair08d19992016-08-10 15:25:31 -0700701 self.launch_server.hold_jobs_in_build = False
702 self.launch_server.release()
James E. Blairfef71632013-09-23 11:15:47 -0700703 self.waitUntilSettled()
704
705 self.assertEqual(len(self.builds), 0)
706 self.assertEqual(len(self.history), 21)
707 self.assertEqual(A.data['status'], 'NEW')
708 self.assertEqual(B.data['status'], 'NEW')
709 self.assertEqual(C.data['status'], 'MERGED')
710 self.assertEqual(A.reported, 2)
711 self.assertEqual(B.reported, 2)
712 self.assertEqual(C.reported, 2)
713
James E. Blairec056492016-07-22 09:45:56 -0700714 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700715 def test_parse_skip_if(self):
716 job_yaml = """
717jobs:
718 - name: job_name
719 skip-if:
720 - project: ^project_name$
721 branch: ^stable/icehouse$
722 all-files-match-any:
723 - ^filename$
724 - project: ^project2_name$
725 all-files-match-any:
726 - ^filename2$
727 """.strip()
728 data = yaml.load(job_yaml)
729 config_job = data.get('jobs')[0]
730 cm = zuul.change_matcher
731 expected = cm.MatchAny([
732 cm.MatchAll([
733 cm.ProjectMatcher('^project_name$'),
734 cm.BranchMatcher('^stable/icehouse$'),
735 cm.MatchAllFiles([cm.FileMatcher('^filename$')]),
736 ]),
737 cm.MatchAll([
738 cm.ProjectMatcher('^project2_name$'),
739 cm.MatchAllFiles([cm.FileMatcher('^filename2$')]),
740 ]),
741 ])
742 matcher = self.sched._parseSkipIf(config_job)
743 self.assertEqual(expected, matcher)
744
James E. Blair8c803f82012-07-31 16:25:42 -0700745 def test_patch_order(self):
746 "Test that dependent patches are tested in the right order"
747 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
748 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
749 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700750 A.addApproval('code-review', 2)
751 B.addApproval('code-review', 2)
752 C.addApproval('code-review', 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700753
754 M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2')
755 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
756 M2.setMerged()
757 M1.setMerged()
758
759 # C -> B -> A -> M1 -> M2
760 # M2 is here to make sure it is never queried. If it is, it
761 # means zuul is walking down the entire history of merged
762 # changes.
763
764 C.setDependsOn(B, 1)
765 B.setDependsOn(A, 1)
766 A.setDependsOn(M1, 1)
767 M1.setDependsOn(M2, 1)
768
James E. Blair8b5408c2016-08-08 15:37:46 -0700769 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair8c803f82012-07-31 16:25:42 -0700770
771 self.waitUntilSettled()
772
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400773 self.assertEqual(A.data['status'], 'NEW')
774 self.assertEqual(B.data['status'], 'NEW')
775 self.assertEqual(C.data['status'], 'NEW')
James E. Blair8c803f82012-07-31 16:25:42 -0700776
James E. Blair8b5408c2016-08-08 15:37:46 -0700777 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
778 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8c803f82012-07-31 16:25:42 -0700779
780 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400781 self.assertEqual(M2.queried, 0)
782 self.assertEqual(A.data['status'], 'MERGED')
783 self.assertEqual(B.data['status'], 'MERGED')
784 self.assertEqual(C.data['status'], 'MERGED')
785 self.assertEqual(A.reported, 2)
786 self.assertEqual(B.reported, 2)
787 self.assertEqual(C.reported, 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700788
James E. Blairec056492016-07-22 09:45:56 -0700789 @skip("Disabled for early v3 development")
James E. Blair063672f2015-01-29 13:09:12 -0800790 def test_needed_changes_enqueue(self):
791 "Test that a needed change is enqueued ahead"
792 # A Given a git tree like this, if we enqueue
793 # / \ change C, we should walk up and down the tree
794 # B G and enqueue changes in the order ABCDEFG.
795 # /|\ This is also the order that you would get if
796 # *C E F you enqueued changes in the order ABCDEFG, so
797 # / the ordering is stable across re-enqueue events.
798 # D
799
800 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
801 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
802 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
803 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
804 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
805 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
806 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
807 B.setDependsOn(A, 1)
808 C.setDependsOn(B, 1)
809 D.setDependsOn(C, 1)
810 E.setDependsOn(B, 1)
811 F.setDependsOn(B, 1)
812 G.setDependsOn(A, 1)
813
James E. Blair8b5408c2016-08-08 15:37:46 -0700814 A.addApproval('code-review', 2)
815 B.addApproval('code-review', 2)
816 C.addApproval('code-review', 2)
817 D.addApproval('code-review', 2)
818 E.addApproval('code-review', 2)
819 F.addApproval('code-review', 2)
820 G.addApproval('code-review', 2)
821 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800822
823 self.waitUntilSettled()
824
825 self.assertEqual(A.data['status'], 'NEW')
826 self.assertEqual(B.data['status'], 'NEW')
827 self.assertEqual(C.data['status'], 'NEW')
828 self.assertEqual(D.data['status'], 'NEW')
829 self.assertEqual(E.data['status'], 'NEW')
830 self.assertEqual(F.data['status'], 'NEW')
831 self.assertEqual(G.data['status'], 'NEW')
832
833 # We're about to add approvals to changes without adding the
834 # triggering events to Zuul, so that we can be sure that it is
835 # enqueing the changes based on dependencies, not because of
836 # triggering events. Since it will have the changes cached
837 # already (without approvals), we need to clear the cache
838 # first.
Joshua Hesketh4bd7da32016-02-17 20:58:47 +1100839 for connection in self.connections.values():
840 connection.maintainCache([])
James E. Blair063672f2015-01-29 13:09:12 -0800841
James E. Blair08d19992016-08-10 15:25:31 -0700842 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -0700843 A.addApproval('approved', 1)
844 B.addApproval('approved', 1)
845 D.addApproval('approved', 1)
846 E.addApproval('approved', 1)
847 F.addApproval('approved', 1)
848 G.addApproval('approved', 1)
849 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800850
851 for x in range(8):
James E. Blair08d19992016-08-10 15:25:31 -0700852 self.launch_server.release('.*-merge')
James E. Blair063672f2015-01-29 13:09:12 -0800853 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700854 self.launch_server.hold_jobs_in_build = False
855 self.launch_server.release()
James E. Blair063672f2015-01-29 13:09:12 -0800856 self.waitUntilSettled()
857
858 self.assertEqual(A.data['status'], 'MERGED')
859 self.assertEqual(B.data['status'], 'MERGED')
860 self.assertEqual(C.data['status'], 'MERGED')
861 self.assertEqual(D.data['status'], 'MERGED')
862 self.assertEqual(E.data['status'], 'MERGED')
863 self.assertEqual(F.data['status'], 'MERGED')
864 self.assertEqual(G.data['status'], 'MERGED')
865 self.assertEqual(A.reported, 2)
866 self.assertEqual(B.reported, 2)
867 self.assertEqual(C.reported, 2)
868 self.assertEqual(D.reported, 2)
869 self.assertEqual(E.reported, 2)
870 self.assertEqual(F.reported, 2)
871 self.assertEqual(G.reported, 2)
872 self.assertEqual(self.history[6].changes,
873 '1,1 2,1 3,1 4,1 5,1 6,1 7,1')
874
James E. Blairec056492016-07-22 09:45:56 -0700875 @skip("Disabled for early v3 development")
Joshua Hesketh850ccb62014-11-27 11:31:02 +1100876 def test_source_cache(self):
877 "Test that the source cache operates correctly"
James E. Blair08d19992016-08-10 15:25:31 -0700878 self.launch_server.hold_jobs_in_build = True
James E. Blair0e933c52013-07-11 10:18:52 -0700879
880 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
881 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
882 X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X')
James E. Blair8b5408c2016-08-08 15:37:46 -0700883 A.addApproval('code-review', 2)
884 B.addApproval('code-review', 2)
James E. Blair0e933c52013-07-11 10:18:52 -0700885
886 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
887 M1.setMerged()
888
889 B.setDependsOn(A, 1)
890 A.setDependsOn(M1, 1)
891
James E. Blair8b5408c2016-08-08 15:37:46 -0700892 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700893 self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1))
894
895 self.waitUntilSettled()
896
897 for build in self.builds:
898 if build.parameters['ZUUL_PIPELINE'] == 'check':
899 build.release()
900 self.waitUntilSettled()
901 for build in self.builds:
902 if build.parameters['ZUUL_PIPELINE'] == 'check':
903 build.release()
904 self.waitUntilSettled()
905
James E. Blair8b5408c2016-08-08 15:37:46 -0700906 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700907 self.waitUntilSettled()
908
Joshua Hesketh352264b2015-08-11 23:42:08 +1000909 self.log.debug("len %s" % self.fake_gerrit._change_cache.keys())
James E. Blair0e933c52013-07-11 10:18:52 -0700910 # there should still be changes in the cache
Joshua Hesketh352264b2015-08-11 23:42:08 +1000911 self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0)
James E. Blair0e933c52013-07-11 10:18:52 -0700912
James E. Blair08d19992016-08-10 15:25:31 -0700913 self.launch_server.hold_jobs_in_build = False
914 self.launch_server.release()
James E. Blair0e933c52013-07-11 10:18:52 -0700915 self.waitUntilSettled()
916
917 self.assertEqual(A.data['status'], 'MERGED')
918 self.assertEqual(B.data['status'], 'MERGED')
919 self.assertEqual(A.queried, 2) # Initial and isMerged
920 self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged
921
James E. Blair8c803f82012-07-31 16:25:42 -0700922 def test_can_merge(self):
James E. Blair4886cc12012-07-18 15:39:41 -0700923 "Test whether a change is ready to merge"
James E. Blair8c803f82012-07-31 16:25:42 -0700924 # TODO: move to test_gerrit (this is a unit test!)
925 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
Paul Belanger9bba4902016-11-02 16:07:33 -0400926 tenant = self.sched.abide.tenants.get('tenant-one')
927 source = tenant.layout.pipelines['gate'].source
928
929 # TODO(pabelanger): As we add more source / trigger APIs we should make
930 # it easier for users to create events for testing.
931 event = zuul.model.TriggerEvent()
932 event.trigger_name = 'gerrit'
933 event.change_number = '1'
934 event.patch_number = '2'
935
936 a = source.getChange(event)
937 mgr = tenant.layout.pipelines['gate'].manager
James E. Blairc0dedf82014-08-06 09:37:52 -0700938 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700939
James E. Blair8b5408c2016-08-08 15:37:46 -0700940 A.addApproval('code-review', 2)
Paul Belanger9bba4902016-11-02 16:07:33 -0400941 a = source.getChange(event, refresh=True)
James E. Blairc0dedf82014-08-06 09:37:52 -0700942 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700943
James E. Blair8b5408c2016-08-08 15:37:46 -0700944 A.addApproval('approved', 1)
Paul Belanger9bba4902016-11-02 16:07:33 -0400945 a = source.getChange(event, refresh=True)
James E. Blairc0dedf82014-08-06 09:37:52 -0700946 self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair4886cc12012-07-18 15:39:41 -0700947
James E. Blairec056492016-07-22 09:45:56 -0700948 @skip("Disabled for early v3 development")
James E. Blair4886cc12012-07-18 15:39:41 -0700949 def test_build_configuration(self):
950 "Test that zuul merges the right commits for testing"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700951
952 self.gearman_server.hold_jobs_in_queue = True
James E. Blair4886cc12012-07-18 15:39:41 -0700953 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
954 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
955 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700956 A.addApproval('code-review', 2)
957 B.addApproval('code-review', 2)
958 C.addApproval('code-review', 2)
959 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
960 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
961 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair4886cc12012-07-18 15:39:41 -0700962 self.waitUntilSettled()
963
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700964 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700965 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700966 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700967 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700968 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700969 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700970 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700971 ref = self.getParameter(queue[-1], 'ZUUL_REF')
972 self.gearman_server.hold_jobs_in_queue = False
973 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -0700974 self.waitUntilSettled()
James E. Blair4886cc12012-07-18 15:39:41 -0700975
Monty Taylorbc758832013-06-17 17:22:42 -0400976 path = os.path.join(self.git_root, "org/project")
James E. Blair4886cc12012-07-18 15:39:41 -0700977 repo = git.Repo(path)
978 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
979 repo_messages.reverse()
James E. Blair4886cc12012-07-18 15:39:41 -0700980 correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400981 self.assertEqual(repo_messages, correct_messages)
James E. Blair973721f2012-08-15 10:19:43 -0700982
James E. Blairec056492016-07-22 09:45:56 -0700983 @skip("Disabled for early v3 development")
James E. Blair973721f2012-08-15 10:19:43 -0700984 def test_build_configuration_conflict(self):
985 "Test that merge conflicts are handled"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700986
987 self.gearman_server.hold_jobs_in_queue = True
James E. Blair6736beb2013-07-11 15:18:15 -0700988 A = self.fake_gerrit.addFakeChange('org/conflict-project',
989 'master', 'A')
James E. Blair973721f2012-08-15 10:19:43 -0700990 A.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700991 B = self.fake_gerrit.addFakeChange('org/conflict-project',
992 'master', 'B')
James E. Blair973721f2012-08-15 10:19:43 -0700993 B.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700994 C = self.fake_gerrit.addFakeChange('org/conflict-project',
995 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700996 A.addApproval('code-review', 2)
997 B.addApproval('code-review', 2)
998 C.addApproval('code-review', 2)
999 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1000 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1001 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair973721f2012-08-15 10:19:43 -07001002 self.waitUntilSettled()
1003
James E. Blair6736beb2013-07-11 15:18:15 -07001004 self.assertEqual(A.reported, 1)
1005 self.assertEqual(B.reported, 1)
1006 self.assertEqual(C.reported, 1)
1007
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001008 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001009 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001010 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001011 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001012 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001013 self.waitUntilSettled()
James E. Blair972e3c72013-08-29 12:04:55 -07001014
1015 self.assertEqual(len(self.history), 2) # A and C merge jobs
1016
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001017 self.gearman_server.hold_jobs_in_queue = False
1018 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -07001019 self.waitUntilSettled()
1020
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001021 self.assertEqual(A.data['status'], 'MERGED')
1022 self.assertEqual(B.data['status'], 'NEW')
1023 self.assertEqual(C.data['status'], 'MERGED')
1024 self.assertEqual(A.reported, 2)
1025 self.assertEqual(B.reported, 2)
1026 self.assertEqual(C.reported, 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001027 self.assertEqual(len(self.history), 6)
James E. Blair6736beb2013-07-11 15:18:15 -07001028
James E. Blairec056492016-07-22 09:45:56 -07001029 @skip("Disabled for early v3 development")
James E. Blairdaabed22012-08-15 15:38:57 -07001030 def test_post(self):
1031 "Test that post jobs run"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001032
Zhongyue Luo5d556072012-09-21 02:00:47 +09001033 e = {
1034 "type": "ref-updated",
1035 "submitter": {
1036 "name": "User Name",
1037 },
1038 "refUpdate": {
1039 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1040 "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543",
1041 "refName": "master",
1042 "project": "org/project",
1043 }
1044 }
James E. Blairdaabed22012-08-15 15:38:57 -07001045 self.fake_gerrit.addEvent(e)
1046 self.waitUntilSettled()
1047
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001048 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001049 self.assertEqual(len(self.history), 1)
1050 self.assertIn('project-post', job_names)
James E. Blairc6294a52012-08-17 10:19:48 -07001051
James E. Blairec056492016-07-22 09:45:56 -07001052 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001053 def test_post_ignore_deletes(self):
1054 "Test that deleting refs does not trigger post jobs"
1055
1056 e = {
1057 "type": "ref-updated",
1058 "submitter": {
1059 "name": "User Name",
1060 },
1061 "refUpdate": {
1062 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1063 "newRev": "0000000000000000000000000000000000000000",
1064 "refName": "master",
1065 "project": "org/project",
1066 }
1067 }
1068 self.fake_gerrit.addEvent(e)
1069 self.waitUntilSettled()
1070
1071 job_names = [x.name for x in self.history]
1072 self.assertEqual(len(self.history), 0)
1073 self.assertNotIn('project-post', job_names)
1074
James E. Blairec056492016-07-22 09:45:56 -07001075 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001076 def test_post_ignore_deletes_negative(self):
1077 "Test that deleting refs does trigger post jobs"
1078
James E. Blairf84026c2015-12-08 16:11:46 -08001079 self.updateConfigLayout(
1080 'tests/fixtures/layout-dont-ignore-deletes.yaml')
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001081 self.sched.reconfigure(self.config)
1082
1083 e = {
1084 "type": "ref-updated",
1085 "submitter": {
1086 "name": "User Name",
1087 },
1088 "refUpdate": {
1089 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1090 "newRev": "0000000000000000000000000000000000000000",
1091 "refName": "master",
1092 "project": "org/project",
1093 }
1094 }
1095 self.fake_gerrit.addEvent(e)
1096 self.waitUntilSettled()
1097
1098 job_names = [x.name for x in self.history]
1099 self.assertEqual(len(self.history), 1)
1100 self.assertIn('project-post', job_names)
1101
James E. Blairec056492016-07-22 09:45:56 -07001102 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001103 def test_build_configuration_branch(self):
1104 "Test that the right commits are on alternate branches"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001105
1106 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001107 A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A')
1108 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1109 C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001110 A.addApproval('code-review', 2)
1111 B.addApproval('code-review', 2)
1112 C.addApproval('code-review', 2)
1113 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1114 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1115 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001116 self.waitUntilSettled()
1117
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001118 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001119 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001120 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001121 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001122 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001123 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001124 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001125 ref = self.getParameter(queue[-1], 'ZUUL_REF')
1126 self.gearman_server.hold_jobs_in_queue = False
1127 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001128 self.waitUntilSettled()
1129
Monty Taylorbc758832013-06-17 17:22:42 -04001130 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001131 repo = git.Repo(path)
1132 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
1133 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001134 correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001135 self.assertEqual(repo_messages, correct_messages)
James E. Blairc6294a52012-08-17 10:19:48 -07001136
James E. Blairec056492016-07-22 09:45:56 -07001137 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001138 def test_build_configuration_branch_interaction(self):
1139 "Test that switching between branches works"
1140 self.test_build_configuration()
1141 self.test_build_configuration_branch()
1142 # C has been merged, undo that
Monty Taylorbc758832013-06-17 17:22:42 -04001143 path = os.path.join(self.upstream_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001144 repo = git.Repo(path)
1145 repo.heads.master.commit = repo.commit('init')
1146 self.test_build_configuration()
1147
James E. Blairec056492016-07-22 09:45:56 -07001148 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001149 def test_build_configuration_multi_branch(self):
1150 "Test that dependent changes on multiple branches are merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001151
1152 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001153 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1154 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1155 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001156 A.addApproval('code-review', 2)
1157 B.addApproval('code-review', 2)
1158 C.addApproval('code-review', 2)
1159 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1160 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1161 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001162 self.waitUntilSettled()
James E. Blairbb1fe502014-03-04 10:15:06 -08001163 queue = self.gearman_server.getQueue()
1164 job_A = None
1165 for job in queue:
1166 if 'project-merge' in job.name:
1167 job_A = job
1168 ref_A = self.getParameter(job_A, 'ZUUL_REF')
1169 commit_A = self.getParameter(job_A, 'ZUUL_COMMIT')
1170 self.log.debug("Got Zuul ref for change A: %s" % ref_A)
1171 self.log.debug("Got Zuul commit for change A: %s" % commit_A)
James E. Blairc6294a52012-08-17 10:19:48 -07001172
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001173 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001174 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001175 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001176 job_B = None
1177 for job in queue:
1178 if 'project-merge' in job.name:
1179 job_B = job
1180 ref_B = self.getParameter(job_B, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001181 commit_B = self.getParameter(job_B, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001182 self.log.debug("Got Zuul ref for change B: %s" % ref_B)
James E. Blairbb1fe502014-03-04 10:15:06 -08001183 self.log.debug("Got Zuul commit for change B: %s" % commit_B)
1184
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001185 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001186 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001187 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001188 for job in queue:
1189 if 'project-merge' in job.name:
1190 job_C = job
1191 ref_C = self.getParameter(job_C, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001192 commit_C = self.getParameter(job_C, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001193 self.log.debug("Got Zuul ref for change C: %s" % ref_C)
James E. Blairbb1fe502014-03-04 10:15:06 -08001194 self.log.debug("Got Zuul commit for change C: %s" % commit_C)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001195 self.gearman_server.hold_jobs_in_queue = False
1196 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001197 self.waitUntilSettled()
1198
Monty Taylorbc758832013-06-17 17:22:42 -04001199 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001200 repo = git.Repo(path)
1201
1202 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001203 for c in repo.iter_commits(ref_C)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001204 repo_shas = [c.hexsha for c in repo.iter_commits(ref_C)]
James E. Blairc6294a52012-08-17 10:19:48 -07001205 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001206 correct_messages = ['initial commit', 'A-1', 'C-1']
James E. Blairbb1fe502014-03-04 10:15:06 -08001207 # Ensure the right commits are in the history for this ref
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001208 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001209 # Ensure ZUUL_REF -> ZUUL_COMMIT
1210 self.assertEqual(repo_shas[0], commit_C)
James E. Blairc6294a52012-08-17 10:19:48 -07001211
1212 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001213 for c in repo.iter_commits(ref_B)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001214 repo_shas = [c.hexsha for c in repo.iter_commits(ref_B)]
James E. Blairc6294a52012-08-17 10:19:48 -07001215 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001216 correct_messages = ['initial commit', 'mp commit', 'B-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001217 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001218 self.assertEqual(repo_shas[0], commit_B)
1219
1220 repo_messages = [c.message.strip()
1221 for c in repo.iter_commits(ref_A)]
1222 repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)]
1223 repo_messages.reverse()
1224 correct_messages = ['initial commit', 'A-1']
1225 self.assertEqual(repo_messages, correct_messages)
1226 self.assertEqual(repo_shas[0], commit_A)
1227
1228 self.assertNotEqual(ref_A, ref_B, ref_C)
1229 self.assertNotEqual(commit_A, commit_B, commit_C)
James E. Blair7f71c802012-08-22 13:04:32 -07001230
James E. Blairec056492016-07-22 09:45:56 -07001231 @skip("Disabled for early v3 development")
James E. Blair7f71c802012-08-22 13:04:32 -07001232 def test_one_job_project(self):
1233 "Test that queueing works with one job"
1234 A = self.fake_gerrit.addFakeChange('org/one-job-project',
1235 'master', 'A')
1236 B = self.fake_gerrit.addFakeChange('org/one-job-project',
1237 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07001238 A.addApproval('code-review', 2)
1239 B.addApproval('code-review', 2)
1240 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1241 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair7f71c802012-08-22 13:04:32 -07001242 self.waitUntilSettled()
1243
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001244 self.assertEqual(A.data['status'], 'MERGED')
1245 self.assertEqual(A.reported, 2)
1246 self.assertEqual(B.data['status'], 'MERGED')
1247 self.assertEqual(B.reported, 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001248
James E. Blairec056492016-07-22 09:45:56 -07001249 @skip("Disabled for early v3 development")
Antoine Musso80edd5a2013-02-13 15:37:53 +01001250 def test_job_from_templates_launched(self):
1251 "Test whether a job generated via a template can be launched"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001252
Antoine Musso80edd5a2013-02-13 15:37:53 +01001253 A = self.fake_gerrit.addFakeChange(
1254 'org/templated-project', 'master', 'A')
1255 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1256 self.waitUntilSettled()
Antoine Musso80edd5a2013-02-13 15:37:53 +01001257
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001258 self.assertEqual(self.getJobFromHistory('project-test1').result,
1259 'SUCCESS')
1260 self.assertEqual(self.getJobFromHistory('project-test2').result,
1261 'SUCCESS')
Antoine Musso80edd5a2013-02-13 15:37:53 +01001262
James E. Blairec056492016-07-22 09:45:56 -07001263 @skip("Disabled for early v3 development")
James E. Blair3e98c022013-12-16 15:25:38 -08001264 def test_layered_templates(self):
1265 "Test whether a job generated via a template can be launched"
1266
1267 A = self.fake_gerrit.addFakeChange(
1268 'org/layered-project', 'master', 'A')
1269 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1270 self.waitUntilSettled()
1271
1272 self.assertEqual(self.getJobFromHistory('project-test1').result,
1273 'SUCCESS')
1274 self.assertEqual(self.getJobFromHistory('project-test2').result,
1275 'SUCCESS')
James E. Blairaea6cf62013-12-16 15:38:12 -08001276 self.assertEqual(self.getJobFromHistory('layered-project-test3'
1277 ).result, 'SUCCESS')
1278 self.assertEqual(self.getJobFromHistory('layered-project-test4'
1279 ).result, 'SUCCESS')
James E. Blair12a92b12014-03-26 11:54:53 -07001280 self.assertEqual(self.getJobFromHistory('layered-project-foo-test5'
1281 ).result, 'SUCCESS')
James E. Blair3e98c022013-12-16 15:25:38 -08001282 self.assertEqual(self.getJobFromHistory('project-test6').result,
1283 'SUCCESS')
1284
James E. Blaircaec0c52012-08-22 14:52:22 -07001285 def test_dependent_changes_dequeue(self):
1286 "Test that dependent patches are not needlessly tested"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001287
James E. Blaircaec0c52012-08-22 14:52:22 -07001288 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1289 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1290 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001291 A.addApproval('code-review', 2)
1292 B.addApproval('code-review', 2)
1293 C.addApproval('code-review', 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001294
1295 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
1296 M1.setMerged()
1297
1298 # C -> B -> A -> M1
1299
1300 C.setDependsOn(B, 1)
1301 B.setDependsOn(A, 1)
1302 A.setDependsOn(M1, 1)
1303
James E. Blair08d19992016-08-10 15:25:31 -07001304 self.launch_server.failJob('project-merge', A)
James E. Blaircaec0c52012-08-22 14:52:22 -07001305
James E. Blair8b5408c2016-08-08 15:37:46 -07001306 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1307 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1308 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircaec0c52012-08-22 14:52:22 -07001309
1310 self.waitUntilSettled()
1311
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001312 self.assertEqual(A.data['status'], 'NEW')
1313 self.assertEqual(A.reported, 2)
1314 self.assertEqual(B.data['status'], 'NEW')
1315 self.assertEqual(B.reported, 2)
1316 self.assertEqual(C.data['status'], 'NEW')
1317 self.assertEqual(C.reported, 2)
1318 self.assertEqual(len(self.history), 1)
James E. Blairec590122012-08-22 15:19:31 -07001319
James E. Blair972e3c72013-08-29 12:04:55 -07001320 def test_failing_dependent_changes(self):
1321 "Test that failing dependent patches are taken out of stream"
James E. Blair08d19992016-08-10 15:25:31 -07001322 self.launch_server.hold_jobs_in_build = True
James E. Blair972e3c72013-08-29 12:04:55 -07001323 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1324 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1325 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1326 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
1327 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
James E. Blair8b5408c2016-08-08 15:37:46 -07001328 A.addApproval('code-review', 2)
1329 B.addApproval('code-review', 2)
1330 C.addApproval('code-review', 2)
1331 D.addApproval('code-review', 2)
1332 E.addApproval('code-review', 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001333
1334 # E, D -> C -> B, A
1335
1336 D.setDependsOn(C, 1)
1337 C.setDependsOn(B, 1)
1338
James E. Blair08d19992016-08-10 15:25:31 -07001339 self.launch_server.failJob('project-test1', B)
James E. Blair972e3c72013-08-29 12:04:55 -07001340
James E. Blair8b5408c2016-08-08 15:37:46 -07001341 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1342 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
1343 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1344 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1345 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair972e3c72013-08-29 12:04:55 -07001346
1347 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001348 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001349 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001350 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001351 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001352 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001353 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001354 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001355 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001356 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001357 self.waitUntilSettled()
1358
James E. Blair08d19992016-08-10 15:25:31 -07001359 self.launch_server.hold_jobs_in_build = False
James E. Blair972e3c72013-08-29 12:04:55 -07001360 for build in self.builds:
1361 if build.parameters['ZUUL_CHANGE'] != '1':
1362 build.release()
1363 self.waitUntilSettled()
1364
James E. Blair08d19992016-08-10 15:25:31 -07001365 self.launch_server.release()
James E. Blair972e3c72013-08-29 12:04:55 -07001366 self.waitUntilSettled()
1367
1368 self.assertEqual(A.data['status'], 'MERGED')
1369 self.assertEqual(A.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001370 self.assertIn('Build succeeded', A.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001371 self.assertEqual(B.data['status'], 'NEW')
1372 self.assertEqual(B.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001373 self.assertIn('Build failed', B.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001374 self.assertEqual(C.data['status'], 'NEW')
1375 self.assertEqual(C.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001376 self.assertIn('depends on a change', C.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001377 self.assertEqual(D.data['status'], 'NEW')
1378 self.assertEqual(D.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001379 self.assertIn('depends on a change', D.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001380 self.assertEqual(E.data['status'], 'MERGED')
1381 self.assertEqual(E.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001382 self.assertIn('Build succeeded', E.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001383 self.assertEqual(len(self.history), 18)
1384
James E. Blairec056492016-07-22 09:45:56 -07001385 @skip("Disabled for early v3 development")
James E. Blairec590122012-08-22 15:19:31 -07001386 def test_head_is_dequeued_once(self):
James E. Blair2fa50962013-01-30 21:50:41 -08001387 "Test that if a change at the head fails it is dequeued only once"
James E. Blairec590122012-08-22 15:19:31 -07001388 # If it's dequeued more than once, we should see extra
1389 # aborted jobs.
James E. Blairec590122012-08-22 15:19:31 -07001390
James E. Blair08d19992016-08-10 15:25:31 -07001391 self.launch_server.hold_jobs_in_build = True
James E. Blairec590122012-08-22 15:19:31 -07001392 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1393 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1394 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001395 A.addApproval('code-review', 2)
1396 B.addApproval('code-review', 2)
1397 C.addApproval('code-review', 2)
James E. Blairec590122012-08-22 15:19:31 -07001398
James E. Blair08d19992016-08-10 15:25:31 -07001399 self.launch_server.failJob('project1-test1', A)
1400 self.launch_server.failJob('project1-test2', A)
1401 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairec590122012-08-22 15:19:31 -07001402
James E. Blair8b5408c2016-08-08 15:37:46 -07001403 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1404 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1405 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairec590122012-08-22 15:19:31 -07001406
1407 self.waitUntilSettled()
James E. Blairec590122012-08-22 15:19:31 -07001408
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001409 self.assertEqual(len(self.builds), 1)
1410 self.assertEqual(self.builds[0].name, 'project1-merge')
1411 self.assertTrue(self.job_has_changes(self.builds[0], A))
James E. Blairec590122012-08-22 15:19:31 -07001412
James E. Blair08d19992016-08-10 15:25:31 -07001413 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001414 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001415 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001416 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001417 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001418 self.waitUntilSettled()
1419
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001420 self.assertEqual(len(self.builds), 9)
1421 self.assertEqual(self.builds[0].name, 'project1-test1')
1422 self.assertEqual(self.builds[1].name, 'project1-test2')
1423 self.assertEqual(self.builds[2].name, 'project1-project2-integration')
1424 self.assertEqual(self.builds[3].name, 'project1-test1')
1425 self.assertEqual(self.builds[4].name, 'project1-test2')
1426 self.assertEqual(self.builds[5].name, 'project1-project2-integration')
1427 self.assertEqual(self.builds[6].name, 'project1-test1')
1428 self.assertEqual(self.builds[7].name, 'project1-test2')
1429 self.assertEqual(self.builds[8].name, 'project1-project2-integration')
James E. Blairec590122012-08-22 15:19:31 -07001430
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001431 self.release(self.builds[0])
James E. Blairec590122012-08-22 15:19:31 -07001432 self.waitUntilSettled()
1433
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001434 self.assertEqual(len(self.builds), 3) # test2,integration, merge for B
1435 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6)
James E. Blairec590122012-08-22 15:19:31 -07001436
James E. Blair08d19992016-08-10 15:25:31 -07001437 self.launch_server.hold_jobs_in_build = False
1438 self.launch_server.release()
James E. Blairec590122012-08-22 15:19:31 -07001439 self.waitUntilSettled()
1440
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001441 self.assertEqual(len(self.builds), 0)
1442 self.assertEqual(len(self.history), 20)
James E. Blaircaec0c52012-08-22 14:52:22 -07001443
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001444 self.assertEqual(A.data['status'], 'NEW')
1445 self.assertEqual(B.data['status'], 'MERGED')
1446 self.assertEqual(C.data['status'], 'MERGED')
1447 self.assertEqual(A.reported, 2)
1448 self.assertEqual(B.reported, 2)
1449 self.assertEqual(C.reported, 2)
James E. Blair4ec821f2012-08-23 15:28:28 -07001450
James E. Blairec056492016-07-22 09:45:56 -07001451 @skip("Disabled for early v3 development")
James E. Blair4ec821f2012-08-23 15:28:28 -07001452 def test_nonvoting_job(self):
1453 "Test that non-voting jobs don't vote."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001454
James E. Blair4ec821f2012-08-23 15:28:28 -07001455 A = self.fake_gerrit.addFakeChange('org/nonvoting-project',
1456 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001457 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07001458 self.launch_server.failJob('nonvoting-project-test2', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07001459 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4ec821f2012-08-23 15:28:28 -07001460
1461 self.waitUntilSettled()
James E. Blair4ec821f2012-08-23 15:28:28 -07001462
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001463 self.assertEqual(A.data['status'], 'MERGED')
1464 self.assertEqual(A.reported, 2)
1465 self.assertEqual(
1466 self.getJobFromHistory('nonvoting-project-merge').result,
1467 'SUCCESS')
1468 self.assertEqual(
1469 self.getJobFromHistory('nonvoting-project-test1').result,
1470 'SUCCESS')
1471 self.assertEqual(
1472 self.getJobFromHistory('nonvoting-project-test2').result,
1473 'FAILURE')
James E. Blaire0487072012-08-29 17:38:31 -07001474
James E. Blair5821bd92015-09-16 08:48:15 -07001475 for build in self.builds:
1476 self.assertEqual(build.parameters['ZUUL_VOTING'], '0')
1477
James E. Blairec056492016-07-22 09:45:56 -07001478 @skip("Disabled for early v3 development")
James E. Blaire0487072012-08-29 17:38:31 -07001479 def test_check_queue_success(self):
1480 "Test successful check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001481
James E. Blaire0487072012-08-29 17:38:31 -07001482 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1483 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1484
1485 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001486
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001487 self.assertEqual(A.data['status'], 'NEW')
1488 self.assertEqual(A.reported, 1)
1489 self.assertEqual(self.getJobFromHistory('project-merge').result,
1490 'SUCCESS')
1491 self.assertEqual(self.getJobFromHistory('project-test1').result,
1492 'SUCCESS')
1493 self.assertEqual(self.getJobFromHistory('project-test2').result,
1494 'SUCCESS')
James E. Blaire0487072012-08-29 17:38:31 -07001495
James E. Blairec056492016-07-22 09:45:56 -07001496 @skip("Disabled for early v3 development")
James E. Blaire0487072012-08-29 17:38:31 -07001497 def test_check_queue_failure(self):
1498 "Test failed check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001499
James E. Blaire0487072012-08-29 17:38:31 -07001500 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair08d19992016-08-10 15:25:31 -07001501 self.launch_server.failJob('project-test2', A)
James E. Blaire0487072012-08-29 17:38:31 -07001502 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1503
1504 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001505
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001506 self.assertEqual(A.data['status'], 'NEW')
1507 self.assertEqual(A.reported, 1)
1508 self.assertEqual(self.getJobFromHistory('project-merge').result,
James E. Blair78e31b32013-07-09 09:11:34 -07001509 'SUCCESS')
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001510 self.assertEqual(self.getJobFromHistory('project-test1').result,
1511 'SUCCESS')
1512 self.assertEqual(self.getJobFromHistory('project-test2').result,
1513 'FAILURE')
James E. Blair127bc182012-08-28 15:55:15 -07001514
James E. Blairec056492016-07-22 09:45:56 -07001515 @skip("Disabled for early v3 development")
James E. Blair127bc182012-08-28 15:55:15 -07001516 def test_dependent_behind_dequeue(self):
1517 "test that dependent changes behind dequeued changes work"
1518 # This complicated test is a reproduction of a real life bug
1519 self.sched.reconfigure(self.config)
James E. Blair127bc182012-08-28 15:55:15 -07001520
James E. Blair08d19992016-08-10 15:25:31 -07001521 self.launch_server.hold_jobs_in_build = True
James E. Blair127bc182012-08-28 15:55:15 -07001522 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1523 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1524 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
1525 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
1526 E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E')
1527 F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F')
1528 D.setDependsOn(C, 1)
1529 E.setDependsOn(D, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07001530 A.addApproval('code-review', 2)
1531 B.addApproval('code-review', 2)
1532 C.addApproval('code-review', 2)
1533 D.addApproval('code-review', 2)
1534 E.addApproval('code-review', 2)
1535 F.addApproval('code-review', 2)
James E. Blair127bc182012-08-28 15:55:15 -07001536
1537 A.fail_merge = True
James E. Blair127bc182012-08-28 15:55:15 -07001538
1539 # Change object re-use in the gerrit trigger is hidden if
1540 # changes are added in quick succession; waiting makes it more
1541 # like real life.
James E. Blair8b5408c2016-08-08 15:37:46 -07001542 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001543 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001544 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001545 self.waitUntilSettled()
1546
James E. Blair08d19992016-08-10 15:25:31 -07001547 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001548 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001549 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001550 self.waitUntilSettled()
1551
James E. Blair8b5408c2016-08-08 15:37:46 -07001552 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001553 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001554 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001555 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001556 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001557 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001558 self.fake_gerrit.addEvent(F.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001559 self.waitUntilSettled()
1560
James E. Blair08d19992016-08-10 15:25:31 -07001561 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001562 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001563 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001564 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001565 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001566 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001567 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001568 self.waitUntilSettled()
1569
1570 # all jobs running
James E. Blaire955e062012-10-08 09:49:03 -07001571
1572 # Grab pointers to the jobs we want to release before
1573 # releasing any, because list indexes may change as
1574 # the jobs complete.
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001575 a, b, c = self.builds[:3]
James E. Blaire955e062012-10-08 09:49:03 -07001576 a.release()
1577 b.release()
1578 c.release()
James E. Blair127bc182012-08-28 15:55:15 -07001579 self.waitUntilSettled()
1580
James E. Blair08d19992016-08-10 15:25:31 -07001581 self.launch_server.hold_jobs_in_build = False
1582 self.launch_server.release()
James E. Blair127bc182012-08-28 15:55:15 -07001583 self.waitUntilSettled()
1584
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001585 self.assertEqual(A.data['status'], 'NEW')
1586 self.assertEqual(B.data['status'], 'MERGED')
1587 self.assertEqual(C.data['status'], 'MERGED')
1588 self.assertEqual(D.data['status'], 'MERGED')
1589 self.assertEqual(E.data['status'], 'MERGED')
1590 self.assertEqual(F.data['status'], 'MERGED')
James E. Blair127bc182012-08-28 15:55:15 -07001591
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001592 self.assertEqual(A.reported, 2)
1593 self.assertEqual(B.reported, 2)
1594 self.assertEqual(C.reported, 2)
1595 self.assertEqual(D.reported, 2)
1596 self.assertEqual(E.reported, 2)
1597 self.assertEqual(F.reported, 2)
James E. Blair127bc182012-08-28 15:55:15 -07001598
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001599 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15)
1600 self.assertEqual(len(self.history), 44)
James E. Blair05fed602012-09-07 12:45:24 -07001601
James E. Blairec056492016-07-22 09:45:56 -07001602 @skip("Disabled for early v3 development")
James E. Blair05fed602012-09-07 12:45:24 -07001603 def test_merger_repack(self):
1604 "Test that the merger works after a repack"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001605
James E. Blair05fed602012-09-07 12:45:24 -07001606 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001607 A.addApproval('code-review', 2)
1608 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001609 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001610 self.assertEqual(self.getJobFromHistory('project-merge').result,
1611 'SUCCESS')
1612 self.assertEqual(self.getJobFromHistory('project-test1').result,
1613 'SUCCESS')
1614 self.assertEqual(self.getJobFromHistory('project-test2').result,
1615 'SUCCESS')
1616 self.assertEqual(A.data['status'], 'MERGED')
1617 self.assertEqual(A.reported, 2)
James E. Blair05fed602012-09-07 12:45:24 -07001618 self.assertEmptyQueues()
James E. Blair4ca985f2013-05-30 12:27:43 -07001619 self.worker.build_history = []
James E. Blair05fed602012-09-07 12:45:24 -07001620
Monty Taylorbc758832013-06-17 17:22:42 -04001621 path = os.path.join(self.git_root, "org/project")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001622 print(repack_repo(path))
James E. Blair05fed602012-09-07 12:45:24 -07001623
1624 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001625 A.addApproval('code-review', 2)
1626 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001627 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001628 self.assertEqual(self.getJobFromHistory('project-merge').result,
1629 'SUCCESS')
1630 self.assertEqual(self.getJobFromHistory('project-test1').result,
1631 'SUCCESS')
1632 self.assertEqual(self.getJobFromHistory('project-test2').result,
1633 'SUCCESS')
1634 self.assertEqual(A.data['status'], 'MERGED')
1635 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001636
James E. Blairec056492016-07-22 09:45:56 -07001637 @skip("Disabled for early v3 development")
James E. Blair4886f282012-11-15 09:27:33 -08001638 def test_merger_repack_large_change(self):
1639 "Test that the merger works with large changes after a repack"
1640 # https://bugs.launchpad.net/zuul/+bug/1078946
James E. Blairac2c3242014-01-24 13:38:51 -08001641 # This test assumes the repo is already cloned; make sure it is
Joshua Hesketh352264b2015-08-11 23:42:08 +10001642 url = self.fake_gerrit.getGitUrl(
James E. Blairac2c3242014-01-24 13:38:51 -08001643 self.sched.layout.projects['org/project1'])
James E. Blair4076e2b2014-01-28 12:42:20 -08001644 self.merge_server.merger.addProject('org/project1', url)
James E. Blair4886f282012-11-15 09:27:33 -08001645 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1646 A.addPatchset(large=True)
Monty Taylorbc758832013-06-17 17:22:42 -04001647 path = os.path.join(self.upstream_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001648 print(repack_repo(path))
Monty Taylorbc758832013-06-17 17:22:42 -04001649 path = os.path.join(self.git_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001650 print(repack_repo(path))
James E. Blair4886f282012-11-15 09:27:33 -08001651
James E. Blair8b5408c2016-08-08 15:37:46 -07001652 A.addApproval('code-review', 2)
1653 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4886f282012-11-15 09:27:33 -08001654 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001655 self.assertEqual(self.getJobFromHistory('project1-merge').result,
1656 'SUCCESS')
1657 self.assertEqual(self.getJobFromHistory('project1-test1').result,
1658 'SUCCESS')
1659 self.assertEqual(self.getJobFromHistory('project1-test2').result,
1660 'SUCCESS')
1661 self.assertEqual(A.data['status'], 'MERGED')
1662 self.assertEqual(A.reported, 2)
James E. Blair4886f282012-11-15 09:27:33 -08001663
James E. Blairec056492016-07-22 09:45:56 -07001664 @skip("Disabled for early v3 development")
James E. Blair7ee88a22012-09-12 18:59:31 +02001665 def test_nonexistent_job(self):
1666 "Test launching a job that doesn't exist"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001667 # Set to the state immediately after a restart
1668 self.resetGearmanServer()
1669 self.launcher.negative_function_cache_ttl = 0
James E. Blair7ee88a22012-09-12 18:59:31 +02001670
1671 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001672 A.addApproval('code-review', 2)
1673 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001674 # There may be a thread about to report a lost change
1675 while A.reported < 2:
1676 self.waitUntilSettled()
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001677 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001678 self.assertFalse(job_names)
1679 self.assertEqual(A.data['status'], 'NEW')
1680 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001681 self.assertEmptyQueues()
1682
1683 # Make sure things still work:
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001684 self.registerJobs()
James E. Blair7ee88a22012-09-12 18:59:31 +02001685 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001686 A.addApproval('code-review', 2)
1687 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001688 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001689 self.assertEqual(self.getJobFromHistory('project-merge').result,
1690 'SUCCESS')
1691 self.assertEqual(self.getJobFromHistory('project-test1').result,
1692 'SUCCESS')
1693 self.assertEqual(self.getJobFromHistory('project-test2').result,
1694 'SUCCESS')
1695 self.assertEqual(A.data['status'], 'MERGED')
1696 self.assertEqual(A.reported, 2)
James E. Blairf62d4282012-12-31 17:01:50 -08001697
James E. Blairec056492016-07-22 09:45:56 -07001698 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001699 def test_new_patchset_dequeues_old(self):
1700 "Test that a new patchset causes the old to be dequeued"
1701 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001702 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001703 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1704 M.setMerged()
1705
1706 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1707 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1708 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1709 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001710 A.addApproval('code-review', 2)
1711 B.addApproval('code-review', 2)
1712 C.addApproval('code-review', 2)
1713 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001714
1715 C.setDependsOn(B, 1)
1716 B.setDependsOn(A, 1)
1717 A.setDependsOn(M, 1)
1718
James E. Blair8b5408c2016-08-08 15:37:46 -07001719 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1720 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1721 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1722 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001723 self.waitUntilSettled()
1724
1725 B.addPatchset()
1726 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1727 self.waitUntilSettled()
1728
James E. Blair08d19992016-08-10 15:25:31 -07001729 self.launch_server.hold_jobs_in_build = False
1730 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001731 self.waitUntilSettled()
1732
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001733 self.assertEqual(A.data['status'], 'MERGED')
1734 self.assertEqual(A.reported, 2)
1735 self.assertEqual(B.data['status'], 'NEW')
1736 self.assertEqual(B.reported, 2)
1737 self.assertEqual(C.data['status'], 'NEW')
1738 self.assertEqual(C.reported, 2)
1739 self.assertEqual(D.data['status'], 'MERGED')
1740 self.assertEqual(D.reported, 2)
1741 self.assertEqual(len(self.history), 9) # 3 each for A, B, D.
James E. Blair2fa50962013-01-30 21:50:41 -08001742
James E. Blairec056492016-07-22 09:45:56 -07001743 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001744 def test_new_patchset_check(self):
1745 "Test a new patchset in check"
Antoine Mussobd86a312014-01-08 14:51:33 +01001746
James E. Blair08d19992016-08-10 15:25:31 -07001747 self.launch_server.hold_jobs_in_build = True
Antoine Mussobd86a312014-01-08 14:51:33 +01001748
1749 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairba437362015-02-07 11:41:52 -08001750 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1751 check_pipeline = self.sched.layout.pipelines['check']
1752
1753 # Add two git-dependent changes
1754 B.setDependsOn(A, 1)
1755 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1756 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001757 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1758 self.waitUntilSettled()
James E. Blairba437362015-02-07 11:41:52 -08001759
1760 # A live item, and a non-live/live pair
1761 items = check_pipeline.getAllItems()
1762 self.assertEqual(len(items), 3)
1763
1764 self.assertEqual(items[0].change.number, '1')
1765 self.assertEqual(items[0].change.patchset, '1')
1766 self.assertFalse(items[0].live)
1767
1768 self.assertEqual(items[1].change.number, '2')
1769 self.assertEqual(items[1].change.patchset, '1')
1770 self.assertTrue(items[1].live)
1771
1772 self.assertEqual(items[2].change.number, '1')
1773 self.assertEqual(items[2].change.patchset, '1')
1774 self.assertTrue(items[2].live)
1775
1776 # Add a new patchset to A
1777 A.addPatchset()
1778 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1779 self.waitUntilSettled()
1780
1781 # The live copy of A,1 should be gone, but the non-live and B
1782 # should continue, and we should have a new A,2
1783 items = check_pipeline.getAllItems()
1784 self.assertEqual(len(items), 3)
1785
1786 self.assertEqual(items[0].change.number, '1')
1787 self.assertEqual(items[0].change.patchset, '1')
1788 self.assertFalse(items[0].live)
1789
1790 self.assertEqual(items[1].change.number, '2')
1791 self.assertEqual(items[1].change.patchset, '1')
1792 self.assertTrue(items[1].live)
1793
1794 self.assertEqual(items[2].change.number, '1')
1795 self.assertEqual(items[2].change.patchset, '2')
1796 self.assertTrue(items[2].live)
1797
1798 # Add a new patchset to B
1799 B.addPatchset()
1800 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1801 self.waitUntilSettled()
1802
1803 # The live copy of B,1 should be gone, and it's non-live copy of A,1
1804 # but we should have a new B,2 (still based on A,1)
1805 items = check_pipeline.getAllItems()
1806 self.assertEqual(len(items), 3)
1807
1808 self.assertEqual(items[0].change.number, '1')
1809 self.assertEqual(items[0].change.patchset, '2')
1810 self.assertTrue(items[0].live)
1811
1812 self.assertEqual(items[1].change.number, '1')
1813 self.assertEqual(items[1].change.patchset, '1')
1814 self.assertFalse(items[1].live)
1815
1816 self.assertEqual(items[2].change.number, '2')
1817 self.assertEqual(items[2].change.patchset, '2')
1818 self.assertTrue(items[2].live)
1819
1820 self.builds[0].release()
1821 self.waitUntilSettled()
1822 self.builds[0].release()
1823 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001824 self.launch_server.hold_jobs_in_build = False
1825 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001826 self.waitUntilSettled()
1827
1828 self.assertEqual(A.reported, 1)
1829 self.assertEqual(B.reported, 1)
1830 self.assertEqual(self.history[0].result, 'ABORTED')
1831 self.assertEqual(self.history[0].changes, '1,1')
1832 self.assertEqual(self.history[1].result, 'ABORTED')
1833 self.assertEqual(self.history[1].changes, '1,1 2,1')
1834 self.assertEqual(self.history[2].result, 'SUCCESS')
1835 self.assertEqual(self.history[2].changes, '1,2')
1836 self.assertEqual(self.history[3].result, 'SUCCESS')
1837 self.assertEqual(self.history[3].changes, '1,1 2,2')
1838
1839 def test_abandoned_gate(self):
1840 "Test that an abandoned change is dequeued from gate"
1841
James E. Blair08d19992016-08-10 15:25:31 -07001842 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001843
1844 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001845 A.addApproval('code-review', 2)
1846 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairba437362015-02-07 11:41:52 -08001847 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001848 self.assertEqual(len(self.builds), 1, "One job being built (on hold)")
1849 self.assertEqual(self.builds[0].name, 'project-merge')
1850
1851 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1852 self.waitUntilSettled()
1853
James E. Blair08d19992016-08-10 15:25:31 -07001854 self.launch_server.release('.*-merge')
Antoine Mussobd86a312014-01-08 14:51:33 +01001855 self.waitUntilSettled()
1856
Arie5b4048c2016-10-05 16:12:06 +03001857 self.assertBuilds([])
1858 self.assertHistory([
1859 dict(name='project-merge', result='ABORTED', changes='1,1')],
1860 ordered=False)
James E. Blairba437362015-02-07 11:41:52 -08001861 self.assertEqual(A.reported, 1,
1862 "Abandoned gate change should report only start")
1863
James E. Blairec056492016-07-22 09:45:56 -07001864 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001865 def test_abandoned_check(self):
1866 "Test that an abandoned change is dequeued from check"
1867
James E. Blair08d19992016-08-10 15:25:31 -07001868 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001869
1870 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1871 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1872 check_pipeline = self.sched.layout.pipelines['check']
1873
1874 # Add two git-dependent changes
1875 B.setDependsOn(A, 1)
1876 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1877 self.waitUntilSettled()
1878 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1879 self.waitUntilSettled()
1880 # A live item, and a non-live/live pair
1881 items = check_pipeline.getAllItems()
1882 self.assertEqual(len(items), 3)
1883
1884 self.assertEqual(items[0].change.number, '1')
1885 self.assertFalse(items[0].live)
1886
1887 self.assertEqual(items[1].change.number, '2')
1888 self.assertTrue(items[1].live)
1889
1890 self.assertEqual(items[2].change.number, '1')
1891 self.assertTrue(items[2].live)
1892
1893 # Abandon A
1894 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1895 self.waitUntilSettled()
1896
1897 # The live copy of A should be gone, but the non-live and B
1898 # should continue
1899 items = check_pipeline.getAllItems()
1900 self.assertEqual(len(items), 2)
1901
1902 self.assertEqual(items[0].change.number, '1')
1903 self.assertFalse(items[0].live)
1904
1905 self.assertEqual(items[1].change.number, '2')
1906 self.assertTrue(items[1].live)
1907
James E. Blair08d19992016-08-10 15:25:31 -07001908 self.launch_server.hold_jobs_in_build = False
1909 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001910 self.waitUntilSettled()
1911
1912 self.assertEqual(len(self.history), 4)
1913 self.assertEqual(self.history[0].result, 'ABORTED',
Antoine Mussobd86a312014-01-08 14:51:33 +01001914 'Build should have been aborted')
1915 self.assertEqual(A.reported, 0, "Abandoned change should not report")
James E. Blairba437362015-02-07 11:41:52 -08001916 self.assertEqual(B.reported, 1, "Change should report")
Antoine Mussobd86a312014-01-08 14:51:33 +01001917
James E. Blairec056492016-07-22 09:45:56 -07001918 @skip("Disabled for early v3 development")
Steve Varnau7b78b312015-04-03 14:49:46 -07001919 def test_abandoned_not_timer(self):
1920 "Test that an abandoned change does not cancel timer jobs"
1921
James E. Blair08d19992016-08-10 15:25:31 -07001922 self.launch_server.hold_jobs_in_build = True
Steve Varnau7b78b312015-04-03 14:49:46 -07001923
1924 # Start timer trigger - also org/project
James E. Blairf84026c2015-12-08 16:11:46 -08001925 self.updateConfigLayout(
1926 'tests/fixtures/layout-idle.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001927 self.sched.reconfigure(self.config)
1928 self.registerJobs()
1929 # The pipeline triggers every second, so we should have seen
1930 # several by now.
1931 time.sleep(5)
1932 self.waitUntilSettled()
1933 # Stop queuing timer triggered jobs so that the assertions
1934 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08001935 self.updateConfigLayout(
1936 'tests/fixtures/layout-no-timer.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001937 self.sched.reconfigure(self.config)
1938 self.registerJobs()
1939 self.assertEqual(len(self.builds), 2, "Two timer jobs")
1940
1941 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1942 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1943 self.waitUntilSettled()
1944 self.assertEqual(len(self.builds), 3, "One change plus two timer jobs")
1945
1946 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1947 self.waitUntilSettled()
1948
1949 self.assertEqual(len(self.builds), 2, "Two timer jobs remain")
1950
James E. Blair08d19992016-08-10 15:25:31 -07001951 self.launch_server.release()
Steve Varnau7b78b312015-04-03 14:49:46 -07001952 self.waitUntilSettled()
1953
James E. Blairec056492016-07-22 09:45:56 -07001954 @skip("Disabled for early v3 development")
Arx Cruzb1b010d2013-10-28 19:49:59 -02001955 def test_zuul_url_return(self):
1956 "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf"
James E. Blair4076e2b2014-01-28 12:42:20 -08001957 self.assertTrue(self.sched.config.has_option('merger', 'zuul_url'))
James E. Blair08d19992016-08-10 15:25:31 -07001958 self.launch_server.hold_jobs_in_build = True
Arx Cruzb1b010d2013-10-28 19:49:59 -02001959
1960 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001961 A.addApproval('code-review', 2)
1962 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Arx Cruzb1b010d2013-10-28 19:49:59 -02001963 self.waitUntilSettled()
1964
1965 self.assertEqual(len(self.builds), 1)
1966 for build in self.builds:
1967 self.assertTrue('ZUUL_URL' in build.parameters)
1968
James E. Blair08d19992016-08-10 15:25:31 -07001969 self.launch_server.hold_jobs_in_build = False
1970 self.launch_server.release()
Arx Cruzb1b010d2013-10-28 19:49:59 -02001971 self.waitUntilSettled()
1972
James E. Blairec056492016-07-22 09:45:56 -07001973 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001974 def test_new_patchset_dequeues_old_on_head(self):
1975 "Test that a new patchset causes the old to be dequeued (at head)"
1976 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001977 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001978 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1979 M.setMerged()
1980 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1981 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1982 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1983 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001984 A.addApproval('code-review', 2)
1985 B.addApproval('code-review', 2)
1986 C.addApproval('code-review', 2)
1987 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001988
1989 C.setDependsOn(B, 1)
1990 B.setDependsOn(A, 1)
1991 A.setDependsOn(M, 1)
1992
James E. Blair8b5408c2016-08-08 15:37:46 -07001993 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1994 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1995 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1996 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001997 self.waitUntilSettled()
1998
1999 A.addPatchset()
2000 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2001 self.waitUntilSettled()
2002
James E. Blair08d19992016-08-10 15:25:31 -07002003 self.launch_server.hold_jobs_in_build = False
2004 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002005 self.waitUntilSettled()
2006
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002007 self.assertEqual(A.data['status'], 'NEW')
2008 self.assertEqual(A.reported, 2)
2009 self.assertEqual(B.data['status'], 'NEW')
2010 self.assertEqual(B.reported, 2)
2011 self.assertEqual(C.data['status'], 'NEW')
2012 self.assertEqual(C.reported, 2)
2013 self.assertEqual(D.data['status'], 'MERGED')
2014 self.assertEqual(D.reported, 2)
2015 self.assertEqual(len(self.history), 7)
James E. Blair2fa50962013-01-30 21:50:41 -08002016
James E. Blairec056492016-07-22 09:45:56 -07002017 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002018 def test_new_patchset_dequeues_old_without_dependents(self):
2019 "Test that a new patchset causes only the old to be dequeued"
James E. Blair08d19992016-08-10 15:25:31 -07002020 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002021 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2022 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2023 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07002024 A.addApproval('code-review', 2)
2025 B.addApproval('code-review', 2)
2026 C.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08002027
James E. Blair8b5408c2016-08-08 15:37:46 -07002028 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2029 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2030 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08002031 self.waitUntilSettled()
2032
2033 B.addPatchset()
2034 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2035 self.waitUntilSettled()
2036
James E. Blair08d19992016-08-10 15:25:31 -07002037 self.launch_server.hold_jobs_in_build = False
2038 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002039 self.waitUntilSettled()
2040
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002041 self.assertEqual(A.data['status'], 'MERGED')
2042 self.assertEqual(A.reported, 2)
2043 self.assertEqual(B.data['status'], 'NEW')
2044 self.assertEqual(B.reported, 2)
2045 self.assertEqual(C.data['status'], 'MERGED')
2046 self.assertEqual(C.reported, 2)
2047 self.assertEqual(len(self.history), 9)
James E. Blair2fa50962013-01-30 21:50:41 -08002048
James E. Blairec056492016-07-22 09:45:56 -07002049 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002050 def test_new_patchset_dequeues_old_independent_queue(self):
2051 "Test that a new patchset causes the old to be dequeued (independent)"
James E. Blair08d19992016-08-10 15:25:31 -07002052 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002053 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2054 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2055 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
2056 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2057 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2058 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2059 self.waitUntilSettled()
2060
2061 B.addPatchset()
2062 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2063 self.waitUntilSettled()
2064
James E. Blair08d19992016-08-10 15:25:31 -07002065 self.launch_server.hold_jobs_in_build = False
2066 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002067 self.waitUntilSettled()
2068
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002069 self.assertEqual(A.data['status'], 'NEW')
2070 self.assertEqual(A.reported, 1)
2071 self.assertEqual(B.data['status'], 'NEW')
2072 self.assertEqual(B.reported, 1)
2073 self.assertEqual(C.data['status'], 'NEW')
2074 self.assertEqual(C.reported, 1)
2075 self.assertEqual(len(self.history), 10)
2076 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002077
James E. Blairec056492016-07-22 09:45:56 -07002078 @skip("Disabled for early v3 development")
James E. Blair18c64442014-03-18 10:14:45 -07002079 def test_noop_job(self):
2080 "Test that the internal noop job works"
2081 A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002082 A.addApproval('code-review', 2)
2083 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair18c64442014-03-18 10:14:45 -07002084 self.waitUntilSettled()
2085
2086 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2087 self.assertTrue(self.sched._areAllBuildsComplete())
2088 self.assertEqual(len(self.history), 0)
2089 self.assertEqual(A.data['status'], 'MERGED')
2090 self.assertEqual(A.reported, 2)
2091
James E. Blairec056492016-07-22 09:45:56 -07002092 @skip("Disabled for early v3 development")
Evgeny Antyshevd6e546c2015-06-11 15:13:57 +00002093 def test_no_job_project(self):
2094 "Test that reports with no jobs don't get sent"
2095 A = self.fake_gerrit.addFakeChange('org/no-jobs-project',
2096 'master', 'A')
2097 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2098 self.waitUntilSettled()
2099
2100 # Change wasn't reported to
2101 self.assertEqual(A.reported, False)
2102
2103 # Check queue is empty afterwards
2104 check_pipeline = self.sched.layout.pipelines['check']
2105 items = check_pipeline.getAllItems()
2106 self.assertEqual(len(items), 0)
2107
2108 self.assertEqual(len(self.history), 0)
2109
James E. Blairec056492016-07-22 09:45:56 -07002110 @skip("Disabled for early v3 development")
James E. Blair7d0dedc2013-02-21 17:26:09 -08002111 def test_zuul_refs(self):
2112 "Test that zuul refs exist and have the right changes"
James E. Blair08d19992016-08-10 15:25:31 -07002113 self.launch_server.hold_jobs_in_build = True
James E. Blair7d0dedc2013-02-21 17:26:09 -08002114 M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1')
2115 M1.setMerged()
2116 M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2')
2117 M2.setMerged()
2118
2119 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2120 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2121 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
2122 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07002123 A.addApproval('code-review', 2)
2124 B.addApproval('code-review', 2)
2125 C.addApproval('code-review', 2)
2126 D.addApproval('code-review', 2)
2127 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2128 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2129 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2130 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002131
2132 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002133 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002134 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002135 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002136 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002137 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002138 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002139 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002140 self.waitUntilSettled()
2141
James E. Blair7d0dedc2013-02-21 17:26:09 -08002142 a_zref = b_zref = c_zref = d_zref = None
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002143 for x in self.builds:
James E. Blair7d0dedc2013-02-21 17:26:09 -08002144 if x.parameters['ZUUL_CHANGE'] == '3':
2145 a_zref = x.parameters['ZUUL_REF']
2146 if x.parameters['ZUUL_CHANGE'] == '4':
2147 b_zref = x.parameters['ZUUL_REF']
2148 if x.parameters['ZUUL_CHANGE'] == '5':
2149 c_zref = x.parameters['ZUUL_REF']
2150 if x.parameters['ZUUL_CHANGE'] == '6':
2151 d_zref = x.parameters['ZUUL_REF']
2152
2153 # There are... four... refs.
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002154 self.assertIsNotNone(a_zref)
2155 self.assertIsNotNone(b_zref)
2156 self.assertIsNotNone(c_zref)
2157 self.assertIsNotNone(d_zref)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002158
2159 # And they should all be different
2160 refs = set([a_zref, b_zref, c_zref, d_zref])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002161 self.assertEqual(len(refs), 4)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002162
2163 # a ref should have a, not b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002164 self.assertTrue(self.ref_has_change(a_zref, A))
2165 self.assertFalse(self.ref_has_change(a_zref, B))
2166 self.assertFalse(self.ref_has_change(a_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002167
2168 # b ref should have a and b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002169 self.assertTrue(self.ref_has_change(b_zref, A))
2170 self.assertTrue(self.ref_has_change(b_zref, B))
2171 self.assertFalse(self.ref_has_change(b_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002172
2173 # c ref should have a and b in 1, c in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002174 self.assertTrue(self.ref_has_change(c_zref, A))
2175 self.assertTrue(self.ref_has_change(c_zref, B))
2176 self.assertTrue(self.ref_has_change(c_zref, C))
2177 self.assertFalse(self.ref_has_change(c_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002178
2179 # d ref should have a and b in 1, c and d in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002180 self.assertTrue(self.ref_has_change(d_zref, A))
2181 self.assertTrue(self.ref_has_change(d_zref, B))
2182 self.assertTrue(self.ref_has_change(d_zref, C))
2183 self.assertTrue(self.ref_has_change(d_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002184
James E. Blair08d19992016-08-10 15:25:31 -07002185 self.launch_server.hold_jobs_in_build = False
2186 self.launch_server.release()
James E. Blair7d0dedc2013-02-21 17:26:09 -08002187 self.waitUntilSettled()
2188
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002189 self.assertEqual(A.data['status'], 'MERGED')
2190 self.assertEqual(A.reported, 2)
2191 self.assertEqual(B.data['status'], 'MERGED')
2192 self.assertEqual(B.reported, 2)
2193 self.assertEqual(C.data['status'], 'MERGED')
2194 self.assertEqual(C.reported, 2)
2195 self.assertEqual(D.data['status'], 'MERGED')
2196 self.assertEqual(D.reported, 2)
James E. Blair70c71582013-03-06 08:50:50 -08002197
James E. Blairec056492016-07-22 09:45:56 -07002198 @skip("Disabled for early v3 development")
James E. Blair4a28a882013-08-23 15:17:33 -07002199 def test_rerun_on_error(self):
2200 "Test that if a worker fails to run a job, it is run again"
James E. Blair08d19992016-08-10 15:25:31 -07002201 self.launch_server.hold_jobs_in_build = True
James E. Blair4a28a882013-08-23 15:17:33 -07002202 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002203 A.addApproval('code-review', 2)
2204 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4a28a882013-08-23 15:17:33 -07002205 self.waitUntilSettled()
2206
2207 self.builds[0].run_error = True
James E. Blair08d19992016-08-10 15:25:31 -07002208 self.launch_server.hold_jobs_in_build = False
2209 self.launch_server.release()
James E. Blair4a28a882013-08-23 15:17:33 -07002210 self.waitUntilSettled()
2211 self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1)
2212 self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3)
2213
James E. Blairec056492016-07-22 09:45:56 -07002214 @skip("Disabled for early v3 development")
James E. Blair412e5582013-04-22 15:50:12 -07002215 def test_statsd(self):
2216 "Test each of the statsd methods used in the scheduler"
2217 import extras
2218 statsd = extras.try_import('statsd.statsd')
2219 statsd.incr('test-incr')
2220 statsd.timing('test-timing', 3)
Alex Gaynor813d39b2014-05-17 16:17:16 -07002221 statsd.gauge('test-gauge', 12)
James E. Blair412e5582013-04-22 15:50:12 -07002222 self.assertReportedStat('test-incr', '1|c')
2223 self.assertReportedStat('test-timing', '3|ms')
Alex Gaynor813d39b2014-05-17 16:17:16 -07002224 self.assertReportedStat('test-gauge', '12|g')
James E. Blair412e5582013-04-22 15:50:12 -07002225
James E. Blairec056492016-07-22 09:45:56 -07002226 @skip("Disabled for early v3 development")
James E. Blairdad52252014-02-07 16:59:17 -08002227 def test_stuck_job_cleanup(self):
2228 "Test that pending jobs are cleaned up if removed from layout"
James E. Blair18c64442014-03-18 10:14:45 -07002229 # This job won't be registered at startup because it is not in
2230 # the standard layout, but we need it to already be registerd
2231 # for when we reconfigure, as that is when Zuul will attempt
2232 # to run the new job.
2233 self.worker.registerFunction('build:gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002234 self.gearman_server.hold_jobs_in_queue = True
2235 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002236 A.addApproval('code-review', 2)
2237 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairdad52252014-02-07 16:59:17 -08002238 self.waitUntilSettled()
2239 self.assertEqual(len(self.gearman_server.getQueue()), 1)
2240
James E. Blairf84026c2015-12-08 16:11:46 -08002241 self.updateConfigLayout(
2242 'tests/fixtures/layout-no-jobs.yaml')
James E. Blairdad52252014-02-07 16:59:17 -08002243 self.sched.reconfigure(self.config)
2244 self.waitUntilSettled()
2245
James E. Blair18c64442014-03-18 10:14:45 -07002246 self.gearman_server.release('gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002247 self.waitUntilSettled()
2248 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2249 self.assertTrue(self.sched._areAllBuildsComplete())
2250
2251 self.assertEqual(len(self.history), 1)
James E. Blair18c64442014-03-18 10:14:45 -07002252 self.assertEqual(self.history[0].name, 'gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002253 self.assertEqual(self.history[0].result, 'SUCCESS')
2254
James E. Blairec056492016-07-22 09:45:56 -07002255 @skip("Disabled for early v3 development")
James E. Blair879dafb2015-07-17 14:04:49 -07002256 def test_file_head(self):
2257 # This is a regression test for an observed bug. A change
2258 # with a file named "HEAD" in the root directory of the repo
2259 # was processed by a merger. It then was unable to reset the
2260 # repo because of:
2261 # GitCommandError: 'git reset --hard HEAD' returned
2262 # with exit code 128
2263 # stderr: 'fatal: ambiguous argument 'HEAD': both revision
2264 # and filename
2265 # Use '--' to separate filenames from revisions'
2266
2267 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2268 A.addPatchset(['HEAD'])
2269 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2270
2271 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2272 self.waitUntilSettled()
2273
2274 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2275 self.waitUntilSettled()
2276
2277 self.assertIn('Build succeeded', A.messages[0])
2278 self.assertIn('Build succeeded', B.messages[0])
2279
James E. Blairec056492016-07-22 09:45:56 -07002280 @skip("Disabled for early v3 development")
James E. Blair70c71582013-03-06 08:50:50 -08002281 def test_file_jobs(self):
2282 "Test that file jobs run only when appropriate"
2283 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2284 A.addPatchset(['pip-requires'])
2285 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002286 A.addApproval('code-review', 2)
2287 B.addApproval('code-review', 2)
2288 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2289 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair70c71582013-03-06 08:50:50 -08002290 self.waitUntilSettled()
2291
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002292 testfile_jobs = [x for x in self.history
James E. Blair70c71582013-03-06 08:50:50 -08002293 if x.name == 'project-testfile']
2294
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002295 self.assertEqual(len(testfile_jobs), 1)
2296 self.assertEqual(testfile_jobs[0].changes, '1,2')
2297 self.assertEqual(A.data['status'], 'MERGED')
2298 self.assertEqual(A.reported, 2)
2299 self.assertEqual(B.data['status'], 'MERGED')
2300 self.assertEqual(B.reported, 2)
James E. Blair3c5e5b52013-04-26 11:17:03 -07002301
James E. Blairec056492016-07-22 09:45:56 -07002302 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002303 def _test_skip_if_jobs(self, branch, should_skip):
2304 "Test that jobs with a skip-if filter run only when appropriate"
James E. Blairf84026c2015-12-08 16:11:46 -08002305 self.updateConfigLayout(
2306 'tests/fixtures/layout-skip-if.yaml')
Maru Newby3fe5f852015-01-13 04:22:14 +00002307 self.sched.reconfigure(self.config)
2308 self.registerJobs()
2309
2310 change = self.fake_gerrit.addFakeChange('org/project',
2311 branch,
2312 'test skip-if')
2313 self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1))
2314 self.waitUntilSettled()
2315
2316 tested_change_ids = [x.changes[0] for x in self.history
2317 if x.name == 'project-test-skip-if']
2318
2319 if should_skip:
2320 self.assertEqual([], tested_change_ids)
2321 else:
2322 self.assertIn(change.data['number'], tested_change_ids)
2323
James E. Blairec056492016-07-22 09:45:56 -07002324 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002325 def test_skip_if_match_skips_job(self):
2326 self._test_skip_if_jobs(branch='master', should_skip=True)
2327
James E. Blairec056492016-07-22 09:45:56 -07002328 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002329 def test_skip_if_no_match_runs_job(self):
2330 self._test_skip_if_jobs(branch='mp', should_skip=False)
2331
James E. Blairec056492016-07-22 09:45:56 -07002332 @skip("Disabled for early v3 development")
James E. Blair3c5e5b52013-04-26 11:17:03 -07002333 def test_test_config(self):
2334 "Test that we can test the config"
James E. Blairf84026c2015-12-08 16:11:46 -08002335 self.sched.testConfig(self.config.get('zuul', 'tenant_config'),
Joshua Hesketh352264b2015-08-11 23:42:08 +10002336 self.connections)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002337
James E. Blairec056492016-07-22 09:45:56 -07002338 @skip("Disabled for early v3 development")
James E. Blairc8a1e052014-02-25 09:29:26 -08002339 def test_queue_names(self):
2340 "Test shared change queue names"
2341 project1 = self.sched.layout.projects['org/project1']
2342 project2 = self.sched.layout.projects['org/project2']
2343 q1 = self.sched.layout.pipelines['gate'].getQueue(project1)
2344 q2 = self.sched.layout.pipelines['gate'].getQueue(project2)
2345 self.assertEqual(q1.name, 'integration')
2346 self.assertEqual(q2.name, 'integration')
2347
James E. Blairf84026c2015-12-08 16:11:46 -08002348 self.updateConfigLayout(
2349 'tests/fixtures/layout-bad-queue.yaml')
James E. Blairc8a1e052014-02-25 09:29:26 -08002350 with testtools.ExpectedException(
2351 Exception, "More than one name assigned to change queue"):
2352 self.sched.reconfigure(self.config)
2353
James E. Blairec056492016-07-22 09:45:56 -07002354 @skip("Disabled for early v3 development")
James E. Blair64ed6f22013-07-10 14:07:23 -07002355 def test_queue_precedence(self):
2356 "Test that queue precedence works"
2357
2358 self.gearman_server.hold_jobs_in_queue = True
James E. Blair08d19992016-08-10 15:25:31 -07002359 self.launch_server.hold_jobs_in_build = True
James E. Blair64ed6f22013-07-10 14:07:23 -07002360 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2361 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
James E. Blair8b5408c2016-08-08 15:37:46 -07002362 A.addApproval('code-review', 2)
2363 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair64ed6f22013-07-10 14:07:23 -07002364
2365 self.waitUntilSettled()
2366 self.gearman_server.hold_jobs_in_queue = False
2367 self.gearman_server.release()
2368 self.waitUntilSettled()
2369
James E. Blair8de58bd2013-07-18 16:23:33 -07002370 # Run one build at a time to ensure non-race order:
James E. Blairb8c16472015-05-05 14:55:26 -07002371 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07002372 self.launch_server.hold_jobs_in_build = False
James E. Blair8de58bd2013-07-18 16:23:33 -07002373 self.waitUntilSettled()
2374
James E. Blair64ed6f22013-07-10 14:07:23 -07002375 self.log.debug(self.history)
2376 self.assertEqual(self.history[0].pipeline, 'gate')
2377 self.assertEqual(self.history[1].pipeline, 'check')
2378 self.assertEqual(self.history[2].pipeline, 'gate')
2379 self.assertEqual(self.history[3].pipeline, 'gate')
2380 self.assertEqual(self.history[4].pipeline, 'check')
2381 self.assertEqual(self.history[5].pipeline, 'check')
2382
James E. Blairec056492016-07-22 09:45:56 -07002383 @skip("Disabled for early v3 development")
Clark Boylana5edbe42014-06-03 16:39:10 -07002384 def test_json_status(self):
James E. Blair1843a552013-07-03 14:19:52 -07002385 "Test that we can retrieve JSON status info"
James E. Blair08d19992016-08-10 15:25:31 -07002386 self.launch_server.hold_jobs_in_build = True
James E. Blair1843a552013-07-03 14:19:52 -07002387 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002388 A.addApproval('code-review', 2)
2389 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1843a552013-07-03 14:19:52 -07002390 self.waitUntilSettled()
2391
James E. Blair08d19992016-08-10 15:25:31 -07002392 self.launch_server.release('project-merge')
James E. Blairb7273ef2016-04-19 08:58:51 -07002393 self.waitUntilSettled()
2394
James E. Blair1843a552013-07-03 14:19:52 -07002395 port = self.webapp.server.socket.getsockname()[1]
2396
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002397 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2398 f = urllib.request.urlopen(req)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002399 headers = f.info()
2400 self.assertIn('Content-Length', headers)
2401 self.assertIn('Content-Type', headers)
Sachi Kingdc963fc2016-03-23 16:00:33 +11002402 self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$',
2403 headers['Content-Type']))
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002404 self.assertIn('Access-Control-Allow-Origin', headers)
2405 self.assertIn('Cache-Control', headers)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002406 self.assertIn('Last-Modified', headers)
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002407 self.assertIn('Expires', headers)
James E. Blair1843a552013-07-03 14:19:52 -07002408 data = f.read()
2409
James E. Blair08d19992016-08-10 15:25:31 -07002410 self.launch_server.hold_jobs_in_build = False
2411 self.launch_server.release()
James E. Blair1843a552013-07-03 14:19:52 -07002412 self.waitUntilSettled()
2413
2414 data = json.loads(data)
James E. Blairb7273ef2016-04-19 08:58:51 -07002415 status_jobs = []
James E. Blair1843a552013-07-03 14:19:52 -07002416 for p in data['pipelines']:
2417 for q in p['change_queues']:
James E. Blairbfb8e042014-12-30 17:01:44 -08002418 if p['name'] in ['gate', 'conflict']:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002419 self.assertEqual(q['window'], 20)
2420 else:
2421 self.assertEqual(q['window'], 0)
James E. Blair1843a552013-07-03 14:19:52 -07002422 for head in q['heads']:
2423 for change in head:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002424 self.assertTrue(change['active'])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002425 self.assertEqual(change['id'], '1,1')
James E. Blair1843a552013-07-03 14:19:52 -07002426 for job in change['jobs']:
James E. Blairb7273ef2016-04-19 08:58:51 -07002427 status_jobs.append(job)
2428 self.assertEqual('project-merge', status_jobs[0]['name'])
2429 self.assertEqual('https://server/job/project-merge/0/',
2430 status_jobs[0]['url'])
2431 self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0',
2432 status_jobs[0]['report_url'])
2433
2434 self.assertEqual('project-test1', status_jobs[1]['name'])
2435 self.assertEqual('https://server/job/project-test1/1/',
2436 status_jobs[1]['url'])
2437 self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1',
2438 status_jobs[1]['report_url'])
2439
2440 self.assertEqual('project-test2', status_jobs[2]['name'])
2441 self.assertEqual('https://server/job/project-test2/2/',
2442 status_jobs[2]['url'])
2443 self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2',
2444 status_jobs[2]['report_url'])
James E. Blair1843a552013-07-03 14:19:52 -07002445
James E. Blairec056492016-07-22 09:45:56 -07002446 @skip("Disabled for early v3 development")
James E. Blairc3d428e2013-12-03 15:06:48 -08002447 def test_merging_queues(self):
2448 "Test that transitively-connected change queues are merged"
James E. Blairf84026c2015-12-08 16:11:46 -08002449 self.updateConfigLayout(
2450 'tests/fixtures/layout-merge-queues.yaml')
James E. Blairc3d428e2013-12-03 15:06:48 -08002451 self.sched.reconfigure(self.config)
2452 self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1)
2453
James E. Blairec056492016-07-22 09:45:56 -07002454 @skip("Disabled for early v3 development")
James E. Blairaf17a972016-02-03 15:07:18 -08002455 def test_mutex(self):
2456 "Test job mutexes"
2457 self.config.set('zuul', 'layout_config',
2458 'tests/fixtures/layout-mutex.yaml')
2459 self.sched.reconfigure(self.config)
2460
James E. Blair08d19992016-08-10 15:25:31 -07002461 self.launch_server.hold_jobs_in_build = True
James E. Blairaf17a972016-02-03 15:07:18 -08002462 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2463 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2464 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2465
2466 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2467 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2468 self.waitUntilSettled()
2469 self.assertEqual(len(self.builds), 3)
2470 self.assertEqual(self.builds[0].name, 'project-test1')
2471 self.assertEqual(self.builds[1].name, 'mutex-one')
2472 self.assertEqual(self.builds[2].name, 'project-test1')
2473
James E. Blair08d19992016-08-10 15:25:31 -07002474 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002475 self.waitUntilSettled()
2476
2477 self.assertEqual(len(self.builds), 3)
2478 self.assertEqual(self.builds[0].name, 'project-test1')
2479 self.assertEqual(self.builds[1].name, 'project-test1')
2480 self.assertEqual(self.builds[2].name, 'mutex-two')
2481 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2482
James E. Blair08d19992016-08-10 15:25:31 -07002483 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002484 self.waitUntilSettled()
2485
2486 self.assertEqual(len(self.builds), 3)
2487 self.assertEqual(self.builds[0].name, 'project-test1')
2488 self.assertEqual(self.builds[1].name, 'project-test1')
2489 self.assertEqual(self.builds[2].name, 'mutex-one')
2490 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2491
James E. Blair08d19992016-08-10 15:25:31 -07002492 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002493 self.waitUntilSettled()
2494
2495 self.assertEqual(len(self.builds), 3)
2496 self.assertEqual(self.builds[0].name, 'project-test1')
2497 self.assertEqual(self.builds[1].name, 'project-test1')
2498 self.assertEqual(self.builds[2].name, 'mutex-two')
2499 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2500
James E. Blair08d19992016-08-10 15:25:31 -07002501 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002502 self.waitUntilSettled()
2503
2504 self.assertEqual(len(self.builds), 2)
2505 self.assertEqual(self.builds[0].name, 'project-test1')
2506 self.assertEqual(self.builds[1].name, 'project-test1')
2507 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2508
James E. Blair08d19992016-08-10 15:25:31 -07002509 self.launch_server.hold_jobs_in_build = False
2510 self.launch_server.release()
James E. Blairaf17a972016-02-03 15:07:18 -08002511
2512 self.waitUntilSettled()
2513 self.assertEqual(len(self.builds), 0)
2514
2515 self.assertEqual(A.reported, 1)
2516 self.assertEqual(B.reported, 1)
2517 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2518
James E. Blairec056492016-07-22 09:45:56 -07002519 @skip("Disabled for early v3 development")
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002520 def test_node_label(self):
2521 "Test that a job runs on a specific node label"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002522 self.worker.registerFunction('build:node-project-test1:debian')
2523
2524 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002525 A.addApproval('code-review', 2)
2526 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002527 self.waitUntilSettled()
James E. Blair4ca985f2013-05-30 12:27:43 -07002528
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002529 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2530 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2531 'debian')
2532 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
James E. Blaircdccd972013-07-01 12:10:22 -07002533
James E. Blairec056492016-07-22 09:45:56 -07002534 @skip("Disabled for early v3 development")
James E. Blaircdccd972013-07-01 12:10:22 -07002535 def test_live_reconfiguration(self):
2536 "Test that live reconfiguration works"
James E. Blair08d19992016-08-10 15:25:31 -07002537 self.launch_server.hold_jobs_in_build = True
James E. Blaircdccd972013-07-01 12:10:22 -07002538 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002539 A.addApproval('code-review', 2)
2540 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircdccd972013-07-01 12:10:22 -07002541 self.waitUntilSettled()
2542
2543 self.sched.reconfigure(self.config)
2544
James E. Blair08d19992016-08-10 15:25:31 -07002545 self.launch_server.hold_jobs_in_build = False
2546 self.launch_server.release()
James E. Blaircdccd972013-07-01 12:10:22 -07002547 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002548 self.assertEqual(self.getJobFromHistory('project-merge').result,
2549 'SUCCESS')
2550 self.assertEqual(self.getJobFromHistory('project-test1').result,
2551 'SUCCESS')
2552 self.assertEqual(self.getJobFromHistory('project-test2').result,
2553 'SUCCESS')
2554 self.assertEqual(A.data['status'], 'MERGED')
2555 self.assertEqual(A.reported, 2)
James E. Blair287c06d2013-07-24 10:39:30 -07002556
James E. Blairec056492016-07-22 09:45:56 -07002557 @skip("Disabled for early v3 development")
James E. Blair6bc782d2015-07-17 16:20:21 -07002558 def test_live_reconfiguration_merge_conflict(self):
2559 # A real-world bug: a change in a gate queue has a merge
2560 # conflict and a job is added to its project while it's
2561 # sitting in the queue. The job gets added to the change and
2562 # enqueued and the change gets stuck.
2563 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002564 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002565
2566 # This change is fine. It's here to stop the queue long
2567 # enough for the next change to be subject to the
2568 # reconfiguration, as well as to provide a conflict for the
2569 # next change. This change will succeed and merge.
2570 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2571 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002572 A.addApproval('code-review', 2)
James E. Blair6bc782d2015-07-17 16:20:21 -07002573
2574 # This change will be in merge conflict. During the
2575 # reconfiguration, we will add a job. We want to make sure
2576 # that doesn't cause it to get stuck.
2577 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2578 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002579 B.addApproval('code-review', 2)
James E. Blair4eb21fa2015-07-27 14:56:47 -07002580
James E. Blair8b5408c2016-08-08 15:37:46 -07002581 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2582 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002583
2584 self.waitUntilSettled()
2585
2586 # No jobs have run yet
2587 self.assertEqual(A.data['status'], 'NEW')
2588 self.assertEqual(A.reported, 1)
2589 self.assertEqual(B.data['status'], 'NEW')
2590 self.assertEqual(B.reported, 1)
2591 self.assertEqual(len(self.history), 0)
2592
2593 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002594 self.updateConfigLayout(
2595 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002596 self.sched.reconfigure(self.config)
2597 self.waitUntilSettled()
2598
James E. Blair08d19992016-08-10 15:25:31 -07002599 self.launch_server.hold_jobs_in_build = False
2600 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002601 self.waitUntilSettled()
2602
2603 self.assertEqual(A.data['status'], 'MERGED')
2604 self.assertEqual(A.reported, 2)
2605 self.assertEqual(B.data['status'], 'NEW')
2606 self.assertEqual(B.reported, 2)
2607 self.assertEqual(self.getJobFromHistory('project-merge').result,
2608 'SUCCESS')
2609 self.assertEqual(self.getJobFromHistory('project-test1').result,
2610 'SUCCESS')
2611 self.assertEqual(self.getJobFromHistory('project-test2').result,
2612 'SUCCESS')
2613 self.assertEqual(self.getJobFromHistory('project-test3').result,
2614 'SUCCESS')
2615 self.assertEqual(len(self.history), 4)
2616
James E. Blairec056492016-07-22 09:45:56 -07002617 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002618 def test_live_reconfiguration_failed_root(self):
James E. Blair6bc782d2015-07-17 16:20:21 -07002619 # An extrapolation of test_live_reconfiguration_merge_conflict
2620 # that tests a job added to a job tree with a failed root does
2621 # not run.
2622 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002623 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002624
2625 # This change is fine. It's here to stop the queue long
2626 # enough for the next change to be subject to the
2627 # reconfiguration. This change will succeed and merge.
2628 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2629 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002630 A.addApproval('code-review', 2)
2631 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002632 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002633 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002634 self.waitUntilSettled()
2635
2636 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair08d19992016-08-10 15:25:31 -07002637 self.launch_server.failJob('project-merge', B)
James E. Blair8b5408c2016-08-08 15:37:46 -07002638 B.addApproval('code-review', 2)
2639 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002640 self.waitUntilSettled()
2641
James E. Blair08d19992016-08-10 15:25:31 -07002642 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002643 self.waitUntilSettled()
2644
2645 # Both -merge jobs have run, but no others.
2646 self.assertEqual(A.data['status'], 'NEW')
2647 self.assertEqual(A.reported, 1)
2648 self.assertEqual(B.data['status'], 'NEW')
2649 self.assertEqual(B.reported, 1)
2650 self.assertEqual(self.history[0].result, 'SUCCESS')
2651 self.assertEqual(self.history[0].name, 'project-merge')
2652 self.assertEqual(self.history[1].result, 'FAILURE')
2653 self.assertEqual(self.history[1].name, 'project-merge')
2654 self.assertEqual(len(self.history), 2)
2655
2656 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002657 self.updateConfigLayout(
2658 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002659 self.sched.reconfigure(self.config)
2660 self.waitUntilSettled()
2661
James E. Blair08d19992016-08-10 15:25:31 -07002662 self.launch_server.hold_jobs_in_build = False
2663 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002664 self.waitUntilSettled()
2665
2666 self.assertEqual(A.data['status'], 'MERGED')
2667 self.assertEqual(A.reported, 2)
2668 self.assertEqual(B.data['status'], 'NEW')
2669 self.assertEqual(B.reported, 2)
2670 self.assertEqual(self.history[0].result, 'SUCCESS')
2671 self.assertEqual(self.history[0].name, 'project-merge')
2672 self.assertEqual(self.history[1].result, 'FAILURE')
2673 self.assertEqual(self.history[1].name, 'project-merge')
2674 self.assertEqual(self.history[2].result, 'SUCCESS')
2675 self.assertEqual(self.history[3].result, 'SUCCESS')
2676 self.assertEqual(self.history[4].result, 'SUCCESS')
2677 self.assertEqual(len(self.history), 5)
2678
James E. Blairec056492016-07-22 09:45:56 -07002679 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002680 def test_live_reconfiguration_failed_job(self):
2681 # Test that a change with a removed failing job does not
2682 # disrupt reconfiguration. If a change has a failed job and
2683 # that job is removed during a reconfiguration, we observed a
2684 # bug where the code to re-set build statuses would run on
2685 # that build and raise an exception because the job no longer
2686 # existed.
James E. Blair08d19992016-08-10 15:25:31 -07002687 self.launch_server.hold_jobs_in_build = True
James E. Blair400e8fd2015-07-30 17:44:45 -07002688
2689 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2690
2691 # This change will fail and later be removed by the reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002692 self.launch_server.failJob('project-test1', A)
James E. Blair400e8fd2015-07-30 17:44:45 -07002693
2694 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2695 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002696 self.launch_server.release('.*-merge')
James E. Blair400e8fd2015-07-30 17:44:45 -07002697 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002698 self.launch_server.release('project-test1')
James E. Blair400e8fd2015-07-30 17:44:45 -07002699 self.waitUntilSettled()
2700
2701 self.assertEqual(A.data['status'], 'NEW')
2702 self.assertEqual(A.reported, 0)
2703
2704 self.assertEqual(self.getJobFromHistory('project-merge').result,
2705 'SUCCESS')
2706 self.assertEqual(self.getJobFromHistory('project-test1').result,
2707 'FAILURE')
2708 self.assertEqual(len(self.history), 2)
2709
2710 # Remove the test1 job.
James E. Blairf84026c2015-12-08 16:11:46 -08002711 self.updateConfigLayout(
2712 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml')
James E. Blair400e8fd2015-07-30 17:44:45 -07002713 self.sched.reconfigure(self.config)
2714 self.waitUntilSettled()
2715
James E. Blair08d19992016-08-10 15:25:31 -07002716 self.launch_server.hold_jobs_in_build = False
2717 self.launch_server.release()
James E. Blair400e8fd2015-07-30 17:44:45 -07002718 self.waitUntilSettled()
2719
2720 self.assertEqual(self.getJobFromHistory('project-test2').result,
2721 'SUCCESS')
2722 self.assertEqual(self.getJobFromHistory('project-testfile').result,
2723 'SUCCESS')
2724 self.assertEqual(len(self.history), 4)
2725
2726 self.assertEqual(A.data['status'], 'NEW')
2727 self.assertEqual(A.reported, 1)
2728 self.assertIn('Build succeeded', A.messages[0])
2729 # Ensure the removed job was not included in the report.
2730 self.assertNotIn('project-test1', A.messages[0])
2731
James E. Blairec056492016-07-22 09:45:56 -07002732 @skip("Disabled for early v3 development")
James E. Blairfe707d12015-08-05 15:18:15 -07002733 def test_live_reconfiguration_shared_queue(self):
2734 # Test that a change with a failing job which was removed from
2735 # this project but otherwise still exists in the system does
2736 # not disrupt reconfiguration.
2737
James E. Blair08d19992016-08-10 15:25:31 -07002738 self.launch_server.hold_jobs_in_build = True
James E. Blairfe707d12015-08-05 15:18:15 -07002739
2740 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2741
James E. Blair08d19992016-08-10 15:25:31 -07002742 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairfe707d12015-08-05 15:18:15 -07002743
2744 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2745 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002746 self.launch_server.release('.*-merge')
James E. Blairfe707d12015-08-05 15:18:15 -07002747 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002748 self.launch_server.release('project1-project2-integration')
James E. Blairfe707d12015-08-05 15:18:15 -07002749 self.waitUntilSettled()
2750
2751 self.assertEqual(A.data['status'], 'NEW')
2752 self.assertEqual(A.reported, 0)
2753
2754 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2755 'SUCCESS')
2756 self.assertEqual(self.getJobFromHistory(
2757 'project1-project2-integration').result, 'FAILURE')
2758 self.assertEqual(len(self.history), 2)
2759
2760 # Remove the integration job.
James E. Blairf84026c2015-12-08 16:11:46 -08002761 self.updateConfigLayout(
2762 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml')
James E. Blairfe707d12015-08-05 15:18:15 -07002763 self.sched.reconfigure(self.config)
2764 self.waitUntilSettled()
2765
James E. Blair08d19992016-08-10 15:25:31 -07002766 self.launch_server.hold_jobs_in_build = False
2767 self.launch_server.release()
James E. Blairfe707d12015-08-05 15:18:15 -07002768 self.waitUntilSettled()
2769
2770 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2771 'SUCCESS')
2772 self.assertEqual(self.getJobFromHistory('project1-test1').result,
2773 'SUCCESS')
2774 self.assertEqual(self.getJobFromHistory('project1-test2').result,
2775 'SUCCESS')
2776 self.assertEqual(self.getJobFromHistory(
2777 'project1-project2-integration').result, 'FAILURE')
2778 self.assertEqual(len(self.history), 4)
2779
2780 self.assertEqual(A.data['status'], 'NEW')
2781 self.assertEqual(A.reported, 1)
2782 self.assertIn('Build succeeded', A.messages[0])
2783 # Ensure the removed job was not included in the report.
2784 self.assertNotIn('project1-project2-integration', A.messages[0])
2785
James E. Blairec056492016-07-22 09:45:56 -07002786 @skip("Disabled for early v3 development")
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002787 def test_double_live_reconfiguration_shared_queue(self):
2788 # This was a real-world regression. A change is added to
2789 # gate; a reconfigure happens, a second change which depends
2790 # on the first is added, and a second reconfiguration happens.
2791 # Ensure that both changes merge.
2792
2793 # A failure may indicate incorrect caching or cleaning up of
2794 # references during a reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002795 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002796
2797 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2798 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2799 B.setDependsOn(A, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07002800 A.addApproval('code-review', 2)
2801 B.addApproval('code-review', 2)
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002802
2803 # Add the parent change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002804 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002805 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002806 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002807 self.waitUntilSettled()
2808
2809 # Reconfigure (with only one change in the pipeline).
2810 self.sched.reconfigure(self.config)
2811 self.waitUntilSettled()
2812
2813 # Add the child change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002814 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002815 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002816 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002817 self.waitUntilSettled()
2818
2819 # Reconfigure (with both in the pipeline).
2820 self.sched.reconfigure(self.config)
2821 self.waitUntilSettled()
2822
James E. Blair08d19992016-08-10 15:25:31 -07002823 self.launch_server.hold_jobs_in_build = False
2824 self.launch_server.release()
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002825 self.waitUntilSettled()
2826
2827 self.assertEqual(len(self.history), 8)
2828
2829 self.assertEqual(A.data['status'], 'MERGED')
2830 self.assertEqual(A.reported, 2)
2831 self.assertEqual(B.data['status'], 'MERGED')
2832 self.assertEqual(B.reported, 2)
2833
James E. Blairec056492016-07-22 09:45:56 -07002834 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002835 def test_live_reconfiguration_del_project(self):
2836 # Test project deletion from layout
2837 # while changes are enqueued
2838
James E. Blair08d19992016-08-10 15:25:31 -07002839 self.launch_server.hold_jobs_in_build = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002840 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2841 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2842 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
2843
2844 # A Depends-On: B
2845 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
2846 A.subject, B.data['id'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002847 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002848
2849 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2850 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2851 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002852 self.launch_server.release('.*-merge')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002853 self.waitUntilSettled()
2854 self.assertEqual(len(self.builds), 5)
2855
2856 # This layout defines only org/project, not org/project1
James E. Blairf84026c2015-12-08 16:11:46 -08002857 self.updateConfigLayout(
2858 'tests/fixtures/layout-live-reconfiguration-del-project.yaml')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002859 self.sched.reconfigure(self.config)
2860 self.waitUntilSettled()
2861
2862 # Builds for C aborted, builds for A succeed,
2863 # and have change B applied ahead
2864 job_c = self.getJobFromHistory('project1-test1')
2865 self.assertEqual(job_c.changes, '3,1')
2866 self.assertEqual(job_c.result, 'ABORTED')
2867
James E. Blair08d19992016-08-10 15:25:31 -07002868 self.launch_server.hold_jobs_in_build = False
2869 self.launch_server.release()
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002870 self.waitUntilSettled()
2871
2872 self.assertEqual(self.getJobFromHistory('project-test1').changes,
2873 '2,1 1,1')
2874
2875 self.assertEqual(A.data['status'], 'NEW')
2876 self.assertEqual(B.data['status'], 'NEW')
2877 self.assertEqual(C.data['status'], 'NEW')
2878 self.assertEqual(A.reported, 1)
2879 self.assertEqual(B.reported, 0)
2880 self.assertEqual(C.reported, 0)
2881
2882 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
2883 self.assertIn('Build succeeded', A.messages[0])
2884
James E. Blairec056492016-07-22 09:45:56 -07002885 @skip("Disabled for early v3 development")
James E. Blaire712d9f2013-07-31 11:40:11 -07002886 def test_live_reconfiguration_functions(self):
2887 "Test live reconfiguration with a custom function"
2888 self.worker.registerFunction('build:node-project-test1:debian')
2889 self.worker.registerFunction('build:node-project-test1:wheezy')
2890 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002891 A.addApproval('code-review', 2)
2892 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002893 self.waitUntilSettled()
2894
2895 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2896 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2897 'debian')
2898 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2899
James E. Blairf84026c2015-12-08 16:11:46 -08002900 self.updateConfigLayout(
2901 'tests/fixtures/layout-live-reconfiguration-functions.yaml')
James E. Blaire712d9f2013-07-31 11:40:11 -07002902 self.sched.reconfigure(self.config)
2903 self.worker.build_history = []
2904
2905 B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002906 B.addApproval('code-review', 2)
2907 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002908 self.waitUntilSettled()
2909
2910 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2911 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2912 'wheezy')
2913 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2914
James E. Blairec056492016-07-22 09:45:56 -07002915 @skip("Disabled for early v3 development")
James E. Blair287c06d2013-07-24 10:39:30 -07002916 def test_delayed_repo_init(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002917 self.updateConfigLayout(
2918 'tests/fixtures/layout-delayed-repo-init.yaml')
James E. Blair287c06d2013-07-24 10:39:30 -07002919 self.sched.reconfigure(self.config)
2920
2921 self.init_repo("org/new-project")
2922 A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A')
2923
James E. Blair8b5408c2016-08-08 15:37:46 -07002924 A.addApproval('code-review', 2)
2925 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair287c06d2013-07-24 10:39:30 -07002926 self.waitUntilSettled()
2927 self.assertEqual(self.getJobFromHistory('project-merge').result,
2928 'SUCCESS')
2929 self.assertEqual(self.getJobFromHistory('project-test1').result,
2930 'SUCCESS')
2931 self.assertEqual(self.getJobFromHistory('project-test2').result,
2932 'SUCCESS')
2933 self.assertEqual(A.data['status'], 'MERGED')
2934 self.assertEqual(A.reported, 2)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002935
James E. Blairec056492016-07-22 09:45:56 -07002936 @skip("Disabled for early v3 development")
Clark Boylan6dbbc482013-10-18 10:57:31 -07002937 def test_repo_deleted(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002938 self.updateConfigLayout(
2939 'tests/fixtures/layout-repo-deleted.yaml')
Clark Boylan6dbbc482013-10-18 10:57:31 -07002940 self.sched.reconfigure(self.config)
2941
2942 self.init_repo("org/delete-project")
2943 A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A')
2944
James E. Blair8b5408c2016-08-08 15:37:46 -07002945 A.addApproval('code-review', 2)
2946 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002947 self.waitUntilSettled()
2948 self.assertEqual(self.getJobFromHistory('project-merge').result,
2949 'SUCCESS')
2950 self.assertEqual(self.getJobFromHistory('project-test1').result,
2951 'SUCCESS')
2952 self.assertEqual(self.getJobFromHistory('project-test2').result,
2953 'SUCCESS')
2954 self.assertEqual(A.data['status'], 'MERGED')
2955 self.assertEqual(A.reported, 2)
2956
2957 # Delete org/new-project zuul repo. Should be recloned.
2958 shutil.rmtree(os.path.join(self.git_root, "org/delete-project"))
2959
2960 B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B')
2961
James E. Blair8b5408c2016-08-08 15:37:46 -07002962 B.addApproval('code-review', 2)
2963 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002964 self.waitUntilSettled()
2965 self.assertEqual(self.getJobFromHistory('project-merge').result,
2966 'SUCCESS')
2967 self.assertEqual(self.getJobFromHistory('project-test1').result,
2968 'SUCCESS')
2969 self.assertEqual(self.getJobFromHistory('project-test2').result,
2970 'SUCCESS')
2971 self.assertEqual(B.data['status'], 'MERGED')
2972 self.assertEqual(B.reported, 2)
2973
James E. Blairec056492016-07-22 09:45:56 -07002974 @skip("Disabled for early v3 development")
James E. Blair456f2fb2016-02-09 09:29:33 -08002975 def test_tags(self):
2976 "Test job tags"
2977 self.config.set('zuul', 'layout_config',
2978 'tests/fixtures/layout-tags.yaml')
2979 self.sched.reconfigure(self.config)
2980
2981 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2982 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
2983 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2984 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2985 self.waitUntilSettled()
2986
2987 results = {'project1-merge': 'extratag merge project1',
2988 'project2-merge': 'merge'}
2989
2990 for build in self.history:
2991 self.assertEqual(results.get(build.name, ''),
2992 build.parameters.get('BUILD_TAGS'))
2993
James E. Blairec056492016-07-22 09:45:56 -07002994 @skip("Disabled for early v3 development")
James E. Blair63bb0ef2013-07-29 17:14:51 -07002995 def test_timer(self):
2996 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07002997 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08002998 self.updateConfigLayout(
2999 'tests/fixtures/layout-timer.yaml')
James E. Blair63bb0ef2013-07-29 17:14:51 -07003000 self.sched.reconfigure(self.config)
3001 self.registerJobs()
3002
Clark Boylan3ee090a2014-04-03 20:55:09 -07003003 # The pipeline triggers every second, so we should have seen
3004 # several by now.
3005 time.sleep(5)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003006 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003007
3008 self.assertEqual(len(self.builds), 2)
3009
James E. Blair63bb0ef2013-07-29 17:14:51 -07003010 port = self.webapp.server.socket.getsockname()[1]
3011
Morgan Fainberg293f7f82016-05-30 14:01:22 -07003012 req = urllib.request.Request("http://localhost:%s/status.json" % port)
3013 f = urllib.request.urlopen(req)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003014 data = f.read()
3015
James E. Blair08d19992016-08-10 15:25:31 -07003016 self.launch_server.hold_jobs_in_build = False
Clark Boylan3ee090a2014-04-03 20:55:09 -07003017 # Stop queuing timer triggered jobs so that the assertions
3018 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003019 self.updateConfigLayout(
3020 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003021 self.sched.reconfigure(self.config)
3022 self.registerJobs()
James E. Blair08d19992016-08-10 15:25:31 -07003023 self.launch_server.release()
James E. Blair63bb0ef2013-07-29 17:14:51 -07003024 self.waitUntilSettled()
3025
3026 self.assertEqual(self.getJobFromHistory(
3027 'project-bitrot-stable-old').result, 'SUCCESS')
3028 self.assertEqual(self.getJobFromHistory(
3029 'project-bitrot-stable-older').result, 'SUCCESS')
3030
3031 data = json.loads(data)
3032 status_jobs = set()
3033 for p in data['pipelines']:
3034 for q in p['change_queues']:
3035 for head in q['heads']:
3036 for change in head:
Alex Gaynorddb9ef32013-09-16 21:04:58 -07003037 self.assertEqual(change['id'], None)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003038 for job in change['jobs']:
3039 status_jobs.add(job['name'])
3040 self.assertIn('project-bitrot-stable-old', status_jobs)
3041 self.assertIn('project-bitrot-stable-older', status_jobs)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003042
James E. Blairec056492016-07-22 09:45:56 -07003043 @skip("Disabled for early v3 development")
James E. Blair4f6033c2014-03-27 15:49:09 -07003044 def test_idle(self):
3045 "Test that frequent periodic jobs work"
James E. Blair08d19992016-08-10 15:25:31 -07003046 self.launch_server.hold_jobs_in_build = True
James E. Blair4f6033c2014-03-27 15:49:09 -07003047
Clark Boylan3ee090a2014-04-03 20:55:09 -07003048 for x in range(1, 3):
3049 # Test that timer triggers periodic jobs even across
3050 # layout config reloads.
3051 # Start timer trigger
James E. Blairf84026c2015-12-08 16:11:46 -08003052 self.updateConfigLayout(
3053 'tests/fixtures/layout-idle.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003054 self.sched.reconfigure(self.config)
3055 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003056 self.waitUntilSettled()
James E. Blair4f6033c2014-03-27 15:49:09 -07003057
Clark Boylan3ee090a2014-04-03 20:55:09 -07003058 # The pipeline triggers every second, so we should have seen
3059 # several by now.
3060 time.sleep(5)
Clark Boylan3ee090a2014-04-03 20:55:09 -07003061
3062 # Stop queuing timer triggered jobs so that the assertions
3063 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003064 self.updateConfigLayout(
3065 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003066 self.sched.reconfigure(self.config)
3067 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003068 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003069
3070 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003071 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003072 self.waitUntilSettled()
3073 self.assertEqual(len(self.builds), 0)
3074 self.assertEqual(len(self.history), x * 2)
James E. Blair4f6033c2014-03-27 15:49:09 -07003075
James E. Blairec056492016-07-22 09:45:56 -07003076 @skip("Disabled for early v3 development")
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003077 def test_check_smtp_pool(self):
James E. Blairf84026c2015-12-08 16:11:46 -08003078 self.updateConfigLayout(
3079 'tests/fixtures/layout-smtp.yaml')
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003080 self.sched.reconfigure(self.config)
3081
3082 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3083 self.waitUntilSettled()
3084
3085 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3086 self.waitUntilSettled()
3087
James E. Blairff80a2f2013-12-27 13:24:06 -08003088 self.assertEqual(len(self.smtp_messages), 2)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003089
3090 # A.messages only holds what FakeGerrit places in it. Thus we
3091 # work on the knowledge of what the first message should be as
3092 # it is only configured to go to SMTP.
3093
3094 self.assertEqual('zuul@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003095 self.smtp_messages[0]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003096 self.assertEqual(['you@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003097 self.smtp_messages[0]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003098 self.assertEqual('Starting check jobs.',
James E. Blairff80a2f2013-12-27 13:24:06 -08003099 self.smtp_messages[0]['body'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003100
3101 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003102 self.smtp_messages[1]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003103 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003104 self.smtp_messages[1]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003105 self.assertEqual(A.messages[0],
James E. Blairff80a2f2013-12-27 13:24:06 -08003106 self.smtp_messages[1]['body'])
James E. Blairad28e912013-11-27 10:43:22 -08003107
James E. Blairec056492016-07-22 09:45:56 -07003108 @skip("Disabled for early v3 development")
James E. Blaire5910202013-12-27 09:50:31 -08003109 def test_timer_smtp(self):
3110 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003111 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003112 self.updateConfigLayout(
3113 'tests/fixtures/layout-timer-smtp.yaml')
James E. Blaire5910202013-12-27 09:50:31 -08003114 self.sched.reconfigure(self.config)
3115 self.registerJobs()
3116
Clark Boylan3ee090a2014-04-03 20:55:09 -07003117 # The pipeline triggers every second, so we should have seen
3118 # several by now.
3119 time.sleep(5)
James E. Blaire5910202013-12-27 09:50:31 -08003120 self.waitUntilSettled()
3121
Clark Boylan3ee090a2014-04-03 20:55:09 -07003122 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003123 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003124 self.waitUntilSettled()
3125 self.assertEqual(len(self.history), 2)
3126
James E. Blaire5910202013-12-27 09:50:31 -08003127 self.assertEqual(self.getJobFromHistory(
3128 'project-bitrot-stable-old').result, 'SUCCESS')
3129 self.assertEqual(self.getJobFromHistory(
3130 'project-bitrot-stable-older').result, 'SUCCESS')
3131
James E. Blairff80a2f2013-12-27 13:24:06 -08003132 self.assertEqual(len(self.smtp_messages), 1)
James E. Blaire5910202013-12-27 09:50:31 -08003133
3134 # A.messages only holds what FakeGerrit places in it. Thus we
3135 # work on the knowledge of what the first message should be as
3136 # it is only configured to go to SMTP.
3137
3138 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003139 self.smtp_messages[0]['from_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003140 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003141 self.smtp_messages[0]['to_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003142 self.assertIn('Subject: Periodic check for org/project succeeded',
James E. Blairff80a2f2013-12-27 13:24:06 -08003143 self.smtp_messages[0]['headers'])
James E. Blaire5910202013-12-27 09:50:31 -08003144
Clark Boylan3ee090a2014-04-03 20:55:09 -07003145 # Stop queuing timer triggered jobs and let any that may have
3146 # queued through so that end of test assertions pass.
James E. Blairf84026c2015-12-08 16:11:46 -08003147 self.updateConfigLayout(
3148 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003149 self.sched.reconfigure(self.config)
3150 self.registerJobs()
James E. Blairf8058972014-08-15 16:09:16 -07003151 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003152 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003153 self.waitUntilSettled()
3154
James E. Blairec056492016-07-22 09:45:56 -07003155 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003156 def test_client_enqueue_change(self):
James E. Blairad28e912013-11-27 10:43:22 -08003157 "Test that the RPC client can enqueue a change"
3158 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003159 A.addApproval('code-review', 2)
3160 A.addApproval('approved', 1)
James E. Blairad28e912013-11-27 10:43:22 -08003161
3162 client = zuul.rpcclient.RPCClient('127.0.0.1',
3163 self.gearman_server.port)
3164 r = client.enqueue(pipeline='gate',
3165 project='org/project',
3166 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003167 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003168 self.waitUntilSettled()
3169 self.assertEqual(self.getJobFromHistory('project-merge').result,
3170 'SUCCESS')
3171 self.assertEqual(self.getJobFromHistory('project-test1').result,
3172 'SUCCESS')
3173 self.assertEqual(self.getJobFromHistory('project-test2').result,
3174 'SUCCESS')
3175 self.assertEqual(A.data['status'], 'MERGED')
3176 self.assertEqual(A.reported, 2)
3177 self.assertEqual(r, True)
3178
James E. Blairec056492016-07-22 09:45:56 -07003179 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003180 def test_client_enqueue_ref(self):
3181 "Test that the RPC client can enqueue a ref"
3182
3183 client = zuul.rpcclient.RPCClient('127.0.0.1',
3184 self.gearman_server.port)
3185 r = client.enqueue_ref(
3186 pipeline='post',
3187 project='org/project',
3188 trigger='gerrit',
3189 ref='master',
3190 oldrev='90f173846e3af9154517b88543ffbd1691f31366',
3191 newrev='d479a0bfcb34da57a31adb2a595c0cf687812543')
3192 self.waitUntilSettled()
3193 job_names = [x.name for x in self.history]
3194 self.assertEqual(len(self.history), 1)
3195 self.assertIn('project-post', job_names)
3196 self.assertEqual(r, True)
3197
James E. Blairec056492016-07-22 09:45:56 -07003198 @skip("Disabled for early v3 development")
James E. Blairad28e912013-11-27 10:43:22 -08003199 def test_client_enqueue_negative(self):
3200 "Test that the RPC client returns errors"
3201 client = zuul.rpcclient.RPCClient('127.0.0.1',
3202 self.gearman_server.port)
3203 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3204 "Invalid project"):
3205 r = client.enqueue(pipeline='gate',
3206 project='project-does-not-exist',
3207 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003208 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003209 client.shutdown()
3210 self.assertEqual(r, False)
3211
3212 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3213 "Invalid pipeline"):
3214 r = client.enqueue(pipeline='pipeline-does-not-exist',
3215 project='org/project',
3216 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003217 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003218 client.shutdown()
3219 self.assertEqual(r, False)
3220
3221 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3222 "Invalid trigger"):
3223 r = client.enqueue(pipeline='gate',
3224 project='org/project',
3225 trigger='trigger-does-not-exist',
James E. Blair36658cf2013-12-06 17:53:48 -08003226 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003227 client.shutdown()
3228 self.assertEqual(r, False)
3229
3230 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3231 "Invalid change"):
3232 r = client.enqueue(pipeline='gate',
3233 project='org/project',
3234 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003235 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003236 client.shutdown()
3237 self.assertEqual(r, False)
3238
3239 self.waitUntilSettled()
3240 self.assertEqual(len(self.history), 0)
3241 self.assertEqual(len(self.builds), 0)
James E. Blair36658cf2013-12-06 17:53:48 -08003242
James E. Blairec056492016-07-22 09:45:56 -07003243 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003244 def test_client_promote(self):
3245 "Test that the RPC client can promote a change"
James E. Blair08d19992016-08-10 15:25:31 -07003246 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003247 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3248 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3249 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003250 A.addApproval('code-review', 2)
3251 B.addApproval('code-review', 2)
3252 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003253
James E. Blair8b5408c2016-08-08 15:37:46 -07003254 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3255 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3256 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003257
3258 self.waitUntilSettled()
3259
Sean Daguef39b9ca2014-01-10 21:34:35 -05003260 items = self.sched.layout.pipelines['gate'].getAllItems()
3261 enqueue_times = {}
3262 for item in items:
3263 enqueue_times[str(item.change)] = item.enqueue_time
3264
James E. Blair36658cf2013-12-06 17:53:48 -08003265 client = zuul.rpcclient.RPCClient('127.0.0.1',
3266 self.gearman_server.port)
3267 r = client.promote(pipeline='gate',
3268 change_ids=['2,1', '3,1'])
3269
Sean Daguef39b9ca2014-01-10 21:34:35 -05003270 # ensure that enqueue times are durable
3271 items = self.sched.layout.pipelines['gate'].getAllItems()
3272 for item in items:
3273 self.assertEqual(
3274 enqueue_times[str(item.change)], item.enqueue_time)
3275
James E. Blair78acec92014-02-06 07:11:32 -08003276 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003277 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003278 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003279 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003280 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003281 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003282 self.waitUntilSettled()
3283
3284 self.assertEqual(len(self.builds), 6)
3285 self.assertEqual(self.builds[0].name, 'project-test1')
3286 self.assertEqual(self.builds[1].name, 'project-test2')
3287 self.assertEqual(self.builds[2].name, 'project-test1')
3288 self.assertEqual(self.builds[3].name, 'project-test2')
3289 self.assertEqual(self.builds[4].name, 'project-test1')
3290 self.assertEqual(self.builds[5].name, 'project-test2')
3291
3292 self.assertTrue(self.job_has_changes(self.builds[0], B))
3293 self.assertFalse(self.job_has_changes(self.builds[0], A))
3294 self.assertFalse(self.job_has_changes(self.builds[0], C))
3295
3296 self.assertTrue(self.job_has_changes(self.builds[2], B))
3297 self.assertTrue(self.job_has_changes(self.builds[2], C))
3298 self.assertFalse(self.job_has_changes(self.builds[2], A))
3299
3300 self.assertTrue(self.job_has_changes(self.builds[4], B))
3301 self.assertTrue(self.job_has_changes(self.builds[4], C))
3302 self.assertTrue(self.job_has_changes(self.builds[4], A))
3303
James E. Blair08d19992016-08-10 15:25:31 -07003304 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003305 self.waitUntilSettled()
3306
3307 self.assertEqual(A.data['status'], 'MERGED')
3308 self.assertEqual(A.reported, 2)
3309 self.assertEqual(B.data['status'], 'MERGED')
3310 self.assertEqual(B.reported, 2)
3311 self.assertEqual(C.data['status'], 'MERGED')
3312 self.assertEqual(C.reported, 2)
3313
3314 client.shutdown()
3315 self.assertEqual(r, True)
3316
James E. Blairec056492016-07-22 09:45:56 -07003317 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003318 def test_client_promote_dependent(self):
3319 "Test that the RPC client can promote a dependent change"
3320 # C (depends on B) -> B -> A ; then promote C to get:
3321 # A -> C (depends on B) -> B
James E. Blair08d19992016-08-10 15:25:31 -07003322 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003323 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3324 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3325 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3326
3327 C.setDependsOn(B, 1)
3328
James E. Blair8b5408c2016-08-08 15:37:46 -07003329 A.addApproval('code-review', 2)
3330 B.addApproval('code-review', 2)
3331 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003332
James E. Blair8b5408c2016-08-08 15:37:46 -07003333 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3334 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3335 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003336
3337 self.waitUntilSettled()
3338
3339 client = zuul.rpcclient.RPCClient('127.0.0.1',
3340 self.gearman_server.port)
3341 r = client.promote(pipeline='gate',
3342 change_ids=['3,1'])
3343
James E. Blair78acec92014-02-06 07:11:32 -08003344 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003345 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003346 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003347 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003348 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003349 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003350 self.waitUntilSettled()
3351
3352 self.assertEqual(len(self.builds), 6)
3353 self.assertEqual(self.builds[0].name, 'project-test1')
3354 self.assertEqual(self.builds[1].name, 'project-test2')
3355 self.assertEqual(self.builds[2].name, 'project-test1')
3356 self.assertEqual(self.builds[3].name, 'project-test2')
3357 self.assertEqual(self.builds[4].name, 'project-test1')
3358 self.assertEqual(self.builds[5].name, 'project-test2')
3359
3360 self.assertTrue(self.job_has_changes(self.builds[0], B))
3361 self.assertFalse(self.job_has_changes(self.builds[0], A))
3362 self.assertFalse(self.job_has_changes(self.builds[0], C))
3363
3364 self.assertTrue(self.job_has_changes(self.builds[2], B))
3365 self.assertTrue(self.job_has_changes(self.builds[2], C))
3366 self.assertFalse(self.job_has_changes(self.builds[2], A))
3367
3368 self.assertTrue(self.job_has_changes(self.builds[4], B))
3369 self.assertTrue(self.job_has_changes(self.builds[4], C))
3370 self.assertTrue(self.job_has_changes(self.builds[4], A))
3371
James E. Blair08d19992016-08-10 15:25:31 -07003372 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003373 self.waitUntilSettled()
3374
3375 self.assertEqual(A.data['status'], 'MERGED')
3376 self.assertEqual(A.reported, 2)
3377 self.assertEqual(B.data['status'], 'MERGED')
3378 self.assertEqual(B.reported, 2)
3379 self.assertEqual(C.data['status'], 'MERGED')
3380 self.assertEqual(C.reported, 2)
3381
3382 client.shutdown()
3383 self.assertEqual(r, True)
3384
James E. Blairec056492016-07-22 09:45:56 -07003385 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003386 def test_client_promote_negative(self):
3387 "Test that the RPC client returns errors for promotion"
James E. Blair08d19992016-08-10 15:25:31 -07003388 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003389 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003390 A.addApproval('code-review', 2)
3391 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003392 self.waitUntilSettled()
3393
3394 client = zuul.rpcclient.RPCClient('127.0.0.1',
3395 self.gearman_server.port)
3396
3397 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3398 r = client.promote(pipeline='nonexistent',
3399 change_ids=['2,1', '3,1'])
3400 client.shutdown()
3401 self.assertEqual(r, False)
3402
3403 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3404 r = client.promote(pipeline='gate',
3405 change_ids=['4,1'])
3406 client.shutdown()
3407 self.assertEqual(r, False)
3408
James E. Blair08d19992016-08-10 15:25:31 -07003409 self.launch_server.hold_jobs_in_build = False
3410 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003411 self.waitUntilSettled()
Clark Boylan7603a372014-01-21 11:43:20 -08003412
James E. Blairec056492016-07-22 09:45:56 -07003413 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003414 def test_queue_rate_limiting(self):
3415 "Test that DependentPipelines are rate limited with dep across window"
James E. Blairf84026c2015-12-08 16:11:46 -08003416 self.updateConfigLayout(
3417 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003418 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003419 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003420 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3421 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3422 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3423
3424 C.setDependsOn(B, 1)
James E. Blair08d19992016-08-10 15:25:31 -07003425 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003426
James E. Blair8b5408c2016-08-08 15:37:46 -07003427 A.addApproval('code-review', 2)
3428 B.addApproval('code-review', 2)
3429 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003430
James E. Blair8b5408c2016-08-08 15:37:46 -07003431 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3432 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3433 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003434 self.waitUntilSettled()
3435
3436 # Only A and B will have their merge jobs queued because
3437 # window is 2.
3438 self.assertEqual(len(self.builds), 2)
3439 self.assertEqual(self.builds[0].name, 'project-merge')
3440 self.assertEqual(self.builds[1].name, 'project-merge')
3441
James E. Blair08d19992016-08-10 15:25:31 -07003442 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003443 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003444 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003445 self.waitUntilSettled()
3446
3447 # Only A and B will have their test jobs queued because
3448 # window is 2.
3449 self.assertEqual(len(self.builds), 4)
3450 self.assertEqual(self.builds[0].name, 'project-test1')
3451 self.assertEqual(self.builds[1].name, 'project-test2')
3452 self.assertEqual(self.builds[2].name, 'project-test1')
3453 self.assertEqual(self.builds[3].name, 'project-test2')
3454
James E. Blair08d19992016-08-10 15:25:31 -07003455 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003456 self.waitUntilSettled()
3457
3458 queue = self.sched.layout.pipelines['gate'].queues[0]
3459 # A failed so window is reduced by 1 to 1.
3460 self.assertEqual(queue.window, 1)
3461 self.assertEqual(queue.window_floor, 1)
3462 self.assertEqual(A.data['status'], 'NEW')
3463
3464 # Gate is reset and only B's merge job is queued because
3465 # window shrunk to 1.
3466 self.assertEqual(len(self.builds), 1)
3467 self.assertEqual(self.builds[0].name, 'project-merge')
3468
James E. Blair08d19992016-08-10 15:25:31 -07003469 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003470 self.waitUntilSettled()
3471
3472 # Only B's test jobs are queued because window is still 1.
3473 self.assertEqual(len(self.builds), 2)
3474 self.assertEqual(self.builds[0].name, 'project-test1')
3475 self.assertEqual(self.builds[1].name, 'project-test2')
3476
James E. Blair08d19992016-08-10 15:25:31 -07003477 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003478 self.waitUntilSettled()
3479
3480 # B was successfully merged so window is increased to 2.
3481 self.assertEqual(queue.window, 2)
3482 self.assertEqual(queue.window_floor, 1)
3483 self.assertEqual(B.data['status'], 'MERGED')
3484
3485 # Only C is left and its merge job is queued.
3486 self.assertEqual(len(self.builds), 1)
3487 self.assertEqual(self.builds[0].name, 'project-merge')
3488
James E. Blair08d19992016-08-10 15:25:31 -07003489 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003490 self.waitUntilSettled()
3491
3492 # After successful merge job the test jobs for C are queued.
3493 self.assertEqual(len(self.builds), 2)
3494 self.assertEqual(self.builds[0].name, 'project-test1')
3495 self.assertEqual(self.builds[1].name, 'project-test2')
3496
James E. Blair08d19992016-08-10 15:25:31 -07003497 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003498 self.waitUntilSettled()
3499
3500 # C successfully merged so window is bumped to 3.
3501 self.assertEqual(queue.window, 3)
3502 self.assertEqual(queue.window_floor, 1)
3503 self.assertEqual(C.data['status'], 'MERGED')
3504
James E. Blairec056492016-07-22 09:45:56 -07003505 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003506 def test_queue_rate_limiting_dependent(self):
3507 "Test that DependentPipelines are rate limited with dep in window"
James E. Blairf84026c2015-12-08 16:11:46 -08003508 self.updateConfigLayout(
3509 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003510 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003511 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003512 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3513 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3514 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3515
3516 B.setDependsOn(A, 1)
3517
James E. Blair08d19992016-08-10 15:25:31 -07003518 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003519
James E. Blair8b5408c2016-08-08 15:37:46 -07003520 A.addApproval('code-review', 2)
3521 B.addApproval('code-review', 2)
3522 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003523
James E. Blair8b5408c2016-08-08 15:37:46 -07003524 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3525 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3526 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003527 self.waitUntilSettled()
3528
3529 # Only A and B will have their merge jobs queued because
3530 # window is 2.
3531 self.assertEqual(len(self.builds), 2)
3532 self.assertEqual(self.builds[0].name, 'project-merge')
3533 self.assertEqual(self.builds[1].name, 'project-merge')
3534
James E. Blair08d19992016-08-10 15:25:31 -07003535 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003536 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003537 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003538 self.waitUntilSettled()
3539
3540 # Only A and B will have their test jobs queued because
3541 # window is 2.
3542 self.assertEqual(len(self.builds), 4)
3543 self.assertEqual(self.builds[0].name, 'project-test1')
3544 self.assertEqual(self.builds[1].name, 'project-test2')
3545 self.assertEqual(self.builds[2].name, 'project-test1')
3546 self.assertEqual(self.builds[3].name, 'project-test2')
3547
James E. Blair08d19992016-08-10 15:25:31 -07003548 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003549 self.waitUntilSettled()
3550
3551 queue = self.sched.layout.pipelines['gate'].queues[0]
3552 # A failed so window is reduced by 1 to 1.
3553 self.assertEqual(queue.window, 1)
3554 self.assertEqual(queue.window_floor, 1)
3555 self.assertEqual(A.data['status'], 'NEW')
3556 self.assertEqual(B.data['status'], 'NEW')
3557
3558 # Gate is reset and only C's merge job is queued because
3559 # window shrunk to 1 and A and B were dequeued.
3560 self.assertEqual(len(self.builds), 1)
3561 self.assertEqual(self.builds[0].name, 'project-merge')
3562
James E. Blair08d19992016-08-10 15:25:31 -07003563 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003564 self.waitUntilSettled()
3565
3566 # Only C's test jobs are queued because window is still 1.
3567 self.assertEqual(len(self.builds), 2)
3568 self.assertEqual(self.builds[0].name, 'project-test1')
3569 self.assertEqual(self.builds[1].name, 'project-test2')
3570
James E. Blair08d19992016-08-10 15:25:31 -07003571 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003572 self.waitUntilSettled()
3573
3574 # C was successfully merged so window is increased to 2.
3575 self.assertEqual(queue.window, 2)
3576 self.assertEqual(queue.window_floor, 1)
3577 self.assertEqual(C.data['status'], 'MERGED')
Joshua Heskethba8776a2014-01-12 14:35:40 +08003578
James E. Blairec056492016-07-22 09:45:56 -07003579 @skip("Disabled for early v3 development")
Joshua Heskethba8776a2014-01-12 14:35:40 +08003580 def test_worker_update_metadata(self):
3581 "Test if a worker can send back metadata about itself"
James E. Blair08d19992016-08-10 15:25:31 -07003582 self.launch_server.hold_jobs_in_build = True
Joshua Heskethba8776a2014-01-12 14:35:40 +08003583
3584 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003585 A.addApproval('code-review', 2)
3586 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethba8776a2014-01-12 14:35:40 +08003587 self.waitUntilSettled()
3588
3589 self.assertEqual(len(self.launcher.builds), 1)
3590
3591 self.log.debug('Current builds:')
3592 self.log.debug(self.launcher.builds)
3593
3594 start = time.time()
3595 while True:
3596 if time.time() - start > 10:
3597 raise Exception("Timeout waiting for gearman server to report "
3598 + "back to the client")
3599 build = self.launcher.builds.values()[0]
3600 if build.worker.name == "My Worker":
3601 break
3602 else:
3603 time.sleep(0)
3604
3605 self.log.debug(build)
3606 self.assertEqual("My Worker", build.worker.name)
3607 self.assertEqual("localhost", build.worker.hostname)
3608 self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips)
3609 self.assertEqual("zuul.example.org", build.worker.fqdn)
3610 self.assertEqual("FakeBuilder", build.worker.program)
3611 self.assertEqual("v1.1", build.worker.version)
3612 self.assertEqual({'something': 'else'}, build.worker.extra)
3613
James E. Blair08d19992016-08-10 15:25:31 -07003614 self.launch_server.hold_jobs_in_build = False
3615 self.launch_server.release()
Joshua Heskethba8776a2014-01-12 14:35:40 +08003616 self.waitUntilSettled()
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003617
James E. Blairec056492016-07-22 09:45:56 -07003618 @skip("Disabled for early v3 development")
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003619 def test_footer_message(self):
3620 "Test a pipeline's footer message is correctly added to the report."
James E. Blairf84026c2015-12-08 16:11:46 -08003621 self.updateConfigLayout(
3622 'tests/fixtures/layout-footer-message.yaml')
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003623 self.sched.reconfigure(self.config)
3624 self.registerJobs()
3625
3626 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003627 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003628 self.launch_server.failJob('test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003629 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003630 self.waitUntilSettled()
3631
3632 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003633 B.addApproval('code-review', 2)
3634 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003635 self.waitUntilSettled()
3636
3637 self.assertEqual(2, len(self.smtp_messages))
3638
3639 failure_body = """\
3640Build failed. For information on how to proceed, see \
3641http://wiki.example.org/Test_Failures
3642
3643- test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s
3644- test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s
3645
3646For CI problems and help debugging, contact ci@example.org"""
3647
3648 success_body = """\
3649Build succeeded.
3650
3651- test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s
3652- test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s
3653
3654For CI problems and help debugging, contact ci@example.org"""
3655
3656 self.assertEqual(failure_body, self.smtp_messages[0]['body'])
3657 self.assertEqual(success_body, self.smtp_messages[1]['body'])
Joshua Heskethb7179772014-01-30 23:30:46 +11003658
James E. Blairec056492016-07-22 09:45:56 -07003659 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003660 def test_merge_failure_reporters(self):
3661 """Check that the config is set up correctly"""
3662
James E. Blairf84026c2015-12-08 16:11:46 -08003663 self.updateConfigLayout(
3664 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003665 self.sched.reconfigure(self.config)
3666 self.registerJobs()
3667
3668 self.assertEqual(
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +00003669 "Merge Failed.\n\nThis change or one of its cross-repo "
3670 "dependencies was unable to be automatically merged with the "
3671 "current state of its repository. Please rebase the change and "
3672 "upload a new patchset.",
Joshua Heskethb7179772014-01-30 23:30:46 +11003673 self.sched.layout.pipelines['check'].merge_failure_message)
3674 self.assertEqual(
3675 "The merge failed! For more information...",
3676 self.sched.layout.pipelines['gate'].merge_failure_message)
3677
3678 self.assertEqual(
3679 len(self.sched.layout.pipelines['check'].merge_failure_actions), 1)
3680 self.assertEqual(
3681 len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2)
3682
3683 self.assertTrue(isinstance(
Joshua Heskethde958652015-11-10 19:19:50 +11003684 self.sched.layout.pipelines['check'].merge_failure_actions[0],
3685 zuul.reporter.gerrit.GerritReporter))
Joshua Heskethb7179772014-01-30 23:30:46 +11003686
3687 self.assertTrue(
3688 (
3689 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003690 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003691 zuul.reporter.smtp.SMTPReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003692 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003693 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003694 zuul.reporter.gerrit.GerritReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003695 ) or (
3696 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003697 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003698 zuul.reporter.gerrit.GerritReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003699 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003700 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003701 zuul.reporter.smtp.SMTPReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003702 )
3703 )
3704
James E. Blairec056492016-07-22 09:45:56 -07003705 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003706 def test_merge_failure_reports(self):
3707 """Check that when a change fails to merge the correct message is sent
3708 to the correct reporter"""
James E. Blairf84026c2015-12-08 16:11:46 -08003709 self.updateConfigLayout(
3710 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003711 self.sched.reconfigure(self.config)
3712 self.registerJobs()
3713
3714 # Check a test failure isn't reported to SMTP
3715 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003716 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003717 self.launch_server.failJob('project-test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003718 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003719 self.waitUntilSettled()
3720
3721 self.assertEqual(3, len(self.history)) # 3 jobs
3722 self.assertEqual(0, len(self.smtp_messages))
3723
3724 # Check a merge failure is reported to SMTP
3725 # B should be merged, but C will conflict with B
3726 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3727 B.addPatchset(['conflict'])
3728 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3729 C.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003730 B.addApproval('code-review', 2)
3731 C.addApproval('code-review', 2)
3732 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3733 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003734 self.waitUntilSettled()
3735
3736 self.assertEqual(6, len(self.history)) # A and B jobs
3737 self.assertEqual(1, len(self.smtp_messages))
3738 self.assertEqual('The merge failed! For more information...',
3739 self.smtp_messages[0]['body'])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003740
James E. Blairec056492016-07-22 09:45:56 -07003741 @skip("Disabled for early v3 development")
James E. Blairf760f0e2016-02-09 08:44:52 -08003742 def test_default_merge_failure_reports(self):
3743 """Check that the default merge failure reports are correct."""
3744
3745 # A should report success, B should report merge failure.
3746 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3747 A.addPatchset(['conflict'])
3748 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3749 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003750 A.addApproval('code-review', 2)
3751 B.addApproval('code-review', 2)
3752 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3753 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairf760f0e2016-02-09 08:44:52 -08003754 self.waitUntilSettled()
3755
3756 self.assertEqual(3, len(self.history)) # A jobs
3757 self.assertEqual(A.reported, 2)
3758 self.assertEqual(B.reported, 2)
3759 self.assertEqual(A.data['status'], 'MERGED')
3760 self.assertEqual(B.data['status'], 'NEW')
3761 self.assertIn('Build succeeded', A.messages[1])
3762 self.assertIn('Merge Failed', B.messages[1])
3763 self.assertIn('automatically merged', B.messages[1])
3764 self.assertNotIn('logs.example.com', B.messages[1])
3765 self.assertNotIn('SKIPPED', B.messages[1])
3766
James E. Blairec056492016-07-22 09:45:56 -07003767 @skip("Disabled for early v3 development")
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003768 def test_swift_instructions(self):
3769 "Test that the correct swift instructions are sent to the workers"
James E. Blairf84026c2015-12-08 16:11:46 -08003770 self.updateConfigLayout(
3771 'tests/fixtures/layout-swift.yaml')
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003772 self.sched.reconfigure(self.config)
3773 self.registerJobs()
3774
James E. Blair08d19992016-08-10 15:25:31 -07003775 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003776 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3777
James E. Blair8b5408c2016-08-08 15:37:46 -07003778 A.addApproval('code-review', 2)
3779 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003780 self.waitUntilSettled()
3781
3782 self.assertEqual(
3783 "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/"
3784 "gate/test-merge/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003785 self.builds[0].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003786 self.assertEqual(5,
3787 len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY'].
3788 split('\n')))
3789 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters)
3790
3791 self.assertEqual(
3792 "https://storage.example.org/V1/AUTH_account/logs/1/1/1/"
3793 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003794 self.builds[1].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003795 self.assertEqual(5,
3796 len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY'].
3797 split('\n')))
3798 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters)
3799
3800 self.assertEqual(
3801 "https://storage.example.org/V1/AUTH_account/stash/1/1/1/"
3802 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003803 self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003804 self.assertEqual(5,
3805 len(self.builds[1].
3806 parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n')))
3807 self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters)
3808
James E. Blair08d19992016-08-10 15:25:31 -07003809 self.launch_server.hold_jobs_in_build = False
3810 self.launch_server.release()
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003811 self.waitUntilSettled()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003812
James E. Blairec056492016-07-22 09:45:56 -07003813 @skip("Disabled for early v3 development")
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003814 def test_client_get_running_jobs(self):
3815 "Test that the RPC client can get a list of running jobs"
James E. Blair08d19992016-08-10 15:25:31 -07003816 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003817 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003818 A.addApproval('code-review', 2)
3819 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003820 self.waitUntilSettled()
3821
3822 client = zuul.rpcclient.RPCClient('127.0.0.1',
3823 self.gearman_server.port)
3824
3825 # Wait for gearman server to send the initial workData back to zuul
3826 start = time.time()
3827 while True:
3828 if time.time() - start > 10:
3829 raise Exception("Timeout waiting for gearman server to report "
3830 + "back to the client")
3831 build = self.launcher.builds.values()[0]
3832 if build.worker.name == "My Worker":
3833 break
3834 else:
3835 time.sleep(0)
3836
3837 running_items = client.get_running_jobs()
3838
3839 self.assertEqual(1, len(running_items))
3840 running_item = running_items[0]
3841 self.assertEqual([], running_item['failing_reasons'])
3842 self.assertEqual([], running_item['items_behind'])
3843 self.assertEqual('https://hostname/1', running_item['url'])
3844 self.assertEqual(None, running_item['item_ahead'])
3845 self.assertEqual('org/project', running_item['project'])
3846 self.assertEqual(None, running_item['remaining_time'])
3847 self.assertEqual(True, running_item['active'])
3848 self.assertEqual('1,1', running_item['id'])
3849
3850 self.assertEqual(3, len(running_item['jobs']))
3851 for job in running_item['jobs']:
3852 if job['name'] == 'project-merge':
3853 self.assertEqual('project-merge', job['name'])
3854 self.assertEqual('gate', job['pipeline'])
3855 self.assertEqual(False, job['retry'])
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003856 self.assertEqual('https://server/job/project-merge/0/',
3857 job['url'])
3858 self.assertEqual(7, len(job['worker']))
3859 self.assertEqual(False, job['canceled'])
3860 self.assertEqual(True, job['voting'])
3861 self.assertEqual(None, job['result'])
3862 self.assertEqual('gate', job['pipeline'])
3863 break
3864
James E. Blair08d19992016-08-10 15:25:31 -07003865 self.launch_server.hold_jobs_in_build = False
3866 self.launch_server.release()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003867 self.waitUntilSettled()
3868
3869 running_items = client.get_running_jobs()
3870 self.assertEqual(0, len(running_items))
James E. Blairbadc1ad2014-04-28 13:55:14 -07003871
3872 def test_nonvoting_pipeline(self):
3873 "Test that a nonvoting pipeline (experimental) can still report"
3874
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003875 A = self.fake_gerrit.addFakeChange('org/experimental-project',
3876 'master', 'A')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003877 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3878 self.waitUntilSettled()
Paul Belanger15e3e202016-10-14 16:27:34 -04003879
3880 self.assertEqual(self.getJobFromHistory('project-merge').result,
3881 'SUCCESS')
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003882 self.assertEqual(
3883 self.getJobFromHistory('experimental-project-test').result,
3884 'SUCCESS')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003885 self.assertEqual(A.reported, 1)
James E. Blair5ee24252014-12-30 10:12:29 -08003886
James E. Blairec056492016-07-22 09:45:56 -07003887 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003888 def test_crd_gate(self):
3889 "Test cross-repo dependencies"
3890 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3891 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003892 A.addApproval('code-review', 2)
3893 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003894
3895 AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2')
3896 AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1')
3897 AM2.setMerged()
3898 AM1.setMerged()
3899
3900 BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2')
3901 BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1')
3902 BM2.setMerged()
3903 BM1.setMerged()
3904
3905 # A -> AM1 -> AM2
3906 # B -> BM1 -> BM2
3907 # A Depends-On: B
3908 # M2 is here to make sure it is never queried. If it is, it
3909 # means zuul is walking down the entire history of merged
3910 # changes.
3911
3912 B.setDependsOn(BM1, 1)
3913 BM1.setDependsOn(BM2, 1)
3914
3915 A.setDependsOn(AM1, 1)
3916 AM1.setDependsOn(AM2, 1)
3917
3918 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3919 A.subject, B.data['id'])
3920
James E. Blair8b5408c2016-08-08 15:37:46 -07003921 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003922 self.waitUntilSettled()
3923
3924 self.assertEqual(A.data['status'], 'NEW')
3925 self.assertEqual(B.data['status'], 'NEW')
3926
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11003927 for connection in self.connections.values():
3928 connection.maintainCache([])
James E. Blair5ee24252014-12-30 10:12:29 -08003929
James E. Blair08d19992016-08-10 15:25:31 -07003930 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003931 B.addApproval('approved', 1)
3932 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003933 self.waitUntilSettled()
3934
James E. Blair08d19992016-08-10 15:25:31 -07003935 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003936 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003937 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003938 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003939 self.launch_server.hold_jobs_in_build = False
3940 self.launch_server.release()
James E. Blair5ee24252014-12-30 10:12:29 -08003941 self.waitUntilSettled()
3942
3943 self.assertEqual(AM2.queried, 0)
3944 self.assertEqual(BM2.queried, 0)
3945 self.assertEqual(A.data['status'], 'MERGED')
3946 self.assertEqual(B.data['status'], 'MERGED')
3947 self.assertEqual(A.reported, 2)
3948 self.assertEqual(B.reported, 2)
3949
James E. Blair8f78d882015-02-05 08:51:37 -08003950 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3951 '2,1 1,1')
3952
James E. Blairec056492016-07-22 09:45:56 -07003953 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003954 def test_crd_branch(self):
3955 "Test cross-repo dependencies in multiple branches"
3956 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3957 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3958 C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C')
3959 C.data['id'] = B.data['id']
James E. Blair8b5408c2016-08-08 15:37:46 -07003960 A.addApproval('code-review', 2)
3961 B.addApproval('code-review', 2)
3962 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003963
3964 # A Depends-On: B+C
3965 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3966 A.subject, B.data['id'])
3967
James E. Blair08d19992016-08-10 15:25:31 -07003968 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003969 B.addApproval('approved', 1)
3970 C.addApproval('approved', 1)
3971 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08003972 self.waitUntilSettled()
3973
James E. Blair08d19992016-08-10 15:25:31 -07003974 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003975 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003976 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003977 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003978 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003979 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003980 self.launch_server.hold_jobs_in_build = False
3981 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08003982 self.waitUntilSettled()
3983
3984 self.assertEqual(A.data['status'], 'MERGED')
3985 self.assertEqual(B.data['status'], 'MERGED')
3986 self.assertEqual(C.data['status'], 'MERGED')
3987 self.assertEqual(A.reported, 2)
3988 self.assertEqual(B.reported, 2)
3989 self.assertEqual(C.reported, 2)
3990
3991 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3992 '2,1 3,1 1,1')
3993
James E. Blairec056492016-07-22 09:45:56 -07003994 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003995 def test_crd_multiline(self):
3996 "Test multiple depends-on lines in commit"
3997 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3998 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3999 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07004000 A.addApproval('code-review', 2)
4001 B.addApproval('code-review', 2)
4002 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08004003
4004 # A Depends-On: B+C
4005 A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % (
4006 A.subject, B.data['id'], C.data['id'])
4007
James E. Blair08d19992016-08-10 15:25:31 -07004008 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004009 B.addApproval('approved', 1)
4010 C.addApproval('approved', 1)
4011 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08004012 self.waitUntilSettled()
4013
James E. Blair08d19992016-08-10 15:25:31 -07004014 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004015 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004016 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004017 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004018 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004019 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004020 self.launch_server.hold_jobs_in_build = False
4021 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08004022 self.waitUntilSettled()
4023
4024 self.assertEqual(A.data['status'], 'MERGED')
4025 self.assertEqual(B.data['status'], 'MERGED')
4026 self.assertEqual(C.data['status'], 'MERGED')
4027 self.assertEqual(A.reported, 2)
4028 self.assertEqual(B.reported, 2)
4029 self.assertEqual(C.reported, 2)
4030
4031 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4032 '2,1 3,1 1,1')
James E. Blair5ee24252014-12-30 10:12:29 -08004033
James E. Blairec056492016-07-22 09:45:56 -07004034 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004035 def test_crd_unshared_gate(self):
4036 "Test cross-repo dependencies in unshared gate queues"
4037 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4038 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004039 A.addApproval('code-review', 2)
4040 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004041
4042 # A Depends-On: B
4043 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4044 A.subject, B.data['id'])
4045
4046 # A and B do not share a queue, make sure that A is unable to
4047 # enqueue B (and therefore, A is unable to be enqueued).
James E. Blair8b5408c2016-08-08 15:37:46 -07004048 B.addApproval('approved', 1)
4049 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004050 self.waitUntilSettled()
4051
4052 self.assertEqual(A.data['status'], 'NEW')
4053 self.assertEqual(B.data['status'], 'NEW')
4054 self.assertEqual(A.reported, 0)
4055 self.assertEqual(B.reported, 0)
4056 self.assertEqual(len(self.history), 0)
4057
4058 # Enqueue and merge B alone.
James E. Blair8b5408c2016-08-08 15:37:46 -07004059 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004060 self.waitUntilSettled()
4061
4062 self.assertEqual(B.data['status'], 'MERGED')
4063 self.assertEqual(B.reported, 2)
4064
4065 # Now that B is merged, A should be able to be enqueued and
4066 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004067 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004068 self.waitUntilSettled()
4069
4070 self.assertEqual(A.data['status'], 'MERGED')
4071 self.assertEqual(A.reported, 2)
4072
James E. Blairec056492016-07-22 09:45:56 -07004073 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004074 def test_crd_gate_reverse(self):
4075 "Test reverse cross-repo dependencies"
4076 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4077 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004078 A.addApproval('code-review', 2)
4079 B.addApproval('code-review', 2)
James E. Blair96698e22015-04-02 07:48:21 -07004080
4081 # A Depends-On: B
4082
4083 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4084 A.subject, B.data['id'])
4085
James E. Blair8b5408c2016-08-08 15:37:46 -07004086 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004087 self.waitUntilSettled()
4088
4089 self.assertEqual(A.data['status'], 'NEW')
4090 self.assertEqual(B.data['status'], 'NEW')
4091
James E. Blair08d19992016-08-10 15:25:31 -07004092 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004093 A.addApproval('approved', 1)
4094 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004095 self.waitUntilSettled()
4096
James E. Blair08d19992016-08-10 15:25:31 -07004097 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004098 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004099 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004100 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004101 self.launch_server.hold_jobs_in_build = False
4102 self.launch_server.release()
James E. Blair96698e22015-04-02 07:48:21 -07004103 self.waitUntilSettled()
4104
4105 self.assertEqual(A.data['status'], 'MERGED')
4106 self.assertEqual(B.data['status'], 'MERGED')
4107 self.assertEqual(A.reported, 2)
4108 self.assertEqual(B.reported, 2)
4109
4110 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4111 '2,1 1,1')
4112
James E. Blairec056492016-07-22 09:45:56 -07004113 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004114 def test_crd_cycle(self):
4115 "Test cross-repo dependency cycles"
4116 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4117 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004118 A.addApproval('code-review', 2)
4119 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004120
4121 # A -> B -> A (via commit-depends)
4122
4123 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4124 A.subject, B.data['id'])
4125 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4126 B.subject, A.data['id'])
4127
James E. Blair8b5408c2016-08-08 15:37:46 -07004128 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004129 self.waitUntilSettled()
4130
4131 self.assertEqual(A.reported, 0)
4132 self.assertEqual(B.reported, 0)
4133 self.assertEqual(A.data['status'], 'NEW')
4134 self.assertEqual(B.data['status'], 'NEW')
James E. Blairbfb8e042014-12-30 17:01:44 -08004135
James E. Blairec056492016-07-22 09:45:56 -07004136 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004137 def test_crd_gate_unknown(self):
4138 "Test unknown projects in dependent pipeline"
4139 self.init_repo("org/unknown")
4140 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4141 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004142 A.addApproval('code-review', 2)
4143 B.addApproval('code-review', 2)
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004144
4145 # A Depends-On: B
4146 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4147 A.subject, B.data['id'])
4148
James E. Blair8b5408c2016-08-08 15:37:46 -07004149 B.addApproval('approved', 1)
4150 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004151 self.waitUntilSettled()
4152
4153 # Unknown projects cannot share a queue with any other
4154 # since they don't have common jobs with any other (they have no jobs).
4155 # Changes which depend on unknown project changes
4156 # should not be processed in dependent pipeline
4157 self.assertEqual(A.data['status'], 'NEW')
4158 self.assertEqual(B.data['status'], 'NEW')
4159 self.assertEqual(A.reported, 0)
4160 self.assertEqual(B.reported, 0)
4161 self.assertEqual(len(self.history), 0)
4162
4163 # Simulate change B being gated outside this layout
James E. Blair8b5408c2016-08-08 15:37:46 -07004164 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004165 B.setMerged()
4166 self.waitUntilSettled()
4167 self.assertEqual(len(self.history), 0)
4168
4169 # Now that B is merged, A should be able to be enqueued and
4170 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004171 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004172 self.waitUntilSettled()
4173
4174 self.assertEqual(A.data['status'], 'MERGED')
4175 self.assertEqual(A.reported, 2)
4176 self.assertEqual(B.data['status'], 'MERGED')
4177 self.assertEqual(B.reported, 0)
4178
James E. Blairec056492016-07-22 09:45:56 -07004179 @skip("Disabled for early v3 development")
James E. Blairbfb8e042014-12-30 17:01:44 -08004180 def test_crd_check(self):
4181 "Test cross-repo dependencies in independent pipelines"
4182
4183 self.gearman_server.hold_jobs_in_queue = True
4184 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4185 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4186
4187 # A Depends-On: B
4188 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4189 A.subject, B.data['id'])
4190
4191 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4192 self.waitUntilSettled()
4193
4194 queue = self.gearman_server.getQueue()
4195 ref = self.getParameter(queue[-1], 'ZUUL_REF')
4196 self.gearman_server.hold_jobs_in_queue = False
4197 self.gearman_server.release()
4198 self.waitUntilSettled()
4199
4200 path = os.path.join(self.git_root, "org/project1")
4201 repo = git.Repo(path)
4202 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4203 repo_messages.reverse()
4204 correct_messages = ['initial commit', 'A-1']
4205 self.assertEqual(repo_messages, correct_messages)
4206
4207 path = os.path.join(self.git_root, "org/project2")
4208 repo = git.Repo(path)
4209 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4210 repo_messages.reverse()
4211 correct_messages = ['initial commit', 'B-1']
4212 self.assertEqual(repo_messages, correct_messages)
4213
4214 self.assertEqual(A.data['status'], 'NEW')
4215 self.assertEqual(B.data['status'], 'NEW')
4216 self.assertEqual(A.reported, 1)
4217 self.assertEqual(B.reported, 0)
4218
4219 self.assertEqual(self.history[0].changes, '2,1 1,1')
4220 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair8f78d882015-02-05 08:51:37 -08004221
James E. Blairec056492016-07-22 09:45:56 -07004222 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004223 def test_crd_check_git_depends(self):
4224 "Test single-repo dependencies in independent pipelines"
James E. Blairb8c16472015-05-05 14:55:26 -07004225 self.gearman_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004226 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4227 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4228
4229 # Add two git-dependent changes and make sure they both report
4230 # success.
4231 B.setDependsOn(A, 1)
4232 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4233 self.waitUntilSettled()
4234 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4235 self.waitUntilSettled()
4236
James E. Blairb8c16472015-05-05 14:55:26 -07004237 self.orderedRelease()
4238 self.gearman_server.hold_jobs_in_build = False
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004239 self.waitUntilSettled()
4240
4241 self.assertEqual(A.data['status'], 'NEW')
4242 self.assertEqual(B.data['status'], 'NEW')
4243 self.assertEqual(A.reported, 1)
4244 self.assertEqual(B.reported, 1)
4245
4246 self.assertEqual(self.history[0].changes, '1,1')
4247 self.assertEqual(self.history[-1].changes, '1,1 2,1')
4248 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4249
4250 self.assertIn('Build succeeded', A.messages[0])
4251 self.assertIn('Build succeeded', B.messages[0])
4252
James E. Blairec056492016-07-22 09:45:56 -07004253 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004254 def test_crd_check_duplicate(self):
4255 "Test duplicate check in independent pipelines"
James E. Blair08d19992016-08-10 15:25:31 -07004256 self.launch_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004257 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4258 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4259 check_pipeline = self.sched.layout.pipelines['check']
4260
4261 # Add two git-dependent changes...
4262 B.setDependsOn(A, 1)
4263 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4264 self.waitUntilSettled()
4265 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4266
4267 # ...make sure the live one is not duplicated...
4268 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4269 self.waitUntilSettled()
4270 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4271
4272 # ...but the non-live one is able to be.
4273 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4274 self.waitUntilSettled()
4275 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4276
Clark Boylandd849822015-03-02 12:38:14 -08004277 # Release jobs in order to avoid races with change A jobs
4278 # finishing before change B jobs.
James E. Blaird7650852015-05-07 15:47:37 -07004279 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07004280 self.launch_server.hold_jobs_in_build = False
4281 self.launch_server.release()
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004282 self.waitUntilSettled()
4283
4284 self.assertEqual(A.data['status'], 'NEW')
4285 self.assertEqual(B.data['status'], 'NEW')
4286 self.assertEqual(A.reported, 1)
4287 self.assertEqual(B.reported, 1)
4288
4289 self.assertEqual(self.history[0].changes, '1,1 2,1')
4290 self.assertEqual(self.history[1].changes, '1,1')
4291 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4292
4293 self.assertIn('Build succeeded', A.messages[0])
4294 self.assertIn('Build succeeded', B.messages[0])
4295
James E. Blairec056492016-07-22 09:45:56 -07004296 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004297 def _test_crd_check_reconfiguration(self, project1, project2):
James E. Blair8f78d882015-02-05 08:51:37 -08004298 "Test cross-repo dependencies re-enqueued in independent pipelines"
4299
4300 self.gearman_server.hold_jobs_in_queue = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004301 A = self.fake_gerrit.addFakeChange(project1, 'master', 'A')
4302 B = self.fake_gerrit.addFakeChange(project2, 'master', 'B')
James E. Blair8f78d882015-02-05 08:51:37 -08004303
4304 # A Depends-On: B
4305 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4306 A.subject, B.data['id'])
4307
4308 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4309 self.waitUntilSettled()
4310
4311 self.sched.reconfigure(self.config)
4312
4313 # Make sure the items still share a change queue, and the
4314 # first one is not live.
4315 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1)
4316 queue = self.sched.layout.pipelines['check'].queues[0]
4317 first_item = queue.queue[0]
4318 for item in queue.queue:
4319 self.assertEqual(item.queue, first_item.queue)
4320 self.assertFalse(first_item.live)
4321 self.assertTrue(queue.queue[1].live)
4322
4323 self.gearman_server.hold_jobs_in_queue = False
4324 self.gearman_server.release()
4325 self.waitUntilSettled()
4326
4327 self.assertEqual(A.data['status'], 'NEW')
4328 self.assertEqual(B.data['status'], 'NEW')
4329 self.assertEqual(A.reported, 1)
4330 self.assertEqual(B.reported, 0)
4331
4332 self.assertEqual(self.history[0].changes, '2,1 1,1')
4333 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair17dd6772015-02-09 14:45:18 -08004334
James E. Blairec056492016-07-22 09:45:56 -07004335 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004336 def test_crd_check_reconfiguration(self):
4337 self._test_crd_check_reconfiguration('org/project1', 'org/project2')
4338
James E. Blairec056492016-07-22 09:45:56 -07004339 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004340 def test_crd_undefined_project(self):
4341 """Test that undefined projects in dependencies are handled for
4342 independent pipelines"""
4343 # It's a hack for fake gerrit,
4344 # as it implies repo creation upon the creation of any change
4345 self.init_repo("org/unknown")
4346 self._test_crd_check_reconfiguration('org/project1', 'org/unknown')
4347
James E. Blairec056492016-07-22 09:45:56 -07004348 @skip("Disabled for early v3 development")
James E. Blair17dd6772015-02-09 14:45:18 -08004349 def test_crd_check_ignore_dependencies(self):
4350 "Test cross-repo dependencies can be ignored"
James E. Blairf84026c2015-12-08 16:11:46 -08004351 self.updateConfigLayout(
4352 'tests/fixtures/layout-ignore-dependencies.yaml')
James E. Blair17dd6772015-02-09 14:45:18 -08004353 self.sched.reconfigure(self.config)
4354 self.registerJobs()
4355
4356 self.gearman_server.hold_jobs_in_queue = True
4357 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4358 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4359 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
4360
4361 # A Depends-On: B
4362 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4363 A.subject, B.data['id'])
4364 # C git-depends on B
4365 C.setDependsOn(B, 1)
4366 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4367 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4368 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4369 self.waitUntilSettled()
4370
4371 # Make sure none of the items share a change queue, and all
4372 # are live.
4373 check_pipeline = self.sched.layout.pipelines['check']
4374 self.assertEqual(len(check_pipeline.queues), 3)
4375 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4376 for item in check_pipeline.getAllItems():
4377 self.assertTrue(item.live)
4378
4379 self.gearman_server.hold_jobs_in_queue = False
4380 self.gearman_server.release()
4381 self.waitUntilSettled()
4382
4383 self.assertEqual(A.data['status'], 'NEW')
4384 self.assertEqual(B.data['status'], 'NEW')
4385 self.assertEqual(C.data['status'], 'NEW')
4386 self.assertEqual(A.reported, 1)
4387 self.assertEqual(B.reported, 1)
4388 self.assertEqual(C.reported, 1)
4389
4390 # Each job should have tested exactly one change
4391 for job in self.history:
4392 self.assertEqual(len(job.changes.split()), 1)
James E. Blair96698e22015-04-02 07:48:21 -07004393
James E. Blairec056492016-07-22 09:45:56 -07004394 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004395 def test_crd_check_transitive(self):
4396 "Test transitive cross-repo dependencies"
4397 # Specifically, if A -> B -> C, and C gets a new patchset and
4398 # A gets a new patchset, ensure the test of A,2 includes B,1
4399 # and C,2 (not C,1 which would indicate stale data in the
4400 # cache for B).
4401 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4402 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4403 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
4404
4405 # A Depends-On: B
4406 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4407 A.subject, B.data['id'])
4408
4409 # B Depends-On: C
4410 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4411 B.subject, C.data['id'])
4412
4413 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4414 self.waitUntilSettled()
4415 self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1')
4416
4417 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4418 self.waitUntilSettled()
4419 self.assertEqual(self.history[-1].changes, '3,1 2,1')
4420
4421 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4422 self.waitUntilSettled()
4423 self.assertEqual(self.history[-1].changes, '3,1')
4424
4425 C.addPatchset()
4426 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2))
4427 self.waitUntilSettled()
4428 self.assertEqual(self.history[-1].changes, '3,2')
4429
4430 A.addPatchset()
4431 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
4432 self.waitUntilSettled()
4433 self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004434
James E. Blairec056492016-07-22 09:45:56 -07004435 @skip("Disabled for early v3 development")
James E. Blaira8b90b32016-08-24 15:18:50 -07004436 def test_crd_check_unknown(self):
4437 "Test unknown projects in independent pipeline"
4438 self.init_repo("org/unknown")
4439 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4440 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D')
4441 # A Depends-On: B
4442 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4443 A.subject, B.data['id'])
4444
4445 # Make sure zuul has seen an event on B.
4446 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4447 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4448 self.waitUntilSettled()
4449
4450 self.assertEqual(A.data['status'], 'NEW')
4451 self.assertEqual(A.reported, 1)
4452 self.assertEqual(B.data['status'], 'NEW')
4453 self.assertEqual(B.reported, 0)
4454
Joshua Heskethefeeb6d2016-09-20 14:42:37 +02004455 @skip("Disabled for early v3 development")
James E. Blair92464a22016-04-05 10:21:26 -07004456 def test_crd_cycle_join(self):
4457 "Test an updated change creates a cycle"
4458 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
4459
4460 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4461 self.waitUntilSettled()
4462
4463 # Create B->A
4464 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4465 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4466 B.subject, A.data['id'])
4467 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4468 self.waitUntilSettled()
4469
4470 # Update A to add A->B (a cycle).
4471 A.addPatchset()
4472 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4473 A.subject, B.data['id'])
4474 # Normally we would submit the patchset-created event for
4475 # processing here, however, we have no way of noting whether
4476 # the dependency cycle detection correctly raised an
4477 # exception, so instead, we reach into the source driver and
4478 # call the method that would ultimately be called by the event
4479 # processing.
4480
4481 source = self.sched.layout.pipelines['gate'].source
4482 with testtools.ExpectedException(
4483 Exception, "Dependency cycle detected"):
4484 source._getChange(u'1', u'2', True)
4485 self.log.debug("Got expected dependency cycle exception")
4486
4487 # Now if we update B to remove the depends-on, everything
4488 # should be okay. B; A->B
4489
4490 B.addPatchset()
4491 B.data['commitMessage'] = '%s\n' % (B.subject,)
4492 source._getChange(u'1', u'2', True)
4493 source._getChange(u'2', u'2', True)
4494
James E. Blairec056492016-07-22 09:45:56 -07004495 @skip("Disabled for early v3 development")
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004496 def test_disable_at(self):
4497 "Test a pipeline will only report to the disabled trigger when failing"
4498
James E. Blairf84026c2015-12-08 16:11:46 -08004499 self.updateConfigLayout(
4500 'tests/fixtures/layout-disable-at.yaml')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004501 self.sched.reconfigure(self.config)
4502
4503 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4504 self.assertEqual(
4505 0, self.sched.layout.pipelines['check']._consecutive_failures)
4506 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4507
4508 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4509 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
4510 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
4511 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
4512 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
4513 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
4514 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
4515 H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H')
4516 I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I')
4517 J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J')
4518 K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K')
4519
James E. Blair08d19992016-08-10 15:25:31 -07004520 self.launch_server.failJob('project-test1', A)
4521 self.launch_server.failJob('project-test1', B)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004522 # Let C pass, resetting the counter
James E. Blair08d19992016-08-10 15:25:31 -07004523 self.launch_server.failJob('project-test1', D)
4524 self.launch_server.failJob('project-test1', E)
4525 self.launch_server.failJob('project-test1', F)
4526 self.launch_server.failJob('project-test1', G)
4527 self.launch_server.failJob('project-test1', H)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004528 # I also passes but should only report to the disabled reporters
James E. Blair08d19992016-08-10 15:25:31 -07004529 self.launch_server.failJob('project-test1', J)
4530 self.launch_server.failJob('project-test1', K)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004531
4532 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4533 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4534 self.waitUntilSettled()
4535
4536 self.assertEqual(
4537 2, self.sched.layout.pipelines['check']._consecutive_failures)
4538 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4539
4540 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4541 self.waitUntilSettled()
4542
4543 self.assertEqual(
4544 0, self.sched.layout.pipelines['check']._consecutive_failures)
4545 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4546
4547 self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1))
4548 self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1))
4549 self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1))
4550 self.waitUntilSettled()
4551
4552 # We should be disabled now
4553 self.assertEqual(
4554 3, self.sched.layout.pipelines['check']._consecutive_failures)
4555 self.assertTrue(self.sched.layout.pipelines['check']._disabled)
4556
4557 # We need to wait between each of these patches to make sure the
4558 # smtp messages come back in an expected order
4559 self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1))
4560 self.waitUntilSettled()
4561 self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1))
4562 self.waitUntilSettled()
4563 self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1))
4564 self.waitUntilSettled()
4565
4566 # The first 6 (ABCDEF) jobs should have reported back to gerrt thus
4567 # leaving a message on each change
4568 self.assertEqual(1, len(A.messages))
4569 self.assertIn('Build failed.', A.messages[0])
4570 self.assertEqual(1, len(B.messages))
4571 self.assertIn('Build failed.', B.messages[0])
4572 self.assertEqual(1, len(C.messages))
4573 self.assertIn('Build succeeded.', C.messages[0])
4574 self.assertEqual(1, len(D.messages))
4575 self.assertIn('Build failed.', D.messages[0])
4576 self.assertEqual(1, len(E.messages))
4577 self.assertIn('Build failed.', E.messages[0])
4578 self.assertEqual(1, len(F.messages))
4579 self.assertIn('Build failed.', F.messages[0])
4580
4581 # The last 3 (GHI) would have only reported via smtp.
4582 self.assertEqual(3, len(self.smtp_messages))
4583 self.assertEqual(0, len(G.messages))
4584 self.assertIn('Build failed.', self.smtp_messages[0]['body'])
4585 self.assertIn('/7/1/check', self.smtp_messages[0]['body'])
4586 self.assertEqual(0, len(H.messages))
4587 self.assertIn('Build failed.', self.smtp_messages[1]['body'])
4588 self.assertIn('/8/1/check', self.smtp_messages[1]['body'])
4589 self.assertEqual(0, len(I.messages))
4590 self.assertIn('Build succeeded.', self.smtp_messages[2]['body'])
4591 self.assertIn('/9/1/check', self.smtp_messages[2]['body'])
4592
4593 # Now reload the configuration (simulate a HUP) to check the pipeline
4594 # comes out of disabled
4595 self.sched.reconfigure(self.config)
4596
4597 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4598 self.assertEqual(
4599 0, self.sched.layout.pipelines['check']._consecutive_failures)
4600 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4601
4602 self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1))
4603 self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1))
4604 self.waitUntilSettled()
4605
4606 self.assertEqual(
4607 2, self.sched.layout.pipelines['check']._consecutive_failures)
4608 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4609
4610 # J and K went back to gerrit
4611 self.assertEqual(1, len(J.messages))
4612 self.assertIn('Build failed.', J.messages[0])
4613 self.assertEqual(1, len(K.messages))
4614 self.assertIn('Build failed.', K.messages[0])
4615 # No more messages reported via smtp
4616 self.assertEqual(3, len(self.smtp_messages))
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004617
James E. Blairec056492016-07-22 09:45:56 -07004618 @skip("Disabled for early v3 development")
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004619 def test_success_pattern(self):
4620 "Ensure bad build params are ignored"
4621
4622 # Use SMTP reporter to grab the result message easier
4623 self.init_repo("org/docs")
4624 self.config.set('zuul', 'layout_config',
4625 'tests/fixtures/layout-success-pattern.yaml')
4626 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07004627 self.launch_server.hold_jobs_in_build = True
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004628 self.registerJobs()
4629
4630 A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A')
4631 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4632 self.waitUntilSettled()
4633
4634 # Grab build id
4635 self.assertEqual(len(self.builds), 1)
4636 uuid = self.builds[0].unique[:7]
4637
James E. Blair08d19992016-08-10 15:25:31 -07004638 self.launch_server.hold_jobs_in_build = False
4639 self.launch_server.release()
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004640 self.waitUntilSettled()
4641
4642 self.assertEqual(len(self.smtp_messages), 1)
4643 body = self.smtp_messages[0]['body'].splitlines()
4644 self.assertEqual('Build succeeded.', body[0])
4645
4646 self.assertIn(
4647 '- docs-draft-test http://docs-draft.example.org/1/1/1/check/'
4648 'docs-draft-test/%s/publish-docs/' % uuid,
4649 body[2])
4650 self.assertIn(
4651 '- docs-draft-test2 https://server/job/docs-draft-test2/1/',
4652 body[3])
Arieb6f068c2016-10-09 13:11:06 +03004653
4654
4655class TestDuplicatePipeline(ZuulTestCase):
4656 tenant_config_file = 'config/duplicate-pipeline/main.yaml'
4657
4658 def test_duplicate_pipelines(self):
4659 "Test that a change matching multiple pipelines works"
4660
4661 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4662 self.fake_gerrit.addEvent(A.getChangeRestoredEvent())
4663 self.waitUntilSettled()
4664
4665 self.assertHistory([
4666 dict(name='project-test1', result='SUCCESS', changes='1,1',
4667 pipeline='dup1'),
4668 dict(name='project-test1', result='SUCCESS', changes='1,1',
4669 pipeline='dup2'),
4670 ])
4671
4672 self.assertEqual(len(A.messages), 2)
4673
4674 self.assertIn('dup1', A.messages[0])
4675 self.assertNotIn('dup2', A.messages[0])
4676 self.assertIn('project-test1', A.messages[0])
4677
4678 self.assertIn('dup2', A.messages[1])
4679 self.assertNotIn('dup1', A.messages[1])
4680 self.assertIn('project-test1', A.messages[1])