blob: be08e1c4175f7a590ec7ca5b9f7ed4938c0d425e [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. Blair063672f2015-01-29 13:09:12 -0800789 def test_needed_changes_enqueue(self):
790 "Test that a needed change is enqueued ahead"
791 # A Given a git tree like this, if we enqueue
792 # / \ change C, we should walk up and down the tree
793 # B G and enqueue changes in the order ABCDEFG.
794 # /|\ This is also the order that you would get if
795 # *C E F you enqueued changes in the order ABCDEFG, so
796 # / the ordering is stable across re-enqueue events.
797 # D
798
799 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
800 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
801 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
802 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
803 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
804 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
805 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
806 B.setDependsOn(A, 1)
807 C.setDependsOn(B, 1)
808 D.setDependsOn(C, 1)
809 E.setDependsOn(B, 1)
810 F.setDependsOn(B, 1)
811 G.setDependsOn(A, 1)
812
James E. Blair8b5408c2016-08-08 15:37:46 -0700813 A.addApproval('code-review', 2)
814 B.addApproval('code-review', 2)
815 C.addApproval('code-review', 2)
816 D.addApproval('code-review', 2)
817 E.addApproval('code-review', 2)
818 F.addApproval('code-review', 2)
819 G.addApproval('code-review', 2)
820 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800821
822 self.waitUntilSettled()
823
824 self.assertEqual(A.data['status'], 'NEW')
825 self.assertEqual(B.data['status'], 'NEW')
826 self.assertEqual(C.data['status'], 'NEW')
827 self.assertEqual(D.data['status'], 'NEW')
828 self.assertEqual(E.data['status'], 'NEW')
829 self.assertEqual(F.data['status'], 'NEW')
830 self.assertEqual(G.data['status'], 'NEW')
831
832 # We're about to add approvals to changes without adding the
833 # triggering events to Zuul, so that we can be sure that it is
834 # enqueing the changes based on dependencies, not because of
835 # triggering events. Since it will have the changes cached
836 # already (without approvals), we need to clear the cache
837 # first.
Paul Belanger593480a2016-11-02 19:06:28 -0400838 for connection in self.connections.connections.values():
Joshua Hesketh4bd7da32016-02-17 20:58:47 +1100839 connection.maintainCache([])
James E. Blair063672f2015-01-29 13:09:12 -0800840
James E. Blair08d19992016-08-10 15:25:31 -0700841 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -0700842 A.addApproval('approved', 1)
843 B.addApproval('approved', 1)
844 D.addApproval('approved', 1)
845 E.addApproval('approved', 1)
846 F.addApproval('approved', 1)
847 G.addApproval('approved', 1)
848 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800849
850 for x in range(8):
James E. Blair08d19992016-08-10 15:25:31 -0700851 self.launch_server.release('.*-merge')
James E. Blair063672f2015-01-29 13:09:12 -0800852 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700853 self.launch_server.hold_jobs_in_build = False
854 self.launch_server.release()
James E. Blair063672f2015-01-29 13:09:12 -0800855 self.waitUntilSettled()
856
857 self.assertEqual(A.data['status'], 'MERGED')
858 self.assertEqual(B.data['status'], 'MERGED')
859 self.assertEqual(C.data['status'], 'MERGED')
860 self.assertEqual(D.data['status'], 'MERGED')
861 self.assertEqual(E.data['status'], 'MERGED')
862 self.assertEqual(F.data['status'], 'MERGED')
863 self.assertEqual(G.data['status'], 'MERGED')
864 self.assertEqual(A.reported, 2)
865 self.assertEqual(B.reported, 2)
866 self.assertEqual(C.reported, 2)
867 self.assertEqual(D.reported, 2)
868 self.assertEqual(E.reported, 2)
869 self.assertEqual(F.reported, 2)
870 self.assertEqual(G.reported, 2)
871 self.assertEqual(self.history[6].changes,
872 '1,1 2,1 3,1 4,1 5,1 6,1 7,1')
873
James E. Blairec056492016-07-22 09:45:56 -0700874 @skip("Disabled for early v3 development")
Joshua Hesketh850ccb62014-11-27 11:31:02 +1100875 def test_source_cache(self):
876 "Test that the source cache operates correctly"
James E. Blair08d19992016-08-10 15:25:31 -0700877 self.launch_server.hold_jobs_in_build = True
James E. Blair0e933c52013-07-11 10:18:52 -0700878
879 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
880 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
881 X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X')
James E. Blair8b5408c2016-08-08 15:37:46 -0700882 A.addApproval('code-review', 2)
883 B.addApproval('code-review', 2)
James E. Blair0e933c52013-07-11 10:18:52 -0700884
885 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
886 M1.setMerged()
887
888 B.setDependsOn(A, 1)
889 A.setDependsOn(M1, 1)
890
James E. Blair8b5408c2016-08-08 15:37:46 -0700891 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700892 self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1))
893
894 self.waitUntilSettled()
895
896 for build in self.builds:
897 if build.parameters['ZUUL_PIPELINE'] == 'check':
898 build.release()
899 self.waitUntilSettled()
900 for build in self.builds:
901 if build.parameters['ZUUL_PIPELINE'] == 'check':
902 build.release()
903 self.waitUntilSettled()
904
James E. Blair8b5408c2016-08-08 15:37:46 -0700905 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700906 self.waitUntilSettled()
907
Joshua Hesketh352264b2015-08-11 23:42:08 +1000908 self.log.debug("len %s" % self.fake_gerrit._change_cache.keys())
James E. Blair0e933c52013-07-11 10:18:52 -0700909 # there should still be changes in the cache
Joshua Hesketh352264b2015-08-11 23:42:08 +1000910 self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0)
James E. Blair0e933c52013-07-11 10:18:52 -0700911
James E. Blair08d19992016-08-10 15:25:31 -0700912 self.launch_server.hold_jobs_in_build = False
913 self.launch_server.release()
James E. Blair0e933c52013-07-11 10:18:52 -0700914 self.waitUntilSettled()
915
916 self.assertEqual(A.data['status'], 'MERGED')
917 self.assertEqual(B.data['status'], 'MERGED')
918 self.assertEqual(A.queried, 2) # Initial and isMerged
919 self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged
920
James E. Blair8c803f82012-07-31 16:25:42 -0700921 def test_can_merge(self):
James E. Blair4886cc12012-07-18 15:39:41 -0700922 "Test whether a change is ready to merge"
James E. Blair8c803f82012-07-31 16:25:42 -0700923 # TODO: move to test_gerrit (this is a unit test!)
924 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
Paul Belanger9bba4902016-11-02 16:07:33 -0400925 tenant = self.sched.abide.tenants.get('tenant-one')
926 source = tenant.layout.pipelines['gate'].source
927
928 # TODO(pabelanger): As we add more source / trigger APIs we should make
929 # it easier for users to create events for testing.
930 event = zuul.model.TriggerEvent()
931 event.trigger_name = 'gerrit'
932 event.change_number = '1'
933 event.patch_number = '2'
934
935 a = source.getChange(event)
936 mgr = tenant.layout.pipelines['gate'].manager
James E. Blairc0dedf82014-08-06 09:37:52 -0700937 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700938
James E. Blair8b5408c2016-08-08 15:37:46 -0700939 A.addApproval('code-review', 2)
Paul Belanger9bba4902016-11-02 16:07:33 -0400940 a = source.getChange(event, refresh=True)
James E. Blairc0dedf82014-08-06 09:37:52 -0700941 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700942
James E. Blair8b5408c2016-08-08 15:37:46 -0700943 A.addApproval('approved', 1)
Paul Belanger9bba4902016-11-02 16:07:33 -0400944 a = source.getChange(event, refresh=True)
James E. Blairc0dedf82014-08-06 09:37:52 -0700945 self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair4886cc12012-07-18 15:39:41 -0700946
James E. Blairec056492016-07-22 09:45:56 -0700947 @skip("Disabled for early v3 development")
James E. Blair4886cc12012-07-18 15:39:41 -0700948 def test_build_configuration(self):
949 "Test that zuul merges the right commits for testing"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700950
951 self.gearman_server.hold_jobs_in_queue = True
James E. Blair4886cc12012-07-18 15:39:41 -0700952 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
953 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
954 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700955 A.addApproval('code-review', 2)
956 B.addApproval('code-review', 2)
957 C.addApproval('code-review', 2)
958 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
959 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
960 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair4886cc12012-07-18 15:39:41 -0700961 self.waitUntilSettled()
962
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700963 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700964 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700965 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700966 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700967 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700968 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700969 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700970 ref = self.getParameter(queue[-1], 'ZUUL_REF')
971 self.gearman_server.hold_jobs_in_queue = False
972 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -0700973 self.waitUntilSettled()
James E. Blair4886cc12012-07-18 15:39:41 -0700974
Monty Taylorbc758832013-06-17 17:22:42 -0400975 path = os.path.join(self.git_root, "org/project")
James E. Blair4886cc12012-07-18 15:39:41 -0700976 repo = git.Repo(path)
977 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
978 repo_messages.reverse()
James E. Blair4886cc12012-07-18 15:39:41 -0700979 correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400980 self.assertEqual(repo_messages, correct_messages)
James E. Blair973721f2012-08-15 10:19:43 -0700981
James E. Blairec056492016-07-22 09:45:56 -0700982 @skip("Disabled for early v3 development")
James E. Blair973721f2012-08-15 10:19:43 -0700983 def test_build_configuration_conflict(self):
984 "Test that merge conflicts are handled"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700985
986 self.gearman_server.hold_jobs_in_queue = True
James E. Blair6736beb2013-07-11 15:18:15 -0700987 A = self.fake_gerrit.addFakeChange('org/conflict-project',
988 'master', 'A')
James E. Blair973721f2012-08-15 10:19:43 -0700989 A.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700990 B = self.fake_gerrit.addFakeChange('org/conflict-project',
991 'master', 'B')
James E. Blair973721f2012-08-15 10:19:43 -0700992 B.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700993 C = self.fake_gerrit.addFakeChange('org/conflict-project',
994 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700995 A.addApproval('code-review', 2)
996 B.addApproval('code-review', 2)
997 C.addApproval('code-review', 2)
998 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
999 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1000 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair973721f2012-08-15 10:19:43 -07001001 self.waitUntilSettled()
1002
James E. Blair6736beb2013-07-11 15:18:15 -07001003 self.assertEqual(A.reported, 1)
1004 self.assertEqual(B.reported, 1)
1005 self.assertEqual(C.reported, 1)
1006
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001007 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001008 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001009 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001010 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001011 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001012 self.waitUntilSettled()
James E. Blair972e3c72013-08-29 12:04:55 -07001013
1014 self.assertEqual(len(self.history), 2) # A and C merge jobs
1015
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001016 self.gearman_server.hold_jobs_in_queue = False
1017 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -07001018 self.waitUntilSettled()
1019
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001020 self.assertEqual(A.data['status'], 'MERGED')
1021 self.assertEqual(B.data['status'], 'NEW')
1022 self.assertEqual(C.data['status'], 'MERGED')
1023 self.assertEqual(A.reported, 2)
1024 self.assertEqual(B.reported, 2)
1025 self.assertEqual(C.reported, 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001026 self.assertEqual(len(self.history), 6)
James E. Blair6736beb2013-07-11 15:18:15 -07001027
James E. Blairec056492016-07-22 09:45:56 -07001028 @skip("Disabled for early v3 development")
James E. Blairdaabed22012-08-15 15:38:57 -07001029 def test_post(self):
1030 "Test that post jobs run"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001031
Zhongyue Luo5d556072012-09-21 02:00:47 +09001032 e = {
1033 "type": "ref-updated",
1034 "submitter": {
1035 "name": "User Name",
1036 },
1037 "refUpdate": {
1038 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1039 "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543",
1040 "refName": "master",
1041 "project": "org/project",
1042 }
1043 }
James E. Blairdaabed22012-08-15 15:38:57 -07001044 self.fake_gerrit.addEvent(e)
1045 self.waitUntilSettled()
1046
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001047 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001048 self.assertEqual(len(self.history), 1)
1049 self.assertIn('project-post', job_names)
James E. Blairc6294a52012-08-17 10:19:48 -07001050
James E. Blairec056492016-07-22 09:45:56 -07001051 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001052 def test_post_ignore_deletes(self):
1053 "Test that deleting refs does not trigger post jobs"
1054
1055 e = {
1056 "type": "ref-updated",
1057 "submitter": {
1058 "name": "User Name",
1059 },
1060 "refUpdate": {
1061 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1062 "newRev": "0000000000000000000000000000000000000000",
1063 "refName": "master",
1064 "project": "org/project",
1065 }
1066 }
1067 self.fake_gerrit.addEvent(e)
1068 self.waitUntilSettled()
1069
1070 job_names = [x.name for x in self.history]
1071 self.assertEqual(len(self.history), 0)
1072 self.assertNotIn('project-post', job_names)
1073
James E. Blairec056492016-07-22 09:45:56 -07001074 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001075 def test_post_ignore_deletes_negative(self):
1076 "Test that deleting refs does trigger post jobs"
1077
James E. Blairf84026c2015-12-08 16:11:46 -08001078 self.updateConfigLayout(
1079 'tests/fixtures/layout-dont-ignore-deletes.yaml')
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001080 self.sched.reconfigure(self.config)
1081
1082 e = {
1083 "type": "ref-updated",
1084 "submitter": {
1085 "name": "User Name",
1086 },
1087 "refUpdate": {
1088 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1089 "newRev": "0000000000000000000000000000000000000000",
1090 "refName": "master",
1091 "project": "org/project",
1092 }
1093 }
1094 self.fake_gerrit.addEvent(e)
1095 self.waitUntilSettled()
1096
1097 job_names = [x.name for x in self.history]
1098 self.assertEqual(len(self.history), 1)
1099 self.assertIn('project-post', job_names)
1100
James E. Blairec056492016-07-22 09:45:56 -07001101 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001102 def test_build_configuration_branch(self):
1103 "Test that the right commits are on alternate branches"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001104
1105 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001106 A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A')
1107 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1108 C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001109 A.addApproval('code-review', 2)
1110 B.addApproval('code-review', 2)
1111 C.addApproval('code-review', 2)
1112 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1113 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1114 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001115 self.waitUntilSettled()
1116
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001117 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001118 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001119 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001120 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001121 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001122 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001123 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001124 ref = self.getParameter(queue[-1], 'ZUUL_REF')
1125 self.gearman_server.hold_jobs_in_queue = False
1126 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001127 self.waitUntilSettled()
1128
Monty Taylorbc758832013-06-17 17:22:42 -04001129 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001130 repo = git.Repo(path)
1131 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
1132 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001133 correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001134 self.assertEqual(repo_messages, correct_messages)
James E. Blairc6294a52012-08-17 10:19:48 -07001135
James E. Blairec056492016-07-22 09:45:56 -07001136 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001137 def test_build_configuration_branch_interaction(self):
1138 "Test that switching between branches works"
1139 self.test_build_configuration()
1140 self.test_build_configuration_branch()
1141 # C has been merged, undo that
Monty Taylorbc758832013-06-17 17:22:42 -04001142 path = os.path.join(self.upstream_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001143 repo = git.Repo(path)
1144 repo.heads.master.commit = repo.commit('init')
1145 self.test_build_configuration()
1146
James E. Blairec056492016-07-22 09:45:56 -07001147 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001148 def test_build_configuration_multi_branch(self):
1149 "Test that dependent changes on multiple branches are merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001150
1151 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001152 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1153 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1154 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001155 A.addApproval('code-review', 2)
1156 B.addApproval('code-review', 2)
1157 C.addApproval('code-review', 2)
1158 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1159 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1160 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001161 self.waitUntilSettled()
James E. Blairbb1fe502014-03-04 10:15:06 -08001162 queue = self.gearman_server.getQueue()
1163 job_A = None
1164 for job in queue:
1165 if 'project-merge' in job.name:
1166 job_A = job
1167 ref_A = self.getParameter(job_A, 'ZUUL_REF')
1168 commit_A = self.getParameter(job_A, 'ZUUL_COMMIT')
1169 self.log.debug("Got Zuul ref for change A: %s" % ref_A)
1170 self.log.debug("Got Zuul commit for change A: %s" % commit_A)
James E. Blairc6294a52012-08-17 10:19:48 -07001171
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001172 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001173 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001174 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001175 job_B = None
1176 for job in queue:
1177 if 'project-merge' in job.name:
1178 job_B = job
1179 ref_B = self.getParameter(job_B, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001180 commit_B = self.getParameter(job_B, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001181 self.log.debug("Got Zuul ref for change B: %s" % ref_B)
James E. Blairbb1fe502014-03-04 10:15:06 -08001182 self.log.debug("Got Zuul commit for change B: %s" % commit_B)
1183
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001184 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001185 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001186 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001187 for job in queue:
1188 if 'project-merge' in job.name:
1189 job_C = job
1190 ref_C = self.getParameter(job_C, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001191 commit_C = self.getParameter(job_C, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001192 self.log.debug("Got Zuul ref for change C: %s" % ref_C)
James E. Blairbb1fe502014-03-04 10:15:06 -08001193 self.log.debug("Got Zuul commit for change C: %s" % commit_C)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001194 self.gearman_server.hold_jobs_in_queue = False
1195 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001196 self.waitUntilSettled()
1197
Monty Taylorbc758832013-06-17 17:22:42 -04001198 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001199 repo = git.Repo(path)
1200
1201 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001202 for c in repo.iter_commits(ref_C)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001203 repo_shas = [c.hexsha for c in repo.iter_commits(ref_C)]
James E. Blairc6294a52012-08-17 10:19:48 -07001204 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001205 correct_messages = ['initial commit', 'A-1', 'C-1']
James E. Blairbb1fe502014-03-04 10:15:06 -08001206 # Ensure the right commits are in the history for this ref
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001207 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001208 # Ensure ZUUL_REF -> ZUUL_COMMIT
1209 self.assertEqual(repo_shas[0], commit_C)
James E. Blairc6294a52012-08-17 10:19:48 -07001210
1211 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001212 for c in repo.iter_commits(ref_B)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001213 repo_shas = [c.hexsha for c in repo.iter_commits(ref_B)]
James E. Blairc6294a52012-08-17 10:19:48 -07001214 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001215 correct_messages = ['initial commit', 'mp commit', 'B-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001216 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001217 self.assertEqual(repo_shas[0], commit_B)
1218
1219 repo_messages = [c.message.strip()
1220 for c in repo.iter_commits(ref_A)]
1221 repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)]
1222 repo_messages.reverse()
1223 correct_messages = ['initial commit', 'A-1']
1224 self.assertEqual(repo_messages, correct_messages)
1225 self.assertEqual(repo_shas[0], commit_A)
1226
1227 self.assertNotEqual(ref_A, ref_B, ref_C)
1228 self.assertNotEqual(commit_A, commit_B, commit_C)
James E. Blair7f71c802012-08-22 13:04:32 -07001229
James E. Blairec056492016-07-22 09:45:56 -07001230 @skip("Disabled for early v3 development")
James E. Blair7f71c802012-08-22 13:04:32 -07001231 def test_one_job_project(self):
1232 "Test that queueing works with one job"
1233 A = self.fake_gerrit.addFakeChange('org/one-job-project',
1234 'master', 'A')
1235 B = self.fake_gerrit.addFakeChange('org/one-job-project',
1236 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07001237 A.addApproval('code-review', 2)
1238 B.addApproval('code-review', 2)
1239 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1240 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair7f71c802012-08-22 13:04:32 -07001241 self.waitUntilSettled()
1242
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001243 self.assertEqual(A.data['status'], 'MERGED')
1244 self.assertEqual(A.reported, 2)
1245 self.assertEqual(B.data['status'], 'MERGED')
1246 self.assertEqual(B.reported, 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001247
James E. Blairec056492016-07-22 09:45:56 -07001248 @skip("Disabled for early v3 development")
Antoine Musso80edd5a2013-02-13 15:37:53 +01001249 def test_job_from_templates_launched(self):
1250 "Test whether a job generated via a template can be launched"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001251
Antoine Musso80edd5a2013-02-13 15:37:53 +01001252 A = self.fake_gerrit.addFakeChange(
1253 'org/templated-project', 'master', 'A')
1254 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1255 self.waitUntilSettled()
Antoine Musso80edd5a2013-02-13 15:37:53 +01001256
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001257 self.assertEqual(self.getJobFromHistory('project-test1').result,
1258 'SUCCESS')
1259 self.assertEqual(self.getJobFromHistory('project-test2').result,
1260 'SUCCESS')
Antoine Musso80edd5a2013-02-13 15:37:53 +01001261
James E. Blairec056492016-07-22 09:45:56 -07001262 @skip("Disabled for early v3 development")
James E. Blair3e98c022013-12-16 15:25:38 -08001263 def test_layered_templates(self):
1264 "Test whether a job generated via a template can be launched"
1265
1266 A = self.fake_gerrit.addFakeChange(
1267 'org/layered-project', 'master', 'A')
1268 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1269 self.waitUntilSettled()
1270
1271 self.assertEqual(self.getJobFromHistory('project-test1').result,
1272 'SUCCESS')
1273 self.assertEqual(self.getJobFromHistory('project-test2').result,
1274 'SUCCESS')
James E. Blairaea6cf62013-12-16 15:38:12 -08001275 self.assertEqual(self.getJobFromHistory('layered-project-test3'
1276 ).result, 'SUCCESS')
1277 self.assertEqual(self.getJobFromHistory('layered-project-test4'
1278 ).result, 'SUCCESS')
James E. Blair12a92b12014-03-26 11:54:53 -07001279 self.assertEqual(self.getJobFromHistory('layered-project-foo-test5'
1280 ).result, 'SUCCESS')
James E. Blair3e98c022013-12-16 15:25:38 -08001281 self.assertEqual(self.getJobFromHistory('project-test6').result,
1282 'SUCCESS')
1283
James E. Blaircaec0c52012-08-22 14:52:22 -07001284 def test_dependent_changes_dequeue(self):
1285 "Test that dependent patches are not needlessly tested"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001286
James E. Blaircaec0c52012-08-22 14:52:22 -07001287 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1288 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1289 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001290 A.addApproval('code-review', 2)
1291 B.addApproval('code-review', 2)
1292 C.addApproval('code-review', 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001293
1294 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
1295 M1.setMerged()
1296
1297 # C -> B -> A -> M1
1298
1299 C.setDependsOn(B, 1)
1300 B.setDependsOn(A, 1)
1301 A.setDependsOn(M1, 1)
1302
James E. Blair08d19992016-08-10 15:25:31 -07001303 self.launch_server.failJob('project-merge', A)
James E. Blaircaec0c52012-08-22 14:52:22 -07001304
James E. Blair8b5408c2016-08-08 15:37:46 -07001305 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1306 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1307 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircaec0c52012-08-22 14:52:22 -07001308
1309 self.waitUntilSettled()
1310
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001311 self.assertEqual(A.data['status'], 'NEW')
1312 self.assertEqual(A.reported, 2)
1313 self.assertEqual(B.data['status'], 'NEW')
1314 self.assertEqual(B.reported, 2)
1315 self.assertEqual(C.data['status'], 'NEW')
1316 self.assertEqual(C.reported, 2)
1317 self.assertEqual(len(self.history), 1)
James E. Blairec590122012-08-22 15:19:31 -07001318
James E. Blair972e3c72013-08-29 12:04:55 -07001319 def test_failing_dependent_changes(self):
1320 "Test that failing dependent patches are taken out of stream"
James E. Blair08d19992016-08-10 15:25:31 -07001321 self.launch_server.hold_jobs_in_build = True
James E. Blair972e3c72013-08-29 12:04:55 -07001322 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1323 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1324 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1325 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
1326 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
James E. Blair8b5408c2016-08-08 15:37:46 -07001327 A.addApproval('code-review', 2)
1328 B.addApproval('code-review', 2)
1329 C.addApproval('code-review', 2)
1330 D.addApproval('code-review', 2)
1331 E.addApproval('code-review', 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001332
1333 # E, D -> C -> B, A
1334
1335 D.setDependsOn(C, 1)
1336 C.setDependsOn(B, 1)
1337
James E. Blair08d19992016-08-10 15:25:31 -07001338 self.launch_server.failJob('project-test1', B)
James E. Blair972e3c72013-08-29 12:04:55 -07001339
James E. Blair8b5408c2016-08-08 15:37:46 -07001340 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1341 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
1342 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1343 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1344 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair972e3c72013-08-29 12:04:55 -07001345
1346 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001347 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001348 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001349 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001350 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001351 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001352 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001353 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001354 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001355 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001356 self.waitUntilSettled()
1357
James E. Blair08d19992016-08-10 15:25:31 -07001358 self.launch_server.hold_jobs_in_build = False
James E. Blair972e3c72013-08-29 12:04:55 -07001359 for build in self.builds:
1360 if build.parameters['ZUUL_CHANGE'] != '1':
1361 build.release()
1362 self.waitUntilSettled()
1363
James E. Blair08d19992016-08-10 15:25:31 -07001364 self.launch_server.release()
James E. Blair972e3c72013-08-29 12:04:55 -07001365 self.waitUntilSettled()
1366
1367 self.assertEqual(A.data['status'], 'MERGED')
1368 self.assertEqual(A.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001369 self.assertIn('Build succeeded', A.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001370 self.assertEqual(B.data['status'], 'NEW')
1371 self.assertEqual(B.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001372 self.assertIn('Build failed', B.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001373 self.assertEqual(C.data['status'], 'NEW')
1374 self.assertEqual(C.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001375 self.assertIn('depends on a change', C.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001376 self.assertEqual(D.data['status'], 'NEW')
1377 self.assertEqual(D.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001378 self.assertIn('depends on a change', D.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001379 self.assertEqual(E.data['status'], 'MERGED')
1380 self.assertEqual(E.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001381 self.assertIn('Build succeeded', E.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001382 self.assertEqual(len(self.history), 18)
1383
James E. Blairec056492016-07-22 09:45:56 -07001384 @skip("Disabled for early v3 development")
James E. Blairec590122012-08-22 15:19:31 -07001385 def test_head_is_dequeued_once(self):
James E. Blair2fa50962013-01-30 21:50:41 -08001386 "Test that if a change at the head fails it is dequeued only once"
James E. Blairec590122012-08-22 15:19:31 -07001387 # If it's dequeued more than once, we should see extra
1388 # aborted jobs.
James E. Blairec590122012-08-22 15:19:31 -07001389
James E. Blair08d19992016-08-10 15:25:31 -07001390 self.launch_server.hold_jobs_in_build = True
James E. Blairec590122012-08-22 15:19:31 -07001391 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1392 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1393 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001394 A.addApproval('code-review', 2)
1395 B.addApproval('code-review', 2)
1396 C.addApproval('code-review', 2)
James E. Blairec590122012-08-22 15:19:31 -07001397
James E. Blair08d19992016-08-10 15:25:31 -07001398 self.launch_server.failJob('project1-test1', A)
1399 self.launch_server.failJob('project1-test2', A)
1400 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairec590122012-08-22 15:19:31 -07001401
James E. Blair8b5408c2016-08-08 15:37:46 -07001402 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1403 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1404 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairec590122012-08-22 15:19:31 -07001405
1406 self.waitUntilSettled()
James E. Blairec590122012-08-22 15:19:31 -07001407
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001408 self.assertEqual(len(self.builds), 1)
1409 self.assertEqual(self.builds[0].name, 'project1-merge')
1410 self.assertTrue(self.job_has_changes(self.builds[0], A))
James E. Blairec590122012-08-22 15:19:31 -07001411
James E. Blair08d19992016-08-10 15:25:31 -07001412 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001413 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001414 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001415 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001416 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001417 self.waitUntilSettled()
1418
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001419 self.assertEqual(len(self.builds), 9)
1420 self.assertEqual(self.builds[0].name, 'project1-test1')
1421 self.assertEqual(self.builds[1].name, 'project1-test2')
1422 self.assertEqual(self.builds[2].name, 'project1-project2-integration')
1423 self.assertEqual(self.builds[3].name, 'project1-test1')
1424 self.assertEqual(self.builds[4].name, 'project1-test2')
1425 self.assertEqual(self.builds[5].name, 'project1-project2-integration')
1426 self.assertEqual(self.builds[6].name, 'project1-test1')
1427 self.assertEqual(self.builds[7].name, 'project1-test2')
1428 self.assertEqual(self.builds[8].name, 'project1-project2-integration')
James E. Blairec590122012-08-22 15:19:31 -07001429
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001430 self.release(self.builds[0])
James E. Blairec590122012-08-22 15:19:31 -07001431 self.waitUntilSettled()
1432
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001433 self.assertEqual(len(self.builds), 3) # test2,integration, merge for B
1434 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6)
James E. Blairec590122012-08-22 15:19:31 -07001435
James E. Blair08d19992016-08-10 15:25:31 -07001436 self.launch_server.hold_jobs_in_build = False
1437 self.launch_server.release()
James E. Blairec590122012-08-22 15:19:31 -07001438 self.waitUntilSettled()
1439
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001440 self.assertEqual(len(self.builds), 0)
1441 self.assertEqual(len(self.history), 20)
James E. Blaircaec0c52012-08-22 14:52:22 -07001442
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001443 self.assertEqual(A.data['status'], 'NEW')
1444 self.assertEqual(B.data['status'], 'MERGED')
1445 self.assertEqual(C.data['status'], 'MERGED')
1446 self.assertEqual(A.reported, 2)
1447 self.assertEqual(B.reported, 2)
1448 self.assertEqual(C.reported, 2)
James E. Blair4ec821f2012-08-23 15:28:28 -07001449
James E. Blairec056492016-07-22 09:45:56 -07001450 @skip("Disabled for early v3 development")
James E. Blair4ec821f2012-08-23 15:28:28 -07001451 def test_nonvoting_job(self):
1452 "Test that non-voting jobs don't vote."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001453
James E. Blair4ec821f2012-08-23 15:28:28 -07001454 A = self.fake_gerrit.addFakeChange('org/nonvoting-project',
1455 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001456 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07001457 self.launch_server.failJob('nonvoting-project-test2', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07001458 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4ec821f2012-08-23 15:28:28 -07001459
1460 self.waitUntilSettled()
James E. Blair4ec821f2012-08-23 15:28:28 -07001461
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001462 self.assertEqual(A.data['status'], 'MERGED')
1463 self.assertEqual(A.reported, 2)
1464 self.assertEqual(
1465 self.getJobFromHistory('nonvoting-project-merge').result,
1466 'SUCCESS')
1467 self.assertEqual(
1468 self.getJobFromHistory('nonvoting-project-test1').result,
1469 'SUCCESS')
1470 self.assertEqual(
1471 self.getJobFromHistory('nonvoting-project-test2').result,
1472 'FAILURE')
James E. Blaire0487072012-08-29 17:38:31 -07001473
James E. Blair5821bd92015-09-16 08:48:15 -07001474 for build in self.builds:
1475 self.assertEqual(build.parameters['ZUUL_VOTING'], '0')
1476
James E. Blairec056492016-07-22 09:45:56 -07001477 @skip("Disabled for early v3 development")
James E. Blaire0487072012-08-29 17:38:31 -07001478 def test_check_queue_success(self):
1479 "Test successful check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001480
James E. Blaire0487072012-08-29 17:38:31 -07001481 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1482 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1483
1484 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001485
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001486 self.assertEqual(A.data['status'], 'NEW')
1487 self.assertEqual(A.reported, 1)
1488 self.assertEqual(self.getJobFromHistory('project-merge').result,
1489 'SUCCESS')
1490 self.assertEqual(self.getJobFromHistory('project-test1').result,
1491 'SUCCESS')
1492 self.assertEqual(self.getJobFromHistory('project-test2').result,
1493 'SUCCESS')
James E. Blaire0487072012-08-29 17:38:31 -07001494
James E. Blairec056492016-07-22 09:45:56 -07001495 @skip("Disabled for early v3 development")
James E. Blaire0487072012-08-29 17:38:31 -07001496 def test_check_queue_failure(self):
1497 "Test failed check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001498
James E. Blaire0487072012-08-29 17:38:31 -07001499 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair08d19992016-08-10 15:25:31 -07001500 self.launch_server.failJob('project-test2', A)
James E. Blaire0487072012-08-29 17:38:31 -07001501 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1502
1503 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001504
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001505 self.assertEqual(A.data['status'], 'NEW')
1506 self.assertEqual(A.reported, 1)
1507 self.assertEqual(self.getJobFromHistory('project-merge').result,
James E. Blair78e31b32013-07-09 09:11:34 -07001508 'SUCCESS')
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001509 self.assertEqual(self.getJobFromHistory('project-test1').result,
1510 'SUCCESS')
1511 self.assertEqual(self.getJobFromHistory('project-test2').result,
1512 'FAILURE')
James E. Blair127bc182012-08-28 15:55:15 -07001513
James E. Blairec056492016-07-22 09:45:56 -07001514 @skip("Disabled for early v3 development")
James E. Blair127bc182012-08-28 15:55:15 -07001515 def test_dependent_behind_dequeue(self):
1516 "test that dependent changes behind dequeued changes work"
1517 # This complicated test is a reproduction of a real life bug
1518 self.sched.reconfigure(self.config)
James E. Blair127bc182012-08-28 15:55:15 -07001519
James E. Blair08d19992016-08-10 15:25:31 -07001520 self.launch_server.hold_jobs_in_build = True
James E. Blair127bc182012-08-28 15:55:15 -07001521 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1522 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1523 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
1524 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
1525 E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E')
1526 F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F')
1527 D.setDependsOn(C, 1)
1528 E.setDependsOn(D, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07001529 A.addApproval('code-review', 2)
1530 B.addApproval('code-review', 2)
1531 C.addApproval('code-review', 2)
1532 D.addApproval('code-review', 2)
1533 E.addApproval('code-review', 2)
1534 F.addApproval('code-review', 2)
James E. Blair127bc182012-08-28 15:55:15 -07001535
1536 A.fail_merge = True
James E. Blair127bc182012-08-28 15:55:15 -07001537
1538 # Change object re-use in the gerrit trigger is hidden if
1539 # changes are added in quick succession; waiting makes it more
1540 # like real life.
James E. Blair8b5408c2016-08-08 15:37:46 -07001541 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001542 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001543 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001544 self.waitUntilSettled()
1545
James E. Blair08d19992016-08-10 15:25:31 -07001546 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001547 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001548 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001549 self.waitUntilSettled()
1550
James E. Blair8b5408c2016-08-08 15:37:46 -07001551 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001552 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001553 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001554 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001555 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001556 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001557 self.fake_gerrit.addEvent(F.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001558 self.waitUntilSettled()
1559
James E. Blair08d19992016-08-10 15:25:31 -07001560 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001561 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001562 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001563 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001564 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001565 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001566 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001567 self.waitUntilSettled()
1568
1569 # all jobs running
James E. Blaire955e062012-10-08 09:49:03 -07001570
1571 # Grab pointers to the jobs we want to release before
1572 # releasing any, because list indexes may change as
1573 # the jobs complete.
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001574 a, b, c = self.builds[:3]
James E. Blaire955e062012-10-08 09:49:03 -07001575 a.release()
1576 b.release()
1577 c.release()
James E. Blair127bc182012-08-28 15:55:15 -07001578 self.waitUntilSettled()
1579
James E. Blair08d19992016-08-10 15:25:31 -07001580 self.launch_server.hold_jobs_in_build = False
1581 self.launch_server.release()
James E. Blair127bc182012-08-28 15:55:15 -07001582 self.waitUntilSettled()
1583
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001584 self.assertEqual(A.data['status'], 'NEW')
1585 self.assertEqual(B.data['status'], 'MERGED')
1586 self.assertEqual(C.data['status'], 'MERGED')
1587 self.assertEqual(D.data['status'], 'MERGED')
1588 self.assertEqual(E.data['status'], 'MERGED')
1589 self.assertEqual(F.data['status'], 'MERGED')
James E. Blair127bc182012-08-28 15:55:15 -07001590
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001591 self.assertEqual(A.reported, 2)
1592 self.assertEqual(B.reported, 2)
1593 self.assertEqual(C.reported, 2)
1594 self.assertEqual(D.reported, 2)
1595 self.assertEqual(E.reported, 2)
1596 self.assertEqual(F.reported, 2)
James E. Blair127bc182012-08-28 15:55:15 -07001597
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001598 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15)
1599 self.assertEqual(len(self.history), 44)
James E. Blair05fed602012-09-07 12:45:24 -07001600
James E. Blairec056492016-07-22 09:45:56 -07001601 @skip("Disabled for early v3 development")
James E. Blair05fed602012-09-07 12:45:24 -07001602 def test_merger_repack(self):
1603 "Test that the merger works after a repack"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001604
James E. Blair05fed602012-09-07 12:45:24 -07001605 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001606 A.addApproval('code-review', 2)
1607 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001608 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001609 self.assertEqual(self.getJobFromHistory('project-merge').result,
1610 'SUCCESS')
1611 self.assertEqual(self.getJobFromHistory('project-test1').result,
1612 'SUCCESS')
1613 self.assertEqual(self.getJobFromHistory('project-test2').result,
1614 'SUCCESS')
1615 self.assertEqual(A.data['status'], 'MERGED')
1616 self.assertEqual(A.reported, 2)
James E. Blair05fed602012-09-07 12:45:24 -07001617 self.assertEmptyQueues()
James E. Blair4ca985f2013-05-30 12:27:43 -07001618 self.worker.build_history = []
James E. Blair05fed602012-09-07 12:45:24 -07001619
Monty Taylorbc758832013-06-17 17:22:42 -04001620 path = os.path.join(self.git_root, "org/project")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001621 print(repack_repo(path))
James E. Blair05fed602012-09-07 12:45:24 -07001622
1623 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001624 A.addApproval('code-review', 2)
1625 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001626 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001627 self.assertEqual(self.getJobFromHistory('project-merge').result,
1628 'SUCCESS')
1629 self.assertEqual(self.getJobFromHistory('project-test1').result,
1630 'SUCCESS')
1631 self.assertEqual(self.getJobFromHistory('project-test2').result,
1632 'SUCCESS')
1633 self.assertEqual(A.data['status'], 'MERGED')
1634 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001635
James E. Blairec056492016-07-22 09:45:56 -07001636 @skip("Disabled for early v3 development")
James E. Blair4886f282012-11-15 09:27:33 -08001637 def test_merger_repack_large_change(self):
1638 "Test that the merger works with large changes after a repack"
1639 # https://bugs.launchpad.net/zuul/+bug/1078946
James E. Blairac2c3242014-01-24 13:38:51 -08001640 # This test assumes the repo is already cloned; make sure it is
Joshua Hesketh352264b2015-08-11 23:42:08 +10001641 url = self.fake_gerrit.getGitUrl(
James E. Blairac2c3242014-01-24 13:38:51 -08001642 self.sched.layout.projects['org/project1'])
James E. Blair4076e2b2014-01-28 12:42:20 -08001643 self.merge_server.merger.addProject('org/project1', url)
James E. Blair4886f282012-11-15 09:27:33 -08001644 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1645 A.addPatchset(large=True)
Monty Taylorbc758832013-06-17 17:22:42 -04001646 path = os.path.join(self.upstream_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001647 print(repack_repo(path))
Monty Taylorbc758832013-06-17 17:22:42 -04001648 path = os.path.join(self.git_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001649 print(repack_repo(path))
James E. Blair4886f282012-11-15 09:27:33 -08001650
James E. Blair8b5408c2016-08-08 15:37:46 -07001651 A.addApproval('code-review', 2)
1652 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4886f282012-11-15 09:27:33 -08001653 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001654 self.assertEqual(self.getJobFromHistory('project1-merge').result,
1655 'SUCCESS')
1656 self.assertEqual(self.getJobFromHistory('project1-test1').result,
1657 'SUCCESS')
1658 self.assertEqual(self.getJobFromHistory('project1-test2').result,
1659 'SUCCESS')
1660 self.assertEqual(A.data['status'], 'MERGED')
1661 self.assertEqual(A.reported, 2)
James E. Blair4886f282012-11-15 09:27:33 -08001662
James E. Blairec056492016-07-22 09:45:56 -07001663 @skip("Disabled for early v3 development")
James E. Blair7ee88a22012-09-12 18:59:31 +02001664 def test_nonexistent_job(self):
1665 "Test launching a job that doesn't exist"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001666 # Set to the state immediately after a restart
1667 self.resetGearmanServer()
1668 self.launcher.negative_function_cache_ttl = 0
James E. Blair7ee88a22012-09-12 18:59:31 +02001669
1670 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001671 A.addApproval('code-review', 2)
1672 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001673 # There may be a thread about to report a lost change
1674 while A.reported < 2:
1675 self.waitUntilSettled()
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001676 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001677 self.assertFalse(job_names)
1678 self.assertEqual(A.data['status'], 'NEW')
1679 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001680 self.assertEmptyQueues()
1681
1682 # Make sure things still work:
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001683 self.registerJobs()
James E. Blair7ee88a22012-09-12 18:59:31 +02001684 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001685 A.addApproval('code-review', 2)
1686 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001687 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001688 self.assertEqual(self.getJobFromHistory('project-merge').result,
1689 'SUCCESS')
1690 self.assertEqual(self.getJobFromHistory('project-test1').result,
1691 'SUCCESS')
1692 self.assertEqual(self.getJobFromHistory('project-test2').result,
1693 'SUCCESS')
1694 self.assertEqual(A.data['status'], 'MERGED')
1695 self.assertEqual(A.reported, 2)
James E. Blairf62d4282012-12-31 17:01:50 -08001696
James E. Blairec056492016-07-22 09:45:56 -07001697 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001698 def test_new_patchset_dequeues_old(self):
1699 "Test that a new patchset causes the old to be dequeued"
1700 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001701 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001702 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1703 M.setMerged()
1704
1705 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1706 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1707 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1708 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001709 A.addApproval('code-review', 2)
1710 B.addApproval('code-review', 2)
1711 C.addApproval('code-review', 2)
1712 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001713
1714 C.setDependsOn(B, 1)
1715 B.setDependsOn(A, 1)
1716 A.setDependsOn(M, 1)
1717
James E. Blair8b5408c2016-08-08 15:37:46 -07001718 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1719 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1720 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1721 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001722 self.waitUntilSettled()
1723
1724 B.addPatchset()
1725 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1726 self.waitUntilSettled()
1727
James E. Blair08d19992016-08-10 15:25:31 -07001728 self.launch_server.hold_jobs_in_build = False
1729 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001730 self.waitUntilSettled()
1731
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001732 self.assertEqual(A.data['status'], 'MERGED')
1733 self.assertEqual(A.reported, 2)
1734 self.assertEqual(B.data['status'], 'NEW')
1735 self.assertEqual(B.reported, 2)
1736 self.assertEqual(C.data['status'], 'NEW')
1737 self.assertEqual(C.reported, 2)
1738 self.assertEqual(D.data['status'], 'MERGED')
1739 self.assertEqual(D.reported, 2)
1740 self.assertEqual(len(self.history), 9) # 3 each for A, B, D.
James E. Blair2fa50962013-01-30 21:50:41 -08001741
James E. Blairec056492016-07-22 09:45:56 -07001742 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001743 def test_new_patchset_check(self):
1744 "Test a new patchset in check"
Antoine Mussobd86a312014-01-08 14:51:33 +01001745
James E. Blair08d19992016-08-10 15:25:31 -07001746 self.launch_server.hold_jobs_in_build = True
Antoine Mussobd86a312014-01-08 14:51:33 +01001747
1748 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairba437362015-02-07 11:41:52 -08001749 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1750 check_pipeline = self.sched.layout.pipelines['check']
1751
1752 # Add two git-dependent changes
1753 B.setDependsOn(A, 1)
1754 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1755 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001756 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1757 self.waitUntilSettled()
James E. Blairba437362015-02-07 11:41:52 -08001758
1759 # A live item, and a non-live/live pair
1760 items = check_pipeline.getAllItems()
1761 self.assertEqual(len(items), 3)
1762
1763 self.assertEqual(items[0].change.number, '1')
1764 self.assertEqual(items[0].change.patchset, '1')
1765 self.assertFalse(items[0].live)
1766
1767 self.assertEqual(items[1].change.number, '2')
1768 self.assertEqual(items[1].change.patchset, '1')
1769 self.assertTrue(items[1].live)
1770
1771 self.assertEqual(items[2].change.number, '1')
1772 self.assertEqual(items[2].change.patchset, '1')
1773 self.assertTrue(items[2].live)
1774
1775 # Add a new patchset to A
1776 A.addPatchset()
1777 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1778 self.waitUntilSettled()
1779
1780 # The live copy of A,1 should be gone, but the non-live and B
1781 # should continue, and we should have a new A,2
1782 items = check_pipeline.getAllItems()
1783 self.assertEqual(len(items), 3)
1784
1785 self.assertEqual(items[0].change.number, '1')
1786 self.assertEqual(items[0].change.patchset, '1')
1787 self.assertFalse(items[0].live)
1788
1789 self.assertEqual(items[1].change.number, '2')
1790 self.assertEqual(items[1].change.patchset, '1')
1791 self.assertTrue(items[1].live)
1792
1793 self.assertEqual(items[2].change.number, '1')
1794 self.assertEqual(items[2].change.patchset, '2')
1795 self.assertTrue(items[2].live)
1796
1797 # Add a new patchset to B
1798 B.addPatchset()
1799 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1800 self.waitUntilSettled()
1801
1802 # The live copy of B,1 should be gone, and it's non-live copy of A,1
1803 # but we should have a new B,2 (still based on A,1)
1804 items = check_pipeline.getAllItems()
1805 self.assertEqual(len(items), 3)
1806
1807 self.assertEqual(items[0].change.number, '1')
1808 self.assertEqual(items[0].change.patchset, '2')
1809 self.assertTrue(items[0].live)
1810
1811 self.assertEqual(items[1].change.number, '1')
1812 self.assertEqual(items[1].change.patchset, '1')
1813 self.assertFalse(items[1].live)
1814
1815 self.assertEqual(items[2].change.number, '2')
1816 self.assertEqual(items[2].change.patchset, '2')
1817 self.assertTrue(items[2].live)
1818
1819 self.builds[0].release()
1820 self.waitUntilSettled()
1821 self.builds[0].release()
1822 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001823 self.launch_server.hold_jobs_in_build = False
1824 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001825 self.waitUntilSettled()
1826
1827 self.assertEqual(A.reported, 1)
1828 self.assertEqual(B.reported, 1)
1829 self.assertEqual(self.history[0].result, 'ABORTED')
1830 self.assertEqual(self.history[0].changes, '1,1')
1831 self.assertEqual(self.history[1].result, 'ABORTED')
1832 self.assertEqual(self.history[1].changes, '1,1 2,1')
1833 self.assertEqual(self.history[2].result, 'SUCCESS')
1834 self.assertEqual(self.history[2].changes, '1,2')
1835 self.assertEqual(self.history[3].result, 'SUCCESS')
1836 self.assertEqual(self.history[3].changes, '1,1 2,2')
1837
1838 def test_abandoned_gate(self):
1839 "Test that an abandoned change is dequeued from gate"
1840
James E. Blair08d19992016-08-10 15:25:31 -07001841 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001842
1843 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001844 A.addApproval('code-review', 2)
1845 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairba437362015-02-07 11:41:52 -08001846 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001847 self.assertEqual(len(self.builds), 1, "One job being built (on hold)")
1848 self.assertEqual(self.builds[0].name, 'project-merge')
1849
1850 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1851 self.waitUntilSettled()
1852
James E. Blair08d19992016-08-10 15:25:31 -07001853 self.launch_server.release('.*-merge')
Antoine Mussobd86a312014-01-08 14:51:33 +01001854 self.waitUntilSettled()
1855
Arie5b4048c2016-10-05 16:12:06 +03001856 self.assertBuilds([])
1857 self.assertHistory([
1858 dict(name='project-merge', result='ABORTED', changes='1,1')],
1859 ordered=False)
James E. Blairba437362015-02-07 11:41:52 -08001860 self.assertEqual(A.reported, 1,
1861 "Abandoned gate change should report only start")
1862
James E. Blairec056492016-07-22 09:45:56 -07001863 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001864 def test_abandoned_check(self):
1865 "Test that an abandoned change is dequeued from check"
1866
James E. Blair08d19992016-08-10 15:25:31 -07001867 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001868
1869 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1870 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1871 check_pipeline = self.sched.layout.pipelines['check']
1872
1873 # Add two git-dependent changes
1874 B.setDependsOn(A, 1)
1875 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1876 self.waitUntilSettled()
1877 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1878 self.waitUntilSettled()
1879 # A live item, and a non-live/live pair
1880 items = check_pipeline.getAllItems()
1881 self.assertEqual(len(items), 3)
1882
1883 self.assertEqual(items[0].change.number, '1')
1884 self.assertFalse(items[0].live)
1885
1886 self.assertEqual(items[1].change.number, '2')
1887 self.assertTrue(items[1].live)
1888
1889 self.assertEqual(items[2].change.number, '1')
1890 self.assertTrue(items[2].live)
1891
1892 # Abandon A
1893 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1894 self.waitUntilSettled()
1895
1896 # The live copy of A should be gone, but the non-live and B
1897 # should continue
1898 items = check_pipeline.getAllItems()
1899 self.assertEqual(len(items), 2)
1900
1901 self.assertEqual(items[0].change.number, '1')
1902 self.assertFalse(items[0].live)
1903
1904 self.assertEqual(items[1].change.number, '2')
1905 self.assertTrue(items[1].live)
1906
James E. Blair08d19992016-08-10 15:25:31 -07001907 self.launch_server.hold_jobs_in_build = False
1908 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001909 self.waitUntilSettled()
1910
1911 self.assertEqual(len(self.history), 4)
1912 self.assertEqual(self.history[0].result, 'ABORTED',
Antoine Mussobd86a312014-01-08 14:51:33 +01001913 'Build should have been aborted')
1914 self.assertEqual(A.reported, 0, "Abandoned change should not report")
James E. Blairba437362015-02-07 11:41:52 -08001915 self.assertEqual(B.reported, 1, "Change should report")
Antoine Mussobd86a312014-01-08 14:51:33 +01001916
James E. Blairec056492016-07-22 09:45:56 -07001917 @skip("Disabled for early v3 development")
Steve Varnau7b78b312015-04-03 14:49:46 -07001918 def test_abandoned_not_timer(self):
1919 "Test that an abandoned change does not cancel timer jobs"
1920
James E. Blair08d19992016-08-10 15:25:31 -07001921 self.launch_server.hold_jobs_in_build = True
Steve Varnau7b78b312015-04-03 14:49:46 -07001922
1923 # Start timer trigger - also org/project
James E. Blairf84026c2015-12-08 16:11:46 -08001924 self.updateConfigLayout(
1925 'tests/fixtures/layout-idle.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001926 self.sched.reconfigure(self.config)
1927 self.registerJobs()
1928 # The pipeline triggers every second, so we should have seen
1929 # several by now.
1930 time.sleep(5)
1931 self.waitUntilSettled()
1932 # Stop queuing timer triggered jobs so that the assertions
1933 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08001934 self.updateConfigLayout(
1935 'tests/fixtures/layout-no-timer.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001936 self.sched.reconfigure(self.config)
1937 self.registerJobs()
1938 self.assertEqual(len(self.builds), 2, "Two timer jobs")
1939
1940 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1941 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1942 self.waitUntilSettled()
1943 self.assertEqual(len(self.builds), 3, "One change plus two timer jobs")
1944
1945 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1946 self.waitUntilSettled()
1947
1948 self.assertEqual(len(self.builds), 2, "Two timer jobs remain")
1949
James E. Blair08d19992016-08-10 15:25:31 -07001950 self.launch_server.release()
Steve Varnau7b78b312015-04-03 14:49:46 -07001951 self.waitUntilSettled()
1952
James E. Blairec056492016-07-22 09:45:56 -07001953 @skip("Disabled for early v3 development")
Arx Cruzb1b010d2013-10-28 19:49:59 -02001954 def test_zuul_url_return(self):
1955 "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf"
James E. Blair4076e2b2014-01-28 12:42:20 -08001956 self.assertTrue(self.sched.config.has_option('merger', 'zuul_url'))
James E. Blair08d19992016-08-10 15:25:31 -07001957 self.launch_server.hold_jobs_in_build = True
Arx Cruzb1b010d2013-10-28 19:49:59 -02001958
1959 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001960 A.addApproval('code-review', 2)
1961 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Arx Cruzb1b010d2013-10-28 19:49:59 -02001962 self.waitUntilSettled()
1963
1964 self.assertEqual(len(self.builds), 1)
1965 for build in self.builds:
1966 self.assertTrue('ZUUL_URL' in build.parameters)
1967
James E. Blair08d19992016-08-10 15:25:31 -07001968 self.launch_server.hold_jobs_in_build = False
1969 self.launch_server.release()
Arx Cruzb1b010d2013-10-28 19:49:59 -02001970 self.waitUntilSettled()
1971
James E. Blairec056492016-07-22 09:45:56 -07001972 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001973 def test_new_patchset_dequeues_old_on_head(self):
1974 "Test that a new patchset causes the old to be dequeued (at head)"
1975 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001976 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001977 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1978 M.setMerged()
1979 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1980 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1981 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1982 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001983 A.addApproval('code-review', 2)
1984 B.addApproval('code-review', 2)
1985 C.addApproval('code-review', 2)
1986 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001987
1988 C.setDependsOn(B, 1)
1989 B.setDependsOn(A, 1)
1990 A.setDependsOn(M, 1)
1991
James E. Blair8b5408c2016-08-08 15:37:46 -07001992 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1993 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1994 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1995 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001996 self.waitUntilSettled()
1997
1998 A.addPatchset()
1999 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2000 self.waitUntilSettled()
2001
James E. Blair08d19992016-08-10 15:25:31 -07002002 self.launch_server.hold_jobs_in_build = False
2003 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002004 self.waitUntilSettled()
2005
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002006 self.assertEqual(A.data['status'], 'NEW')
2007 self.assertEqual(A.reported, 2)
2008 self.assertEqual(B.data['status'], 'NEW')
2009 self.assertEqual(B.reported, 2)
2010 self.assertEqual(C.data['status'], 'NEW')
2011 self.assertEqual(C.reported, 2)
2012 self.assertEqual(D.data['status'], 'MERGED')
2013 self.assertEqual(D.reported, 2)
2014 self.assertEqual(len(self.history), 7)
James E. Blair2fa50962013-01-30 21:50:41 -08002015
James E. Blairec056492016-07-22 09:45:56 -07002016 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002017 def test_new_patchset_dequeues_old_without_dependents(self):
2018 "Test that a new patchset causes only the old to be dequeued"
James E. Blair08d19992016-08-10 15:25:31 -07002019 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002020 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2021 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2022 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07002023 A.addApproval('code-review', 2)
2024 B.addApproval('code-review', 2)
2025 C.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08002026
James E. Blair8b5408c2016-08-08 15:37:46 -07002027 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2028 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2029 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08002030 self.waitUntilSettled()
2031
2032 B.addPatchset()
2033 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2034 self.waitUntilSettled()
2035
James E. Blair08d19992016-08-10 15:25:31 -07002036 self.launch_server.hold_jobs_in_build = False
2037 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002038 self.waitUntilSettled()
2039
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002040 self.assertEqual(A.data['status'], 'MERGED')
2041 self.assertEqual(A.reported, 2)
2042 self.assertEqual(B.data['status'], 'NEW')
2043 self.assertEqual(B.reported, 2)
2044 self.assertEqual(C.data['status'], 'MERGED')
2045 self.assertEqual(C.reported, 2)
2046 self.assertEqual(len(self.history), 9)
James E. Blair2fa50962013-01-30 21:50:41 -08002047
James E. Blairec056492016-07-22 09:45:56 -07002048 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002049 def test_new_patchset_dequeues_old_independent_queue(self):
2050 "Test that a new patchset causes the old to be dequeued (independent)"
James E. Blair08d19992016-08-10 15:25:31 -07002051 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002052 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2053 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2054 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
2055 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2056 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2057 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2058 self.waitUntilSettled()
2059
2060 B.addPatchset()
2061 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2062 self.waitUntilSettled()
2063
James E. Blair08d19992016-08-10 15:25:31 -07002064 self.launch_server.hold_jobs_in_build = False
2065 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002066 self.waitUntilSettled()
2067
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002068 self.assertEqual(A.data['status'], 'NEW')
2069 self.assertEqual(A.reported, 1)
2070 self.assertEqual(B.data['status'], 'NEW')
2071 self.assertEqual(B.reported, 1)
2072 self.assertEqual(C.data['status'], 'NEW')
2073 self.assertEqual(C.reported, 1)
2074 self.assertEqual(len(self.history), 10)
2075 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002076
James E. Blairec056492016-07-22 09:45:56 -07002077 @skip("Disabled for early v3 development")
James E. Blair18c64442014-03-18 10:14:45 -07002078 def test_noop_job(self):
2079 "Test that the internal noop job works"
2080 A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002081 A.addApproval('code-review', 2)
2082 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair18c64442014-03-18 10:14:45 -07002083 self.waitUntilSettled()
2084
2085 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2086 self.assertTrue(self.sched._areAllBuildsComplete())
2087 self.assertEqual(len(self.history), 0)
2088 self.assertEqual(A.data['status'], 'MERGED')
2089 self.assertEqual(A.reported, 2)
2090
James E. Blairec056492016-07-22 09:45:56 -07002091 @skip("Disabled for early v3 development")
Evgeny Antyshevd6e546c2015-06-11 15:13:57 +00002092 def test_no_job_project(self):
2093 "Test that reports with no jobs don't get sent"
2094 A = self.fake_gerrit.addFakeChange('org/no-jobs-project',
2095 'master', 'A')
2096 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2097 self.waitUntilSettled()
2098
2099 # Change wasn't reported to
2100 self.assertEqual(A.reported, False)
2101
2102 # Check queue is empty afterwards
2103 check_pipeline = self.sched.layout.pipelines['check']
2104 items = check_pipeline.getAllItems()
2105 self.assertEqual(len(items), 0)
2106
2107 self.assertEqual(len(self.history), 0)
2108
James E. Blairec056492016-07-22 09:45:56 -07002109 @skip("Disabled for early v3 development")
James E. Blair7d0dedc2013-02-21 17:26:09 -08002110 def test_zuul_refs(self):
2111 "Test that zuul refs exist and have the right changes"
James E. Blair08d19992016-08-10 15:25:31 -07002112 self.launch_server.hold_jobs_in_build = True
James E. Blair7d0dedc2013-02-21 17:26:09 -08002113 M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1')
2114 M1.setMerged()
2115 M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2')
2116 M2.setMerged()
2117
2118 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2119 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2120 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
2121 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07002122 A.addApproval('code-review', 2)
2123 B.addApproval('code-review', 2)
2124 C.addApproval('code-review', 2)
2125 D.addApproval('code-review', 2)
2126 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2127 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2128 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2129 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002130
2131 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002132 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002133 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002134 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002135 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002136 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002137 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002138 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002139 self.waitUntilSettled()
2140
James E. Blair7d0dedc2013-02-21 17:26:09 -08002141 a_zref = b_zref = c_zref = d_zref = None
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002142 for x in self.builds:
James E. Blair7d0dedc2013-02-21 17:26:09 -08002143 if x.parameters['ZUUL_CHANGE'] == '3':
2144 a_zref = x.parameters['ZUUL_REF']
2145 if x.parameters['ZUUL_CHANGE'] == '4':
2146 b_zref = x.parameters['ZUUL_REF']
2147 if x.parameters['ZUUL_CHANGE'] == '5':
2148 c_zref = x.parameters['ZUUL_REF']
2149 if x.parameters['ZUUL_CHANGE'] == '6':
2150 d_zref = x.parameters['ZUUL_REF']
2151
2152 # There are... four... refs.
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002153 self.assertIsNotNone(a_zref)
2154 self.assertIsNotNone(b_zref)
2155 self.assertIsNotNone(c_zref)
2156 self.assertIsNotNone(d_zref)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002157
2158 # And they should all be different
2159 refs = set([a_zref, b_zref, c_zref, d_zref])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002160 self.assertEqual(len(refs), 4)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002161
2162 # a ref should have a, not b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002163 self.assertTrue(self.ref_has_change(a_zref, A))
2164 self.assertFalse(self.ref_has_change(a_zref, B))
2165 self.assertFalse(self.ref_has_change(a_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002166
2167 # b ref should have a and b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002168 self.assertTrue(self.ref_has_change(b_zref, A))
2169 self.assertTrue(self.ref_has_change(b_zref, B))
2170 self.assertFalse(self.ref_has_change(b_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002171
2172 # c ref should have a and b in 1, c in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002173 self.assertTrue(self.ref_has_change(c_zref, A))
2174 self.assertTrue(self.ref_has_change(c_zref, B))
2175 self.assertTrue(self.ref_has_change(c_zref, C))
2176 self.assertFalse(self.ref_has_change(c_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002177
2178 # d ref should have a and b in 1, c and d in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002179 self.assertTrue(self.ref_has_change(d_zref, A))
2180 self.assertTrue(self.ref_has_change(d_zref, B))
2181 self.assertTrue(self.ref_has_change(d_zref, C))
2182 self.assertTrue(self.ref_has_change(d_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002183
James E. Blair08d19992016-08-10 15:25:31 -07002184 self.launch_server.hold_jobs_in_build = False
2185 self.launch_server.release()
James E. Blair7d0dedc2013-02-21 17:26:09 -08002186 self.waitUntilSettled()
2187
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002188 self.assertEqual(A.data['status'], 'MERGED')
2189 self.assertEqual(A.reported, 2)
2190 self.assertEqual(B.data['status'], 'MERGED')
2191 self.assertEqual(B.reported, 2)
2192 self.assertEqual(C.data['status'], 'MERGED')
2193 self.assertEqual(C.reported, 2)
2194 self.assertEqual(D.data['status'], 'MERGED')
2195 self.assertEqual(D.reported, 2)
James E. Blair70c71582013-03-06 08:50:50 -08002196
James E. Blairec056492016-07-22 09:45:56 -07002197 @skip("Disabled for early v3 development")
James E. Blair4a28a882013-08-23 15:17:33 -07002198 def test_rerun_on_error(self):
2199 "Test that if a worker fails to run a job, it is run again"
James E. Blair08d19992016-08-10 15:25:31 -07002200 self.launch_server.hold_jobs_in_build = True
James E. Blair4a28a882013-08-23 15:17:33 -07002201 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002202 A.addApproval('code-review', 2)
2203 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4a28a882013-08-23 15:17:33 -07002204 self.waitUntilSettled()
2205
2206 self.builds[0].run_error = True
James E. Blair08d19992016-08-10 15:25:31 -07002207 self.launch_server.hold_jobs_in_build = False
2208 self.launch_server.release()
James E. Blair4a28a882013-08-23 15:17:33 -07002209 self.waitUntilSettled()
2210 self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1)
2211 self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3)
2212
James E. Blairec056492016-07-22 09:45:56 -07002213 @skip("Disabled for early v3 development")
James E. Blair412e5582013-04-22 15:50:12 -07002214 def test_statsd(self):
2215 "Test each of the statsd methods used in the scheduler"
2216 import extras
2217 statsd = extras.try_import('statsd.statsd')
2218 statsd.incr('test-incr')
2219 statsd.timing('test-timing', 3)
Alex Gaynor813d39b2014-05-17 16:17:16 -07002220 statsd.gauge('test-gauge', 12)
James E. Blair412e5582013-04-22 15:50:12 -07002221 self.assertReportedStat('test-incr', '1|c')
2222 self.assertReportedStat('test-timing', '3|ms')
Alex Gaynor813d39b2014-05-17 16:17:16 -07002223 self.assertReportedStat('test-gauge', '12|g')
James E. Blair412e5582013-04-22 15:50:12 -07002224
James E. Blairec056492016-07-22 09:45:56 -07002225 @skip("Disabled for early v3 development")
James E. Blairdad52252014-02-07 16:59:17 -08002226 def test_stuck_job_cleanup(self):
2227 "Test that pending jobs are cleaned up if removed from layout"
James E. Blair18c64442014-03-18 10:14:45 -07002228 # This job won't be registered at startup because it is not in
2229 # the standard layout, but we need it to already be registerd
2230 # for when we reconfigure, as that is when Zuul will attempt
2231 # to run the new job.
2232 self.worker.registerFunction('build:gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002233 self.gearman_server.hold_jobs_in_queue = True
2234 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002235 A.addApproval('code-review', 2)
2236 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairdad52252014-02-07 16:59:17 -08002237 self.waitUntilSettled()
2238 self.assertEqual(len(self.gearman_server.getQueue()), 1)
2239
James E. Blairf84026c2015-12-08 16:11:46 -08002240 self.updateConfigLayout(
2241 'tests/fixtures/layout-no-jobs.yaml')
James E. Blairdad52252014-02-07 16:59:17 -08002242 self.sched.reconfigure(self.config)
2243 self.waitUntilSettled()
2244
James E. Blair18c64442014-03-18 10:14:45 -07002245 self.gearman_server.release('gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002246 self.waitUntilSettled()
2247 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2248 self.assertTrue(self.sched._areAllBuildsComplete())
2249
2250 self.assertEqual(len(self.history), 1)
James E. Blair18c64442014-03-18 10:14:45 -07002251 self.assertEqual(self.history[0].name, 'gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002252 self.assertEqual(self.history[0].result, 'SUCCESS')
2253
James E. Blairec056492016-07-22 09:45:56 -07002254 @skip("Disabled for early v3 development")
James E. Blair879dafb2015-07-17 14:04:49 -07002255 def test_file_head(self):
2256 # This is a regression test for an observed bug. A change
2257 # with a file named "HEAD" in the root directory of the repo
2258 # was processed by a merger. It then was unable to reset the
2259 # repo because of:
2260 # GitCommandError: 'git reset --hard HEAD' returned
2261 # with exit code 128
2262 # stderr: 'fatal: ambiguous argument 'HEAD': both revision
2263 # and filename
2264 # Use '--' to separate filenames from revisions'
2265
2266 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2267 A.addPatchset(['HEAD'])
2268 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2269
2270 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2271 self.waitUntilSettled()
2272
2273 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2274 self.waitUntilSettled()
2275
2276 self.assertIn('Build succeeded', A.messages[0])
2277 self.assertIn('Build succeeded', B.messages[0])
2278
James E. Blairec056492016-07-22 09:45:56 -07002279 @skip("Disabled for early v3 development")
James E. Blair70c71582013-03-06 08:50:50 -08002280 def test_file_jobs(self):
2281 "Test that file jobs run only when appropriate"
2282 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2283 A.addPatchset(['pip-requires'])
2284 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002285 A.addApproval('code-review', 2)
2286 B.addApproval('code-review', 2)
2287 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2288 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair70c71582013-03-06 08:50:50 -08002289 self.waitUntilSettled()
2290
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002291 testfile_jobs = [x for x in self.history
James E. Blair70c71582013-03-06 08:50:50 -08002292 if x.name == 'project-testfile']
2293
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002294 self.assertEqual(len(testfile_jobs), 1)
2295 self.assertEqual(testfile_jobs[0].changes, '1,2')
2296 self.assertEqual(A.data['status'], 'MERGED')
2297 self.assertEqual(A.reported, 2)
2298 self.assertEqual(B.data['status'], 'MERGED')
2299 self.assertEqual(B.reported, 2)
James E. Blair3c5e5b52013-04-26 11:17:03 -07002300
James E. Blairec056492016-07-22 09:45:56 -07002301 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002302 def _test_skip_if_jobs(self, branch, should_skip):
2303 "Test that jobs with a skip-if filter run only when appropriate"
James E. Blairf84026c2015-12-08 16:11:46 -08002304 self.updateConfigLayout(
2305 'tests/fixtures/layout-skip-if.yaml')
Maru Newby3fe5f852015-01-13 04:22:14 +00002306 self.sched.reconfigure(self.config)
2307 self.registerJobs()
2308
2309 change = self.fake_gerrit.addFakeChange('org/project',
2310 branch,
2311 'test skip-if')
2312 self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1))
2313 self.waitUntilSettled()
2314
2315 tested_change_ids = [x.changes[0] for x in self.history
2316 if x.name == 'project-test-skip-if']
2317
2318 if should_skip:
2319 self.assertEqual([], tested_change_ids)
2320 else:
2321 self.assertIn(change.data['number'], tested_change_ids)
2322
James E. Blairec056492016-07-22 09:45:56 -07002323 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002324 def test_skip_if_match_skips_job(self):
2325 self._test_skip_if_jobs(branch='master', should_skip=True)
2326
James E. Blairec056492016-07-22 09:45:56 -07002327 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002328 def test_skip_if_no_match_runs_job(self):
2329 self._test_skip_if_jobs(branch='mp', should_skip=False)
2330
James E. Blairec056492016-07-22 09:45:56 -07002331 @skip("Disabled for early v3 development")
James E. Blair3c5e5b52013-04-26 11:17:03 -07002332 def test_test_config(self):
2333 "Test that we can test the config"
James E. Blairf84026c2015-12-08 16:11:46 -08002334 self.sched.testConfig(self.config.get('zuul', 'tenant_config'),
Joshua Hesketh352264b2015-08-11 23:42:08 +10002335 self.connections)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002336
James E. Blairec056492016-07-22 09:45:56 -07002337 @skip("Disabled for early v3 development")
James E. Blairc8a1e052014-02-25 09:29:26 -08002338 def test_queue_names(self):
2339 "Test shared change queue names"
2340 project1 = self.sched.layout.projects['org/project1']
2341 project2 = self.sched.layout.projects['org/project2']
2342 q1 = self.sched.layout.pipelines['gate'].getQueue(project1)
2343 q2 = self.sched.layout.pipelines['gate'].getQueue(project2)
2344 self.assertEqual(q1.name, 'integration')
2345 self.assertEqual(q2.name, 'integration')
2346
James E. Blairf84026c2015-12-08 16:11:46 -08002347 self.updateConfigLayout(
2348 'tests/fixtures/layout-bad-queue.yaml')
James E. Blairc8a1e052014-02-25 09:29:26 -08002349 with testtools.ExpectedException(
2350 Exception, "More than one name assigned to change queue"):
2351 self.sched.reconfigure(self.config)
2352
James E. Blairec056492016-07-22 09:45:56 -07002353 @skip("Disabled for early v3 development")
James E. Blair64ed6f22013-07-10 14:07:23 -07002354 def test_queue_precedence(self):
2355 "Test that queue precedence works"
2356
2357 self.gearman_server.hold_jobs_in_queue = True
James E. Blair08d19992016-08-10 15:25:31 -07002358 self.launch_server.hold_jobs_in_build = True
James E. Blair64ed6f22013-07-10 14:07:23 -07002359 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2360 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
James E. Blair8b5408c2016-08-08 15:37:46 -07002361 A.addApproval('code-review', 2)
2362 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair64ed6f22013-07-10 14:07:23 -07002363
2364 self.waitUntilSettled()
2365 self.gearman_server.hold_jobs_in_queue = False
2366 self.gearman_server.release()
2367 self.waitUntilSettled()
2368
James E. Blair8de58bd2013-07-18 16:23:33 -07002369 # Run one build at a time to ensure non-race order:
James E. Blairb8c16472015-05-05 14:55:26 -07002370 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07002371 self.launch_server.hold_jobs_in_build = False
James E. Blair8de58bd2013-07-18 16:23:33 -07002372 self.waitUntilSettled()
2373
James E. Blair64ed6f22013-07-10 14:07:23 -07002374 self.log.debug(self.history)
2375 self.assertEqual(self.history[0].pipeline, 'gate')
2376 self.assertEqual(self.history[1].pipeline, 'check')
2377 self.assertEqual(self.history[2].pipeline, 'gate')
2378 self.assertEqual(self.history[3].pipeline, 'gate')
2379 self.assertEqual(self.history[4].pipeline, 'check')
2380 self.assertEqual(self.history[5].pipeline, 'check')
2381
James E. Blairec056492016-07-22 09:45:56 -07002382 @skip("Disabled for early v3 development")
Clark Boylana5edbe42014-06-03 16:39:10 -07002383 def test_json_status(self):
James E. Blair1843a552013-07-03 14:19:52 -07002384 "Test that we can retrieve JSON status info"
James E. Blair08d19992016-08-10 15:25:31 -07002385 self.launch_server.hold_jobs_in_build = True
James E. Blair1843a552013-07-03 14:19:52 -07002386 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002387 A.addApproval('code-review', 2)
2388 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1843a552013-07-03 14:19:52 -07002389 self.waitUntilSettled()
2390
James E. Blair08d19992016-08-10 15:25:31 -07002391 self.launch_server.release('project-merge')
James E. Blairb7273ef2016-04-19 08:58:51 -07002392 self.waitUntilSettled()
2393
James E. Blair1843a552013-07-03 14:19:52 -07002394 port = self.webapp.server.socket.getsockname()[1]
2395
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002396 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2397 f = urllib.request.urlopen(req)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002398 headers = f.info()
2399 self.assertIn('Content-Length', headers)
2400 self.assertIn('Content-Type', headers)
Sachi Kingdc963fc2016-03-23 16:00:33 +11002401 self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$',
2402 headers['Content-Type']))
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002403 self.assertIn('Access-Control-Allow-Origin', headers)
2404 self.assertIn('Cache-Control', headers)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002405 self.assertIn('Last-Modified', headers)
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002406 self.assertIn('Expires', headers)
James E. Blair1843a552013-07-03 14:19:52 -07002407 data = f.read()
2408
James E. Blair08d19992016-08-10 15:25:31 -07002409 self.launch_server.hold_jobs_in_build = False
2410 self.launch_server.release()
James E. Blair1843a552013-07-03 14:19:52 -07002411 self.waitUntilSettled()
2412
2413 data = json.loads(data)
James E. Blairb7273ef2016-04-19 08:58:51 -07002414 status_jobs = []
James E. Blair1843a552013-07-03 14:19:52 -07002415 for p in data['pipelines']:
2416 for q in p['change_queues']:
James E. Blairbfb8e042014-12-30 17:01:44 -08002417 if p['name'] in ['gate', 'conflict']:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002418 self.assertEqual(q['window'], 20)
2419 else:
2420 self.assertEqual(q['window'], 0)
James E. Blair1843a552013-07-03 14:19:52 -07002421 for head in q['heads']:
2422 for change in head:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002423 self.assertTrue(change['active'])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002424 self.assertEqual(change['id'], '1,1')
James E. Blair1843a552013-07-03 14:19:52 -07002425 for job in change['jobs']:
James E. Blairb7273ef2016-04-19 08:58:51 -07002426 status_jobs.append(job)
2427 self.assertEqual('project-merge', status_jobs[0]['name'])
2428 self.assertEqual('https://server/job/project-merge/0/',
2429 status_jobs[0]['url'])
2430 self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0',
2431 status_jobs[0]['report_url'])
2432
2433 self.assertEqual('project-test1', status_jobs[1]['name'])
2434 self.assertEqual('https://server/job/project-test1/1/',
2435 status_jobs[1]['url'])
2436 self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1',
2437 status_jobs[1]['report_url'])
2438
2439 self.assertEqual('project-test2', status_jobs[2]['name'])
2440 self.assertEqual('https://server/job/project-test2/2/',
2441 status_jobs[2]['url'])
2442 self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2',
2443 status_jobs[2]['report_url'])
James E. Blair1843a552013-07-03 14:19:52 -07002444
James E. Blairec056492016-07-22 09:45:56 -07002445 @skip("Disabled for early v3 development")
James E. Blairc3d428e2013-12-03 15:06:48 -08002446 def test_merging_queues(self):
2447 "Test that transitively-connected change queues are merged"
James E. Blairf84026c2015-12-08 16:11:46 -08002448 self.updateConfigLayout(
2449 'tests/fixtures/layout-merge-queues.yaml')
James E. Blairc3d428e2013-12-03 15:06:48 -08002450 self.sched.reconfigure(self.config)
2451 self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1)
2452
James E. Blairec056492016-07-22 09:45:56 -07002453 @skip("Disabled for early v3 development")
James E. Blairaf17a972016-02-03 15:07:18 -08002454 def test_mutex(self):
2455 "Test job mutexes"
2456 self.config.set('zuul', 'layout_config',
2457 'tests/fixtures/layout-mutex.yaml')
2458 self.sched.reconfigure(self.config)
2459
James E. Blair08d19992016-08-10 15:25:31 -07002460 self.launch_server.hold_jobs_in_build = True
James E. Blairaf17a972016-02-03 15:07:18 -08002461 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2462 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2463 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2464
2465 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2466 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2467 self.waitUntilSettled()
2468 self.assertEqual(len(self.builds), 3)
2469 self.assertEqual(self.builds[0].name, 'project-test1')
2470 self.assertEqual(self.builds[1].name, 'mutex-one')
2471 self.assertEqual(self.builds[2].name, 'project-test1')
2472
James E. Blair08d19992016-08-10 15:25:31 -07002473 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002474 self.waitUntilSettled()
2475
2476 self.assertEqual(len(self.builds), 3)
2477 self.assertEqual(self.builds[0].name, 'project-test1')
2478 self.assertEqual(self.builds[1].name, 'project-test1')
2479 self.assertEqual(self.builds[2].name, 'mutex-two')
2480 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2481
James E. Blair08d19992016-08-10 15:25:31 -07002482 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002483 self.waitUntilSettled()
2484
2485 self.assertEqual(len(self.builds), 3)
2486 self.assertEqual(self.builds[0].name, 'project-test1')
2487 self.assertEqual(self.builds[1].name, 'project-test1')
2488 self.assertEqual(self.builds[2].name, 'mutex-one')
2489 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2490
James E. Blair08d19992016-08-10 15:25:31 -07002491 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002492 self.waitUntilSettled()
2493
2494 self.assertEqual(len(self.builds), 3)
2495 self.assertEqual(self.builds[0].name, 'project-test1')
2496 self.assertEqual(self.builds[1].name, 'project-test1')
2497 self.assertEqual(self.builds[2].name, 'mutex-two')
2498 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2499
James E. Blair08d19992016-08-10 15:25:31 -07002500 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002501 self.waitUntilSettled()
2502
2503 self.assertEqual(len(self.builds), 2)
2504 self.assertEqual(self.builds[0].name, 'project-test1')
2505 self.assertEqual(self.builds[1].name, 'project-test1')
2506 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2507
James E. Blair08d19992016-08-10 15:25:31 -07002508 self.launch_server.hold_jobs_in_build = False
2509 self.launch_server.release()
James E. Blairaf17a972016-02-03 15:07:18 -08002510
2511 self.waitUntilSettled()
2512 self.assertEqual(len(self.builds), 0)
2513
2514 self.assertEqual(A.reported, 1)
2515 self.assertEqual(B.reported, 1)
2516 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2517
James E. Blairec056492016-07-22 09:45:56 -07002518 @skip("Disabled for early v3 development")
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002519 def test_node_label(self):
2520 "Test that a job runs on a specific node label"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002521 self.worker.registerFunction('build:node-project-test1:debian')
2522
2523 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002524 A.addApproval('code-review', 2)
2525 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002526 self.waitUntilSettled()
James E. Blair4ca985f2013-05-30 12:27:43 -07002527
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002528 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2529 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2530 'debian')
2531 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
James E. Blaircdccd972013-07-01 12:10:22 -07002532
James E. Blairec056492016-07-22 09:45:56 -07002533 @skip("Disabled for early v3 development")
James E. Blaircdccd972013-07-01 12:10:22 -07002534 def test_live_reconfiguration(self):
2535 "Test that live reconfiguration works"
James E. Blair08d19992016-08-10 15:25:31 -07002536 self.launch_server.hold_jobs_in_build = True
James E. Blaircdccd972013-07-01 12:10:22 -07002537 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002538 A.addApproval('code-review', 2)
2539 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircdccd972013-07-01 12:10:22 -07002540 self.waitUntilSettled()
2541
2542 self.sched.reconfigure(self.config)
2543
James E. Blair08d19992016-08-10 15:25:31 -07002544 self.launch_server.hold_jobs_in_build = False
2545 self.launch_server.release()
James E. Blaircdccd972013-07-01 12:10:22 -07002546 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002547 self.assertEqual(self.getJobFromHistory('project-merge').result,
2548 'SUCCESS')
2549 self.assertEqual(self.getJobFromHistory('project-test1').result,
2550 'SUCCESS')
2551 self.assertEqual(self.getJobFromHistory('project-test2').result,
2552 'SUCCESS')
2553 self.assertEqual(A.data['status'], 'MERGED')
2554 self.assertEqual(A.reported, 2)
James E. Blair287c06d2013-07-24 10:39:30 -07002555
James E. Blairec056492016-07-22 09:45:56 -07002556 @skip("Disabled for early v3 development")
James E. Blair6bc782d2015-07-17 16:20:21 -07002557 def test_live_reconfiguration_merge_conflict(self):
2558 # A real-world bug: a change in a gate queue has a merge
2559 # conflict and a job is added to its project while it's
2560 # sitting in the queue. The job gets added to the change and
2561 # enqueued and the change gets stuck.
2562 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002563 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002564
2565 # This change is fine. It's here to stop the queue long
2566 # enough for the next change to be subject to the
2567 # reconfiguration, as well as to provide a conflict for the
2568 # next change. This change will succeed and merge.
2569 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2570 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002571 A.addApproval('code-review', 2)
James E. Blair6bc782d2015-07-17 16:20:21 -07002572
2573 # This change will be in merge conflict. During the
2574 # reconfiguration, we will add a job. We want to make sure
2575 # that doesn't cause it to get stuck.
2576 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2577 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002578 B.addApproval('code-review', 2)
James E. Blair4eb21fa2015-07-27 14:56:47 -07002579
James E. Blair8b5408c2016-08-08 15:37:46 -07002580 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2581 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002582
2583 self.waitUntilSettled()
2584
2585 # No jobs have run yet
2586 self.assertEqual(A.data['status'], 'NEW')
2587 self.assertEqual(A.reported, 1)
2588 self.assertEqual(B.data['status'], 'NEW')
2589 self.assertEqual(B.reported, 1)
2590 self.assertEqual(len(self.history), 0)
2591
2592 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002593 self.updateConfigLayout(
2594 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002595 self.sched.reconfigure(self.config)
2596 self.waitUntilSettled()
2597
James E. Blair08d19992016-08-10 15:25:31 -07002598 self.launch_server.hold_jobs_in_build = False
2599 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002600 self.waitUntilSettled()
2601
2602 self.assertEqual(A.data['status'], 'MERGED')
2603 self.assertEqual(A.reported, 2)
2604 self.assertEqual(B.data['status'], 'NEW')
2605 self.assertEqual(B.reported, 2)
2606 self.assertEqual(self.getJobFromHistory('project-merge').result,
2607 'SUCCESS')
2608 self.assertEqual(self.getJobFromHistory('project-test1').result,
2609 'SUCCESS')
2610 self.assertEqual(self.getJobFromHistory('project-test2').result,
2611 'SUCCESS')
2612 self.assertEqual(self.getJobFromHistory('project-test3').result,
2613 'SUCCESS')
2614 self.assertEqual(len(self.history), 4)
2615
James E. Blairec056492016-07-22 09:45:56 -07002616 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002617 def test_live_reconfiguration_failed_root(self):
James E. Blair6bc782d2015-07-17 16:20:21 -07002618 # An extrapolation of test_live_reconfiguration_merge_conflict
2619 # that tests a job added to a job tree with a failed root does
2620 # not run.
2621 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002622 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002623
2624 # This change is fine. It's here to stop the queue long
2625 # enough for the next change to be subject to the
2626 # reconfiguration. This change will succeed and merge.
2627 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2628 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002629 A.addApproval('code-review', 2)
2630 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002631 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002632 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002633 self.waitUntilSettled()
2634
2635 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair08d19992016-08-10 15:25:31 -07002636 self.launch_server.failJob('project-merge', B)
James E. Blair8b5408c2016-08-08 15:37:46 -07002637 B.addApproval('code-review', 2)
2638 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002639 self.waitUntilSettled()
2640
James E. Blair08d19992016-08-10 15:25:31 -07002641 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002642 self.waitUntilSettled()
2643
2644 # Both -merge jobs have run, but no others.
2645 self.assertEqual(A.data['status'], 'NEW')
2646 self.assertEqual(A.reported, 1)
2647 self.assertEqual(B.data['status'], 'NEW')
2648 self.assertEqual(B.reported, 1)
2649 self.assertEqual(self.history[0].result, 'SUCCESS')
2650 self.assertEqual(self.history[0].name, 'project-merge')
2651 self.assertEqual(self.history[1].result, 'FAILURE')
2652 self.assertEqual(self.history[1].name, 'project-merge')
2653 self.assertEqual(len(self.history), 2)
2654
2655 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002656 self.updateConfigLayout(
2657 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002658 self.sched.reconfigure(self.config)
2659 self.waitUntilSettled()
2660
James E. Blair08d19992016-08-10 15:25:31 -07002661 self.launch_server.hold_jobs_in_build = False
2662 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002663 self.waitUntilSettled()
2664
2665 self.assertEqual(A.data['status'], 'MERGED')
2666 self.assertEqual(A.reported, 2)
2667 self.assertEqual(B.data['status'], 'NEW')
2668 self.assertEqual(B.reported, 2)
2669 self.assertEqual(self.history[0].result, 'SUCCESS')
2670 self.assertEqual(self.history[0].name, 'project-merge')
2671 self.assertEqual(self.history[1].result, 'FAILURE')
2672 self.assertEqual(self.history[1].name, 'project-merge')
2673 self.assertEqual(self.history[2].result, 'SUCCESS')
2674 self.assertEqual(self.history[3].result, 'SUCCESS')
2675 self.assertEqual(self.history[4].result, 'SUCCESS')
2676 self.assertEqual(len(self.history), 5)
2677
James E. Blairec056492016-07-22 09:45:56 -07002678 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002679 def test_live_reconfiguration_failed_job(self):
2680 # Test that a change with a removed failing job does not
2681 # disrupt reconfiguration. If a change has a failed job and
2682 # that job is removed during a reconfiguration, we observed a
2683 # bug where the code to re-set build statuses would run on
2684 # that build and raise an exception because the job no longer
2685 # existed.
James E. Blair08d19992016-08-10 15:25:31 -07002686 self.launch_server.hold_jobs_in_build = True
James E. Blair400e8fd2015-07-30 17:44:45 -07002687
2688 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2689
2690 # This change will fail and later be removed by the reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002691 self.launch_server.failJob('project-test1', A)
James E. Blair400e8fd2015-07-30 17:44:45 -07002692
2693 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2694 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002695 self.launch_server.release('.*-merge')
James E. Blair400e8fd2015-07-30 17:44:45 -07002696 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002697 self.launch_server.release('project-test1')
James E. Blair400e8fd2015-07-30 17:44:45 -07002698 self.waitUntilSettled()
2699
2700 self.assertEqual(A.data['status'], 'NEW')
2701 self.assertEqual(A.reported, 0)
2702
2703 self.assertEqual(self.getJobFromHistory('project-merge').result,
2704 'SUCCESS')
2705 self.assertEqual(self.getJobFromHistory('project-test1').result,
2706 'FAILURE')
2707 self.assertEqual(len(self.history), 2)
2708
2709 # Remove the test1 job.
James E. Blairf84026c2015-12-08 16:11:46 -08002710 self.updateConfigLayout(
2711 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml')
James E. Blair400e8fd2015-07-30 17:44:45 -07002712 self.sched.reconfigure(self.config)
2713 self.waitUntilSettled()
2714
James E. Blair08d19992016-08-10 15:25:31 -07002715 self.launch_server.hold_jobs_in_build = False
2716 self.launch_server.release()
James E. Blair400e8fd2015-07-30 17:44:45 -07002717 self.waitUntilSettled()
2718
2719 self.assertEqual(self.getJobFromHistory('project-test2').result,
2720 'SUCCESS')
2721 self.assertEqual(self.getJobFromHistory('project-testfile').result,
2722 'SUCCESS')
2723 self.assertEqual(len(self.history), 4)
2724
2725 self.assertEqual(A.data['status'], 'NEW')
2726 self.assertEqual(A.reported, 1)
2727 self.assertIn('Build succeeded', A.messages[0])
2728 # Ensure the removed job was not included in the report.
2729 self.assertNotIn('project-test1', A.messages[0])
2730
James E. Blairec056492016-07-22 09:45:56 -07002731 @skip("Disabled for early v3 development")
James E. Blairfe707d12015-08-05 15:18:15 -07002732 def test_live_reconfiguration_shared_queue(self):
2733 # Test that a change with a failing job which was removed from
2734 # this project but otherwise still exists in the system does
2735 # not disrupt reconfiguration.
2736
James E. Blair08d19992016-08-10 15:25:31 -07002737 self.launch_server.hold_jobs_in_build = True
James E. Blairfe707d12015-08-05 15:18:15 -07002738
2739 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2740
James E. Blair08d19992016-08-10 15:25:31 -07002741 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairfe707d12015-08-05 15:18:15 -07002742
2743 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2744 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002745 self.launch_server.release('.*-merge')
James E. Blairfe707d12015-08-05 15:18:15 -07002746 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002747 self.launch_server.release('project1-project2-integration')
James E. Blairfe707d12015-08-05 15:18:15 -07002748 self.waitUntilSettled()
2749
2750 self.assertEqual(A.data['status'], 'NEW')
2751 self.assertEqual(A.reported, 0)
2752
2753 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2754 'SUCCESS')
2755 self.assertEqual(self.getJobFromHistory(
2756 'project1-project2-integration').result, 'FAILURE')
2757 self.assertEqual(len(self.history), 2)
2758
2759 # Remove the integration job.
James E. Blairf84026c2015-12-08 16:11:46 -08002760 self.updateConfigLayout(
2761 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml')
James E. Blairfe707d12015-08-05 15:18:15 -07002762 self.sched.reconfigure(self.config)
2763 self.waitUntilSettled()
2764
James E. Blair08d19992016-08-10 15:25:31 -07002765 self.launch_server.hold_jobs_in_build = False
2766 self.launch_server.release()
James E. Blairfe707d12015-08-05 15:18:15 -07002767 self.waitUntilSettled()
2768
2769 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2770 'SUCCESS')
2771 self.assertEqual(self.getJobFromHistory('project1-test1').result,
2772 'SUCCESS')
2773 self.assertEqual(self.getJobFromHistory('project1-test2').result,
2774 'SUCCESS')
2775 self.assertEqual(self.getJobFromHistory(
2776 'project1-project2-integration').result, 'FAILURE')
2777 self.assertEqual(len(self.history), 4)
2778
2779 self.assertEqual(A.data['status'], 'NEW')
2780 self.assertEqual(A.reported, 1)
2781 self.assertIn('Build succeeded', A.messages[0])
2782 # Ensure the removed job was not included in the report.
2783 self.assertNotIn('project1-project2-integration', A.messages[0])
2784
James E. Blairec056492016-07-22 09:45:56 -07002785 @skip("Disabled for early v3 development")
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002786 def test_double_live_reconfiguration_shared_queue(self):
2787 # This was a real-world regression. A change is added to
2788 # gate; a reconfigure happens, a second change which depends
2789 # on the first is added, and a second reconfiguration happens.
2790 # Ensure that both changes merge.
2791
2792 # A failure may indicate incorrect caching or cleaning up of
2793 # references during a reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002794 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002795
2796 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2797 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2798 B.setDependsOn(A, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07002799 A.addApproval('code-review', 2)
2800 B.addApproval('code-review', 2)
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002801
2802 # Add the parent change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002803 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002804 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002805 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002806 self.waitUntilSettled()
2807
2808 # Reconfigure (with only one change in the pipeline).
2809 self.sched.reconfigure(self.config)
2810 self.waitUntilSettled()
2811
2812 # Add the child change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002813 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002814 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002815 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002816 self.waitUntilSettled()
2817
2818 # Reconfigure (with both in the pipeline).
2819 self.sched.reconfigure(self.config)
2820 self.waitUntilSettled()
2821
James E. Blair08d19992016-08-10 15:25:31 -07002822 self.launch_server.hold_jobs_in_build = False
2823 self.launch_server.release()
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002824 self.waitUntilSettled()
2825
2826 self.assertEqual(len(self.history), 8)
2827
2828 self.assertEqual(A.data['status'], 'MERGED')
2829 self.assertEqual(A.reported, 2)
2830 self.assertEqual(B.data['status'], 'MERGED')
2831 self.assertEqual(B.reported, 2)
2832
James E. Blairec056492016-07-22 09:45:56 -07002833 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002834 def test_live_reconfiguration_del_project(self):
2835 # Test project deletion from layout
2836 # while changes are enqueued
2837
James E. Blair08d19992016-08-10 15:25:31 -07002838 self.launch_server.hold_jobs_in_build = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002839 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2840 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2841 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
2842
2843 # A Depends-On: B
2844 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
2845 A.subject, B.data['id'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002846 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002847
2848 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2849 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2850 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002851 self.launch_server.release('.*-merge')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002852 self.waitUntilSettled()
2853 self.assertEqual(len(self.builds), 5)
2854
2855 # This layout defines only org/project, not org/project1
James E. Blairf84026c2015-12-08 16:11:46 -08002856 self.updateConfigLayout(
2857 'tests/fixtures/layout-live-reconfiguration-del-project.yaml')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002858 self.sched.reconfigure(self.config)
2859 self.waitUntilSettled()
2860
2861 # Builds for C aborted, builds for A succeed,
2862 # and have change B applied ahead
2863 job_c = self.getJobFromHistory('project1-test1')
2864 self.assertEqual(job_c.changes, '3,1')
2865 self.assertEqual(job_c.result, 'ABORTED')
2866
James E. Blair08d19992016-08-10 15:25:31 -07002867 self.launch_server.hold_jobs_in_build = False
2868 self.launch_server.release()
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002869 self.waitUntilSettled()
2870
2871 self.assertEqual(self.getJobFromHistory('project-test1').changes,
2872 '2,1 1,1')
2873
2874 self.assertEqual(A.data['status'], 'NEW')
2875 self.assertEqual(B.data['status'], 'NEW')
2876 self.assertEqual(C.data['status'], 'NEW')
2877 self.assertEqual(A.reported, 1)
2878 self.assertEqual(B.reported, 0)
2879 self.assertEqual(C.reported, 0)
2880
2881 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
2882 self.assertIn('Build succeeded', A.messages[0])
2883
James E. Blairec056492016-07-22 09:45:56 -07002884 @skip("Disabled for early v3 development")
James E. Blaire712d9f2013-07-31 11:40:11 -07002885 def test_live_reconfiguration_functions(self):
2886 "Test live reconfiguration with a custom function"
2887 self.worker.registerFunction('build:node-project-test1:debian')
2888 self.worker.registerFunction('build:node-project-test1:wheezy')
2889 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002890 A.addApproval('code-review', 2)
2891 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002892 self.waitUntilSettled()
2893
2894 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2895 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2896 'debian')
2897 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2898
James E. Blairf84026c2015-12-08 16:11:46 -08002899 self.updateConfigLayout(
2900 'tests/fixtures/layout-live-reconfiguration-functions.yaml')
James E. Blaire712d9f2013-07-31 11:40:11 -07002901 self.sched.reconfigure(self.config)
2902 self.worker.build_history = []
2903
2904 B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002905 B.addApproval('code-review', 2)
2906 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002907 self.waitUntilSettled()
2908
2909 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2910 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2911 'wheezy')
2912 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2913
James E. Blairec056492016-07-22 09:45:56 -07002914 @skip("Disabled for early v3 development")
James E. Blair287c06d2013-07-24 10:39:30 -07002915 def test_delayed_repo_init(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002916 self.updateConfigLayout(
2917 'tests/fixtures/layout-delayed-repo-init.yaml')
James E. Blair287c06d2013-07-24 10:39:30 -07002918 self.sched.reconfigure(self.config)
2919
2920 self.init_repo("org/new-project")
2921 A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A')
2922
James E. Blair8b5408c2016-08-08 15:37:46 -07002923 A.addApproval('code-review', 2)
2924 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair287c06d2013-07-24 10:39:30 -07002925 self.waitUntilSettled()
2926 self.assertEqual(self.getJobFromHistory('project-merge').result,
2927 'SUCCESS')
2928 self.assertEqual(self.getJobFromHistory('project-test1').result,
2929 'SUCCESS')
2930 self.assertEqual(self.getJobFromHistory('project-test2').result,
2931 'SUCCESS')
2932 self.assertEqual(A.data['status'], 'MERGED')
2933 self.assertEqual(A.reported, 2)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002934
James E. Blairec056492016-07-22 09:45:56 -07002935 @skip("Disabled for early v3 development")
Clark Boylan6dbbc482013-10-18 10:57:31 -07002936 def test_repo_deleted(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002937 self.updateConfigLayout(
2938 'tests/fixtures/layout-repo-deleted.yaml')
Clark Boylan6dbbc482013-10-18 10:57:31 -07002939 self.sched.reconfigure(self.config)
2940
2941 self.init_repo("org/delete-project")
2942 A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A')
2943
James E. Blair8b5408c2016-08-08 15:37:46 -07002944 A.addApproval('code-review', 2)
2945 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002946 self.waitUntilSettled()
2947 self.assertEqual(self.getJobFromHistory('project-merge').result,
2948 'SUCCESS')
2949 self.assertEqual(self.getJobFromHistory('project-test1').result,
2950 'SUCCESS')
2951 self.assertEqual(self.getJobFromHistory('project-test2').result,
2952 'SUCCESS')
2953 self.assertEqual(A.data['status'], 'MERGED')
2954 self.assertEqual(A.reported, 2)
2955
2956 # Delete org/new-project zuul repo. Should be recloned.
2957 shutil.rmtree(os.path.join(self.git_root, "org/delete-project"))
2958
2959 B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B')
2960
James E. Blair8b5408c2016-08-08 15:37:46 -07002961 B.addApproval('code-review', 2)
2962 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002963 self.waitUntilSettled()
2964 self.assertEqual(self.getJobFromHistory('project-merge').result,
2965 'SUCCESS')
2966 self.assertEqual(self.getJobFromHistory('project-test1').result,
2967 'SUCCESS')
2968 self.assertEqual(self.getJobFromHistory('project-test2').result,
2969 'SUCCESS')
2970 self.assertEqual(B.data['status'], 'MERGED')
2971 self.assertEqual(B.reported, 2)
2972
James E. Blairec056492016-07-22 09:45:56 -07002973 @skip("Disabled for early v3 development")
James E. Blair456f2fb2016-02-09 09:29:33 -08002974 def test_tags(self):
2975 "Test job tags"
2976 self.config.set('zuul', 'layout_config',
2977 'tests/fixtures/layout-tags.yaml')
2978 self.sched.reconfigure(self.config)
2979
2980 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2981 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
2982 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2983 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2984 self.waitUntilSettled()
2985
2986 results = {'project1-merge': 'extratag merge project1',
2987 'project2-merge': 'merge'}
2988
2989 for build in self.history:
2990 self.assertEqual(results.get(build.name, ''),
2991 build.parameters.get('BUILD_TAGS'))
2992
James E. Blairec056492016-07-22 09:45:56 -07002993 @skip("Disabled for early v3 development")
James E. Blair63bb0ef2013-07-29 17:14:51 -07002994 def test_timer(self):
2995 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07002996 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08002997 self.updateConfigLayout(
2998 'tests/fixtures/layout-timer.yaml')
James E. Blair63bb0ef2013-07-29 17:14:51 -07002999 self.sched.reconfigure(self.config)
3000 self.registerJobs()
3001
Clark Boylan3ee090a2014-04-03 20:55:09 -07003002 # The pipeline triggers every second, so we should have seen
3003 # several by now.
3004 time.sleep(5)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003005 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003006
3007 self.assertEqual(len(self.builds), 2)
3008
James E. Blair63bb0ef2013-07-29 17:14:51 -07003009 port = self.webapp.server.socket.getsockname()[1]
3010
Morgan Fainberg293f7f82016-05-30 14:01:22 -07003011 req = urllib.request.Request("http://localhost:%s/status.json" % port)
3012 f = urllib.request.urlopen(req)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003013 data = f.read()
3014
James E. Blair08d19992016-08-10 15:25:31 -07003015 self.launch_server.hold_jobs_in_build = False
Clark Boylan3ee090a2014-04-03 20:55:09 -07003016 # Stop queuing timer triggered jobs so that the assertions
3017 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003018 self.updateConfigLayout(
3019 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003020 self.sched.reconfigure(self.config)
3021 self.registerJobs()
James E. Blair08d19992016-08-10 15:25:31 -07003022 self.launch_server.release()
James E. Blair63bb0ef2013-07-29 17:14:51 -07003023 self.waitUntilSettled()
3024
3025 self.assertEqual(self.getJobFromHistory(
3026 'project-bitrot-stable-old').result, 'SUCCESS')
3027 self.assertEqual(self.getJobFromHistory(
3028 'project-bitrot-stable-older').result, 'SUCCESS')
3029
3030 data = json.loads(data)
3031 status_jobs = set()
3032 for p in data['pipelines']:
3033 for q in p['change_queues']:
3034 for head in q['heads']:
3035 for change in head:
Alex Gaynorddb9ef32013-09-16 21:04:58 -07003036 self.assertEqual(change['id'], None)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003037 for job in change['jobs']:
3038 status_jobs.add(job['name'])
3039 self.assertIn('project-bitrot-stable-old', status_jobs)
3040 self.assertIn('project-bitrot-stable-older', status_jobs)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003041
James E. Blairec056492016-07-22 09:45:56 -07003042 @skip("Disabled for early v3 development")
James E. Blair4f6033c2014-03-27 15:49:09 -07003043 def test_idle(self):
3044 "Test that frequent periodic jobs work"
James E. Blair08d19992016-08-10 15:25:31 -07003045 self.launch_server.hold_jobs_in_build = True
James E. Blair4f6033c2014-03-27 15:49:09 -07003046
Clark Boylan3ee090a2014-04-03 20:55:09 -07003047 for x in range(1, 3):
3048 # Test that timer triggers periodic jobs even across
3049 # layout config reloads.
3050 # Start timer trigger
James E. Blairf84026c2015-12-08 16:11:46 -08003051 self.updateConfigLayout(
3052 'tests/fixtures/layout-idle.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003053 self.sched.reconfigure(self.config)
3054 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003055 self.waitUntilSettled()
James E. Blair4f6033c2014-03-27 15:49:09 -07003056
Clark Boylan3ee090a2014-04-03 20:55:09 -07003057 # The pipeline triggers every second, so we should have seen
3058 # several by now.
3059 time.sleep(5)
Clark Boylan3ee090a2014-04-03 20:55:09 -07003060
3061 # Stop queuing timer triggered jobs so that the assertions
3062 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003063 self.updateConfigLayout(
3064 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003065 self.sched.reconfigure(self.config)
3066 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003067 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003068
3069 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003070 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003071 self.waitUntilSettled()
3072 self.assertEqual(len(self.builds), 0)
3073 self.assertEqual(len(self.history), x * 2)
James E. Blair4f6033c2014-03-27 15:49:09 -07003074
James E. Blairec056492016-07-22 09:45:56 -07003075 @skip("Disabled for early v3 development")
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003076 def test_check_smtp_pool(self):
James E. Blairf84026c2015-12-08 16:11:46 -08003077 self.updateConfigLayout(
3078 'tests/fixtures/layout-smtp.yaml')
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003079 self.sched.reconfigure(self.config)
3080
3081 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3082 self.waitUntilSettled()
3083
3084 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3085 self.waitUntilSettled()
3086
James E. Blairff80a2f2013-12-27 13:24:06 -08003087 self.assertEqual(len(self.smtp_messages), 2)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003088
3089 # A.messages only holds what FakeGerrit places in it. Thus we
3090 # work on the knowledge of what the first message should be as
3091 # it is only configured to go to SMTP.
3092
3093 self.assertEqual('zuul@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003094 self.smtp_messages[0]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003095 self.assertEqual(['you@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003096 self.smtp_messages[0]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003097 self.assertEqual('Starting check jobs.',
James E. Blairff80a2f2013-12-27 13:24:06 -08003098 self.smtp_messages[0]['body'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003099
3100 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003101 self.smtp_messages[1]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003102 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003103 self.smtp_messages[1]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003104 self.assertEqual(A.messages[0],
James E. Blairff80a2f2013-12-27 13:24:06 -08003105 self.smtp_messages[1]['body'])
James E. Blairad28e912013-11-27 10:43:22 -08003106
James E. Blairec056492016-07-22 09:45:56 -07003107 @skip("Disabled for early v3 development")
James E. Blaire5910202013-12-27 09:50:31 -08003108 def test_timer_smtp(self):
3109 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003110 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003111 self.updateConfigLayout(
3112 'tests/fixtures/layout-timer-smtp.yaml')
James E. Blaire5910202013-12-27 09:50:31 -08003113 self.sched.reconfigure(self.config)
3114 self.registerJobs()
3115
Clark Boylan3ee090a2014-04-03 20:55:09 -07003116 # The pipeline triggers every second, so we should have seen
3117 # several by now.
3118 time.sleep(5)
James E. Blaire5910202013-12-27 09:50:31 -08003119 self.waitUntilSettled()
3120
Clark Boylan3ee090a2014-04-03 20:55:09 -07003121 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003122 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003123 self.waitUntilSettled()
3124 self.assertEqual(len(self.history), 2)
3125
James E. Blaire5910202013-12-27 09:50:31 -08003126 self.assertEqual(self.getJobFromHistory(
3127 'project-bitrot-stable-old').result, 'SUCCESS')
3128 self.assertEqual(self.getJobFromHistory(
3129 'project-bitrot-stable-older').result, 'SUCCESS')
3130
James E. Blairff80a2f2013-12-27 13:24:06 -08003131 self.assertEqual(len(self.smtp_messages), 1)
James E. Blaire5910202013-12-27 09:50:31 -08003132
3133 # A.messages only holds what FakeGerrit places in it. Thus we
3134 # work on the knowledge of what the first message should be as
3135 # it is only configured to go to SMTP.
3136
3137 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003138 self.smtp_messages[0]['from_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003139 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003140 self.smtp_messages[0]['to_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003141 self.assertIn('Subject: Periodic check for org/project succeeded',
James E. Blairff80a2f2013-12-27 13:24:06 -08003142 self.smtp_messages[0]['headers'])
James E. Blaire5910202013-12-27 09:50:31 -08003143
Clark Boylan3ee090a2014-04-03 20:55:09 -07003144 # Stop queuing timer triggered jobs and let any that may have
3145 # queued through so that end of test assertions pass.
James E. Blairf84026c2015-12-08 16:11:46 -08003146 self.updateConfigLayout(
3147 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003148 self.sched.reconfigure(self.config)
3149 self.registerJobs()
James E. Blairf8058972014-08-15 16:09:16 -07003150 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003151 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003152 self.waitUntilSettled()
3153
James E. Blairec056492016-07-22 09:45:56 -07003154 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003155 def test_client_enqueue_change(self):
James E. Blairad28e912013-11-27 10:43:22 -08003156 "Test that the RPC client can enqueue a change"
3157 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003158 A.addApproval('code-review', 2)
3159 A.addApproval('approved', 1)
James E. Blairad28e912013-11-27 10:43:22 -08003160
3161 client = zuul.rpcclient.RPCClient('127.0.0.1',
3162 self.gearman_server.port)
3163 r = client.enqueue(pipeline='gate',
3164 project='org/project',
3165 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003166 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003167 self.waitUntilSettled()
3168 self.assertEqual(self.getJobFromHistory('project-merge').result,
3169 'SUCCESS')
3170 self.assertEqual(self.getJobFromHistory('project-test1').result,
3171 'SUCCESS')
3172 self.assertEqual(self.getJobFromHistory('project-test2').result,
3173 'SUCCESS')
3174 self.assertEqual(A.data['status'], 'MERGED')
3175 self.assertEqual(A.reported, 2)
3176 self.assertEqual(r, True)
3177
James E. Blairec056492016-07-22 09:45:56 -07003178 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003179 def test_client_enqueue_ref(self):
3180 "Test that the RPC client can enqueue a ref"
3181
3182 client = zuul.rpcclient.RPCClient('127.0.0.1',
3183 self.gearman_server.port)
3184 r = client.enqueue_ref(
3185 pipeline='post',
3186 project='org/project',
3187 trigger='gerrit',
3188 ref='master',
3189 oldrev='90f173846e3af9154517b88543ffbd1691f31366',
3190 newrev='d479a0bfcb34da57a31adb2a595c0cf687812543')
3191 self.waitUntilSettled()
3192 job_names = [x.name for x in self.history]
3193 self.assertEqual(len(self.history), 1)
3194 self.assertIn('project-post', job_names)
3195 self.assertEqual(r, True)
3196
James E. Blairec056492016-07-22 09:45:56 -07003197 @skip("Disabled for early v3 development")
James E. Blairad28e912013-11-27 10:43:22 -08003198 def test_client_enqueue_negative(self):
3199 "Test that the RPC client returns errors"
3200 client = zuul.rpcclient.RPCClient('127.0.0.1',
3201 self.gearman_server.port)
3202 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3203 "Invalid project"):
3204 r = client.enqueue(pipeline='gate',
3205 project='project-does-not-exist',
3206 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003207 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003208 client.shutdown()
3209 self.assertEqual(r, False)
3210
3211 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3212 "Invalid pipeline"):
3213 r = client.enqueue(pipeline='pipeline-does-not-exist',
3214 project='org/project',
3215 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003216 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003217 client.shutdown()
3218 self.assertEqual(r, False)
3219
3220 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3221 "Invalid trigger"):
3222 r = client.enqueue(pipeline='gate',
3223 project='org/project',
3224 trigger='trigger-does-not-exist',
James E. Blair36658cf2013-12-06 17:53:48 -08003225 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003226 client.shutdown()
3227 self.assertEqual(r, False)
3228
3229 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3230 "Invalid change"):
3231 r = client.enqueue(pipeline='gate',
3232 project='org/project',
3233 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003234 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003235 client.shutdown()
3236 self.assertEqual(r, False)
3237
3238 self.waitUntilSettled()
3239 self.assertEqual(len(self.history), 0)
3240 self.assertEqual(len(self.builds), 0)
James E. Blair36658cf2013-12-06 17:53:48 -08003241
James E. Blairec056492016-07-22 09:45:56 -07003242 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003243 def test_client_promote(self):
3244 "Test that the RPC client can promote a change"
James E. Blair08d19992016-08-10 15:25:31 -07003245 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003246 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3247 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3248 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003249 A.addApproval('code-review', 2)
3250 B.addApproval('code-review', 2)
3251 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003252
James E. Blair8b5408c2016-08-08 15:37:46 -07003253 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3254 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3255 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003256
3257 self.waitUntilSettled()
3258
Sean Daguef39b9ca2014-01-10 21:34:35 -05003259 items = self.sched.layout.pipelines['gate'].getAllItems()
3260 enqueue_times = {}
3261 for item in items:
3262 enqueue_times[str(item.change)] = item.enqueue_time
3263
James E. Blair36658cf2013-12-06 17:53:48 -08003264 client = zuul.rpcclient.RPCClient('127.0.0.1',
3265 self.gearman_server.port)
3266 r = client.promote(pipeline='gate',
3267 change_ids=['2,1', '3,1'])
3268
Sean Daguef39b9ca2014-01-10 21:34:35 -05003269 # ensure that enqueue times are durable
3270 items = self.sched.layout.pipelines['gate'].getAllItems()
3271 for item in items:
3272 self.assertEqual(
3273 enqueue_times[str(item.change)], item.enqueue_time)
3274
James E. Blair78acec92014-02-06 07:11:32 -08003275 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003276 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003277 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003278 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003279 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003280 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003281 self.waitUntilSettled()
3282
3283 self.assertEqual(len(self.builds), 6)
3284 self.assertEqual(self.builds[0].name, 'project-test1')
3285 self.assertEqual(self.builds[1].name, 'project-test2')
3286 self.assertEqual(self.builds[2].name, 'project-test1')
3287 self.assertEqual(self.builds[3].name, 'project-test2')
3288 self.assertEqual(self.builds[4].name, 'project-test1')
3289 self.assertEqual(self.builds[5].name, 'project-test2')
3290
3291 self.assertTrue(self.job_has_changes(self.builds[0], B))
3292 self.assertFalse(self.job_has_changes(self.builds[0], A))
3293 self.assertFalse(self.job_has_changes(self.builds[0], C))
3294
3295 self.assertTrue(self.job_has_changes(self.builds[2], B))
3296 self.assertTrue(self.job_has_changes(self.builds[2], C))
3297 self.assertFalse(self.job_has_changes(self.builds[2], A))
3298
3299 self.assertTrue(self.job_has_changes(self.builds[4], B))
3300 self.assertTrue(self.job_has_changes(self.builds[4], C))
3301 self.assertTrue(self.job_has_changes(self.builds[4], A))
3302
James E. Blair08d19992016-08-10 15:25:31 -07003303 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003304 self.waitUntilSettled()
3305
3306 self.assertEqual(A.data['status'], 'MERGED')
3307 self.assertEqual(A.reported, 2)
3308 self.assertEqual(B.data['status'], 'MERGED')
3309 self.assertEqual(B.reported, 2)
3310 self.assertEqual(C.data['status'], 'MERGED')
3311 self.assertEqual(C.reported, 2)
3312
3313 client.shutdown()
3314 self.assertEqual(r, True)
3315
James E. Blairec056492016-07-22 09:45:56 -07003316 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003317 def test_client_promote_dependent(self):
3318 "Test that the RPC client can promote a dependent change"
3319 # C (depends on B) -> B -> A ; then promote C to get:
3320 # A -> C (depends on B) -> B
James E. Blair08d19992016-08-10 15:25:31 -07003321 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003322 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3323 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3324 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3325
3326 C.setDependsOn(B, 1)
3327
James E. Blair8b5408c2016-08-08 15:37:46 -07003328 A.addApproval('code-review', 2)
3329 B.addApproval('code-review', 2)
3330 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003331
James E. Blair8b5408c2016-08-08 15:37:46 -07003332 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3333 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3334 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003335
3336 self.waitUntilSettled()
3337
3338 client = zuul.rpcclient.RPCClient('127.0.0.1',
3339 self.gearman_server.port)
3340 r = client.promote(pipeline='gate',
3341 change_ids=['3,1'])
3342
James E. Blair78acec92014-02-06 07:11:32 -08003343 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003344 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003345 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003346 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003347 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003348 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003349 self.waitUntilSettled()
3350
3351 self.assertEqual(len(self.builds), 6)
3352 self.assertEqual(self.builds[0].name, 'project-test1')
3353 self.assertEqual(self.builds[1].name, 'project-test2')
3354 self.assertEqual(self.builds[2].name, 'project-test1')
3355 self.assertEqual(self.builds[3].name, 'project-test2')
3356 self.assertEqual(self.builds[4].name, 'project-test1')
3357 self.assertEqual(self.builds[5].name, 'project-test2')
3358
3359 self.assertTrue(self.job_has_changes(self.builds[0], B))
3360 self.assertFalse(self.job_has_changes(self.builds[0], A))
3361 self.assertFalse(self.job_has_changes(self.builds[0], C))
3362
3363 self.assertTrue(self.job_has_changes(self.builds[2], B))
3364 self.assertTrue(self.job_has_changes(self.builds[2], C))
3365 self.assertFalse(self.job_has_changes(self.builds[2], A))
3366
3367 self.assertTrue(self.job_has_changes(self.builds[4], B))
3368 self.assertTrue(self.job_has_changes(self.builds[4], C))
3369 self.assertTrue(self.job_has_changes(self.builds[4], A))
3370
James E. Blair08d19992016-08-10 15:25:31 -07003371 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003372 self.waitUntilSettled()
3373
3374 self.assertEqual(A.data['status'], 'MERGED')
3375 self.assertEqual(A.reported, 2)
3376 self.assertEqual(B.data['status'], 'MERGED')
3377 self.assertEqual(B.reported, 2)
3378 self.assertEqual(C.data['status'], 'MERGED')
3379 self.assertEqual(C.reported, 2)
3380
3381 client.shutdown()
3382 self.assertEqual(r, True)
3383
James E. Blairec056492016-07-22 09:45:56 -07003384 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003385 def test_client_promote_negative(self):
3386 "Test that the RPC client returns errors for promotion"
James E. Blair08d19992016-08-10 15:25:31 -07003387 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003388 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003389 A.addApproval('code-review', 2)
3390 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003391 self.waitUntilSettled()
3392
3393 client = zuul.rpcclient.RPCClient('127.0.0.1',
3394 self.gearman_server.port)
3395
3396 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3397 r = client.promote(pipeline='nonexistent',
3398 change_ids=['2,1', '3,1'])
3399 client.shutdown()
3400 self.assertEqual(r, False)
3401
3402 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3403 r = client.promote(pipeline='gate',
3404 change_ids=['4,1'])
3405 client.shutdown()
3406 self.assertEqual(r, False)
3407
James E. Blair08d19992016-08-10 15:25:31 -07003408 self.launch_server.hold_jobs_in_build = False
3409 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003410 self.waitUntilSettled()
Clark Boylan7603a372014-01-21 11:43:20 -08003411
James E. Blairec056492016-07-22 09:45:56 -07003412 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003413 def test_queue_rate_limiting(self):
3414 "Test that DependentPipelines are rate limited with dep across window"
James E. Blairf84026c2015-12-08 16:11:46 -08003415 self.updateConfigLayout(
3416 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003417 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003418 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003419 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3420 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3421 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3422
3423 C.setDependsOn(B, 1)
James E. Blair08d19992016-08-10 15:25:31 -07003424 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003425
James E. Blair8b5408c2016-08-08 15:37:46 -07003426 A.addApproval('code-review', 2)
3427 B.addApproval('code-review', 2)
3428 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003429
James E. Blair8b5408c2016-08-08 15:37:46 -07003430 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3431 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3432 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003433 self.waitUntilSettled()
3434
3435 # Only A and B will have their merge jobs queued because
3436 # window is 2.
3437 self.assertEqual(len(self.builds), 2)
3438 self.assertEqual(self.builds[0].name, 'project-merge')
3439 self.assertEqual(self.builds[1].name, 'project-merge')
3440
James E. Blair08d19992016-08-10 15:25:31 -07003441 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003442 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003443 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003444 self.waitUntilSettled()
3445
3446 # Only A and B will have their test jobs queued because
3447 # window is 2.
3448 self.assertEqual(len(self.builds), 4)
3449 self.assertEqual(self.builds[0].name, 'project-test1')
3450 self.assertEqual(self.builds[1].name, 'project-test2')
3451 self.assertEqual(self.builds[2].name, 'project-test1')
3452 self.assertEqual(self.builds[3].name, 'project-test2')
3453
James E. Blair08d19992016-08-10 15:25:31 -07003454 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003455 self.waitUntilSettled()
3456
3457 queue = self.sched.layout.pipelines['gate'].queues[0]
3458 # A failed so window is reduced by 1 to 1.
3459 self.assertEqual(queue.window, 1)
3460 self.assertEqual(queue.window_floor, 1)
3461 self.assertEqual(A.data['status'], 'NEW')
3462
3463 # Gate is reset and only B's merge job is queued because
3464 # window shrunk to 1.
3465 self.assertEqual(len(self.builds), 1)
3466 self.assertEqual(self.builds[0].name, 'project-merge')
3467
James E. Blair08d19992016-08-10 15:25:31 -07003468 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003469 self.waitUntilSettled()
3470
3471 # Only B's test jobs are queued because window is still 1.
3472 self.assertEqual(len(self.builds), 2)
3473 self.assertEqual(self.builds[0].name, 'project-test1')
3474 self.assertEqual(self.builds[1].name, 'project-test2')
3475
James E. Blair08d19992016-08-10 15:25:31 -07003476 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003477 self.waitUntilSettled()
3478
3479 # B was successfully merged so window is increased to 2.
3480 self.assertEqual(queue.window, 2)
3481 self.assertEqual(queue.window_floor, 1)
3482 self.assertEqual(B.data['status'], 'MERGED')
3483
3484 # Only C is left and its merge job is queued.
3485 self.assertEqual(len(self.builds), 1)
3486 self.assertEqual(self.builds[0].name, 'project-merge')
3487
James E. Blair08d19992016-08-10 15:25:31 -07003488 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003489 self.waitUntilSettled()
3490
3491 # After successful merge job the test jobs for C are queued.
3492 self.assertEqual(len(self.builds), 2)
3493 self.assertEqual(self.builds[0].name, 'project-test1')
3494 self.assertEqual(self.builds[1].name, 'project-test2')
3495
James E. Blair08d19992016-08-10 15:25:31 -07003496 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003497 self.waitUntilSettled()
3498
3499 # C successfully merged so window is bumped to 3.
3500 self.assertEqual(queue.window, 3)
3501 self.assertEqual(queue.window_floor, 1)
3502 self.assertEqual(C.data['status'], 'MERGED')
3503
James E. Blairec056492016-07-22 09:45:56 -07003504 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003505 def test_queue_rate_limiting_dependent(self):
3506 "Test that DependentPipelines are rate limited with dep in window"
James E. Blairf84026c2015-12-08 16:11:46 -08003507 self.updateConfigLayout(
3508 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003509 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003510 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003511 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3512 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3513 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3514
3515 B.setDependsOn(A, 1)
3516
James E. Blair08d19992016-08-10 15:25:31 -07003517 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003518
James E. Blair8b5408c2016-08-08 15:37:46 -07003519 A.addApproval('code-review', 2)
3520 B.addApproval('code-review', 2)
3521 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003522
James E. Blair8b5408c2016-08-08 15:37:46 -07003523 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3524 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3525 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003526 self.waitUntilSettled()
3527
3528 # Only A and B will have their merge jobs queued because
3529 # window is 2.
3530 self.assertEqual(len(self.builds), 2)
3531 self.assertEqual(self.builds[0].name, 'project-merge')
3532 self.assertEqual(self.builds[1].name, 'project-merge')
3533
James E. Blair08d19992016-08-10 15:25:31 -07003534 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003535 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003536 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003537 self.waitUntilSettled()
3538
3539 # Only A and B will have their test jobs queued because
3540 # window is 2.
3541 self.assertEqual(len(self.builds), 4)
3542 self.assertEqual(self.builds[0].name, 'project-test1')
3543 self.assertEqual(self.builds[1].name, 'project-test2')
3544 self.assertEqual(self.builds[2].name, 'project-test1')
3545 self.assertEqual(self.builds[3].name, 'project-test2')
3546
James E. Blair08d19992016-08-10 15:25:31 -07003547 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003548 self.waitUntilSettled()
3549
3550 queue = self.sched.layout.pipelines['gate'].queues[0]
3551 # A failed so window is reduced by 1 to 1.
3552 self.assertEqual(queue.window, 1)
3553 self.assertEqual(queue.window_floor, 1)
3554 self.assertEqual(A.data['status'], 'NEW')
3555 self.assertEqual(B.data['status'], 'NEW')
3556
3557 # Gate is reset and only C's merge job is queued because
3558 # window shrunk to 1 and A and B were dequeued.
3559 self.assertEqual(len(self.builds), 1)
3560 self.assertEqual(self.builds[0].name, 'project-merge')
3561
James E. Blair08d19992016-08-10 15:25:31 -07003562 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003563 self.waitUntilSettled()
3564
3565 # Only C's test jobs are queued because window is still 1.
3566 self.assertEqual(len(self.builds), 2)
3567 self.assertEqual(self.builds[0].name, 'project-test1')
3568 self.assertEqual(self.builds[1].name, 'project-test2')
3569
James E. Blair08d19992016-08-10 15:25:31 -07003570 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003571 self.waitUntilSettled()
3572
3573 # C was successfully merged so window is increased to 2.
3574 self.assertEqual(queue.window, 2)
3575 self.assertEqual(queue.window_floor, 1)
3576 self.assertEqual(C.data['status'], 'MERGED')
Joshua Heskethba8776a2014-01-12 14:35:40 +08003577
James E. Blairec056492016-07-22 09:45:56 -07003578 @skip("Disabled for early v3 development")
Joshua Heskethba8776a2014-01-12 14:35:40 +08003579 def test_worker_update_metadata(self):
3580 "Test if a worker can send back metadata about itself"
James E. Blair08d19992016-08-10 15:25:31 -07003581 self.launch_server.hold_jobs_in_build = True
Joshua Heskethba8776a2014-01-12 14:35:40 +08003582
3583 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003584 A.addApproval('code-review', 2)
3585 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethba8776a2014-01-12 14:35:40 +08003586 self.waitUntilSettled()
3587
3588 self.assertEqual(len(self.launcher.builds), 1)
3589
3590 self.log.debug('Current builds:')
3591 self.log.debug(self.launcher.builds)
3592
3593 start = time.time()
3594 while True:
3595 if time.time() - start > 10:
3596 raise Exception("Timeout waiting for gearman server to report "
3597 + "back to the client")
3598 build = self.launcher.builds.values()[0]
3599 if build.worker.name == "My Worker":
3600 break
3601 else:
3602 time.sleep(0)
3603
3604 self.log.debug(build)
3605 self.assertEqual("My Worker", build.worker.name)
3606 self.assertEqual("localhost", build.worker.hostname)
3607 self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips)
3608 self.assertEqual("zuul.example.org", build.worker.fqdn)
3609 self.assertEqual("FakeBuilder", build.worker.program)
3610 self.assertEqual("v1.1", build.worker.version)
3611 self.assertEqual({'something': 'else'}, build.worker.extra)
3612
James E. Blair08d19992016-08-10 15:25:31 -07003613 self.launch_server.hold_jobs_in_build = False
3614 self.launch_server.release()
Joshua Heskethba8776a2014-01-12 14:35:40 +08003615 self.waitUntilSettled()
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003616
James E. Blairec056492016-07-22 09:45:56 -07003617 @skip("Disabled for early v3 development")
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003618 def test_footer_message(self):
3619 "Test a pipeline's footer message is correctly added to the report."
James E. Blairf84026c2015-12-08 16:11:46 -08003620 self.updateConfigLayout(
3621 'tests/fixtures/layout-footer-message.yaml')
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003622 self.sched.reconfigure(self.config)
3623 self.registerJobs()
3624
3625 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003626 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003627 self.launch_server.failJob('test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003628 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003629 self.waitUntilSettled()
3630
3631 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003632 B.addApproval('code-review', 2)
3633 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003634 self.waitUntilSettled()
3635
3636 self.assertEqual(2, len(self.smtp_messages))
3637
3638 failure_body = """\
3639Build failed. For information on how to proceed, see \
3640http://wiki.example.org/Test_Failures
3641
3642- test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s
3643- test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s
3644
3645For CI problems and help debugging, contact ci@example.org"""
3646
3647 success_body = """\
3648Build succeeded.
3649
3650- test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s
3651- test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s
3652
3653For CI problems and help debugging, contact ci@example.org"""
3654
3655 self.assertEqual(failure_body, self.smtp_messages[0]['body'])
3656 self.assertEqual(success_body, self.smtp_messages[1]['body'])
Joshua Heskethb7179772014-01-30 23:30:46 +11003657
James E. Blairec056492016-07-22 09:45:56 -07003658 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003659 def test_merge_failure_reporters(self):
3660 """Check that the config is set up correctly"""
3661
James E. Blairf84026c2015-12-08 16:11:46 -08003662 self.updateConfigLayout(
3663 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003664 self.sched.reconfigure(self.config)
3665 self.registerJobs()
3666
3667 self.assertEqual(
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +00003668 "Merge Failed.\n\nThis change or one of its cross-repo "
3669 "dependencies was unable to be automatically merged with the "
3670 "current state of its repository. Please rebase the change and "
3671 "upload a new patchset.",
Joshua Heskethb7179772014-01-30 23:30:46 +11003672 self.sched.layout.pipelines['check'].merge_failure_message)
3673 self.assertEqual(
3674 "The merge failed! For more information...",
3675 self.sched.layout.pipelines['gate'].merge_failure_message)
3676
3677 self.assertEqual(
3678 len(self.sched.layout.pipelines['check'].merge_failure_actions), 1)
3679 self.assertEqual(
3680 len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2)
3681
3682 self.assertTrue(isinstance(
Joshua Heskethde958652015-11-10 19:19:50 +11003683 self.sched.layout.pipelines['check'].merge_failure_actions[0],
3684 zuul.reporter.gerrit.GerritReporter))
Joshua Heskethb7179772014-01-30 23:30:46 +11003685
3686 self.assertTrue(
3687 (
3688 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003689 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003690 zuul.reporter.smtp.SMTPReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003691 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003692 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003693 zuul.reporter.gerrit.GerritReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003694 ) or (
3695 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003696 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003697 zuul.reporter.gerrit.GerritReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003698 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003699 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003700 zuul.reporter.smtp.SMTPReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003701 )
3702 )
3703
James E. Blairec056492016-07-22 09:45:56 -07003704 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003705 def test_merge_failure_reports(self):
3706 """Check that when a change fails to merge the correct message is sent
3707 to the correct reporter"""
James E. Blairf84026c2015-12-08 16:11:46 -08003708 self.updateConfigLayout(
3709 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003710 self.sched.reconfigure(self.config)
3711 self.registerJobs()
3712
3713 # Check a test failure isn't reported to SMTP
3714 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003715 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003716 self.launch_server.failJob('project-test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003717 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003718 self.waitUntilSettled()
3719
3720 self.assertEqual(3, len(self.history)) # 3 jobs
3721 self.assertEqual(0, len(self.smtp_messages))
3722
3723 # Check a merge failure is reported to SMTP
3724 # B should be merged, but C will conflict with B
3725 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3726 B.addPatchset(['conflict'])
3727 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3728 C.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003729 B.addApproval('code-review', 2)
3730 C.addApproval('code-review', 2)
3731 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3732 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003733 self.waitUntilSettled()
3734
3735 self.assertEqual(6, len(self.history)) # A and B jobs
3736 self.assertEqual(1, len(self.smtp_messages))
3737 self.assertEqual('The merge failed! For more information...',
3738 self.smtp_messages[0]['body'])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003739
James E. Blairec056492016-07-22 09:45:56 -07003740 @skip("Disabled for early v3 development")
James E. Blairf760f0e2016-02-09 08:44:52 -08003741 def test_default_merge_failure_reports(self):
3742 """Check that the default merge failure reports are correct."""
3743
3744 # A should report success, B should report merge failure.
3745 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3746 A.addPatchset(['conflict'])
3747 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3748 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003749 A.addApproval('code-review', 2)
3750 B.addApproval('code-review', 2)
3751 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3752 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairf760f0e2016-02-09 08:44:52 -08003753 self.waitUntilSettled()
3754
3755 self.assertEqual(3, len(self.history)) # A jobs
3756 self.assertEqual(A.reported, 2)
3757 self.assertEqual(B.reported, 2)
3758 self.assertEqual(A.data['status'], 'MERGED')
3759 self.assertEqual(B.data['status'], 'NEW')
3760 self.assertIn('Build succeeded', A.messages[1])
3761 self.assertIn('Merge Failed', B.messages[1])
3762 self.assertIn('automatically merged', B.messages[1])
3763 self.assertNotIn('logs.example.com', B.messages[1])
3764 self.assertNotIn('SKIPPED', B.messages[1])
3765
James E. Blairec056492016-07-22 09:45:56 -07003766 @skip("Disabled for early v3 development")
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003767 def test_swift_instructions(self):
3768 "Test that the correct swift instructions are sent to the workers"
James E. Blairf84026c2015-12-08 16:11:46 -08003769 self.updateConfigLayout(
3770 'tests/fixtures/layout-swift.yaml')
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003771 self.sched.reconfigure(self.config)
3772 self.registerJobs()
3773
James E. Blair08d19992016-08-10 15:25:31 -07003774 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003775 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3776
James E. Blair8b5408c2016-08-08 15:37:46 -07003777 A.addApproval('code-review', 2)
3778 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003779 self.waitUntilSettled()
3780
3781 self.assertEqual(
3782 "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/"
3783 "gate/test-merge/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003784 self.builds[0].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003785 self.assertEqual(5,
3786 len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY'].
3787 split('\n')))
3788 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters)
3789
3790 self.assertEqual(
3791 "https://storage.example.org/V1/AUTH_account/logs/1/1/1/"
3792 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003793 self.builds[1].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003794 self.assertEqual(5,
3795 len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY'].
3796 split('\n')))
3797 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters)
3798
3799 self.assertEqual(
3800 "https://storage.example.org/V1/AUTH_account/stash/1/1/1/"
3801 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003802 self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003803 self.assertEqual(5,
3804 len(self.builds[1].
3805 parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n')))
3806 self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters)
3807
James E. Blair08d19992016-08-10 15:25:31 -07003808 self.launch_server.hold_jobs_in_build = False
3809 self.launch_server.release()
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003810 self.waitUntilSettled()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003811
James E. Blairec056492016-07-22 09:45:56 -07003812 @skip("Disabled for early v3 development")
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003813 def test_client_get_running_jobs(self):
3814 "Test that the RPC client can get a list of running jobs"
James E. Blair08d19992016-08-10 15:25:31 -07003815 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003816 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003817 A.addApproval('code-review', 2)
3818 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003819 self.waitUntilSettled()
3820
3821 client = zuul.rpcclient.RPCClient('127.0.0.1',
3822 self.gearman_server.port)
3823
3824 # Wait for gearman server to send the initial workData back to zuul
3825 start = time.time()
3826 while True:
3827 if time.time() - start > 10:
3828 raise Exception("Timeout waiting for gearman server to report "
3829 + "back to the client")
3830 build = self.launcher.builds.values()[0]
3831 if build.worker.name == "My Worker":
3832 break
3833 else:
3834 time.sleep(0)
3835
3836 running_items = client.get_running_jobs()
3837
3838 self.assertEqual(1, len(running_items))
3839 running_item = running_items[0]
3840 self.assertEqual([], running_item['failing_reasons'])
3841 self.assertEqual([], running_item['items_behind'])
3842 self.assertEqual('https://hostname/1', running_item['url'])
3843 self.assertEqual(None, running_item['item_ahead'])
3844 self.assertEqual('org/project', running_item['project'])
3845 self.assertEqual(None, running_item['remaining_time'])
3846 self.assertEqual(True, running_item['active'])
3847 self.assertEqual('1,1', running_item['id'])
3848
3849 self.assertEqual(3, len(running_item['jobs']))
3850 for job in running_item['jobs']:
3851 if job['name'] == 'project-merge':
3852 self.assertEqual('project-merge', job['name'])
3853 self.assertEqual('gate', job['pipeline'])
3854 self.assertEqual(False, job['retry'])
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003855 self.assertEqual('https://server/job/project-merge/0/',
3856 job['url'])
3857 self.assertEqual(7, len(job['worker']))
3858 self.assertEqual(False, job['canceled'])
3859 self.assertEqual(True, job['voting'])
3860 self.assertEqual(None, job['result'])
3861 self.assertEqual('gate', job['pipeline'])
3862 break
3863
James E. Blair08d19992016-08-10 15:25:31 -07003864 self.launch_server.hold_jobs_in_build = False
3865 self.launch_server.release()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003866 self.waitUntilSettled()
3867
3868 running_items = client.get_running_jobs()
3869 self.assertEqual(0, len(running_items))
James E. Blairbadc1ad2014-04-28 13:55:14 -07003870
3871 def test_nonvoting_pipeline(self):
3872 "Test that a nonvoting pipeline (experimental) can still report"
3873
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003874 A = self.fake_gerrit.addFakeChange('org/experimental-project',
3875 'master', 'A')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003876 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3877 self.waitUntilSettled()
Paul Belanger15e3e202016-10-14 16:27:34 -04003878
3879 self.assertEqual(self.getJobFromHistory('project-merge').result,
3880 'SUCCESS')
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003881 self.assertEqual(
3882 self.getJobFromHistory('experimental-project-test').result,
3883 'SUCCESS')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003884 self.assertEqual(A.reported, 1)
James E. Blair5ee24252014-12-30 10:12:29 -08003885
James E. Blairec056492016-07-22 09:45:56 -07003886 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003887 def test_crd_gate(self):
3888 "Test cross-repo dependencies"
3889 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3890 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003891 A.addApproval('code-review', 2)
3892 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003893
3894 AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2')
3895 AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1')
3896 AM2.setMerged()
3897 AM1.setMerged()
3898
3899 BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2')
3900 BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1')
3901 BM2.setMerged()
3902 BM1.setMerged()
3903
3904 # A -> AM1 -> AM2
3905 # B -> BM1 -> BM2
3906 # A Depends-On: B
3907 # M2 is here to make sure it is never queried. If it is, it
3908 # means zuul is walking down the entire history of merged
3909 # changes.
3910
3911 B.setDependsOn(BM1, 1)
3912 BM1.setDependsOn(BM2, 1)
3913
3914 A.setDependsOn(AM1, 1)
3915 AM1.setDependsOn(AM2, 1)
3916
3917 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3918 A.subject, B.data['id'])
3919
James E. Blair8b5408c2016-08-08 15:37:46 -07003920 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003921 self.waitUntilSettled()
3922
3923 self.assertEqual(A.data['status'], 'NEW')
3924 self.assertEqual(B.data['status'], 'NEW')
3925
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11003926 for connection in self.connections.values():
3927 connection.maintainCache([])
James E. Blair5ee24252014-12-30 10:12:29 -08003928
James E. Blair08d19992016-08-10 15:25:31 -07003929 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003930 B.addApproval('approved', 1)
3931 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003932 self.waitUntilSettled()
3933
James E. Blair08d19992016-08-10 15:25:31 -07003934 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003935 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003936 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003937 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003938 self.launch_server.hold_jobs_in_build = False
3939 self.launch_server.release()
James E. Blair5ee24252014-12-30 10:12:29 -08003940 self.waitUntilSettled()
3941
3942 self.assertEqual(AM2.queried, 0)
3943 self.assertEqual(BM2.queried, 0)
3944 self.assertEqual(A.data['status'], 'MERGED')
3945 self.assertEqual(B.data['status'], 'MERGED')
3946 self.assertEqual(A.reported, 2)
3947 self.assertEqual(B.reported, 2)
3948
James E. Blair8f78d882015-02-05 08:51:37 -08003949 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3950 '2,1 1,1')
3951
James E. Blairec056492016-07-22 09:45:56 -07003952 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003953 def test_crd_branch(self):
3954 "Test cross-repo dependencies in multiple branches"
3955 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3956 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3957 C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C')
3958 C.data['id'] = B.data['id']
James E. Blair8b5408c2016-08-08 15:37:46 -07003959 A.addApproval('code-review', 2)
3960 B.addApproval('code-review', 2)
3961 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003962
3963 # A Depends-On: B+C
3964 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3965 A.subject, B.data['id'])
3966
James E. Blair08d19992016-08-10 15:25:31 -07003967 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003968 B.addApproval('approved', 1)
3969 C.addApproval('approved', 1)
3970 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08003971 self.waitUntilSettled()
3972
James E. Blair08d19992016-08-10 15:25:31 -07003973 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003974 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003975 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003976 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003977 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003978 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003979 self.launch_server.hold_jobs_in_build = False
3980 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08003981 self.waitUntilSettled()
3982
3983 self.assertEqual(A.data['status'], 'MERGED')
3984 self.assertEqual(B.data['status'], 'MERGED')
3985 self.assertEqual(C.data['status'], 'MERGED')
3986 self.assertEqual(A.reported, 2)
3987 self.assertEqual(B.reported, 2)
3988 self.assertEqual(C.reported, 2)
3989
3990 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3991 '2,1 3,1 1,1')
3992
James E. Blairec056492016-07-22 09:45:56 -07003993 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003994 def test_crd_multiline(self):
3995 "Test multiple depends-on lines in commit"
3996 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3997 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3998 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003999 A.addApproval('code-review', 2)
4000 B.addApproval('code-review', 2)
4001 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08004002
4003 # A Depends-On: B+C
4004 A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % (
4005 A.subject, B.data['id'], C.data['id'])
4006
James E. Blair08d19992016-08-10 15:25:31 -07004007 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004008 B.addApproval('approved', 1)
4009 C.addApproval('approved', 1)
4010 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08004011 self.waitUntilSettled()
4012
James E. Blair08d19992016-08-10 15:25:31 -07004013 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004014 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004015 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004016 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004017 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004018 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004019 self.launch_server.hold_jobs_in_build = False
4020 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08004021 self.waitUntilSettled()
4022
4023 self.assertEqual(A.data['status'], 'MERGED')
4024 self.assertEqual(B.data['status'], 'MERGED')
4025 self.assertEqual(C.data['status'], 'MERGED')
4026 self.assertEqual(A.reported, 2)
4027 self.assertEqual(B.reported, 2)
4028 self.assertEqual(C.reported, 2)
4029
4030 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4031 '2,1 3,1 1,1')
James E. Blair5ee24252014-12-30 10:12:29 -08004032
James E. Blairec056492016-07-22 09:45:56 -07004033 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004034 def test_crd_unshared_gate(self):
4035 "Test cross-repo dependencies in unshared gate queues"
4036 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4037 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004038 A.addApproval('code-review', 2)
4039 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004040
4041 # A Depends-On: B
4042 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4043 A.subject, B.data['id'])
4044
4045 # A and B do not share a queue, make sure that A is unable to
4046 # enqueue B (and therefore, A is unable to be enqueued).
James E. Blair8b5408c2016-08-08 15:37:46 -07004047 B.addApproval('approved', 1)
4048 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004049 self.waitUntilSettled()
4050
4051 self.assertEqual(A.data['status'], 'NEW')
4052 self.assertEqual(B.data['status'], 'NEW')
4053 self.assertEqual(A.reported, 0)
4054 self.assertEqual(B.reported, 0)
4055 self.assertEqual(len(self.history), 0)
4056
4057 # Enqueue and merge B alone.
James E. Blair8b5408c2016-08-08 15:37:46 -07004058 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004059 self.waitUntilSettled()
4060
4061 self.assertEqual(B.data['status'], 'MERGED')
4062 self.assertEqual(B.reported, 2)
4063
4064 # Now that B is merged, A should be able to be enqueued and
4065 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004066 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004067 self.waitUntilSettled()
4068
4069 self.assertEqual(A.data['status'], 'MERGED')
4070 self.assertEqual(A.reported, 2)
4071
James E. Blairec056492016-07-22 09:45:56 -07004072 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004073 def test_crd_gate_reverse(self):
4074 "Test reverse cross-repo dependencies"
4075 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4076 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004077 A.addApproval('code-review', 2)
4078 B.addApproval('code-review', 2)
James E. Blair96698e22015-04-02 07:48:21 -07004079
4080 # A Depends-On: B
4081
4082 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4083 A.subject, B.data['id'])
4084
James E. Blair8b5408c2016-08-08 15:37:46 -07004085 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004086 self.waitUntilSettled()
4087
4088 self.assertEqual(A.data['status'], 'NEW')
4089 self.assertEqual(B.data['status'], 'NEW')
4090
James E. Blair08d19992016-08-10 15:25:31 -07004091 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004092 A.addApproval('approved', 1)
4093 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004094 self.waitUntilSettled()
4095
James E. Blair08d19992016-08-10 15:25:31 -07004096 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004097 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004098 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004099 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004100 self.launch_server.hold_jobs_in_build = False
4101 self.launch_server.release()
James E. Blair96698e22015-04-02 07:48:21 -07004102 self.waitUntilSettled()
4103
4104 self.assertEqual(A.data['status'], 'MERGED')
4105 self.assertEqual(B.data['status'], 'MERGED')
4106 self.assertEqual(A.reported, 2)
4107 self.assertEqual(B.reported, 2)
4108
4109 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4110 '2,1 1,1')
4111
James E. Blairec056492016-07-22 09:45:56 -07004112 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004113 def test_crd_cycle(self):
4114 "Test cross-repo dependency cycles"
4115 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4116 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004117 A.addApproval('code-review', 2)
4118 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004119
4120 # A -> B -> A (via commit-depends)
4121
4122 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4123 A.subject, B.data['id'])
4124 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4125 B.subject, A.data['id'])
4126
James E. Blair8b5408c2016-08-08 15:37:46 -07004127 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004128 self.waitUntilSettled()
4129
4130 self.assertEqual(A.reported, 0)
4131 self.assertEqual(B.reported, 0)
4132 self.assertEqual(A.data['status'], 'NEW')
4133 self.assertEqual(B.data['status'], 'NEW')
James E. Blairbfb8e042014-12-30 17:01:44 -08004134
James E. Blairec056492016-07-22 09:45:56 -07004135 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004136 def test_crd_gate_unknown(self):
4137 "Test unknown projects in dependent pipeline"
4138 self.init_repo("org/unknown")
4139 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4140 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004141 A.addApproval('code-review', 2)
4142 B.addApproval('code-review', 2)
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004143
4144 # A Depends-On: B
4145 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4146 A.subject, B.data['id'])
4147
James E. Blair8b5408c2016-08-08 15:37:46 -07004148 B.addApproval('approved', 1)
4149 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004150 self.waitUntilSettled()
4151
4152 # Unknown projects cannot share a queue with any other
4153 # since they don't have common jobs with any other (they have no jobs).
4154 # Changes which depend on unknown project changes
4155 # should not be processed in dependent pipeline
4156 self.assertEqual(A.data['status'], 'NEW')
4157 self.assertEqual(B.data['status'], 'NEW')
4158 self.assertEqual(A.reported, 0)
4159 self.assertEqual(B.reported, 0)
4160 self.assertEqual(len(self.history), 0)
4161
4162 # Simulate change B being gated outside this layout
James E. Blair8b5408c2016-08-08 15:37:46 -07004163 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004164 B.setMerged()
4165 self.waitUntilSettled()
4166 self.assertEqual(len(self.history), 0)
4167
4168 # Now that B is merged, A should be able to be enqueued and
4169 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004170 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004171 self.waitUntilSettled()
4172
4173 self.assertEqual(A.data['status'], 'MERGED')
4174 self.assertEqual(A.reported, 2)
4175 self.assertEqual(B.data['status'], 'MERGED')
4176 self.assertEqual(B.reported, 0)
4177
James E. Blairec056492016-07-22 09:45:56 -07004178 @skip("Disabled for early v3 development")
James E. Blairbfb8e042014-12-30 17:01:44 -08004179 def test_crd_check(self):
4180 "Test cross-repo dependencies in independent pipelines"
4181
4182 self.gearman_server.hold_jobs_in_queue = True
4183 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4184 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4185
4186 # A Depends-On: B
4187 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4188 A.subject, B.data['id'])
4189
4190 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4191 self.waitUntilSettled()
4192
4193 queue = self.gearman_server.getQueue()
4194 ref = self.getParameter(queue[-1], 'ZUUL_REF')
4195 self.gearman_server.hold_jobs_in_queue = False
4196 self.gearman_server.release()
4197 self.waitUntilSettled()
4198
4199 path = os.path.join(self.git_root, "org/project1")
4200 repo = git.Repo(path)
4201 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4202 repo_messages.reverse()
4203 correct_messages = ['initial commit', 'A-1']
4204 self.assertEqual(repo_messages, correct_messages)
4205
4206 path = os.path.join(self.git_root, "org/project2")
4207 repo = git.Repo(path)
4208 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4209 repo_messages.reverse()
4210 correct_messages = ['initial commit', 'B-1']
4211 self.assertEqual(repo_messages, correct_messages)
4212
4213 self.assertEqual(A.data['status'], 'NEW')
4214 self.assertEqual(B.data['status'], 'NEW')
4215 self.assertEqual(A.reported, 1)
4216 self.assertEqual(B.reported, 0)
4217
4218 self.assertEqual(self.history[0].changes, '2,1 1,1')
4219 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair8f78d882015-02-05 08:51:37 -08004220
James E. Blairec056492016-07-22 09:45:56 -07004221 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004222 def test_crd_check_git_depends(self):
4223 "Test single-repo dependencies in independent pipelines"
James E. Blairb8c16472015-05-05 14:55:26 -07004224 self.gearman_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004225 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4226 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4227
4228 # Add two git-dependent changes and make sure they both report
4229 # success.
4230 B.setDependsOn(A, 1)
4231 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4232 self.waitUntilSettled()
4233 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4234 self.waitUntilSettled()
4235
James E. Blairb8c16472015-05-05 14:55:26 -07004236 self.orderedRelease()
4237 self.gearman_server.hold_jobs_in_build = False
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004238 self.waitUntilSettled()
4239
4240 self.assertEqual(A.data['status'], 'NEW')
4241 self.assertEqual(B.data['status'], 'NEW')
4242 self.assertEqual(A.reported, 1)
4243 self.assertEqual(B.reported, 1)
4244
4245 self.assertEqual(self.history[0].changes, '1,1')
4246 self.assertEqual(self.history[-1].changes, '1,1 2,1')
4247 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4248
4249 self.assertIn('Build succeeded', A.messages[0])
4250 self.assertIn('Build succeeded', B.messages[0])
4251
James E. Blairec056492016-07-22 09:45:56 -07004252 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004253 def test_crd_check_duplicate(self):
4254 "Test duplicate check in independent pipelines"
James E. Blair08d19992016-08-10 15:25:31 -07004255 self.launch_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004256 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4257 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4258 check_pipeline = self.sched.layout.pipelines['check']
4259
4260 # Add two git-dependent changes...
4261 B.setDependsOn(A, 1)
4262 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4263 self.waitUntilSettled()
4264 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4265
4266 # ...make sure the live one is not duplicated...
4267 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4268 self.waitUntilSettled()
4269 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4270
4271 # ...but the non-live one is able to be.
4272 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4273 self.waitUntilSettled()
4274 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4275
Clark Boylandd849822015-03-02 12:38:14 -08004276 # Release jobs in order to avoid races with change A jobs
4277 # finishing before change B jobs.
James E. Blaird7650852015-05-07 15:47:37 -07004278 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07004279 self.launch_server.hold_jobs_in_build = False
4280 self.launch_server.release()
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004281 self.waitUntilSettled()
4282
4283 self.assertEqual(A.data['status'], 'NEW')
4284 self.assertEqual(B.data['status'], 'NEW')
4285 self.assertEqual(A.reported, 1)
4286 self.assertEqual(B.reported, 1)
4287
4288 self.assertEqual(self.history[0].changes, '1,1 2,1')
4289 self.assertEqual(self.history[1].changes, '1,1')
4290 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4291
4292 self.assertIn('Build succeeded', A.messages[0])
4293 self.assertIn('Build succeeded', B.messages[0])
4294
James E. Blairec056492016-07-22 09:45:56 -07004295 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004296 def _test_crd_check_reconfiguration(self, project1, project2):
James E. Blair8f78d882015-02-05 08:51:37 -08004297 "Test cross-repo dependencies re-enqueued in independent pipelines"
4298
4299 self.gearman_server.hold_jobs_in_queue = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004300 A = self.fake_gerrit.addFakeChange(project1, 'master', 'A')
4301 B = self.fake_gerrit.addFakeChange(project2, 'master', 'B')
James E. Blair8f78d882015-02-05 08:51:37 -08004302
4303 # A Depends-On: B
4304 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4305 A.subject, B.data['id'])
4306
4307 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4308 self.waitUntilSettled()
4309
4310 self.sched.reconfigure(self.config)
4311
4312 # Make sure the items still share a change queue, and the
4313 # first one is not live.
4314 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1)
4315 queue = self.sched.layout.pipelines['check'].queues[0]
4316 first_item = queue.queue[0]
4317 for item in queue.queue:
4318 self.assertEqual(item.queue, first_item.queue)
4319 self.assertFalse(first_item.live)
4320 self.assertTrue(queue.queue[1].live)
4321
4322 self.gearman_server.hold_jobs_in_queue = False
4323 self.gearman_server.release()
4324 self.waitUntilSettled()
4325
4326 self.assertEqual(A.data['status'], 'NEW')
4327 self.assertEqual(B.data['status'], 'NEW')
4328 self.assertEqual(A.reported, 1)
4329 self.assertEqual(B.reported, 0)
4330
4331 self.assertEqual(self.history[0].changes, '2,1 1,1')
4332 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair17dd6772015-02-09 14:45:18 -08004333
James E. Blairec056492016-07-22 09:45:56 -07004334 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004335 def test_crd_check_reconfiguration(self):
4336 self._test_crd_check_reconfiguration('org/project1', 'org/project2')
4337
James E. Blairec056492016-07-22 09:45:56 -07004338 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004339 def test_crd_undefined_project(self):
4340 """Test that undefined projects in dependencies are handled for
4341 independent pipelines"""
4342 # It's a hack for fake gerrit,
4343 # as it implies repo creation upon the creation of any change
4344 self.init_repo("org/unknown")
4345 self._test_crd_check_reconfiguration('org/project1', 'org/unknown')
4346
James E. Blairec056492016-07-22 09:45:56 -07004347 @skip("Disabled for early v3 development")
James E. Blair17dd6772015-02-09 14:45:18 -08004348 def test_crd_check_ignore_dependencies(self):
4349 "Test cross-repo dependencies can be ignored"
James E. Blairf84026c2015-12-08 16:11:46 -08004350 self.updateConfigLayout(
4351 'tests/fixtures/layout-ignore-dependencies.yaml')
James E. Blair17dd6772015-02-09 14:45:18 -08004352 self.sched.reconfigure(self.config)
4353 self.registerJobs()
4354
4355 self.gearman_server.hold_jobs_in_queue = True
4356 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4357 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4358 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
4359
4360 # A Depends-On: B
4361 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4362 A.subject, B.data['id'])
4363 # C git-depends on B
4364 C.setDependsOn(B, 1)
4365 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4366 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4367 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4368 self.waitUntilSettled()
4369
4370 # Make sure none of the items share a change queue, and all
4371 # are live.
4372 check_pipeline = self.sched.layout.pipelines['check']
4373 self.assertEqual(len(check_pipeline.queues), 3)
4374 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4375 for item in check_pipeline.getAllItems():
4376 self.assertTrue(item.live)
4377
4378 self.gearman_server.hold_jobs_in_queue = False
4379 self.gearman_server.release()
4380 self.waitUntilSettled()
4381
4382 self.assertEqual(A.data['status'], 'NEW')
4383 self.assertEqual(B.data['status'], 'NEW')
4384 self.assertEqual(C.data['status'], 'NEW')
4385 self.assertEqual(A.reported, 1)
4386 self.assertEqual(B.reported, 1)
4387 self.assertEqual(C.reported, 1)
4388
4389 # Each job should have tested exactly one change
4390 for job in self.history:
4391 self.assertEqual(len(job.changes.split()), 1)
James E. Blair96698e22015-04-02 07:48:21 -07004392
James E. Blairec056492016-07-22 09:45:56 -07004393 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004394 def test_crd_check_transitive(self):
4395 "Test transitive cross-repo dependencies"
4396 # Specifically, if A -> B -> C, and C gets a new patchset and
4397 # A gets a new patchset, ensure the test of A,2 includes B,1
4398 # and C,2 (not C,1 which would indicate stale data in the
4399 # cache for B).
4400 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4401 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4402 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
4403
4404 # A Depends-On: B
4405 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4406 A.subject, B.data['id'])
4407
4408 # B Depends-On: C
4409 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4410 B.subject, C.data['id'])
4411
4412 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4413 self.waitUntilSettled()
4414 self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1')
4415
4416 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4417 self.waitUntilSettled()
4418 self.assertEqual(self.history[-1].changes, '3,1 2,1')
4419
4420 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4421 self.waitUntilSettled()
4422 self.assertEqual(self.history[-1].changes, '3,1')
4423
4424 C.addPatchset()
4425 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2))
4426 self.waitUntilSettled()
4427 self.assertEqual(self.history[-1].changes, '3,2')
4428
4429 A.addPatchset()
4430 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
4431 self.waitUntilSettled()
4432 self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004433
James E. Blairec056492016-07-22 09:45:56 -07004434 @skip("Disabled for early v3 development")
James E. Blaira8b90b32016-08-24 15:18:50 -07004435 def test_crd_check_unknown(self):
4436 "Test unknown projects in independent pipeline"
4437 self.init_repo("org/unknown")
4438 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4439 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D')
4440 # A Depends-On: B
4441 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4442 A.subject, B.data['id'])
4443
4444 # Make sure zuul has seen an event on B.
4445 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4446 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4447 self.waitUntilSettled()
4448
4449 self.assertEqual(A.data['status'], 'NEW')
4450 self.assertEqual(A.reported, 1)
4451 self.assertEqual(B.data['status'], 'NEW')
4452 self.assertEqual(B.reported, 0)
4453
Joshua Heskethefeeb6d2016-09-20 14:42:37 +02004454 @skip("Disabled for early v3 development")
James E. Blair92464a22016-04-05 10:21:26 -07004455 def test_crd_cycle_join(self):
4456 "Test an updated change creates a cycle"
4457 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
4458
4459 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4460 self.waitUntilSettled()
4461
4462 # Create B->A
4463 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4464 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4465 B.subject, A.data['id'])
4466 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4467 self.waitUntilSettled()
4468
4469 # Update A to add A->B (a cycle).
4470 A.addPatchset()
4471 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4472 A.subject, B.data['id'])
4473 # Normally we would submit the patchset-created event for
4474 # processing here, however, we have no way of noting whether
4475 # the dependency cycle detection correctly raised an
4476 # exception, so instead, we reach into the source driver and
4477 # call the method that would ultimately be called by the event
4478 # processing.
4479
4480 source = self.sched.layout.pipelines['gate'].source
4481 with testtools.ExpectedException(
4482 Exception, "Dependency cycle detected"):
4483 source._getChange(u'1', u'2', True)
4484 self.log.debug("Got expected dependency cycle exception")
4485
4486 # Now if we update B to remove the depends-on, everything
4487 # should be okay. B; A->B
4488
4489 B.addPatchset()
4490 B.data['commitMessage'] = '%s\n' % (B.subject,)
4491 source._getChange(u'1', u'2', True)
4492 source._getChange(u'2', u'2', True)
4493
James E. Blairec056492016-07-22 09:45:56 -07004494 @skip("Disabled for early v3 development")
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004495 def test_disable_at(self):
4496 "Test a pipeline will only report to the disabled trigger when failing"
4497
James E. Blairf84026c2015-12-08 16:11:46 -08004498 self.updateConfigLayout(
4499 'tests/fixtures/layout-disable-at.yaml')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004500 self.sched.reconfigure(self.config)
4501
4502 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4503 self.assertEqual(
4504 0, self.sched.layout.pipelines['check']._consecutive_failures)
4505 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4506
4507 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4508 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
4509 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
4510 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
4511 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
4512 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
4513 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
4514 H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H')
4515 I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I')
4516 J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J')
4517 K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K')
4518
James E. Blair08d19992016-08-10 15:25:31 -07004519 self.launch_server.failJob('project-test1', A)
4520 self.launch_server.failJob('project-test1', B)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004521 # Let C pass, resetting the counter
James E. Blair08d19992016-08-10 15:25:31 -07004522 self.launch_server.failJob('project-test1', D)
4523 self.launch_server.failJob('project-test1', E)
4524 self.launch_server.failJob('project-test1', F)
4525 self.launch_server.failJob('project-test1', G)
4526 self.launch_server.failJob('project-test1', H)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004527 # I also passes but should only report to the disabled reporters
James E. Blair08d19992016-08-10 15:25:31 -07004528 self.launch_server.failJob('project-test1', J)
4529 self.launch_server.failJob('project-test1', K)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004530
4531 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4532 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4533 self.waitUntilSettled()
4534
4535 self.assertEqual(
4536 2, self.sched.layout.pipelines['check']._consecutive_failures)
4537 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4538
4539 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4540 self.waitUntilSettled()
4541
4542 self.assertEqual(
4543 0, self.sched.layout.pipelines['check']._consecutive_failures)
4544 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4545
4546 self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1))
4547 self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1))
4548 self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1))
4549 self.waitUntilSettled()
4550
4551 # We should be disabled now
4552 self.assertEqual(
4553 3, self.sched.layout.pipelines['check']._consecutive_failures)
4554 self.assertTrue(self.sched.layout.pipelines['check']._disabled)
4555
4556 # We need to wait between each of these patches to make sure the
4557 # smtp messages come back in an expected order
4558 self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1))
4559 self.waitUntilSettled()
4560 self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1))
4561 self.waitUntilSettled()
4562 self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1))
4563 self.waitUntilSettled()
4564
4565 # The first 6 (ABCDEF) jobs should have reported back to gerrt thus
4566 # leaving a message on each change
4567 self.assertEqual(1, len(A.messages))
4568 self.assertIn('Build failed.', A.messages[0])
4569 self.assertEqual(1, len(B.messages))
4570 self.assertIn('Build failed.', B.messages[0])
4571 self.assertEqual(1, len(C.messages))
4572 self.assertIn('Build succeeded.', C.messages[0])
4573 self.assertEqual(1, len(D.messages))
4574 self.assertIn('Build failed.', D.messages[0])
4575 self.assertEqual(1, len(E.messages))
4576 self.assertIn('Build failed.', E.messages[0])
4577 self.assertEqual(1, len(F.messages))
4578 self.assertIn('Build failed.', F.messages[0])
4579
4580 # The last 3 (GHI) would have only reported via smtp.
4581 self.assertEqual(3, len(self.smtp_messages))
4582 self.assertEqual(0, len(G.messages))
4583 self.assertIn('Build failed.', self.smtp_messages[0]['body'])
4584 self.assertIn('/7/1/check', self.smtp_messages[0]['body'])
4585 self.assertEqual(0, len(H.messages))
4586 self.assertIn('Build failed.', self.smtp_messages[1]['body'])
4587 self.assertIn('/8/1/check', self.smtp_messages[1]['body'])
4588 self.assertEqual(0, len(I.messages))
4589 self.assertIn('Build succeeded.', self.smtp_messages[2]['body'])
4590 self.assertIn('/9/1/check', self.smtp_messages[2]['body'])
4591
4592 # Now reload the configuration (simulate a HUP) to check the pipeline
4593 # comes out of disabled
4594 self.sched.reconfigure(self.config)
4595
4596 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4597 self.assertEqual(
4598 0, self.sched.layout.pipelines['check']._consecutive_failures)
4599 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4600
4601 self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1))
4602 self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1))
4603 self.waitUntilSettled()
4604
4605 self.assertEqual(
4606 2, self.sched.layout.pipelines['check']._consecutive_failures)
4607 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4608
4609 # J and K went back to gerrit
4610 self.assertEqual(1, len(J.messages))
4611 self.assertIn('Build failed.', J.messages[0])
4612 self.assertEqual(1, len(K.messages))
4613 self.assertIn('Build failed.', K.messages[0])
4614 # No more messages reported via smtp
4615 self.assertEqual(3, len(self.smtp_messages))
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004616
James E. Blairec056492016-07-22 09:45:56 -07004617 @skip("Disabled for early v3 development")
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004618 def test_success_pattern(self):
4619 "Ensure bad build params are ignored"
4620
4621 # Use SMTP reporter to grab the result message easier
4622 self.init_repo("org/docs")
4623 self.config.set('zuul', 'layout_config',
4624 'tests/fixtures/layout-success-pattern.yaml')
4625 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07004626 self.launch_server.hold_jobs_in_build = True
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004627 self.registerJobs()
4628
4629 A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A')
4630 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4631 self.waitUntilSettled()
4632
4633 # Grab build id
4634 self.assertEqual(len(self.builds), 1)
4635 uuid = self.builds[0].unique[:7]
4636
James E. Blair08d19992016-08-10 15:25:31 -07004637 self.launch_server.hold_jobs_in_build = False
4638 self.launch_server.release()
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004639 self.waitUntilSettled()
4640
4641 self.assertEqual(len(self.smtp_messages), 1)
4642 body = self.smtp_messages[0]['body'].splitlines()
4643 self.assertEqual('Build succeeded.', body[0])
4644
4645 self.assertIn(
4646 '- docs-draft-test http://docs-draft.example.org/1/1/1/check/'
4647 'docs-draft-test/%s/publish-docs/' % uuid,
4648 body[2])
4649 self.assertIn(
4650 '- docs-draft-test2 https://server/job/docs-draft-test2/1/',
4651 body[3])
Arieb6f068c2016-10-09 13:11:06 +03004652
4653
4654class TestDuplicatePipeline(ZuulTestCase):
4655 tenant_config_file = 'config/duplicate-pipeline/main.yaml'
4656
4657 def test_duplicate_pipelines(self):
4658 "Test that a change matching multiple pipelines works"
4659
4660 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4661 self.fake_gerrit.addEvent(A.getChangeRestoredEvent())
4662 self.waitUntilSettled()
4663
4664 self.assertHistory([
4665 dict(name='project-test1', result='SUCCESS', changes='1,1',
4666 pipeline='dup1'),
4667 dict(name='project-test1', result='SUCCESS', changes='1,1',
4668 pipeline='dup2'),
4669 ])
4670
4671 self.assertEqual(len(A.messages), 2)
4672
4673 self.assertIn('dup1', A.messages[0])
4674 self.assertNotIn('dup2', A.messages[0])
4675 self.assertIn('project-test1', A.messages[0])
4676
4677 self.assertIn('dup2', A.messages[1])
4678 self.assertNotIn('dup1', A.messages[1])
4679 self.assertIn('project-test1', A.messages[1])