blob: 4a8954662f284c5d9358f3d98058a1a81dbb4386 [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
James E. Blairb0fcae42012-07-17 11:12:10 -070035
Maru Newby3fe5f852015-01-13 04:22:14 +000036from tests.base import (
Maru Newby3fe5f852015-01-13 04:22:14 +000037 ZuulTestCase,
38 repack_repo,
39)
James E. Blairb0fcae42012-07-17 11:12:10 -070040
James E. Blair1f4c2bb2013-04-26 08:40:46 -070041logging.basicConfig(level=logging.DEBUG,
42 format='%(asctime)s %(name)-32s '
43 '%(levelname)-8s %(message)s')
James E. Blairb0fcae42012-07-17 11:12:10 -070044
45
Clark Boylanb640e052014-04-03 16:41:46 -070046class TestScheduler(ZuulTestCase):
James E. Blair552b54f2016-07-22 13:55:32 -070047 tenant_config_file = 'config/single-tenant/main.yaml'
Antoine Mussobd86a312014-01-08 14:51:33 +010048
James E. Blairb0fcae42012-07-17 11:12:10 -070049 def test_jobs_launched(self):
50 "Test that jobs are launched and a change is merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -070051
James E. Blairb0fcae42012-07-17 11:12:10 -070052 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -070053 A.addApproval('code-review', 2)
54 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairb0fcae42012-07-17 11:12:10 -070055 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -040056 self.assertEqual(self.getJobFromHistory('project-merge').result,
57 'SUCCESS')
58 self.assertEqual(self.getJobFromHistory('project-test1').result,
59 'SUCCESS')
60 self.assertEqual(self.getJobFromHistory('project-test2').result,
61 'SUCCESS')
62 self.assertEqual(A.data['status'], 'MERGED')
63 self.assertEqual(A.reported, 2)
James E. Blairb0fcae42012-07-17 11:12:10 -070064
James E. Blair552b54f2016-07-22 13:55:32 -070065 # TODOv3(jeblair): we may want to report stats by tenant (also?).
James E. Blair66eeebf2013-07-27 17:44:32 -070066 self.assertReportedStat('gerrit.event.comment-added', value='1|c')
67 self.assertReportedStat('zuul.pipeline.gate.current_changes',
68 value='1|g')
69 self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',
70 kind='ms')
71 self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',
72 value='1|c')
73 self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms')
74 self.assertReportedStat('zuul.pipeline.gate.total_changes',
75 value='1|c')
James E. Blair412e5582013-04-22 15:50:12 -070076 self.assertReportedStat(
James E. Blair66eeebf2013-07-27 17:44:32 -070077 'zuul.pipeline.gate.org.project.resident_time', kind='ms')
James E. Blair412e5582013-04-22 15:50:12 -070078 self.assertReportedStat(
James E. Blair66eeebf2013-07-27 17:44:32 -070079 'zuul.pipeline.gate.org.project.total_changes', value='1|c')
James E. Blair412e5582013-04-22 15:50:12 -070080
James E. Blair5821bd92015-09-16 08:48:15 -070081 for build in self.builds:
82 self.assertEqual(build.parameters['ZUUL_VOTING'], '1')
83
James E. Blair3cb10702013-08-24 08:56:03 -070084 def test_initial_pipeline_gauges(self):
85 "Test that each pipeline reported its length on start"
James E. Blair7da51b72016-07-25 15:29:43 -070086 self.assertReportedStat('zuul.pipeline.gate.current_changes',
87 value='0|g')
88 self.assertReportedStat('zuul.pipeline.check.current_changes',
89 value='0|g')
James E. Blair3cb10702013-08-24 08:56:03 -070090
James E. Blairec056492016-07-22 09:45:56 -070091 @skip("Disabled for early v3 development")
James E. Blair42f74822013-05-14 15:18:03 -070092 def test_duplicate_pipelines(self):
93 "Test that a change matching multiple pipelines works"
James E. Blair1b4d9722013-05-21 10:32:04 -070094
James E. Blair42f74822013-05-14 15:18:03 -070095 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
96 self.fake_gerrit.addEvent(A.getChangeRestoredEvent())
97 self.waitUntilSettled()
James E. Blair42f74822013-05-14 15:18:03 -070098
Monty Taylor98f0f3e2013-07-06 16:02:31 -040099 self.assertEqual(len(self.history), 2)
Monty Taylor6bef8ef2013-06-02 08:17:12 -0400100 self.history[0].name == 'project-test1'
101 self.history[1].name == 'project-test1'
James E. Blair42f74822013-05-14 15:18:03 -0700102
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400103 self.assertEqual(len(A.messages), 2)
James E. Blair42f74822013-05-14 15:18:03 -0700104 if 'dup1/project-test1' in A.messages[0]:
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400105 self.assertIn('dup1/project-test1', A.messages[0])
106 self.assertNotIn('dup2/project-test1', A.messages[0])
107 self.assertNotIn('dup1/project-test1', A.messages[1])
108 self.assertIn('dup2/project-test1', A.messages[1])
James E. Blair42f74822013-05-14 15:18:03 -0700109 else:
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400110 self.assertIn('dup1/project-test1', A.messages[1])
111 self.assertNotIn('dup2/project-test1', A.messages[1])
112 self.assertNotIn('dup1/project-test1', A.messages[0])
113 self.assertIn('dup2/project-test1', A.messages[0])
James E. Blair42f74822013-05-14 15:18:03 -0700114
James E. Blairb0fcae42012-07-17 11:12:10 -0700115 def test_parallel_changes(self):
116 "Test that changes are tested in parallel and merged in series"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700117
James E. Blair791b5392016-08-03 11:25:56 -0700118 self.launch_server.hold_jobs_in_build = True
James E. Blairb0fcae42012-07-17 11:12:10 -0700119 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
120 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
121 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700122 A.addApproval('code-review', 2)
123 B.addApproval('code-review', 2)
124 C.addApproval('code-review', 2)
James E. Blairb0fcae42012-07-17 11:12:10 -0700125
James E. Blair8b5408c2016-08-08 15:37:46 -0700126 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
127 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
128 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairb0fcae42012-07-17 11:12:10 -0700129
130 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400131 self.assertEqual(len(self.builds), 1)
132 self.assertEqual(self.builds[0].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700133 self.assertTrue(self.builds[0].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700134
James E. Blair791b5392016-08-03 11:25:56 -0700135 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700136 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400137 self.assertEqual(len(self.builds), 3)
138 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700139 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400140 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700141 self.assertTrue(self.builds[1].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400142 self.assertEqual(self.builds[2].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700143 self.assertTrue(self.builds[2].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700144
James E. Blair791b5392016-08-03 11:25:56 -0700145 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700146 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400147 self.assertEqual(len(self.builds), 5)
148 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700149 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400150 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700151 self.assertTrue(self.builds[1].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700152
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400153 self.assertEqual(self.builds[2].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700154 self.assertTrue(self.builds[2].hasChanges(A, B))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400155 self.assertEqual(self.builds[3].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700156 self.assertTrue(self.builds[3].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700157
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400158 self.assertEqual(self.builds[4].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700159 self.assertTrue(self.builds[4].hasChanges(A, B, C))
James E. Blairb0fcae42012-07-17 11:12:10 -0700160
James E. Blair791b5392016-08-03 11:25:56 -0700161 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700162 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400163 self.assertEqual(len(self.builds), 6)
164 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700165 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400166 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700167 self.assertTrue(self.builds[1].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700168
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400169 self.assertEqual(self.builds[2].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700170 self.assertTrue(self.builds[2].hasChanges(A, B))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400171 self.assertEqual(self.builds[3].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700172 self.assertTrue(self.builds[3].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700173
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400174 self.assertEqual(self.builds[4].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700175 self.assertTrue(self.builds[4].hasChanges(A, B, C))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400176 self.assertEqual(self.builds[5].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700177 self.assertTrue(self.builds[5].hasChanges(A, B, C))
James E. Blairb0fcae42012-07-17 11:12:10 -0700178
James E. Blair791b5392016-08-03 11:25:56 -0700179 self.launch_server.hold_jobs_in_build = False
180 self.launch_server.release()
James E. Blairb0fcae42012-07-17 11:12:10 -0700181 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400182 self.assertEqual(len(self.builds), 0)
James E. Blairb0fcae42012-07-17 11:12:10 -0700183
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400184 self.assertEqual(len(self.history), 9)
185 self.assertEqual(A.data['status'], 'MERGED')
186 self.assertEqual(B.data['status'], 'MERGED')
187 self.assertEqual(C.data['status'], 'MERGED')
188 self.assertEqual(A.reported, 2)
189 self.assertEqual(B.reported, 2)
190 self.assertEqual(C.reported, 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700191
James E. Blairec056492016-07-22 09:45:56 -0700192 @skip("Disabled for early v3 development")
James E. Blairb02a3bb2012-07-30 17:49:55 -0700193 def test_failed_changes(self):
194 "Test that a change behind a failed change is retested"
James E. Blair08d19992016-08-10 15:25:31 -0700195 self.launch_server.hold_jobs_in_build = True
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700196
James E. Blairb02a3bb2012-07-30 17:49:55 -0700197 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
198 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -0700199 A.addApproval('code-review', 2)
200 B.addApproval('code-review', 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700201
James E. Blair08d19992016-08-10 15:25:31 -0700202 self.launch_server.failJob('project-test1', A)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700203
James E. Blair8b5408c2016-08-08 15:37:46 -0700204 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
205 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700206 self.waitUntilSettled()
James E. Blaire2819012013-06-28 17:17:26 -0400207
James E. Blair08d19992016-08-10 15:25:31 -0700208 self.launch_server.release('.*-merge')
James E. Blaire2819012013-06-28 17:17:26 -0400209 self.waitUntilSettled()
210
James E. Blair08d19992016-08-10 15:25:31 -0700211 self.launch_server.hold_jobs_in_build = False
212 self.launch_server.release()
James E. Blaire2819012013-06-28 17:17:26 -0400213
214 self.waitUntilSettled()
215 # It's certain that the merge job for change 2 will run, but
216 # the test1 and test2 jobs may or may not run.
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400217 self.assertTrue(len(self.history) > 6)
218 self.assertEqual(A.data['status'], 'NEW')
219 self.assertEqual(B.data['status'], 'MERGED')
220 self.assertEqual(A.reported, 2)
221 self.assertEqual(B.reported, 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700222
James E. Blairec056492016-07-22 09:45:56 -0700223 @skip("Disabled for early v3 development")
James E. Blairb02a3bb2012-07-30 17:49:55 -0700224 def test_independent_queues(self):
225 "Test that changes end up in the right queues"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700226
James E. Blair08d19992016-08-10 15:25:31 -0700227 self.launch_server.hold_jobs_in_build = True
Zhongyue Luo5d556072012-09-21 02:00:47 +0900228 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700229 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
230 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700231 A.addApproval('code-review', 2)
232 B.addApproval('code-review', 2)
233 C.addApproval('code-review', 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700234
James E. Blair8b5408c2016-08-08 15:37:46 -0700235 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
236 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
237 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700238
James E. Blairb02a3bb2012-07-30 17:49:55 -0700239 self.waitUntilSettled()
240
241 # There should be one merge job at the head of each queue running
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400242 self.assertEqual(len(self.builds), 2)
243 self.assertEqual(self.builds[0].name, 'project-merge')
244 self.assertTrue(self.job_has_changes(self.builds[0], A))
245 self.assertEqual(self.builds[1].name, 'project1-merge')
246 self.assertTrue(self.job_has_changes(self.builds[1], B))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700247
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700248 # Release the current merge builds
James E. Blair08d19992016-08-10 15:25:31 -0700249 self.launch_server.release('.*-merge')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700250 self.waitUntilSettled()
251 # Release the merge job for project2 which is behind project1
James E. Blair08d19992016-08-10 15:25:31 -0700252 self.launch_server.release('.*-merge')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700253 self.waitUntilSettled()
254
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700255 # All the test builds should be running:
James E. Blairb02a3bb2012-07-30 17:49:55 -0700256 # project1 (3) + project2 (3) + project (2) = 8
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400257 self.assertEqual(len(self.builds), 8)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700258
James E. Blair08d19992016-08-10 15:25:31 -0700259 self.launch_server.release()
James E. Blairb02a3bb2012-07-30 17:49:55 -0700260 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400261 self.assertEqual(len(self.builds), 0)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700262
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400263 self.assertEqual(len(self.history), 11)
264 self.assertEqual(A.data['status'], 'MERGED')
265 self.assertEqual(B.data['status'], 'MERGED')
266 self.assertEqual(C.data['status'], 'MERGED')
267 self.assertEqual(A.reported, 2)
268 self.assertEqual(B.reported, 2)
269 self.assertEqual(C.reported, 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700270
James E. Blairec056492016-07-22 09:45:56 -0700271 @skip("Disabled for early v3 development")
James E. Blaird466dc42012-07-31 10:42:56 -0700272 def test_failed_change_at_head(self):
273 "Test that if a change at the head fails, jobs behind it are canceled"
James E. Blaird466dc42012-07-31 10:42:56 -0700274
James E. Blair08d19992016-08-10 15:25:31 -0700275 self.launch_server.hold_jobs_in_build = True
James E. Blaird466dc42012-07-31 10:42:56 -0700276 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
277 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
278 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700279 A.addApproval('code-review', 2)
280 B.addApproval('code-review', 2)
281 C.addApproval('code-review', 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700282
James E. Blair08d19992016-08-10 15:25:31 -0700283 self.launch_server.failJob('project-test1', A)
James E. Blaird466dc42012-07-31 10:42:56 -0700284
James E. Blair8b5408c2016-08-08 15:37:46 -0700285 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
286 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
287 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blaird466dc42012-07-31 10:42:56 -0700288
289 self.waitUntilSettled()
James E. Blaird466dc42012-07-31 10:42:56 -0700290
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400291 self.assertEqual(len(self.builds), 1)
292 self.assertEqual(self.builds[0].name, 'project-merge')
293 self.assertTrue(self.job_has_changes(self.builds[0], A))
James E. Blaird466dc42012-07-31 10:42:56 -0700294
James E. Blair08d19992016-08-10 15:25:31 -0700295 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700296 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700297 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700298 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700299 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700300 self.waitUntilSettled()
301
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400302 self.assertEqual(len(self.builds), 6)
303 self.assertEqual(self.builds[0].name, 'project-test1')
304 self.assertEqual(self.builds[1].name, 'project-test2')
305 self.assertEqual(self.builds[2].name, 'project-test1')
306 self.assertEqual(self.builds[3].name, 'project-test2')
307 self.assertEqual(self.builds[4].name, 'project-test1')
308 self.assertEqual(self.builds[5].name, 'project-test2')
James E. Blaird466dc42012-07-31 10:42:56 -0700309
Monty Taylor6bef8ef2013-06-02 08:17:12 -0400310 self.release(self.builds[0])
James E. Blaird466dc42012-07-31 10:42:56 -0700311 self.waitUntilSettled()
312
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400313 # project-test2, project-merge for B
314 self.assertEqual(len(self.builds), 2)
315 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4)
James E. Blaird466dc42012-07-31 10:42:56 -0700316
James E. Blair08d19992016-08-10 15:25:31 -0700317 self.launch_server.hold_jobs_in_build = False
318 self.launch_server.release()
James E. Blaird466dc42012-07-31 10:42:56 -0700319 self.waitUntilSettled()
320
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400321 self.assertEqual(len(self.builds), 0)
322 self.assertEqual(len(self.history), 15)
323 self.assertEqual(A.data['status'], 'NEW')
324 self.assertEqual(B.data['status'], 'MERGED')
325 self.assertEqual(C.data['status'], 'MERGED')
326 self.assertEqual(A.reported, 2)
327 self.assertEqual(B.reported, 2)
328 self.assertEqual(C.reported, 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700329
James E. Blairec056492016-07-22 09:45:56 -0700330 @skip("Disabled for early v3 development")
James E. Blair0aac4872013-08-23 14:02:38 -0700331 def test_failed_change_in_middle(self):
332 "Test a failed change in the middle of the queue"
333
James E. Blair08d19992016-08-10 15:25:31 -0700334 self.launch_server.hold_jobs_in_build = True
James E. Blair0aac4872013-08-23 14:02:38 -0700335 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
336 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
337 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700338 A.addApproval('code-review', 2)
339 B.addApproval('code-review', 2)
340 C.addApproval('code-review', 2)
James E. Blair0aac4872013-08-23 14:02:38 -0700341
James E. Blair08d19992016-08-10 15:25:31 -0700342 self.launch_server.failJob('project-test1', B)
James E. Blair0aac4872013-08-23 14:02:38 -0700343
James E. Blair8b5408c2016-08-08 15:37:46 -0700344 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
345 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
346 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair0aac4872013-08-23 14:02:38 -0700347
348 self.waitUntilSettled()
349
James E. Blair08d19992016-08-10 15:25:31 -0700350 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700351 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700352 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700353 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700354 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700355 self.waitUntilSettled()
356
357 self.assertEqual(len(self.builds), 6)
358 self.assertEqual(self.builds[0].name, 'project-test1')
359 self.assertEqual(self.builds[1].name, 'project-test2')
360 self.assertEqual(self.builds[2].name, 'project-test1')
361 self.assertEqual(self.builds[3].name, 'project-test2')
362 self.assertEqual(self.builds[4].name, 'project-test1')
363 self.assertEqual(self.builds[5].name, 'project-test2')
364
365 self.release(self.builds[2])
366 self.waitUntilSettled()
367
James E. Blair972e3c72013-08-29 12:04:55 -0700368 # project-test1 and project-test2 for A
369 # project-test2 for B
370 # project-merge for C (without B)
371 self.assertEqual(len(self.builds), 4)
James E. Blair0aac4872013-08-23 14:02:38 -0700372 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2)
373
James E. Blair08d19992016-08-10 15:25:31 -0700374 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -0700375 self.waitUntilSettled()
376
377 # project-test1 and project-test2 for A
378 # project-test2 for B
379 # project-test1 and project-test2 for C
380 self.assertEqual(len(self.builds), 5)
381
James E. Blair0aac4872013-08-23 14:02:38 -0700382 items = self.sched.layout.pipelines['gate'].getAllItems()
383 builds = items[0].current_build_set.getBuilds()
384 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
385 self.assertEqual(self.countJobResults(builds, None), 2)
386 builds = items[1].current_build_set.getBuilds()
387 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
388 self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1)
389 self.assertEqual(self.countJobResults(builds, None), 1)
390 builds = items[2].current_build_set.getBuilds()
391 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
James E. Blair972e3c72013-08-29 12:04:55 -0700392 self.assertEqual(self.countJobResults(builds, None), 2)
James E. Blair0aac4872013-08-23 14:02:38 -0700393
James E. Blair08d19992016-08-10 15:25:31 -0700394 self.launch_server.hold_jobs_in_build = False
395 self.launch_server.release()
James E. Blair0aac4872013-08-23 14:02:38 -0700396 self.waitUntilSettled()
397
398 self.assertEqual(len(self.builds), 0)
399 self.assertEqual(len(self.history), 12)
400 self.assertEqual(A.data['status'], 'MERGED')
401 self.assertEqual(B.data['status'], 'NEW')
402 self.assertEqual(C.data['status'], 'MERGED')
403 self.assertEqual(A.reported, 2)
404 self.assertEqual(B.reported, 2)
405 self.assertEqual(C.reported, 2)
406
James E. Blairec056492016-07-22 09:45:56 -0700407 @skip("Disabled for early v3 development")
James E. Blaird466dc42012-07-31 10:42:56 -0700408 def test_failed_change_at_head_with_queue(self):
409 "Test that if a change at the head fails, queued jobs are canceled"
James E. Blaird466dc42012-07-31 10:42:56 -0700410
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700411 self.gearman_server.hold_jobs_in_queue = True
James E. Blaird466dc42012-07-31 10:42:56 -0700412 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
413 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
414 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700415 A.addApproval('code-review', 2)
416 B.addApproval('code-review', 2)
417 C.addApproval('code-review', 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700418
James E. Blair08d19992016-08-10 15:25:31 -0700419 self.launch_server.failJob('project-test1', A)
James E. Blaird466dc42012-07-31 10:42:56 -0700420
James E. Blair8b5408c2016-08-08 15:37:46 -0700421 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
422 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
423 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blaird466dc42012-07-31 10:42:56 -0700424
425 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700426 queue = self.gearman_server.getQueue()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400427 self.assertEqual(len(self.builds), 0)
428 self.assertEqual(len(queue), 1)
429 self.assertEqual(queue[0].name, 'build:project-merge')
430 self.assertTrue(self.job_has_changes(queue[0], A))
James E. Blaird466dc42012-07-31 10:42:56 -0700431
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700432 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700433 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700434 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700435 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700436 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700437 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700438 queue = self.gearman_server.getQueue()
James E. Blaird466dc42012-07-31 10:42:56 -0700439
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400440 self.assertEqual(len(self.builds), 0)
441 self.assertEqual(len(queue), 6)
442 self.assertEqual(queue[0].name, 'build:project-test1')
443 self.assertEqual(queue[1].name, 'build:project-test2')
444 self.assertEqual(queue[2].name, 'build:project-test1')
445 self.assertEqual(queue[3].name, 'build:project-test2')
446 self.assertEqual(queue[4].name, 'build:project-test1')
447 self.assertEqual(queue[5].name, 'build:project-test2')
James E. Blaird466dc42012-07-31 10:42:56 -0700448
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700449 self.release(queue[0])
James E. Blaird466dc42012-07-31 10:42:56 -0700450 self.waitUntilSettled()
451
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400452 self.assertEqual(len(self.builds), 0)
James E. Blair701c5b42013-06-06 09:34:59 -0700453 queue = self.gearman_server.getQueue()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400454 self.assertEqual(len(queue), 2) # project-test2, project-merge for B
455 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0)
James E. Blaird466dc42012-07-31 10:42:56 -0700456
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700457 self.gearman_server.hold_jobs_in_queue = False
458 self.gearman_server.release()
James E. Blaird466dc42012-07-31 10:42:56 -0700459 self.waitUntilSettled()
460
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400461 self.assertEqual(len(self.builds), 0)
462 self.assertEqual(len(self.history), 11)
463 self.assertEqual(A.data['status'], 'NEW')
464 self.assertEqual(B.data['status'], 'MERGED')
465 self.assertEqual(C.data['status'], 'MERGED')
466 self.assertEqual(A.reported, 2)
467 self.assertEqual(B.reported, 2)
468 self.assertEqual(C.reported, 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700469
James E. Blairec056492016-07-22 09:45:56 -0700470 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700471 def _test_time_database(self, iteration):
James E. Blair08d19992016-08-10 15:25:31 -0700472 self.launch_server.hold_jobs_in_build = True
James E. Blairce8a2132016-05-19 15:21:52 -0700473 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -0700474 A.addApproval('code-review', 2)
475 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairce8a2132016-05-19 15:21:52 -0700476 self.waitUntilSettled()
477 time.sleep(2)
478
479 data = json.loads(self.sched.formatStatusJSON())
480 found_job = None
481 for pipeline in data['pipelines']:
482 if pipeline['name'] != 'gate':
483 continue
484 for queue in pipeline['change_queues']:
485 for head in queue['heads']:
486 for item in head:
487 for job in item['jobs']:
488 if job['name'] == 'project-merge':
489 found_job = job
490 break
491
492 self.assertIsNotNone(found_job)
493 if iteration == 1:
494 self.assertIsNotNone(found_job['estimated_time'])
495 self.assertIsNone(found_job['remaining_time'])
496 else:
497 self.assertIsNotNone(found_job['estimated_time'])
498 self.assertTrue(found_job['estimated_time'] >= 2)
499 self.assertIsNotNone(found_job['remaining_time'])
500
James E. Blair08d19992016-08-10 15:25:31 -0700501 self.launch_server.hold_jobs_in_build = False
502 self.launch_server.release()
James E. Blairce8a2132016-05-19 15:21:52 -0700503 self.waitUntilSettled()
504
James E. Blairec056492016-07-22 09:45:56 -0700505 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700506 def test_time_database(self):
507 "Test the time database"
508
509 self._test_time_database(1)
510 self._test_time_database(2)
511
James E. Blairec056492016-07-22 09:45:56 -0700512 @skip("Disabled for early v3 development")
James E. Blairfef71632013-09-23 11:15:47 -0700513 def test_two_failed_changes_at_head(self):
514 "Test that changes are reparented correctly if 2 fail at head"
515
James E. Blair08d19992016-08-10 15:25:31 -0700516 self.launch_server.hold_jobs_in_build = True
James E. Blairfef71632013-09-23 11:15:47 -0700517 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
518 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
519 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700520 A.addApproval('code-review', 2)
521 B.addApproval('code-review', 2)
522 C.addApproval('code-review', 2)
James E. Blairfef71632013-09-23 11:15:47 -0700523
James E. Blair08d19992016-08-10 15:25:31 -0700524 self.launch_server.failJob('project-test1', A)
525 self.launch_server.failJob('project-test1', B)
James E. Blairfef71632013-09-23 11:15:47 -0700526
James E. Blair8b5408c2016-08-08 15:37:46 -0700527 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
528 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
529 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairfef71632013-09-23 11:15:47 -0700530 self.waitUntilSettled()
531
James E. Blair08d19992016-08-10 15:25:31 -0700532 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700533 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700534 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700535 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700536 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700537 self.waitUntilSettled()
538
539 self.assertEqual(len(self.builds), 6)
540 self.assertEqual(self.builds[0].name, 'project-test1')
541 self.assertEqual(self.builds[1].name, 'project-test2')
542 self.assertEqual(self.builds[2].name, 'project-test1')
543 self.assertEqual(self.builds[3].name, 'project-test2')
544 self.assertEqual(self.builds[4].name, 'project-test1')
545 self.assertEqual(self.builds[5].name, 'project-test2')
546
547 self.assertTrue(self.job_has_changes(self.builds[0], A))
548 self.assertTrue(self.job_has_changes(self.builds[2], A))
549 self.assertTrue(self.job_has_changes(self.builds[2], B))
550 self.assertTrue(self.job_has_changes(self.builds[4], A))
551 self.assertTrue(self.job_has_changes(self.builds[4], B))
552 self.assertTrue(self.job_has_changes(self.builds[4], C))
553
554 # Fail change B first
555 self.release(self.builds[2])
556 self.waitUntilSettled()
557
558 # restart of C after B failure
James E. Blair08d19992016-08-10 15:25:31 -0700559 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700560 self.waitUntilSettled()
561
562 self.assertEqual(len(self.builds), 5)
563 self.assertEqual(self.builds[0].name, 'project-test1')
564 self.assertEqual(self.builds[1].name, 'project-test2')
565 self.assertEqual(self.builds[2].name, 'project-test2')
566 self.assertEqual(self.builds[3].name, 'project-test1')
567 self.assertEqual(self.builds[4].name, 'project-test2')
568
569 self.assertTrue(self.job_has_changes(self.builds[1], A))
570 self.assertTrue(self.job_has_changes(self.builds[2], A))
571 self.assertTrue(self.job_has_changes(self.builds[2], B))
572 self.assertTrue(self.job_has_changes(self.builds[4], A))
573 self.assertFalse(self.job_has_changes(self.builds[4], B))
574 self.assertTrue(self.job_has_changes(self.builds[4], C))
575
576 # Finish running all passing jobs for change A
577 self.release(self.builds[1])
578 self.waitUntilSettled()
579 # Fail and report change A
580 self.release(self.builds[0])
581 self.waitUntilSettled()
582
583 # restart of B,C after A failure
James E. Blair08d19992016-08-10 15:25:31 -0700584 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700585 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700586 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700587 self.waitUntilSettled()
588
589 self.assertEqual(len(self.builds), 4)
590 self.assertEqual(self.builds[0].name, 'project-test1') # B
591 self.assertEqual(self.builds[1].name, 'project-test2') # B
592 self.assertEqual(self.builds[2].name, 'project-test1') # C
593 self.assertEqual(self.builds[3].name, 'project-test2') # C
594
595 self.assertFalse(self.job_has_changes(self.builds[1], A))
596 self.assertTrue(self.job_has_changes(self.builds[1], B))
597 self.assertFalse(self.job_has_changes(self.builds[1], C))
598
599 self.assertFalse(self.job_has_changes(self.builds[2], A))
600 # After A failed and B and C restarted, B should be back in
601 # C's tests because it has not failed yet.
602 self.assertTrue(self.job_has_changes(self.builds[2], B))
603 self.assertTrue(self.job_has_changes(self.builds[2], C))
604
James E. Blair08d19992016-08-10 15:25:31 -0700605 self.launch_server.hold_jobs_in_build = False
606 self.launch_server.release()
James E. Blairfef71632013-09-23 11:15:47 -0700607 self.waitUntilSettled()
608
609 self.assertEqual(len(self.builds), 0)
610 self.assertEqual(len(self.history), 21)
611 self.assertEqual(A.data['status'], 'NEW')
612 self.assertEqual(B.data['status'], 'NEW')
613 self.assertEqual(C.data['status'], 'MERGED')
614 self.assertEqual(A.reported, 2)
615 self.assertEqual(B.reported, 2)
616 self.assertEqual(C.reported, 2)
617
James E. Blairec056492016-07-22 09:45:56 -0700618 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700619 def test_parse_skip_if(self):
620 job_yaml = """
621jobs:
622 - name: job_name
623 skip-if:
624 - project: ^project_name$
625 branch: ^stable/icehouse$
626 all-files-match-any:
627 - ^filename$
628 - project: ^project2_name$
629 all-files-match-any:
630 - ^filename2$
631 """.strip()
632 data = yaml.load(job_yaml)
633 config_job = data.get('jobs')[0]
634 cm = zuul.change_matcher
635 expected = cm.MatchAny([
636 cm.MatchAll([
637 cm.ProjectMatcher('^project_name$'),
638 cm.BranchMatcher('^stable/icehouse$'),
639 cm.MatchAllFiles([cm.FileMatcher('^filename$')]),
640 ]),
641 cm.MatchAll([
642 cm.ProjectMatcher('^project2_name$'),
643 cm.MatchAllFiles([cm.FileMatcher('^filename2$')]),
644 ]),
645 ])
646 matcher = self.sched._parseSkipIf(config_job)
647 self.assertEqual(expected, matcher)
648
James E. Blairec056492016-07-22 09:45:56 -0700649 @skip("Disabled for early v3 development")
James E. Blair8c803f82012-07-31 16:25:42 -0700650 def test_patch_order(self):
651 "Test that dependent patches are tested in the right order"
652 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
653 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
654 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700655 A.addApproval('code-review', 2)
656 B.addApproval('code-review', 2)
657 C.addApproval('code-review', 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700658
659 M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2')
660 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
661 M2.setMerged()
662 M1.setMerged()
663
664 # C -> B -> A -> M1 -> M2
665 # M2 is here to make sure it is never queried. If it is, it
666 # means zuul is walking down the entire history of merged
667 # changes.
668
669 C.setDependsOn(B, 1)
670 B.setDependsOn(A, 1)
671 A.setDependsOn(M1, 1)
672 M1.setDependsOn(M2, 1)
673
James E. Blair8b5408c2016-08-08 15:37:46 -0700674 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair8c803f82012-07-31 16:25:42 -0700675
676 self.waitUntilSettled()
677
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400678 self.assertEqual(A.data['status'], 'NEW')
679 self.assertEqual(B.data['status'], 'NEW')
680 self.assertEqual(C.data['status'], 'NEW')
James E. Blair8c803f82012-07-31 16:25:42 -0700681
James E. Blair8b5408c2016-08-08 15:37:46 -0700682 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
683 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8c803f82012-07-31 16:25:42 -0700684
685 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400686 self.assertEqual(M2.queried, 0)
687 self.assertEqual(A.data['status'], 'MERGED')
688 self.assertEqual(B.data['status'], 'MERGED')
689 self.assertEqual(C.data['status'], 'MERGED')
690 self.assertEqual(A.reported, 2)
691 self.assertEqual(B.reported, 2)
692 self.assertEqual(C.reported, 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700693
James E. Blairec056492016-07-22 09:45:56 -0700694 @skip("Disabled for early v3 development")
James E. Blair063672f2015-01-29 13:09:12 -0800695 def test_needed_changes_enqueue(self):
696 "Test that a needed change is enqueued ahead"
697 # A Given a git tree like this, if we enqueue
698 # / \ change C, we should walk up and down the tree
699 # B G and enqueue changes in the order ABCDEFG.
700 # /|\ This is also the order that you would get if
701 # *C E F you enqueued changes in the order ABCDEFG, so
702 # / the ordering is stable across re-enqueue events.
703 # D
704
705 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
706 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
707 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
708 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
709 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
710 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
711 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
712 B.setDependsOn(A, 1)
713 C.setDependsOn(B, 1)
714 D.setDependsOn(C, 1)
715 E.setDependsOn(B, 1)
716 F.setDependsOn(B, 1)
717 G.setDependsOn(A, 1)
718
James E. Blair8b5408c2016-08-08 15:37:46 -0700719 A.addApproval('code-review', 2)
720 B.addApproval('code-review', 2)
721 C.addApproval('code-review', 2)
722 D.addApproval('code-review', 2)
723 E.addApproval('code-review', 2)
724 F.addApproval('code-review', 2)
725 G.addApproval('code-review', 2)
726 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800727
728 self.waitUntilSettled()
729
730 self.assertEqual(A.data['status'], 'NEW')
731 self.assertEqual(B.data['status'], 'NEW')
732 self.assertEqual(C.data['status'], 'NEW')
733 self.assertEqual(D.data['status'], 'NEW')
734 self.assertEqual(E.data['status'], 'NEW')
735 self.assertEqual(F.data['status'], 'NEW')
736 self.assertEqual(G.data['status'], 'NEW')
737
738 # We're about to add approvals to changes without adding the
739 # triggering events to Zuul, so that we can be sure that it is
740 # enqueing the changes based on dependencies, not because of
741 # triggering events. Since it will have the changes cached
742 # already (without approvals), we need to clear the cache
743 # first.
Joshua Hesketh4bd7da32016-02-17 20:58:47 +1100744 for connection in self.connections.values():
745 connection.maintainCache([])
James E. Blair063672f2015-01-29 13:09:12 -0800746
James E. Blair08d19992016-08-10 15:25:31 -0700747 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -0700748 A.addApproval('approved', 1)
749 B.addApproval('approved', 1)
750 D.addApproval('approved', 1)
751 E.addApproval('approved', 1)
752 F.addApproval('approved', 1)
753 G.addApproval('approved', 1)
754 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800755
756 for x in range(8):
James E. Blair08d19992016-08-10 15:25:31 -0700757 self.launch_server.release('.*-merge')
James E. Blair063672f2015-01-29 13:09:12 -0800758 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700759 self.launch_server.hold_jobs_in_build = False
760 self.launch_server.release()
James E. Blair063672f2015-01-29 13:09:12 -0800761 self.waitUntilSettled()
762
763 self.assertEqual(A.data['status'], 'MERGED')
764 self.assertEqual(B.data['status'], 'MERGED')
765 self.assertEqual(C.data['status'], 'MERGED')
766 self.assertEqual(D.data['status'], 'MERGED')
767 self.assertEqual(E.data['status'], 'MERGED')
768 self.assertEqual(F.data['status'], 'MERGED')
769 self.assertEqual(G.data['status'], 'MERGED')
770 self.assertEqual(A.reported, 2)
771 self.assertEqual(B.reported, 2)
772 self.assertEqual(C.reported, 2)
773 self.assertEqual(D.reported, 2)
774 self.assertEqual(E.reported, 2)
775 self.assertEqual(F.reported, 2)
776 self.assertEqual(G.reported, 2)
777 self.assertEqual(self.history[6].changes,
778 '1,1 2,1 3,1 4,1 5,1 6,1 7,1')
779
James E. Blairec056492016-07-22 09:45:56 -0700780 @skip("Disabled for early v3 development")
Joshua Hesketh850ccb62014-11-27 11:31:02 +1100781 def test_source_cache(self):
782 "Test that the source cache operates correctly"
James E. Blair08d19992016-08-10 15:25:31 -0700783 self.launch_server.hold_jobs_in_build = True
James E. Blair0e933c52013-07-11 10:18:52 -0700784
785 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
786 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
787 X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X')
James E. Blair8b5408c2016-08-08 15:37:46 -0700788 A.addApproval('code-review', 2)
789 B.addApproval('code-review', 2)
James E. Blair0e933c52013-07-11 10:18:52 -0700790
791 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
792 M1.setMerged()
793
794 B.setDependsOn(A, 1)
795 A.setDependsOn(M1, 1)
796
James E. Blair8b5408c2016-08-08 15:37:46 -0700797 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700798 self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1))
799
800 self.waitUntilSettled()
801
802 for build in self.builds:
803 if build.parameters['ZUUL_PIPELINE'] == 'check':
804 build.release()
805 self.waitUntilSettled()
806 for build in self.builds:
807 if build.parameters['ZUUL_PIPELINE'] == 'check':
808 build.release()
809 self.waitUntilSettled()
810
James E. Blair8b5408c2016-08-08 15:37:46 -0700811 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700812 self.waitUntilSettled()
813
Joshua Hesketh352264b2015-08-11 23:42:08 +1000814 self.log.debug("len %s" % self.fake_gerrit._change_cache.keys())
James E. Blair0e933c52013-07-11 10:18:52 -0700815 # there should still be changes in the cache
Joshua Hesketh352264b2015-08-11 23:42:08 +1000816 self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0)
James E. Blair0e933c52013-07-11 10:18:52 -0700817
James E. Blair08d19992016-08-10 15:25:31 -0700818 self.launch_server.hold_jobs_in_build = False
819 self.launch_server.release()
James E. Blair0e933c52013-07-11 10:18:52 -0700820 self.waitUntilSettled()
821
822 self.assertEqual(A.data['status'], 'MERGED')
823 self.assertEqual(B.data['status'], 'MERGED')
824 self.assertEqual(A.queried, 2) # Initial and isMerged
825 self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged
826
James E. Blairec056492016-07-22 09:45:56 -0700827 @skip("Disabled for early v3 development")
James E. Blair8c803f82012-07-31 16:25:42 -0700828 def test_can_merge(self):
James E. Blair4886cc12012-07-18 15:39:41 -0700829 "Test whether a change is ready to merge"
James E. Blair8c803f82012-07-31 16:25:42 -0700830 # TODO: move to test_gerrit (this is a unit test!)
831 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairc0dedf82014-08-06 09:37:52 -0700832 source = self.sched.layout.pipelines['gate'].source
833 a = source._getChange(1, 2)
James E. Blaireff88162013-07-01 12:44:14 -0400834 mgr = self.sched.layout.pipelines['gate'].manager
James E. Blairc0dedf82014-08-06 09:37:52 -0700835 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700836
James E. Blair8b5408c2016-08-08 15:37:46 -0700837 A.addApproval('code-review', 2)
James E. Blairc0dedf82014-08-06 09:37:52 -0700838 a = source._getChange(1, 2, refresh=True)
839 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700840
James E. Blair8b5408c2016-08-08 15:37:46 -0700841 A.addApproval('approved', 1)
James E. Blairc0dedf82014-08-06 09:37:52 -0700842 a = source._getChange(1, 2, refresh=True)
843 self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair4886cc12012-07-18 15:39:41 -0700844
James E. Blairec056492016-07-22 09:45:56 -0700845 @skip("Disabled for early v3 development")
James E. Blair4886cc12012-07-18 15:39:41 -0700846 def test_build_configuration(self):
847 "Test that zuul merges the right commits for testing"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700848
849 self.gearman_server.hold_jobs_in_queue = True
James E. Blair4886cc12012-07-18 15:39:41 -0700850 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
851 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
852 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700853 A.addApproval('code-review', 2)
854 B.addApproval('code-review', 2)
855 C.addApproval('code-review', 2)
856 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
857 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
858 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair4886cc12012-07-18 15:39:41 -0700859 self.waitUntilSettled()
860
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700861 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700862 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700863 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700864 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700865 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700866 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700867 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700868 ref = self.getParameter(queue[-1], 'ZUUL_REF')
869 self.gearman_server.hold_jobs_in_queue = False
870 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -0700871 self.waitUntilSettled()
James E. Blair4886cc12012-07-18 15:39:41 -0700872
Monty Taylorbc758832013-06-17 17:22:42 -0400873 path = os.path.join(self.git_root, "org/project")
James E. Blair4886cc12012-07-18 15:39:41 -0700874 repo = git.Repo(path)
875 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
876 repo_messages.reverse()
James E. Blair4886cc12012-07-18 15:39:41 -0700877 correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400878 self.assertEqual(repo_messages, correct_messages)
James E. Blair973721f2012-08-15 10:19:43 -0700879
James E. Blairec056492016-07-22 09:45:56 -0700880 @skip("Disabled for early v3 development")
James E. Blair973721f2012-08-15 10:19:43 -0700881 def test_build_configuration_conflict(self):
882 "Test that merge conflicts are handled"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700883
884 self.gearman_server.hold_jobs_in_queue = True
James E. Blair6736beb2013-07-11 15:18:15 -0700885 A = self.fake_gerrit.addFakeChange('org/conflict-project',
886 'master', 'A')
James E. Blair973721f2012-08-15 10:19:43 -0700887 A.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700888 B = self.fake_gerrit.addFakeChange('org/conflict-project',
889 'master', 'B')
James E. Blair973721f2012-08-15 10:19:43 -0700890 B.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700891 C = self.fake_gerrit.addFakeChange('org/conflict-project',
892 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700893 A.addApproval('code-review', 2)
894 B.addApproval('code-review', 2)
895 C.addApproval('code-review', 2)
896 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
897 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
898 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair973721f2012-08-15 10:19:43 -0700899 self.waitUntilSettled()
900
James E. Blair6736beb2013-07-11 15:18:15 -0700901 self.assertEqual(A.reported, 1)
902 self.assertEqual(B.reported, 1)
903 self.assertEqual(C.reported, 1)
904
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700905 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -0700906 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700907 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -0700908 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700909 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -0700910 self.waitUntilSettled()
James E. Blair972e3c72013-08-29 12:04:55 -0700911
912 self.assertEqual(len(self.history), 2) # A and C merge jobs
913
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700914 self.gearman_server.hold_jobs_in_queue = False
915 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -0700916 self.waitUntilSettled()
917
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400918 self.assertEqual(A.data['status'], 'MERGED')
919 self.assertEqual(B.data['status'], 'NEW')
920 self.assertEqual(C.data['status'], 'MERGED')
921 self.assertEqual(A.reported, 2)
922 self.assertEqual(B.reported, 2)
923 self.assertEqual(C.reported, 2)
James E. Blair972e3c72013-08-29 12:04:55 -0700924 self.assertEqual(len(self.history), 6)
James E. Blair6736beb2013-07-11 15:18:15 -0700925
James E. Blairec056492016-07-22 09:45:56 -0700926 @skip("Disabled for early v3 development")
James E. Blairdaabed22012-08-15 15:38:57 -0700927 def test_post(self):
928 "Test that post jobs run"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700929
Zhongyue Luo5d556072012-09-21 02:00:47 +0900930 e = {
931 "type": "ref-updated",
932 "submitter": {
933 "name": "User Name",
934 },
935 "refUpdate": {
936 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
937 "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543",
938 "refName": "master",
939 "project": "org/project",
940 }
941 }
James E. Blairdaabed22012-08-15 15:38:57 -0700942 self.fake_gerrit.addEvent(e)
943 self.waitUntilSettled()
944
Monty Taylor6bef8ef2013-06-02 08:17:12 -0400945 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400946 self.assertEqual(len(self.history), 1)
947 self.assertIn('project-post', job_names)
James E. Blairc6294a52012-08-17 10:19:48 -0700948
James E. Blairec056492016-07-22 09:45:56 -0700949 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -0700950 def test_post_ignore_deletes(self):
951 "Test that deleting refs does not trigger post jobs"
952
953 e = {
954 "type": "ref-updated",
955 "submitter": {
956 "name": "User Name",
957 },
958 "refUpdate": {
959 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
960 "newRev": "0000000000000000000000000000000000000000",
961 "refName": "master",
962 "project": "org/project",
963 }
964 }
965 self.fake_gerrit.addEvent(e)
966 self.waitUntilSettled()
967
968 job_names = [x.name for x in self.history]
969 self.assertEqual(len(self.history), 0)
970 self.assertNotIn('project-post', job_names)
971
James E. Blairec056492016-07-22 09:45:56 -0700972 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -0700973 def test_post_ignore_deletes_negative(self):
974 "Test that deleting refs does trigger post jobs"
975
James E. Blairf84026c2015-12-08 16:11:46 -0800976 self.updateConfigLayout(
977 'tests/fixtures/layout-dont-ignore-deletes.yaml')
K Jonathan Harkerf95e7232015-04-29 13:33:16 -0700978 self.sched.reconfigure(self.config)
979
980 e = {
981 "type": "ref-updated",
982 "submitter": {
983 "name": "User Name",
984 },
985 "refUpdate": {
986 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
987 "newRev": "0000000000000000000000000000000000000000",
988 "refName": "master",
989 "project": "org/project",
990 }
991 }
992 self.fake_gerrit.addEvent(e)
993 self.waitUntilSettled()
994
995 job_names = [x.name for x in self.history]
996 self.assertEqual(len(self.history), 1)
997 self.assertIn('project-post', job_names)
998
James E. Blairec056492016-07-22 09:45:56 -0700999 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001000 def test_build_configuration_branch(self):
1001 "Test that the right commits are on alternate branches"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001002
1003 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001004 A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A')
1005 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1006 C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001007 A.addApproval('code-review', 2)
1008 B.addApproval('code-review', 2)
1009 C.addApproval('code-review', 2)
1010 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1011 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1012 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001013 self.waitUntilSettled()
1014
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001015 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001016 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001017 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001018 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001019 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001020 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001021 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001022 ref = self.getParameter(queue[-1], 'ZUUL_REF')
1023 self.gearman_server.hold_jobs_in_queue = False
1024 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001025 self.waitUntilSettled()
1026
Monty Taylorbc758832013-06-17 17:22:42 -04001027 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001028 repo = git.Repo(path)
1029 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
1030 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001031 correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001032 self.assertEqual(repo_messages, correct_messages)
James E. Blairc6294a52012-08-17 10:19:48 -07001033
James E. Blairec056492016-07-22 09:45:56 -07001034 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001035 def test_build_configuration_branch_interaction(self):
1036 "Test that switching between branches works"
1037 self.test_build_configuration()
1038 self.test_build_configuration_branch()
1039 # C has been merged, undo that
Monty Taylorbc758832013-06-17 17:22:42 -04001040 path = os.path.join(self.upstream_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001041 repo = git.Repo(path)
1042 repo.heads.master.commit = repo.commit('init')
1043 self.test_build_configuration()
1044
James E. Blairec056492016-07-22 09:45:56 -07001045 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001046 def test_build_configuration_multi_branch(self):
1047 "Test that dependent changes on multiple branches are merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001048
1049 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001050 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1051 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1052 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001053 A.addApproval('code-review', 2)
1054 B.addApproval('code-review', 2)
1055 C.addApproval('code-review', 2)
1056 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1057 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1058 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001059 self.waitUntilSettled()
James E. Blairbb1fe502014-03-04 10:15:06 -08001060 queue = self.gearman_server.getQueue()
1061 job_A = None
1062 for job in queue:
1063 if 'project-merge' in job.name:
1064 job_A = job
1065 ref_A = self.getParameter(job_A, 'ZUUL_REF')
1066 commit_A = self.getParameter(job_A, 'ZUUL_COMMIT')
1067 self.log.debug("Got Zuul ref for change A: %s" % ref_A)
1068 self.log.debug("Got Zuul commit for change A: %s" % commit_A)
James E. Blairc6294a52012-08-17 10:19:48 -07001069
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001070 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001071 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001072 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001073 job_B = None
1074 for job in queue:
1075 if 'project-merge' in job.name:
1076 job_B = job
1077 ref_B = self.getParameter(job_B, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001078 commit_B = self.getParameter(job_B, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001079 self.log.debug("Got Zuul ref for change B: %s" % ref_B)
James E. Blairbb1fe502014-03-04 10:15:06 -08001080 self.log.debug("Got Zuul commit for change B: %s" % commit_B)
1081
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001082 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001083 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001084 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001085 for job in queue:
1086 if 'project-merge' in job.name:
1087 job_C = job
1088 ref_C = self.getParameter(job_C, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001089 commit_C = self.getParameter(job_C, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001090 self.log.debug("Got Zuul ref for change C: %s" % ref_C)
James E. Blairbb1fe502014-03-04 10:15:06 -08001091 self.log.debug("Got Zuul commit for change C: %s" % commit_C)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001092 self.gearman_server.hold_jobs_in_queue = False
1093 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001094 self.waitUntilSettled()
1095
Monty Taylorbc758832013-06-17 17:22:42 -04001096 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001097 repo = git.Repo(path)
1098
1099 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001100 for c in repo.iter_commits(ref_C)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001101 repo_shas = [c.hexsha for c in repo.iter_commits(ref_C)]
James E. Blairc6294a52012-08-17 10:19:48 -07001102 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001103 correct_messages = ['initial commit', 'A-1', 'C-1']
James E. Blairbb1fe502014-03-04 10:15:06 -08001104 # Ensure the right commits are in the history for this ref
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001105 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001106 # Ensure ZUUL_REF -> ZUUL_COMMIT
1107 self.assertEqual(repo_shas[0], commit_C)
James E. Blairc6294a52012-08-17 10:19:48 -07001108
1109 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001110 for c in repo.iter_commits(ref_B)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001111 repo_shas = [c.hexsha for c in repo.iter_commits(ref_B)]
James E. Blairc6294a52012-08-17 10:19:48 -07001112 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001113 correct_messages = ['initial commit', 'mp commit', 'B-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001114 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001115 self.assertEqual(repo_shas[0], commit_B)
1116
1117 repo_messages = [c.message.strip()
1118 for c in repo.iter_commits(ref_A)]
1119 repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)]
1120 repo_messages.reverse()
1121 correct_messages = ['initial commit', 'A-1']
1122 self.assertEqual(repo_messages, correct_messages)
1123 self.assertEqual(repo_shas[0], commit_A)
1124
1125 self.assertNotEqual(ref_A, ref_B, ref_C)
1126 self.assertNotEqual(commit_A, commit_B, commit_C)
James E. Blair7f71c802012-08-22 13:04:32 -07001127
James E. Blairec056492016-07-22 09:45:56 -07001128 @skip("Disabled for early v3 development")
James E. Blair7f71c802012-08-22 13:04:32 -07001129 def test_one_job_project(self):
1130 "Test that queueing works with one job"
1131 A = self.fake_gerrit.addFakeChange('org/one-job-project',
1132 'master', 'A')
1133 B = self.fake_gerrit.addFakeChange('org/one-job-project',
1134 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07001135 A.addApproval('code-review', 2)
1136 B.addApproval('code-review', 2)
1137 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1138 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair7f71c802012-08-22 13:04:32 -07001139 self.waitUntilSettled()
1140
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001141 self.assertEqual(A.data['status'], 'MERGED')
1142 self.assertEqual(A.reported, 2)
1143 self.assertEqual(B.data['status'], 'MERGED')
1144 self.assertEqual(B.reported, 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001145
James E. Blairec056492016-07-22 09:45:56 -07001146 @skip("Disabled for early v3 development")
Antoine Musso80edd5a2013-02-13 15:37:53 +01001147 def test_job_from_templates_launched(self):
1148 "Test whether a job generated via a template can be launched"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001149
Antoine Musso80edd5a2013-02-13 15:37:53 +01001150 A = self.fake_gerrit.addFakeChange(
1151 'org/templated-project', 'master', 'A')
1152 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1153 self.waitUntilSettled()
Antoine Musso80edd5a2013-02-13 15:37:53 +01001154
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001155 self.assertEqual(self.getJobFromHistory('project-test1').result,
1156 'SUCCESS')
1157 self.assertEqual(self.getJobFromHistory('project-test2').result,
1158 'SUCCESS')
Antoine Musso80edd5a2013-02-13 15:37:53 +01001159
James E. Blairec056492016-07-22 09:45:56 -07001160 @skip("Disabled for early v3 development")
James E. Blair3e98c022013-12-16 15:25:38 -08001161 def test_layered_templates(self):
1162 "Test whether a job generated via a template can be launched"
1163
1164 A = self.fake_gerrit.addFakeChange(
1165 'org/layered-project', 'master', 'A')
1166 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1167 self.waitUntilSettled()
1168
1169 self.assertEqual(self.getJobFromHistory('project-test1').result,
1170 'SUCCESS')
1171 self.assertEqual(self.getJobFromHistory('project-test2').result,
1172 'SUCCESS')
James E. Blairaea6cf62013-12-16 15:38:12 -08001173 self.assertEqual(self.getJobFromHistory('layered-project-test3'
1174 ).result, 'SUCCESS')
1175 self.assertEqual(self.getJobFromHistory('layered-project-test4'
1176 ).result, 'SUCCESS')
James E. Blair12a92b12014-03-26 11:54:53 -07001177 self.assertEqual(self.getJobFromHistory('layered-project-foo-test5'
1178 ).result, 'SUCCESS')
James E. Blair3e98c022013-12-16 15:25:38 -08001179 self.assertEqual(self.getJobFromHistory('project-test6').result,
1180 'SUCCESS')
1181
James E. Blairec056492016-07-22 09:45:56 -07001182 @skip("Disabled for early v3 development")
James E. Blaircaec0c52012-08-22 14:52:22 -07001183 def test_dependent_changes_dequeue(self):
1184 "Test that dependent patches are not needlessly tested"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001185
James E. Blaircaec0c52012-08-22 14:52:22 -07001186 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1187 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1188 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001189 A.addApproval('code-review', 2)
1190 B.addApproval('code-review', 2)
1191 C.addApproval('code-review', 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001192
1193 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
1194 M1.setMerged()
1195
1196 # C -> B -> A -> M1
1197
1198 C.setDependsOn(B, 1)
1199 B.setDependsOn(A, 1)
1200 A.setDependsOn(M1, 1)
1201
James E. Blair08d19992016-08-10 15:25:31 -07001202 self.launch_server.failJob('project-merge', A)
James E. Blaircaec0c52012-08-22 14:52:22 -07001203
James E. Blair8b5408c2016-08-08 15:37:46 -07001204 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1205 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1206 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircaec0c52012-08-22 14:52:22 -07001207
1208 self.waitUntilSettled()
1209
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001210 self.assertEqual(A.data['status'], 'NEW')
1211 self.assertEqual(A.reported, 2)
1212 self.assertEqual(B.data['status'], 'NEW')
1213 self.assertEqual(B.reported, 2)
1214 self.assertEqual(C.data['status'], 'NEW')
1215 self.assertEqual(C.reported, 2)
1216 self.assertEqual(len(self.history), 1)
James E. Blairec590122012-08-22 15:19:31 -07001217
James E. Blairec056492016-07-22 09:45:56 -07001218 @skip("Disabled for early v3 development")
James E. Blair972e3c72013-08-29 12:04:55 -07001219 def test_failing_dependent_changes(self):
1220 "Test that failing dependent patches are taken out of stream"
James E. Blair08d19992016-08-10 15:25:31 -07001221 self.launch_server.hold_jobs_in_build = True
James E. Blair972e3c72013-08-29 12:04:55 -07001222 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1223 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1224 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1225 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
1226 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
James E. Blair8b5408c2016-08-08 15:37:46 -07001227 A.addApproval('code-review', 2)
1228 B.addApproval('code-review', 2)
1229 C.addApproval('code-review', 2)
1230 D.addApproval('code-review', 2)
1231 E.addApproval('code-review', 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001232
1233 # E, D -> C -> B, A
1234
1235 D.setDependsOn(C, 1)
1236 C.setDependsOn(B, 1)
1237
James E. Blair08d19992016-08-10 15:25:31 -07001238 self.launch_server.failJob('project-test1', B)
James E. Blair972e3c72013-08-29 12:04:55 -07001239
James E. Blair8b5408c2016-08-08 15:37:46 -07001240 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1241 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
1242 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1243 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1244 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair972e3c72013-08-29 12:04:55 -07001245
1246 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001247 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001248 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001249 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001250 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001251 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001252 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001253 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001254 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001255 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001256 self.waitUntilSettled()
1257
James E. Blair08d19992016-08-10 15:25:31 -07001258 self.launch_server.hold_jobs_in_build = False
James E. Blair972e3c72013-08-29 12:04:55 -07001259 for build in self.builds:
1260 if build.parameters['ZUUL_CHANGE'] != '1':
1261 build.release()
1262 self.waitUntilSettled()
1263
James E. Blair08d19992016-08-10 15:25:31 -07001264 self.launch_server.release()
James E. Blair972e3c72013-08-29 12:04:55 -07001265 self.waitUntilSettled()
1266
1267 self.assertEqual(A.data['status'], 'MERGED')
1268 self.assertEqual(A.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001269 self.assertIn('Build succeeded', A.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001270 self.assertEqual(B.data['status'], 'NEW')
1271 self.assertEqual(B.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001272 self.assertIn('Build failed', B.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001273 self.assertEqual(C.data['status'], 'NEW')
1274 self.assertEqual(C.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001275 self.assertIn('depends on a change', C.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001276 self.assertEqual(D.data['status'], 'NEW')
1277 self.assertEqual(D.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001278 self.assertIn('depends on a change', D.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001279 self.assertEqual(E.data['status'], 'MERGED')
1280 self.assertEqual(E.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001281 self.assertIn('Build succeeded', E.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001282 self.assertEqual(len(self.history), 18)
1283
James E. Blairec056492016-07-22 09:45:56 -07001284 @skip("Disabled for early v3 development")
James E. Blairec590122012-08-22 15:19:31 -07001285 def test_head_is_dequeued_once(self):
James E. Blair2fa50962013-01-30 21:50:41 -08001286 "Test that if a change at the head fails it is dequeued only once"
James E. Blairec590122012-08-22 15:19:31 -07001287 # If it's dequeued more than once, we should see extra
1288 # aborted jobs.
James E. Blairec590122012-08-22 15:19:31 -07001289
James E. Blair08d19992016-08-10 15:25:31 -07001290 self.launch_server.hold_jobs_in_build = True
James E. Blairec590122012-08-22 15:19:31 -07001291 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1292 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1293 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001294 A.addApproval('code-review', 2)
1295 B.addApproval('code-review', 2)
1296 C.addApproval('code-review', 2)
James E. Blairec590122012-08-22 15:19:31 -07001297
James E. Blair08d19992016-08-10 15:25:31 -07001298 self.launch_server.failJob('project1-test1', A)
1299 self.launch_server.failJob('project1-test2', A)
1300 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairec590122012-08-22 15:19:31 -07001301
James E. Blair8b5408c2016-08-08 15:37:46 -07001302 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1303 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1304 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairec590122012-08-22 15:19:31 -07001305
1306 self.waitUntilSettled()
James E. Blairec590122012-08-22 15:19:31 -07001307
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001308 self.assertEqual(len(self.builds), 1)
1309 self.assertEqual(self.builds[0].name, 'project1-merge')
1310 self.assertTrue(self.job_has_changes(self.builds[0], A))
James E. Blairec590122012-08-22 15:19:31 -07001311
James E. Blair08d19992016-08-10 15:25:31 -07001312 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001313 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001314 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001315 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001316 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001317 self.waitUntilSettled()
1318
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001319 self.assertEqual(len(self.builds), 9)
1320 self.assertEqual(self.builds[0].name, 'project1-test1')
1321 self.assertEqual(self.builds[1].name, 'project1-test2')
1322 self.assertEqual(self.builds[2].name, 'project1-project2-integration')
1323 self.assertEqual(self.builds[3].name, 'project1-test1')
1324 self.assertEqual(self.builds[4].name, 'project1-test2')
1325 self.assertEqual(self.builds[5].name, 'project1-project2-integration')
1326 self.assertEqual(self.builds[6].name, 'project1-test1')
1327 self.assertEqual(self.builds[7].name, 'project1-test2')
1328 self.assertEqual(self.builds[8].name, 'project1-project2-integration')
James E. Blairec590122012-08-22 15:19:31 -07001329
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001330 self.release(self.builds[0])
James E. Blairec590122012-08-22 15:19:31 -07001331 self.waitUntilSettled()
1332
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001333 self.assertEqual(len(self.builds), 3) # test2,integration, merge for B
1334 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6)
James E. Blairec590122012-08-22 15:19:31 -07001335
James E. Blair08d19992016-08-10 15:25:31 -07001336 self.launch_server.hold_jobs_in_build = False
1337 self.launch_server.release()
James E. Blairec590122012-08-22 15:19:31 -07001338 self.waitUntilSettled()
1339
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001340 self.assertEqual(len(self.builds), 0)
1341 self.assertEqual(len(self.history), 20)
James E. Blaircaec0c52012-08-22 14:52:22 -07001342
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001343 self.assertEqual(A.data['status'], 'NEW')
1344 self.assertEqual(B.data['status'], 'MERGED')
1345 self.assertEqual(C.data['status'], 'MERGED')
1346 self.assertEqual(A.reported, 2)
1347 self.assertEqual(B.reported, 2)
1348 self.assertEqual(C.reported, 2)
James E. Blair4ec821f2012-08-23 15:28:28 -07001349
James E. Blairec056492016-07-22 09:45:56 -07001350 @skip("Disabled for early v3 development")
James E. Blair4ec821f2012-08-23 15:28:28 -07001351 def test_nonvoting_job(self):
1352 "Test that non-voting jobs don't vote."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001353
James E. Blair4ec821f2012-08-23 15:28:28 -07001354 A = self.fake_gerrit.addFakeChange('org/nonvoting-project',
1355 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001356 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07001357 self.launch_server.failJob('nonvoting-project-test2', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07001358 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4ec821f2012-08-23 15:28:28 -07001359
1360 self.waitUntilSettled()
James E. Blair4ec821f2012-08-23 15:28:28 -07001361
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001362 self.assertEqual(A.data['status'], 'MERGED')
1363 self.assertEqual(A.reported, 2)
1364 self.assertEqual(
1365 self.getJobFromHistory('nonvoting-project-merge').result,
1366 'SUCCESS')
1367 self.assertEqual(
1368 self.getJobFromHistory('nonvoting-project-test1').result,
1369 'SUCCESS')
1370 self.assertEqual(
1371 self.getJobFromHistory('nonvoting-project-test2').result,
1372 'FAILURE')
James E. Blaire0487072012-08-29 17:38:31 -07001373
James E. Blair5821bd92015-09-16 08:48:15 -07001374 for build in self.builds:
1375 self.assertEqual(build.parameters['ZUUL_VOTING'], '0')
1376
James E. Blairec056492016-07-22 09:45:56 -07001377 @skip("Disabled for early v3 development")
James E. Blaire0487072012-08-29 17:38:31 -07001378 def test_check_queue_success(self):
1379 "Test successful check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001380
James E. Blaire0487072012-08-29 17:38:31 -07001381 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1382 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1383
1384 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001385
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001386 self.assertEqual(A.data['status'], 'NEW')
1387 self.assertEqual(A.reported, 1)
1388 self.assertEqual(self.getJobFromHistory('project-merge').result,
1389 'SUCCESS')
1390 self.assertEqual(self.getJobFromHistory('project-test1').result,
1391 'SUCCESS')
1392 self.assertEqual(self.getJobFromHistory('project-test2').result,
1393 'SUCCESS')
James E. Blaire0487072012-08-29 17:38:31 -07001394
James E. Blairec056492016-07-22 09:45:56 -07001395 @skip("Disabled for early v3 development")
James E. Blaire0487072012-08-29 17:38:31 -07001396 def test_check_queue_failure(self):
1397 "Test failed check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001398
James E. Blaire0487072012-08-29 17:38:31 -07001399 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair08d19992016-08-10 15:25:31 -07001400 self.launch_server.failJob('project-test2', A)
James E. Blaire0487072012-08-29 17:38:31 -07001401 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1402
1403 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001404
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001405 self.assertEqual(A.data['status'], 'NEW')
1406 self.assertEqual(A.reported, 1)
1407 self.assertEqual(self.getJobFromHistory('project-merge').result,
James E. Blair78e31b32013-07-09 09:11:34 -07001408 'SUCCESS')
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001409 self.assertEqual(self.getJobFromHistory('project-test1').result,
1410 'SUCCESS')
1411 self.assertEqual(self.getJobFromHistory('project-test2').result,
1412 'FAILURE')
James E. Blair127bc182012-08-28 15:55:15 -07001413
James E. Blairec056492016-07-22 09:45:56 -07001414 @skip("Disabled for early v3 development")
James E. Blair127bc182012-08-28 15:55:15 -07001415 def test_dependent_behind_dequeue(self):
1416 "test that dependent changes behind dequeued changes work"
1417 # This complicated test is a reproduction of a real life bug
1418 self.sched.reconfigure(self.config)
James E. Blair127bc182012-08-28 15:55:15 -07001419
James E. Blair08d19992016-08-10 15:25:31 -07001420 self.launch_server.hold_jobs_in_build = True
James E. Blair127bc182012-08-28 15:55:15 -07001421 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1422 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1423 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
1424 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
1425 E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E')
1426 F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F')
1427 D.setDependsOn(C, 1)
1428 E.setDependsOn(D, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07001429 A.addApproval('code-review', 2)
1430 B.addApproval('code-review', 2)
1431 C.addApproval('code-review', 2)
1432 D.addApproval('code-review', 2)
1433 E.addApproval('code-review', 2)
1434 F.addApproval('code-review', 2)
James E. Blair127bc182012-08-28 15:55:15 -07001435
1436 A.fail_merge = True
James E. Blair127bc182012-08-28 15:55:15 -07001437
1438 # Change object re-use in the gerrit trigger is hidden if
1439 # changes are added in quick succession; waiting makes it more
1440 # like real life.
James E. Blair8b5408c2016-08-08 15:37:46 -07001441 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001442 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001443 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001444 self.waitUntilSettled()
1445
James E. Blair08d19992016-08-10 15:25:31 -07001446 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001447 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001448 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001449 self.waitUntilSettled()
1450
James E. Blair8b5408c2016-08-08 15:37:46 -07001451 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001452 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001453 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001454 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001455 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001456 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001457 self.fake_gerrit.addEvent(F.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001458 self.waitUntilSettled()
1459
James E. Blair08d19992016-08-10 15:25:31 -07001460 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001461 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001462 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001463 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001464 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001465 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001466 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001467 self.waitUntilSettled()
1468
1469 # all jobs running
James E. Blaire955e062012-10-08 09:49:03 -07001470
1471 # Grab pointers to the jobs we want to release before
1472 # releasing any, because list indexes may change as
1473 # the jobs complete.
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001474 a, b, c = self.builds[:3]
James E. Blaire955e062012-10-08 09:49:03 -07001475 a.release()
1476 b.release()
1477 c.release()
James E. Blair127bc182012-08-28 15:55:15 -07001478 self.waitUntilSettled()
1479
James E. Blair08d19992016-08-10 15:25:31 -07001480 self.launch_server.hold_jobs_in_build = False
1481 self.launch_server.release()
James E. Blair127bc182012-08-28 15:55:15 -07001482 self.waitUntilSettled()
1483
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001484 self.assertEqual(A.data['status'], 'NEW')
1485 self.assertEqual(B.data['status'], 'MERGED')
1486 self.assertEqual(C.data['status'], 'MERGED')
1487 self.assertEqual(D.data['status'], 'MERGED')
1488 self.assertEqual(E.data['status'], 'MERGED')
1489 self.assertEqual(F.data['status'], 'MERGED')
James E. Blair127bc182012-08-28 15:55:15 -07001490
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001491 self.assertEqual(A.reported, 2)
1492 self.assertEqual(B.reported, 2)
1493 self.assertEqual(C.reported, 2)
1494 self.assertEqual(D.reported, 2)
1495 self.assertEqual(E.reported, 2)
1496 self.assertEqual(F.reported, 2)
James E. Blair127bc182012-08-28 15:55:15 -07001497
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001498 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15)
1499 self.assertEqual(len(self.history), 44)
James E. Blair05fed602012-09-07 12:45:24 -07001500
James E. Blairec056492016-07-22 09:45:56 -07001501 @skip("Disabled for early v3 development")
James E. Blair05fed602012-09-07 12:45:24 -07001502 def test_merger_repack(self):
1503 "Test that the merger works after a repack"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001504
James E. Blair05fed602012-09-07 12:45:24 -07001505 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001506 A.addApproval('code-review', 2)
1507 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001508 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001509 self.assertEqual(self.getJobFromHistory('project-merge').result,
1510 'SUCCESS')
1511 self.assertEqual(self.getJobFromHistory('project-test1').result,
1512 'SUCCESS')
1513 self.assertEqual(self.getJobFromHistory('project-test2').result,
1514 'SUCCESS')
1515 self.assertEqual(A.data['status'], 'MERGED')
1516 self.assertEqual(A.reported, 2)
James E. Blair05fed602012-09-07 12:45:24 -07001517 self.assertEmptyQueues()
James E. Blair4ca985f2013-05-30 12:27:43 -07001518 self.worker.build_history = []
James E. Blair05fed602012-09-07 12:45:24 -07001519
Monty Taylorbc758832013-06-17 17:22:42 -04001520 path = os.path.join(self.git_root, "org/project")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001521 print(repack_repo(path))
James E. Blair05fed602012-09-07 12:45:24 -07001522
1523 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001524 A.addApproval('code-review', 2)
1525 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001526 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001527 self.assertEqual(self.getJobFromHistory('project-merge').result,
1528 'SUCCESS')
1529 self.assertEqual(self.getJobFromHistory('project-test1').result,
1530 'SUCCESS')
1531 self.assertEqual(self.getJobFromHistory('project-test2').result,
1532 'SUCCESS')
1533 self.assertEqual(A.data['status'], 'MERGED')
1534 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001535
James E. Blairec056492016-07-22 09:45:56 -07001536 @skip("Disabled for early v3 development")
James E. Blair4886f282012-11-15 09:27:33 -08001537 def test_merger_repack_large_change(self):
1538 "Test that the merger works with large changes after a repack"
1539 # https://bugs.launchpad.net/zuul/+bug/1078946
James E. Blairac2c3242014-01-24 13:38:51 -08001540 # This test assumes the repo is already cloned; make sure it is
Joshua Hesketh352264b2015-08-11 23:42:08 +10001541 url = self.fake_gerrit.getGitUrl(
James E. Blairac2c3242014-01-24 13:38:51 -08001542 self.sched.layout.projects['org/project1'])
James E. Blair4076e2b2014-01-28 12:42:20 -08001543 self.merge_server.merger.addProject('org/project1', url)
James E. Blair4886f282012-11-15 09:27:33 -08001544 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1545 A.addPatchset(large=True)
Monty Taylorbc758832013-06-17 17:22:42 -04001546 path = os.path.join(self.upstream_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001547 print(repack_repo(path))
Monty Taylorbc758832013-06-17 17:22:42 -04001548 path = os.path.join(self.git_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001549 print(repack_repo(path))
James E. Blair4886f282012-11-15 09:27:33 -08001550
James E. Blair8b5408c2016-08-08 15:37:46 -07001551 A.addApproval('code-review', 2)
1552 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4886f282012-11-15 09:27:33 -08001553 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001554 self.assertEqual(self.getJobFromHistory('project1-merge').result,
1555 'SUCCESS')
1556 self.assertEqual(self.getJobFromHistory('project1-test1').result,
1557 'SUCCESS')
1558 self.assertEqual(self.getJobFromHistory('project1-test2').result,
1559 'SUCCESS')
1560 self.assertEqual(A.data['status'], 'MERGED')
1561 self.assertEqual(A.reported, 2)
James E. Blair4886f282012-11-15 09:27:33 -08001562
James E. Blairec056492016-07-22 09:45:56 -07001563 @skip("Disabled for early v3 development")
James E. Blair7ee88a22012-09-12 18:59:31 +02001564 def test_nonexistent_job(self):
1565 "Test launching a job that doesn't exist"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001566 # Set to the state immediately after a restart
1567 self.resetGearmanServer()
1568 self.launcher.negative_function_cache_ttl = 0
James E. Blair7ee88a22012-09-12 18:59:31 +02001569
1570 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001571 A.addApproval('code-review', 2)
1572 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001573 # There may be a thread about to report a lost change
1574 while A.reported < 2:
1575 self.waitUntilSettled()
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001576 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001577 self.assertFalse(job_names)
1578 self.assertEqual(A.data['status'], 'NEW')
1579 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001580 self.assertEmptyQueues()
1581
1582 # Make sure things still work:
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001583 self.registerJobs()
James E. Blair7ee88a22012-09-12 18:59:31 +02001584 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001585 A.addApproval('code-review', 2)
1586 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001587 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001588 self.assertEqual(self.getJobFromHistory('project-merge').result,
1589 'SUCCESS')
1590 self.assertEqual(self.getJobFromHistory('project-test1').result,
1591 'SUCCESS')
1592 self.assertEqual(self.getJobFromHistory('project-test2').result,
1593 'SUCCESS')
1594 self.assertEqual(A.data['status'], 'MERGED')
1595 self.assertEqual(A.reported, 2)
James E. Blairf62d4282012-12-31 17:01:50 -08001596
James E. Blairec056492016-07-22 09:45:56 -07001597 @skip("Disabled for early v3 development")
James E. Blairf62d4282012-12-31 17:01:50 -08001598 def test_single_nonexistent_post_job(self):
1599 "Test launching a single post job that doesn't exist"
James E. Blairf62d4282012-12-31 17:01:50 -08001600 e = {
1601 "type": "ref-updated",
1602 "submitter": {
1603 "name": "User Name",
1604 },
1605 "refUpdate": {
1606 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1607 "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543",
1608 "refName": "master",
1609 "project": "org/project",
1610 }
1611 }
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001612 # Set to the state immediately after a restart
1613 self.resetGearmanServer()
1614 self.launcher.negative_function_cache_ttl = 0
1615
James E. Blairf62d4282012-12-31 17:01:50 -08001616 self.fake_gerrit.addEvent(e)
1617 self.waitUntilSettled()
1618
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001619 self.assertEqual(len(self.history), 0)
James E. Blair2fa50962013-01-30 21:50:41 -08001620
James E. Blairec056492016-07-22 09:45:56 -07001621 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001622 def test_new_patchset_dequeues_old(self):
1623 "Test that a new patchset causes the old to be dequeued"
1624 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001625 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001626 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1627 M.setMerged()
1628
1629 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1630 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1631 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1632 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001633 A.addApproval('code-review', 2)
1634 B.addApproval('code-review', 2)
1635 C.addApproval('code-review', 2)
1636 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001637
1638 C.setDependsOn(B, 1)
1639 B.setDependsOn(A, 1)
1640 A.setDependsOn(M, 1)
1641
James E. Blair8b5408c2016-08-08 15:37:46 -07001642 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1643 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1644 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1645 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001646 self.waitUntilSettled()
1647
1648 B.addPatchset()
1649 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1650 self.waitUntilSettled()
1651
James E. Blair08d19992016-08-10 15:25:31 -07001652 self.launch_server.hold_jobs_in_build = False
1653 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001654 self.waitUntilSettled()
1655
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001656 self.assertEqual(A.data['status'], 'MERGED')
1657 self.assertEqual(A.reported, 2)
1658 self.assertEqual(B.data['status'], 'NEW')
1659 self.assertEqual(B.reported, 2)
1660 self.assertEqual(C.data['status'], 'NEW')
1661 self.assertEqual(C.reported, 2)
1662 self.assertEqual(D.data['status'], 'MERGED')
1663 self.assertEqual(D.reported, 2)
1664 self.assertEqual(len(self.history), 9) # 3 each for A, B, D.
James E. Blair2fa50962013-01-30 21:50:41 -08001665
James E. Blairec056492016-07-22 09:45:56 -07001666 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001667 def test_new_patchset_check(self):
1668 "Test a new patchset in check"
Antoine Mussobd86a312014-01-08 14:51:33 +01001669
James E. Blair08d19992016-08-10 15:25:31 -07001670 self.launch_server.hold_jobs_in_build = True
Antoine Mussobd86a312014-01-08 14:51:33 +01001671
1672 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairba437362015-02-07 11:41:52 -08001673 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1674 check_pipeline = self.sched.layout.pipelines['check']
1675
1676 # Add two git-dependent changes
1677 B.setDependsOn(A, 1)
1678 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1679 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001680 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1681 self.waitUntilSettled()
James E. Blairba437362015-02-07 11:41:52 -08001682
1683 # A live item, and a non-live/live pair
1684 items = check_pipeline.getAllItems()
1685 self.assertEqual(len(items), 3)
1686
1687 self.assertEqual(items[0].change.number, '1')
1688 self.assertEqual(items[0].change.patchset, '1')
1689 self.assertFalse(items[0].live)
1690
1691 self.assertEqual(items[1].change.number, '2')
1692 self.assertEqual(items[1].change.patchset, '1')
1693 self.assertTrue(items[1].live)
1694
1695 self.assertEqual(items[2].change.number, '1')
1696 self.assertEqual(items[2].change.patchset, '1')
1697 self.assertTrue(items[2].live)
1698
1699 # Add a new patchset to A
1700 A.addPatchset()
1701 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1702 self.waitUntilSettled()
1703
1704 # The live copy of A,1 should be gone, but the non-live and B
1705 # should continue, and we should have a new A,2
1706 items = check_pipeline.getAllItems()
1707 self.assertEqual(len(items), 3)
1708
1709 self.assertEqual(items[0].change.number, '1')
1710 self.assertEqual(items[0].change.patchset, '1')
1711 self.assertFalse(items[0].live)
1712
1713 self.assertEqual(items[1].change.number, '2')
1714 self.assertEqual(items[1].change.patchset, '1')
1715 self.assertTrue(items[1].live)
1716
1717 self.assertEqual(items[2].change.number, '1')
1718 self.assertEqual(items[2].change.patchset, '2')
1719 self.assertTrue(items[2].live)
1720
1721 # Add a new patchset to B
1722 B.addPatchset()
1723 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1724 self.waitUntilSettled()
1725
1726 # The live copy of B,1 should be gone, and it's non-live copy of A,1
1727 # but we should have a new B,2 (still based on A,1)
1728 items = check_pipeline.getAllItems()
1729 self.assertEqual(len(items), 3)
1730
1731 self.assertEqual(items[0].change.number, '1')
1732 self.assertEqual(items[0].change.patchset, '2')
1733 self.assertTrue(items[0].live)
1734
1735 self.assertEqual(items[1].change.number, '1')
1736 self.assertEqual(items[1].change.patchset, '1')
1737 self.assertFalse(items[1].live)
1738
1739 self.assertEqual(items[2].change.number, '2')
1740 self.assertEqual(items[2].change.patchset, '2')
1741 self.assertTrue(items[2].live)
1742
1743 self.builds[0].release()
1744 self.waitUntilSettled()
1745 self.builds[0].release()
1746 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001747 self.launch_server.hold_jobs_in_build = False
1748 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001749 self.waitUntilSettled()
1750
1751 self.assertEqual(A.reported, 1)
1752 self.assertEqual(B.reported, 1)
1753 self.assertEqual(self.history[0].result, 'ABORTED')
1754 self.assertEqual(self.history[0].changes, '1,1')
1755 self.assertEqual(self.history[1].result, 'ABORTED')
1756 self.assertEqual(self.history[1].changes, '1,1 2,1')
1757 self.assertEqual(self.history[2].result, 'SUCCESS')
1758 self.assertEqual(self.history[2].changes, '1,2')
1759 self.assertEqual(self.history[3].result, 'SUCCESS')
1760 self.assertEqual(self.history[3].changes, '1,1 2,2')
1761
James E. Blairec056492016-07-22 09:45:56 -07001762 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001763 def test_abandoned_gate(self):
1764 "Test that an abandoned change is dequeued from gate"
1765
James E. Blair08d19992016-08-10 15:25:31 -07001766 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001767
1768 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001769 A.addApproval('code-review', 2)
1770 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairba437362015-02-07 11:41:52 -08001771 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001772 self.assertEqual(len(self.builds), 1, "One job being built (on hold)")
1773 self.assertEqual(self.builds[0].name, 'project-merge')
1774
1775 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1776 self.waitUntilSettled()
1777
James E. Blair08d19992016-08-10 15:25:31 -07001778 self.launch_server.release('.*-merge')
Antoine Mussobd86a312014-01-08 14:51:33 +01001779 self.waitUntilSettled()
1780
1781 self.assertEqual(len(self.builds), 0, "No job running")
Antoine Mussobd86a312014-01-08 14:51:33 +01001782 self.assertEqual(len(self.history), 1, "Only one build in history")
1783 self.assertEqual(self.history[0].result, 'ABORTED',
James E. Blairba437362015-02-07 11:41:52 -08001784 "Build should have been aborted")
1785 self.assertEqual(A.reported, 1,
1786 "Abandoned gate change should report only start")
1787
James E. Blairec056492016-07-22 09:45:56 -07001788 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001789 def test_abandoned_check(self):
1790 "Test that an abandoned change is dequeued from check"
1791
James E. Blair08d19992016-08-10 15:25:31 -07001792 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001793
1794 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1795 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1796 check_pipeline = self.sched.layout.pipelines['check']
1797
1798 # Add two git-dependent changes
1799 B.setDependsOn(A, 1)
1800 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1801 self.waitUntilSettled()
1802 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1803 self.waitUntilSettled()
1804 # A live item, and a non-live/live pair
1805 items = check_pipeline.getAllItems()
1806 self.assertEqual(len(items), 3)
1807
1808 self.assertEqual(items[0].change.number, '1')
1809 self.assertFalse(items[0].live)
1810
1811 self.assertEqual(items[1].change.number, '2')
1812 self.assertTrue(items[1].live)
1813
1814 self.assertEqual(items[2].change.number, '1')
1815 self.assertTrue(items[2].live)
1816
1817 # Abandon A
1818 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1819 self.waitUntilSettled()
1820
1821 # The live copy of A should be gone, but the non-live and B
1822 # should continue
1823 items = check_pipeline.getAllItems()
1824 self.assertEqual(len(items), 2)
1825
1826 self.assertEqual(items[0].change.number, '1')
1827 self.assertFalse(items[0].live)
1828
1829 self.assertEqual(items[1].change.number, '2')
1830 self.assertTrue(items[1].live)
1831
James E. Blair08d19992016-08-10 15:25:31 -07001832 self.launch_server.hold_jobs_in_build = False
1833 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001834 self.waitUntilSettled()
1835
1836 self.assertEqual(len(self.history), 4)
1837 self.assertEqual(self.history[0].result, 'ABORTED',
Antoine Mussobd86a312014-01-08 14:51:33 +01001838 'Build should have been aborted')
1839 self.assertEqual(A.reported, 0, "Abandoned change should not report")
James E. Blairba437362015-02-07 11:41:52 -08001840 self.assertEqual(B.reported, 1, "Change should report")
Antoine Mussobd86a312014-01-08 14:51:33 +01001841
James E. Blairec056492016-07-22 09:45:56 -07001842 @skip("Disabled for early v3 development")
Steve Varnau7b78b312015-04-03 14:49:46 -07001843 def test_abandoned_not_timer(self):
1844 "Test that an abandoned change does not cancel timer jobs"
1845
James E. Blair08d19992016-08-10 15:25:31 -07001846 self.launch_server.hold_jobs_in_build = True
Steve Varnau7b78b312015-04-03 14:49:46 -07001847
1848 # Start timer trigger - also org/project
James E. Blairf84026c2015-12-08 16:11:46 -08001849 self.updateConfigLayout(
1850 'tests/fixtures/layout-idle.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001851 self.sched.reconfigure(self.config)
1852 self.registerJobs()
1853 # The pipeline triggers every second, so we should have seen
1854 # several by now.
1855 time.sleep(5)
1856 self.waitUntilSettled()
1857 # Stop queuing timer triggered jobs so that the assertions
1858 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08001859 self.updateConfigLayout(
1860 'tests/fixtures/layout-no-timer.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001861 self.sched.reconfigure(self.config)
1862 self.registerJobs()
1863 self.assertEqual(len(self.builds), 2, "Two timer jobs")
1864
1865 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1866 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1867 self.waitUntilSettled()
1868 self.assertEqual(len(self.builds), 3, "One change plus two timer jobs")
1869
1870 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1871 self.waitUntilSettled()
1872
1873 self.assertEqual(len(self.builds), 2, "Two timer jobs remain")
1874
James E. Blair08d19992016-08-10 15:25:31 -07001875 self.launch_server.release()
Steve Varnau7b78b312015-04-03 14:49:46 -07001876 self.waitUntilSettled()
1877
James E. Blairec056492016-07-22 09:45:56 -07001878 @skip("Disabled for early v3 development")
Arx Cruzb1b010d2013-10-28 19:49:59 -02001879 def test_zuul_url_return(self):
1880 "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf"
James E. Blair4076e2b2014-01-28 12:42:20 -08001881 self.assertTrue(self.sched.config.has_option('merger', 'zuul_url'))
James E. Blair08d19992016-08-10 15:25:31 -07001882 self.launch_server.hold_jobs_in_build = True
Arx Cruzb1b010d2013-10-28 19:49:59 -02001883
1884 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001885 A.addApproval('code-review', 2)
1886 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Arx Cruzb1b010d2013-10-28 19:49:59 -02001887 self.waitUntilSettled()
1888
1889 self.assertEqual(len(self.builds), 1)
1890 for build in self.builds:
1891 self.assertTrue('ZUUL_URL' in build.parameters)
1892
James E. Blair08d19992016-08-10 15:25:31 -07001893 self.launch_server.hold_jobs_in_build = False
1894 self.launch_server.release()
Arx Cruzb1b010d2013-10-28 19:49:59 -02001895 self.waitUntilSettled()
1896
James E. Blairec056492016-07-22 09:45:56 -07001897 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001898 def test_new_patchset_dequeues_old_on_head(self):
1899 "Test that a new patchset causes the old to be dequeued (at head)"
1900 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001901 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001902 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1903 M.setMerged()
1904 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1905 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1906 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1907 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001908 A.addApproval('code-review', 2)
1909 B.addApproval('code-review', 2)
1910 C.addApproval('code-review', 2)
1911 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001912
1913 C.setDependsOn(B, 1)
1914 B.setDependsOn(A, 1)
1915 A.setDependsOn(M, 1)
1916
James E. Blair8b5408c2016-08-08 15:37:46 -07001917 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1918 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1919 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1920 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001921 self.waitUntilSettled()
1922
1923 A.addPatchset()
1924 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1925 self.waitUntilSettled()
1926
James E. Blair08d19992016-08-10 15:25:31 -07001927 self.launch_server.hold_jobs_in_build = False
1928 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001929 self.waitUntilSettled()
1930
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001931 self.assertEqual(A.data['status'], 'NEW')
1932 self.assertEqual(A.reported, 2)
1933 self.assertEqual(B.data['status'], 'NEW')
1934 self.assertEqual(B.reported, 2)
1935 self.assertEqual(C.data['status'], 'NEW')
1936 self.assertEqual(C.reported, 2)
1937 self.assertEqual(D.data['status'], 'MERGED')
1938 self.assertEqual(D.reported, 2)
1939 self.assertEqual(len(self.history), 7)
James E. Blair2fa50962013-01-30 21:50:41 -08001940
James E. Blairec056492016-07-22 09:45:56 -07001941 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001942 def test_new_patchset_dequeues_old_without_dependents(self):
1943 "Test that a new patchset causes only the old to be dequeued"
James E. Blair08d19992016-08-10 15:25:31 -07001944 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001945 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1946 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1947 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001948 A.addApproval('code-review', 2)
1949 B.addApproval('code-review', 2)
1950 C.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001951
James E. Blair8b5408c2016-08-08 15:37:46 -07001952 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1953 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1954 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001955 self.waitUntilSettled()
1956
1957 B.addPatchset()
1958 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1959 self.waitUntilSettled()
1960
James E. Blair08d19992016-08-10 15:25:31 -07001961 self.launch_server.hold_jobs_in_build = False
1962 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001963 self.waitUntilSettled()
1964
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001965 self.assertEqual(A.data['status'], 'MERGED')
1966 self.assertEqual(A.reported, 2)
1967 self.assertEqual(B.data['status'], 'NEW')
1968 self.assertEqual(B.reported, 2)
1969 self.assertEqual(C.data['status'], 'MERGED')
1970 self.assertEqual(C.reported, 2)
1971 self.assertEqual(len(self.history), 9)
James E. Blair2fa50962013-01-30 21:50:41 -08001972
James E. Blairec056492016-07-22 09:45:56 -07001973 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001974 def test_new_patchset_dequeues_old_independent_queue(self):
1975 "Test that a new patchset causes the old to be dequeued (independent)"
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 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1978 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1979 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1980 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1981 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1982 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
1983 self.waitUntilSettled()
1984
1985 B.addPatchset()
1986 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1987 self.waitUntilSettled()
1988
James E. Blair08d19992016-08-10 15:25:31 -07001989 self.launch_server.hold_jobs_in_build = False
1990 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001991 self.waitUntilSettled()
1992
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001993 self.assertEqual(A.data['status'], 'NEW')
1994 self.assertEqual(A.reported, 1)
1995 self.assertEqual(B.data['status'], 'NEW')
1996 self.assertEqual(B.reported, 1)
1997 self.assertEqual(C.data['status'], 'NEW')
1998 self.assertEqual(C.reported, 1)
1999 self.assertEqual(len(self.history), 10)
2000 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002001
James E. Blairec056492016-07-22 09:45:56 -07002002 @skip("Disabled for early v3 development")
James E. Blair18c64442014-03-18 10:14:45 -07002003 def test_noop_job(self):
2004 "Test that the internal noop job works"
2005 A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002006 A.addApproval('code-review', 2)
2007 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair18c64442014-03-18 10:14:45 -07002008 self.waitUntilSettled()
2009
2010 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2011 self.assertTrue(self.sched._areAllBuildsComplete())
2012 self.assertEqual(len(self.history), 0)
2013 self.assertEqual(A.data['status'], 'MERGED')
2014 self.assertEqual(A.reported, 2)
2015
James E. Blairec056492016-07-22 09:45:56 -07002016 @skip("Disabled for early v3 development")
Evgeny Antyshevd6e546c2015-06-11 15:13:57 +00002017 def test_no_job_project(self):
2018 "Test that reports with no jobs don't get sent"
2019 A = self.fake_gerrit.addFakeChange('org/no-jobs-project',
2020 'master', 'A')
2021 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2022 self.waitUntilSettled()
2023
2024 # Change wasn't reported to
2025 self.assertEqual(A.reported, False)
2026
2027 # Check queue is empty afterwards
2028 check_pipeline = self.sched.layout.pipelines['check']
2029 items = check_pipeline.getAllItems()
2030 self.assertEqual(len(items), 0)
2031
2032 self.assertEqual(len(self.history), 0)
2033
James E. Blairec056492016-07-22 09:45:56 -07002034 @skip("Disabled for early v3 development")
James E. Blair7d0dedc2013-02-21 17:26:09 -08002035 def test_zuul_refs(self):
2036 "Test that zuul refs exist and have the right changes"
James E. Blair08d19992016-08-10 15:25:31 -07002037 self.launch_server.hold_jobs_in_build = True
James E. Blair7d0dedc2013-02-21 17:26:09 -08002038 M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1')
2039 M1.setMerged()
2040 M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2')
2041 M2.setMerged()
2042
2043 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2044 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2045 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
2046 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07002047 A.addApproval('code-review', 2)
2048 B.addApproval('code-review', 2)
2049 C.addApproval('code-review', 2)
2050 D.addApproval('code-review', 2)
2051 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2052 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2053 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2054 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002055
2056 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002057 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002058 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002059 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002060 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002061 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002062 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002063 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002064 self.waitUntilSettled()
2065
James E. Blair7d0dedc2013-02-21 17:26:09 -08002066 a_zref = b_zref = c_zref = d_zref = None
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002067 for x in self.builds:
James E. Blair7d0dedc2013-02-21 17:26:09 -08002068 if x.parameters['ZUUL_CHANGE'] == '3':
2069 a_zref = x.parameters['ZUUL_REF']
2070 if x.parameters['ZUUL_CHANGE'] == '4':
2071 b_zref = x.parameters['ZUUL_REF']
2072 if x.parameters['ZUUL_CHANGE'] == '5':
2073 c_zref = x.parameters['ZUUL_REF']
2074 if x.parameters['ZUUL_CHANGE'] == '6':
2075 d_zref = x.parameters['ZUUL_REF']
2076
2077 # There are... four... refs.
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002078 self.assertIsNotNone(a_zref)
2079 self.assertIsNotNone(b_zref)
2080 self.assertIsNotNone(c_zref)
2081 self.assertIsNotNone(d_zref)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002082
2083 # And they should all be different
2084 refs = set([a_zref, b_zref, c_zref, d_zref])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002085 self.assertEqual(len(refs), 4)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002086
2087 # a ref should have a, not b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002088 self.assertTrue(self.ref_has_change(a_zref, A))
2089 self.assertFalse(self.ref_has_change(a_zref, B))
2090 self.assertFalse(self.ref_has_change(a_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002091
2092 # b ref should have a and b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002093 self.assertTrue(self.ref_has_change(b_zref, A))
2094 self.assertTrue(self.ref_has_change(b_zref, B))
2095 self.assertFalse(self.ref_has_change(b_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002096
2097 # c ref should have a and b in 1, c in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002098 self.assertTrue(self.ref_has_change(c_zref, A))
2099 self.assertTrue(self.ref_has_change(c_zref, B))
2100 self.assertTrue(self.ref_has_change(c_zref, C))
2101 self.assertFalse(self.ref_has_change(c_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002102
2103 # d ref should have a and b in 1, c and d in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002104 self.assertTrue(self.ref_has_change(d_zref, A))
2105 self.assertTrue(self.ref_has_change(d_zref, B))
2106 self.assertTrue(self.ref_has_change(d_zref, C))
2107 self.assertTrue(self.ref_has_change(d_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002108
James E. Blair08d19992016-08-10 15:25:31 -07002109 self.launch_server.hold_jobs_in_build = False
2110 self.launch_server.release()
James E. Blair7d0dedc2013-02-21 17:26:09 -08002111 self.waitUntilSettled()
2112
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002113 self.assertEqual(A.data['status'], 'MERGED')
2114 self.assertEqual(A.reported, 2)
2115 self.assertEqual(B.data['status'], 'MERGED')
2116 self.assertEqual(B.reported, 2)
2117 self.assertEqual(C.data['status'], 'MERGED')
2118 self.assertEqual(C.reported, 2)
2119 self.assertEqual(D.data['status'], 'MERGED')
2120 self.assertEqual(D.reported, 2)
James E. Blair70c71582013-03-06 08:50:50 -08002121
James E. Blairec056492016-07-22 09:45:56 -07002122 @skip("Disabled for early v3 development")
James E. Blair4a28a882013-08-23 15:17:33 -07002123 def test_rerun_on_error(self):
2124 "Test that if a worker fails to run a job, it is run again"
James E. Blair08d19992016-08-10 15:25:31 -07002125 self.launch_server.hold_jobs_in_build = True
James E. Blair4a28a882013-08-23 15:17:33 -07002126 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002127 A.addApproval('code-review', 2)
2128 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4a28a882013-08-23 15:17:33 -07002129 self.waitUntilSettled()
2130
2131 self.builds[0].run_error = True
James E. Blair08d19992016-08-10 15:25:31 -07002132 self.launch_server.hold_jobs_in_build = False
2133 self.launch_server.release()
James E. Blair4a28a882013-08-23 15:17:33 -07002134 self.waitUntilSettled()
2135 self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1)
2136 self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3)
2137
James E. Blairec056492016-07-22 09:45:56 -07002138 @skip("Disabled for early v3 development")
James E. Blair412e5582013-04-22 15:50:12 -07002139 def test_statsd(self):
2140 "Test each of the statsd methods used in the scheduler"
2141 import extras
2142 statsd = extras.try_import('statsd.statsd')
2143 statsd.incr('test-incr')
2144 statsd.timing('test-timing', 3)
Alex Gaynor813d39b2014-05-17 16:17:16 -07002145 statsd.gauge('test-gauge', 12)
James E. Blair412e5582013-04-22 15:50:12 -07002146 self.assertReportedStat('test-incr', '1|c')
2147 self.assertReportedStat('test-timing', '3|ms')
Alex Gaynor813d39b2014-05-17 16:17:16 -07002148 self.assertReportedStat('test-gauge', '12|g')
James E. Blair412e5582013-04-22 15:50:12 -07002149
James E. Blairec056492016-07-22 09:45:56 -07002150 @skip("Disabled for early v3 development")
James E. Blairdad52252014-02-07 16:59:17 -08002151 def test_stuck_job_cleanup(self):
2152 "Test that pending jobs are cleaned up if removed from layout"
James E. Blair18c64442014-03-18 10:14:45 -07002153 # This job won't be registered at startup because it is not in
2154 # the standard layout, but we need it to already be registerd
2155 # for when we reconfigure, as that is when Zuul will attempt
2156 # to run the new job.
2157 self.worker.registerFunction('build:gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002158 self.gearman_server.hold_jobs_in_queue = True
2159 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002160 A.addApproval('code-review', 2)
2161 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairdad52252014-02-07 16:59:17 -08002162 self.waitUntilSettled()
2163 self.assertEqual(len(self.gearman_server.getQueue()), 1)
2164
James E. Blairf84026c2015-12-08 16:11:46 -08002165 self.updateConfigLayout(
2166 'tests/fixtures/layout-no-jobs.yaml')
James E. Blairdad52252014-02-07 16:59:17 -08002167 self.sched.reconfigure(self.config)
2168 self.waitUntilSettled()
2169
James E. Blair18c64442014-03-18 10:14:45 -07002170 self.gearman_server.release('gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002171 self.waitUntilSettled()
2172 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2173 self.assertTrue(self.sched._areAllBuildsComplete())
2174
2175 self.assertEqual(len(self.history), 1)
James E. Blair18c64442014-03-18 10:14:45 -07002176 self.assertEqual(self.history[0].name, 'gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002177 self.assertEqual(self.history[0].result, 'SUCCESS')
2178
James E. Blairec056492016-07-22 09:45:56 -07002179 @skip("Disabled for early v3 development")
James E. Blair879dafb2015-07-17 14:04:49 -07002180 def test_file_head(self):
2181 # This is a regression test for an observed bug. A change
2182 # with a file named "HEAD" in the root directory of the repo
2183 # was processed by a merger. It then was unable to reset the
2184 # repo because of:
2185 # GitCommandError: 'git reset --hard HEAD' returned
2186 # with exit code 128
2187 # stderr: 'fatal: ambiguous argument 'HEAD': both revision
2188 # and filename
2189 # Use '--' to separate filenames from revisions'
2190
2191 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2192 A.addPatchset(['HEAD'])
2193 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2194
2195 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2196 self.waitUntilSettled()
2197
2198 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2199 self.waitUntilSettled()
2200
2201 self.assertIn('Build succeeded', A.messages[0])
2202 self.assertIn('Build succeeded', B.messages[0])
2203
James E. Blairec056492016-07-22 09:45:56 -07002204 @skip("Disabled for early v3 development")
James E. Blair70c71582013-03-06 08:50:50 -08002205 def test_file_jobs(self):
2206 "Test that file jobs run only when appropriate"
2207 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2208 A.addPatchset(['pip-requires'])
2209 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002210 A.addApproval('code-review', 2)
2211 B.addApproval('code-review', 2)
2212 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2213 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair70c71582013-03-06 08:50:50 -08002214 self.waitUntilSettled()
2215
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002216 testfile_jobs = [x for x in self.history
James E. Blair70c71582013-03-06 08:50:50 -08002217 if x.name == 'project-testfile']
2218
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002219 self.assertEqual(len(testfile_jobs), 1)
2220 self.assertEqual(testfile_jobs[0].changes, '1,2')
2221 self.assertEqual(A.data['status'], 'MERGED')
2222 self.assertEqual(A.reported, 2)
2223 self.assertEqual(B.data['status'], 'MERGED')
2224 self.assertEqual(B.reported, 2)
James E. Blair3c5e5b52013-04-26 11:17:03 -07002225
James E. Blairec056492016-07-22 09:45:56 -07002226 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002227 def _test_skip_if_jobs(self, branch, should_skip):
2228 "Test that jobs with a skip-if filter run only when appropriate"
James E. Blairf84026c2015-12-08 16:11:46 -08002229 self.updateConfigLayout(
2230 'tests/fixtures/layout-skip-if.yaml')
Maru Newby3fe5f852015-01-13 04:22:14 +00002231 self.sched.reconfigure(self.config)
2232 self.registerJobs()
2233
2234 change = self.fake_gerrit.addFakeChange('org/project',
2235 branch,
2236 'test skip-if')
2237 self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1))
2238 self.waitUntilSettled()
2239
2240 tested_change_ids = [x.changes[0] for x in self.history
2241 if x.name == 'project-test-skip-if']
2242
2243 if should_skip:
2244 self.assertEqual([], tested_change_ids)
2245 else:
2246 self.assertIn(change.data['number'], tested_change_ids)
2247
James E. Blairec056492016-07-22 09:45:56 -07002248 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002249 def test_skip_if_match_skips_job(self):
2250 self._test_skip_if_jobs(branch='master', should_skip=True)
2251
James E. Blairec056492016-07-22 09:45:56 -07002252 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002253 def test_skip_if_no_match_runs_job(self):
2254 self._test_skip_if_jobs(branch='mp', should_skip=False)
2255
James E. Blairec056492016-07-22 09:45:56 -07002256 @skip("Disabled for early v3 development")
James E. Blair3c5e5b52013-04-26 11:17:03 -07002257 def test_test_config(self):
2258 "Test that we can test the config"
James E. Blairf84026c2015-12-08 16:11:46 -08002259 self.sched.testConfig(self.config.get('zuul', 'tenant_config'),
Joshua Hesketh352264b2015-08-11 23:42:08 +10002260 self.connections)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002261
James E. Blairec056492016-07-22 09:45:56 -07002262 @skip("Disabled for early v3 development")
James E. Blairc8a1e052014-02-25 09:29:26 -08002263 def test_queue_names(self):
2264 "Test shared change queue names"
2265 project1 = self.sched.layout.projects['org/project1']
2266 project2 = self.sched.layout.projects['org/project2']
2267 q1 = self.sched.layout.pipelines['gate'].getQueue(project1)
2268 q2 = self.sched.layout.pipelines['gate'].getQueue(project2)
2269 self.assertEqual(q1.name, 'integration')
2270 self.assertEqual(q2.name, 'integration')
2271
James E. Blairf84026c2015-12-08 16:11:46 -08002272 self.updateConfigLayout(
2273 'tests/fixtures/layout-bad-queue.yaml')
James E. Blairc8a1e052014-02-25 09:29:26 -08002274 with testtools.ExpectedException(
2275 Exception, "More than one name assigned to change queue"):
2276 self.sched.reconfigure(self.config)
2277
James E. Blairec056492016-07-22 09:45:56 -07002278 @skip("Disabled for early v3 development")
James E. Blair64ed6f22013-07-10 14:07:23 -07002279 def test_queue_precedence(self):
2280 "Test that queue precedence works"
2281
2282 self.gearman_server.hold_jobs_in_queue = True
James E. Blair08d19992016-08-10 15:25:31 -07002283 self.launch_server.hold_jobs_in_build = True
James E. Blair64ed6f22013-07-10 14:07:23 -07002284 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2285 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
James E. Blair8b5408c2016-08-08 15:37:46 -07002286 A.addApproval('code-review', 2)
2287 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair64ed6f22013-07-10 14:07:23 -07002288
2289 self.waitUntilSettled()
2290 self.gearman_server.hold_jobs_in_queue = False
2291 self.gearman_server.release()
2292 self.waitUntilSettled()
2293
James E. Blair8de58bd2013-07-18 16:23:33 -07002294 # Run one build at a time to ensure non-race order:
James E. Blairb8c16472015-05-05 14:55:26 -07002295 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07002296 self.launch_server.hold_jobs_in_build = False
James E. Blair8de58bd2013-07-18 16:23:33 -07002297 self.waitUntilSettled()
2298
James E. Blair64ed6f22013-07-10 14:07:23 -07002299 self.log.debug(self.history)
2300 self.assertEqual(self.history[0].pipeline, 'gate')
2301 self.assertEqual(self.history[1].pipeline, 'check')
2302 self.assertEqual(self.history[2].pipeline, 'gate')
2303 self.assertEqual(self.history[3].pipeline, 'gate')
2304 self.assertEqual(self.history[4].pipeline, 'check')
2305 self.assertEqual(self.history[5].pipeline, 'check')
2306
James E. Blairec056492016-07-22 09:45:56 -07002307 @skip("Disabled for early v3 development")
Clark Boylana5edbe42014-06-03 16:39:10 -07002308 def test_json_status(self):
James E. Blair1843a552013-07-03 14:19:52 -07002309 "Test that we can retrieve JSON status info"
James E. Blair08d19992016-08-10 15:25:31 -07002310 self.launch_server.hold_jobs_in_build = True
James E. Blair1843a552013-07-03 14:19:52 -07002311 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002312 A.addApproval('code-review', 2)
2313 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1843a552013-07-03 14:19:52 -07002314 self.waitUntilSettled()
2315
James E. Blair08d19992016-08-10 15:25:31 -07002316 self.launch_server.release('project-merge')
James E. Blairb7273ef2016-04-19 08:58:51 -07002317 self.waitUntilSettled()
2318
James E. Blair1843a552013-07-03 14:19:52 -07002319 port = self.webapp.server.socket.getsockname()[1]
2320
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002321 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2322 f = urllib.request.urlopen(req)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002323 headers = f.info()
2324 self.assertIn('Content-Length', headers)
2325 self.assertIn('Content-Type', headers)
Sachi Kingdc963fc2016-03-23 16:00:33 +11002326 self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$',
2327 headers['Content-Type']))
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002328 self.assertIn('Access-Control-Allow-Origin', headers)
2329 self.assertIn('Cache-Control', headers)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002330 self.assertIn('Last-Modified', headers)
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002331 self.assertIn('Expires', headers)
James E. Blair1843a552013-07-03 14:19:52 -07002332 data = f.read()
2333
James E. Blair08d19992016-08-10 15:25:31 -07002334 self.launch_server.hold_jobs_in_build = False
2335 self.launch_server.release()
James E. Blair1843a552013-07-03 14:19:52 -07002336 self.waitUntilSettled()
2337
2338 data = json.loads(data)
James E. Blairb7273ef2016-04-19 08:58:51 -07002339 status_jobs = []
James E. Blair1843a552013-07-03 14:19:52 -07002340 for p in data['pipelines']:
2341 for q in p['change_queues']:
James E. Blairbfb8e042014-12-30 17:01:44 -08002342 if p['name'] in ['gate', 'conflict']:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002343 self.assertEqual(q['window'], 20)
2344 else:
2345 self.assertEqual(q['window'], 0)
James E. Blair1843a552013-07-03 14:19:52 -07002346 for head in q['heads']:
2347 for change in head:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002348 self.assertTrue(change['active'])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002349 self.assertEqual(change['id'], '1,1')
James E. Blair1843a552013-07-03 14:19:52 -07002350 for job in change['jobs']:
James E. Blairb7273ef2016-04-19 08:58:51 -07002351 status_jobs.append(job)
2352 self.assertEqual('project-merge', status_jobs[0]['name'])
2353 self.assertEqual('https://server/job/project-merge/0/',
2354 status_jobs[0]['url'])
2355 self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0',
2356 status_jobs[0]['report_url'])
2357
2358 self.assertEqual('project-test1', status_jobs[1]['name'])
2359 self.assertEqual('https://server/job/project-test1/1/',
2360 status_jobs[1]['url'])
2361 self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1',
2362 status_jobs[1]['report_url'])
2363
2364 self.assertEqual('project-test2', status_jobs[2]['name'])
2365 self.assertEqual('https://server/job/project-test2/2/',
2366 status_jobs[2]['url'])
2367 self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2',
2368 status_jobs[2]['report_url'])
James E. Blair1843a552013-07-03 14:19:52 -07002369
James E. Blairec056492016-07-22 09:45:56 -07002370 @skip("Disabled for early v3 development")
James E. Blairc3d428e2013-12-03 15:06:48 -08002371 def test_merging_queues(self):
2372 "Test that transitively-connected change queues are merged"
James E. Blairf84026c2015-12-08 16:11:46 -08002373 self.updateConfigLayout(
2374 'tests/fixtures/layout-merge-queues.yaml')
James E. Blairc3d428e2013-12-03 15:06:48 -08002375 self.sched.reconfigure(self.config)
2376 self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1)
2377
James E. Blairec056492016-07-22 09:45:56 -07002378 @skip("Disabled for early v3 development")
James E. Blairaf17a972016-02-03 15:07:18 -08002379 def test_mutex(self):
2380 "Test job mutexes"
2381 self.config.set('zuul', 'layout_config',
2382 'tests/fixtures/layout-mutex.yaml')
2383 self.sched.reconfigure(self.config)
2384
James E. Blair08d19992016-08-10 15:25:31 -07002385 self.launch_server.hold_jobs_in_build = True
James E. Blairaf17a972016-02-03 15:07:18 -08002386 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2387 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2388 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2389
2390 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2391 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2392 self.waitUntilSettled()
2393 self.assertEqual(len(self.builds), 3)
2394 self.assertEqual(self.builds[0].name, 'project-test1')
2395 self.assertEqual(self.builds[1].name, 'mutex-one')
2396 self.assertEqual(self.builds[2].name, 'project-test1')
2397
James E. Blair08d19992016-08-10 15:25:31 -07002398 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002399 self.waitUntilSettled()
2400
2401 self.assertEqual(len(self.builds), 3)
2402 self.assertEqual(self.builds[0].name, 'project-test1')
2403 self.assertEqual(self.builds[1].name, 'project-test1')
2404 self.assertEqual(self.builds[2].name, 'mutex-two')
2405 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2406
James E. Blair08d19992016-08-10 15:25:31 -07002407 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002408 self.waitUntilSettled()
2409
2410 self.assertEqual(len(self.builds), 3)
2411 self.assertEqual(self.builds[0].name, 'project-test1')
2412 self.assertEqual(self.builds[1].name, 'project-test1')
2413 self.assertEqual(self.builds[2].name, 'mutex-one')
2414 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2415
James E. Blair08d19992016-08-10 15:25:31 -07002416 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002417 self.waitUntilSettled()
2418
2419 self.assertEqual(len(self.builds), 3)
2420 self.assertEqual(self.builds[0].name, 'project-test1')
2421 self.assertEqual(self.builds[1].name, 'project-test1')
2422 self.assertEqual(self.builds[2].name, 'mutex-two')
2423 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2424
James E. Blair08d19992016-08-10 15:25:31 -07002425 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002426 self.waitUntilSettled()
2427
2428 self.assertEqual(len(self.builds), 2)
2429 self.assertEqual(self.builds[0].name, 'project-test1')
2430 self.assertEqual(self.builds[1].name, 'project-test1')
2431 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2432
James E. Blair08d19992016-08-10 15:25:31 -07002433 self.launch_server.hold_jobs_in_build = False
2434 self.launch_server.release()
James E. Blairaf17a972016-02-03 15:07:18 -08002435
2436 self.waitUntilSettled()
2437 self.assertEqual(len(self.builds), 0)
2438
2439 self.assertEqual(A.reported, 1)
2440 self.assertEqual(B.reported, 1)
2441 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2442
James E. Blairec056492016-07-22 09:45:56 -07002443 @skip("Disabled for early v3 development")
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002444 def test_node_label(self):
2445 "Test that a job runs on a specific node label"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002446 self.worker.registerFunction('build:node-project-test1:debian')
2447
2448 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002449 A.addApproval('code-review', 2)
2450 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002451 self.waitUntilSettled()
James E. Blair4ca985f2013-05-30 12:27:43 -07002452
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002453 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2454 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2455 'debian')
2456 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
James E. Blaircdccd972013-07-01 12:10:22 -07002457
James E. Blairec056492016-07-22 09:45:56 -07002458 @skip("Disabled for early v3 development")
James E. Blaircdccd972013-07-01 12:10:22 -07002459 def test_live_reconfiguration(self):
2460 "Test that live reconfiguration works"
James E. Blair08d19992016-08-10 15:25:31 -07002461 self.launch_server.hold_jobs_in_build = True
James E. Blaircdccd972013-07-01 12:10:22 -07002462 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002463 A.addApproval('code-review', 2)
2464 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircdccd972013-07-01 12:10:22 -07002465 self.waitUntilSettled()
2466
2467 self.sched.reconfigure(self.config)
2468
James E. Blair08d19992016-08-10 15:25:31 -07002469 self.launch_server.hold_jobs_in_build = False
2470 self.launch_server.release()
James E. Blaircdccd972013-07-01 12:10:22 -07002471 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002472 self.assertEqual(self.getJobFromHistory('project-merge').result,
2473 'SUCCESS')
2474 self.assertEqual(self.getJobFromHistory('project-test1').result,
2475 'SUCCESS')
2476 self.assertEqual(self.getJobFromHistory('project-test2').result,
2477 'SUCCESS')
2478 self.assertEqual(A.data['status'], 'MERGED')
2479 self.assertEqual(A.reported, 2)
James E. Blair287c06d2013-07-24 10:39:30 -07002480
James E. Blairec056492016-07-22 09:45:56 -07002481 @skip("Disabled for early v3 development")
James E. Blair6bc782d2015-07-17 16:20:21 -07002482 def test_live_reconfiguration_merge_conflict(self):
2483 # A real-world bug: a change in a gate queue has a merge
2484 # conflict and a job is added to its project while it's
2485 # sitting in the queue. The job gets added to the change and
2486 # enqueued and the change gets stuck.
2487 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002488 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002489
2490 # This change is fine. It's here to stop the queue long
2491 # enough for the next change to be subject to the
2492 # reconfiguration, as well as to provide a conflict for the
2493 # next change. This change will succeed and merge.
2494 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2495 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002496 A.addApproval('code-review', 2)
James E. Blair6bc782d2015-07-17 16:20:21 -07002497
2498 # This change will be in merge conflict. During the
2499 # reconfiguration, we will add a job. We want to make sure
2500 # that doesn't cause it to get stuck.
2501 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2502 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002503 B.addApproval('code-review', 2)
James E. Blair4eb21fa2015-07-27 14:56:47 -07002504
James E. Blair8b5408c2016-08-08 15:37:46 -07002505 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2506 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002507
2508 self.waitUntilSettled()
2509
2510 # No jobs have run yet
2511 self.assertEqual(A.data['status'], 'NEW')
2512 self.assertEqual(A.reported, 1)
2513 self.assertEqual(B.data['status'], 'NEW')
2514 self.assertEqual(B.reported, 1)
2515 self.assertEqual(len(self.history), 0)
2516
2517 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002518 self.updateConfigLayout(
2519 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002520 self.sched.reconfigure(self.config)
2521 self.waitUntilSettled()
2522
James E. Blair08d19992016-08-10 15:25:31 -07002523 self.launch_server.hold_jobs_in_build = False
2524 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002525 self.waitUntilSettled()
2526
2527 self.assertEqual(A.data['status'], 'MERGED')
2528 self.assertEqual(A.reported, 2)
2529 self.assertEqual(B.data['status'], 'NEW')
2530 self.assertEqual(B.reported, 2)
2531 self.assertEqual(self.getJobFromHistory('project-merge').result,
2532 'SUCCESS')
2533 self.assertEqual(self.getJobFromHistory('project-test1').result,
2534 'SUCCESS')
2535 self.assertEqual(self.getJobFromHistory('project-test2').result,
2536 'SUCCESS')
2537 self.assertEqual(self.getJobFromHistory('project-test3').result,
2538 'SUCCESS')
2539 self.assertEqual(len(self.history), 4)
2540
James E. Blairec056492016-07-22 09:45:56 -07002541 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002542 def test_live_reconfiguration_failed_root(self):
James E. Blair6bc782d2015-07-17 16:20:21 -07002543 # An extrapolation of test_live_reconfiguration_merge_conflict
2544 # that tests a job added to a job tree with a failed root does
2545 # not run.
2546 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002547 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002548
2549 # This change is fine. It's here to stop the queue long
2550 # enough for the next change to be subject to the
2551 # reconfiguration. This change will succeed and merge.
2552 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2553 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002554 A.addApproval('code-review', 2)
2555 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002556 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002557 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002558 self.waitUntilSettled()
2559
2560 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair08d19992016-08-10 15:25:31 -07002561 self.launch_server.failJob('project-merge', B)
James E. Blair8b5408c2016-08-08 15:37:46 -07002562 B.addApproval('code-review', 2)
2563 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002564 self.waitUntilSettled()
2565
James E. Blair08d19992016-08-10 15:25:31 -07002566 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002567 self.waitUntilSettled()
2568
2569 # Both -merge jobs have run, but no others.
2570 self.assertEqual(A.data['status'], 'NEW')
2571 self.assertEqual(A.reported, 1)
2572 self.assertEqual(B.data['status'], 'NEW')
2573 self.assertEqual(B.reported, 1)
2574 self.assertEqual(self.history[0].result, 'SUCCESS')
2575 self.assertEqual(self.history[0].name, 'project-merge')
2576 self.assertEqual(self.history[1].result, 'FAILURE')
2577 self.assertEqual(self.history[1].name, 'project-merge')
2578 self.assertEqual(len(self.history), 2)
2579
2580 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002581 self.updateConfigLayout(
2582 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002583 self.sched.reconfigure(self.config)
2584 self.waitUntilSettled()
2585
James E. Blair08d19992016-08-10 15:25:31 -07002586 self.launch_server.hold_jobs_in_build = False
2587 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002588 self.waitUntilSettled()
2589
2590 self.assertEqual(A.data['status'], 'MERGED')
2591 self.assertEqual(A.reported, 2)
2592 self.assertEqual(B.data['status'], 'NEW')
2593 self.assertEqual(B.reported, 2)
2594 self.assertEqual(self.history[0].result, 'SUCCESS')
2595 self.assertEqual(self.history[0].name, 'project-merge')
2596 self.assertEqual(self.history[1].result, 'FAILURE')
2597 self.assertEqual(self.history[1].name, 'project-merge')
2598 self.assertEqual(self.history[2].result, 'SUCCESS')
2599 self.assertEqual(self.history[3].result, 'SUCCESS')
2600 self.assertEqual(self.history[4].result, 'SUCCESS')
2601 self.assertEqual(len(self.history), 5)
2602
James E. Blairec056492016-07-22 09:45:56 -07002603 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002604 def test_live_reconfiguration_failed_job(self):
2605 # Test that a change with a removed failing job does not
2606 # disrupt reconfiguration. If a change has a failed job and
2607 # that job is removed during a reconfiguration, we observed a
2608 # bug where the code to re-set build statuses would run on
2609 # that build and raise an exception because the job no longer
2610 # existed.
James E. Blair08d19992016-08-10 15:25:31 -07002611 self.launch_server.hold_jobs_in_build = True
James E. Blair400e8fd2015-07-30 17:44:45 -07002612
2613 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2614
2615 # This change will fail and later be removed by the reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002616 self.launch_server.failJob('project-test1', A)
James E. Blair400e8fd2015-07-30 17:44:45 -07002617
2618 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2619 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002620 self.launch_server.release('.*-merge')
James E. Blair400e8fd2015-07-30 17:44:45 -07002621 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002622 self.launch_server.release('project-test1')
James E. Blair400e8fd2015-07-30 17:44:45 -07002623 self.waitUntilSettled()
2624
2625 self.assertEqual(A.data['status'], 'NEW')
2626 self.assertEqual(A.reported, 0)
2627
2628 self.assertEqual(self.getJobFromHistory('project-merge').result,
2629 'SUCCESS')
2630 self.assertEqual(self.getJobFromHistory('project-test1').result,
2631 'FAILURE')
2632 self.assertEqual(len(self.history), 2)
2633
2634 # Remove the test1 job.
James E. Blairf84026c2015-12-08 16:11:46 -08002635 self.updateConfigLayout(
2636 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml')
James E. Blair400e8fd2015-07-30 17:44:45 -07002637 self.sched.reconfigure(self.config)
2638 self.waitUntilSettled()
2639
James E. Blair08d19992016-08-10 15:25:31 -07002640 self.launch_server.hold_jobs_in_build = False
2641 self.launch_server.release()
James E. Blair400e8fd2015-07-30 17:44:45 -07002642 self.waitUntilSettled()
2643
2644 self.assertEqual(self.getJobFromHistory('project-test2').result,
2645 'SUCCESS')
2646 self.assertEqual(self.getJobFromHistory('project-testfile').result,
2647 'SUCCESS')
2648 self.assertEqual(len(self.history), 4)
2649
2650 self.assertEqual(A.data['status'], 'NEW')
2651 self.assertEqual(A.reported, 1)
2652 self.assertIn('Build succeeded', A.messages[0])
2653 # Ensure the removed job was not included in the report.
2654 self.assertNotIn('project-test1', A.messages[0])
2655
James E. Blairec056492016-07-22 09:45:56 -07002656 @skip("Disabled for early v3 development")
James E. Blairfe707d12015-08-05 15:18:15 -07002657 def test_live_reconfiguration_shared_queue(self):
2658 # Test that a change with a failing job which was removed from
2659 # this project but otherwise still exists in the system does
2660 # not disrupt reconfiguration.
2661
James E. Blair08d19992016-08-10 15:25:31 -07002662 self.launch_server.hold_jobs_in_build = True
James E. Blairfe707d12015-08-05 15:18:15 -07002663
2664 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2665
James E. Blair08d19992016-08-10 15:25:31 -07002666 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairfe707d12015-08-05 15:18:15 -07002667
2668 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2669 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002670 self.launch_server.release('.*-merge')
James E. Blairfe707d12015-08-05 15:18:15 -07002671 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002672 self.launch_server.release('project1-project2-integration')
James E. Blairfe707d12015-08-05 15:18:15 -07002673 self.waitUntilSettled()
2674
2675 self.assertEqual(A.data['status'], 'NEW')
2676 self.assertEqual(A.reported, 0)
2677
2678 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2679 'SUCCESS')
2680 self.assertEqual(self.getJobFromHistory(
2681 'project1-project2-integration').result, 'FAILURE')
2682 self.assertEqual(len(self.history), 2)
2683
2684 # Remove the integration job.
James E. Blairf84026c2015-12-08 16:11:46 -08002685 self.updateConfigLayout(
2686 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml')
James E. Blairfe707d12015-08-05 15:18:15 -07002687 self.sched.reconfigure(self.config)
2688 self.waitUntilSettled()
2689
James E. Blair08d19992016-08-10 15:25:31 -07002690 self.launch_server.hold_jobs_in_build = False
2691 self.launch_server.release()
James E. Blairfe707d12015-08-05 15:18:15 -07002692 self.waitUntilSettled()
2693
2694 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2695 'SUCCESS')
2696 self.assertEqual(self.getJobFromHistory('project1-test1').result,
2697 'SUCCESS')
2698 self.assertEqual(self.getJobFromHistory('project1-test2').result,
2699 'SUCCESS')
2700 self.assertEqual(self.getJobFromHistory(
2701 'project1-project2-integration').result, 'FAILURE')
2702 self.assertEqual(len(self.history), 4)
2703
2704 self.assertEqual(A.data['status'], 'NEW')
2705 self.assertEqual(A.reported, 1)
2706 self.assertIn('Build succeeded', A.messages[0])
2707 # Ensure the removed job was not included in the report.
2708 self.assertNotIn('project1-project2-integration', A.messages[0])
2709
James E. Blairec056492016-07-22 09:45:56 -07002710 @skip("Disabled for early v3 development")
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002711 def test_double_live_reconfiguration_shared_queue(self):
2712 # This was a real-world regression. A change is added to
2713 # gate; a reconfigure happens, a second change which depends
2714 # on the first is added, and a second reconfiguration happens.
2715 # Ensure that both changes merge.
2716
2717 # A failure may indicate incorrect caching or cleaning up of
2718 # references during a reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002719 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002720
2721 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2722 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2723 B.setDependsOn(A, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07002724 A.addApproval('code-review', 2)
2725 B.addApproval('code-review', 2)
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002726
2727 # Add the parent change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002728 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002729 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002730 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002731 self.waitUntilSettled()
2732
2733 # Reconfigure (with only one change in the pipeline).
2734 self.sched.reconfigure(self.config)
2735 self.waitUntilSettled()
2736
2737 # Add the child change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002738 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002739 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002740 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002741 self.waitUntilSettled()
2742
2743 # Reconfigure (with both in the pipeline).
2744 self.sched.reconfigure(self.config)
2745 self.waitUntilSettled()
2746
James E. Blair08d19992016-08-10 15:25:31 -07002747 self.launch_server.hold_jobs_in_build = False
2748 self.launch_server.release()
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002749 self.waitUntilSettled()
2750
2751 self.assertEqual(len(self.history), 8)
2752
2753 self.assertEqual(A.data['status'], 'MERGED')
2754 self.assertEqual(A.reported, 2)
2755 self.assertEqual(B.data['status'], 'MERGED')
2756 self.assertEqual(B.reported, 2)
2757
James E. Blairec056492016-07-22 09:45:56 -07002758 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002759 def test_live_reconfiguration_del_project(self):
2760 # Test project deletion from layout
2761 # while changes are enqueued
2762
James E. Blair08d19992016-08-10 15:25:31 -07002763 self.launch_server.hold_jobs_in_build = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002764 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2765 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2766 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
2767
2768 # A Depends-On: B
2769 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
2770 A.subject, B.data['id'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002771 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002772
2773 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2774 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2775 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002776 self.launch_server.release('.*-merge')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002777 self.waitUntilSettled()
2778 self.assertEqual(len(self.builds), 5)
2779
2780 # This layout defines only org/project, not org/project1
James E. Blairf84026c2015-12-08 16:11:46 -08002781 self.updateConfigLayout(
2782 'tests/fixtures/layout-live-reconfiguration-del-project.yaml')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002783 self.sched.reconfigure(self.config)
2784 self.waitUntilSettled()
2785
2786 # Builds for C aborted, builds for A succeed,
2787 # and have change B applied ahead
2788 job_c = self.getJobFromHistory('project1-test1')
2789 self.assertEqual(job_c.changes, '3,1')
2790 self.assertEqual(job_c.result, 'ABORTED')
2791
James E. Blair08d19992016-08-10 15:25:31 -07002792 self.launch_server.hold_jobs_in_build = False
2793 self.launch_server.release()
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002794 self.waitUntilSettled()
2795
2796 self.assertEqual(self.getJobFromHistory('project-test1').changes,
2797 '2,1 1,1')
2798
2799 self.assertEqual(A.data['status'], 'NEW')
2800 self.assertEqual(B.data['status'], 'NEW')
2801 self.assertEqual(C.data['status'], 'NEW')
2802 self.assertEqual(A.reported, 1)
2803 self.assertEqual(B.reported, 0)
2804 self.assertEqual(C.reported, 0)
2805
2806 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
2807 self.assertIn('Build succeeded', A.messages[0])
2808
James E. Blairec056492016-07-22 09:45:56 -07002809 @skip("Disabled for early v3 development")
James E. Blaire712d9f2013-07-31 11:40:11 -07002810 def test_live_reconfiguration_functions(self):
2811 "Test live reconfiguration with a custom function"
2812 self.worker.registerFunction('build:node-project-test1:debian')
2813 self.worker.registerFunction('build:node-project-test1:wheezy')
2814 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002815 A.addApproval('code-review', 2)
2816 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002817 self.waitUntilSettled()
2818
2819 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2820 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2821 'debian')
2822 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2823
James E. Blairf84026c2015-12-08 16:11:46 -08002824 self.updateConfigLayout(
2825 'tests/fixtures/layout-live-reconfiguration-functions.yaml')
James E. Blaire712d9f2013-07-31 11:40:11 -07002826 self.sched.reconfigure(self.config)
2827 self.worker.build_history = []
2828
2829 B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002830 B.addApproval('code-review', 2)
2831 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002832 self.waitUntilSettled()
2833
2834 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2835 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2836 'wheezy')
2837 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2838
James E. Blairec056492016-07-22 09:45:56 -07002839 @skip("Disabled for early v3 development")
James E. Blair287c06d2013-07-24 10:39:30 -07002840 def test_delayed_repo_init(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002841 self.updateConfigLayout(
2842 'tests/fixtures/layout-delayed-repo-init.yaml')
James E. Blair287c06d2013-07-24 10:39:30 -07002843 self.sched.reconfigure(self.config)
2844
2845 self.init_repo("org/new-project")
2846 A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A')
2847
James E. Blair8b5408c2016-08-08 15:37:46 -07002848 A.addApproval('code-review', 2)
2849 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair287c06d2013-07-24 10:39:30 -07002850 self.waitUntilSettled()
2851 self.assertEqual(self.getJobFromHistory('project-merge').result,
2852 'SUCCESS')
2853 self.assertEqual(self.getJobFromHistory('project-test1').result,
2854 'SUCCESS')
2855 self.assertEqual(self.getJobFromHistory('project-test2').result,
2856 'SUCCESS')
2857 self.assertEqual(A.data['status'], 'MERGED')
2858 self.assertEqual(A.reported, 2)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002859
James E. Blairec056492016-07-22 09:45:56 -07002860 @skip("Disabled for early v3 development")
Clark Boylan6dbbc482013-10-18 10:57:31 -07002861 def test_repo_deleted(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002862 self.updateConfigLayout(
2863 'tests/fixtures/layout-repo-deleted.yaml')
Clark Boylan6dbbc482013-10-18 10:57:31 -07002864 self.sched.reconfigure(self.config)
2865
2866 self.init_repo("org/delete-project")
2867 A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A')
2868
James E. Blair8b5408c2016-08-08 15:37:46 -07002869 A.addApproval('code-review', 2)
2870 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002871 self.waitUntilSettled()
2872 self.assertEqual(self.getJobFromHistory('project-merge').result,
2873 'SUCCESS')
2874 self.assertEqual(self.getJobFromHistory('project-test1').result,
2875 'SUCCESS')
2876 self.assertEqual(self.getJobFromHistory('project-test2').result,
2877 'SUCCESS')
2878 self.assertEqual(A.data['status'], 'MERGED')
2879 self.assertEqual(A.reported, 2)
2880
2881 # Delete org/new-project zuul repo. Should be recloned.
2882 shutil.rmtree(os.path.join(self.git_root, "org/delete-project"))
2883
2884 B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B')
2885
James E. Blair8b5408c2016-08-08 15:37:46 -07002886 B.addApproval('code-review', 2)
2887 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002888 self.waitUntilSettled()
2889 self.assertEqual(self.getJobFromHistory('project-merge').result,
2890 'SUCCESS')
2891 self.assertEqual(self.getJobFromHistory('project-test1').result,
2892 'SUCCESS')
2893 self.assertEqual(self.getJobFromHistory('project-test2').result,
2894 'SUCCESS')
2895 self.assertEqual(B.data['status'], 'MERGED')
2896 self.assertEqual(B.reported, 2)
2897
James E. Blairec056492016-07-22 09:45:56 -07002898 @skip("Disabled for early v3 development")
James E. Blair456f2fb2016-02-09 09:29:33 -08002899 def test_tags(self):
2900 "Test job tags"
2901 self.config.set('zuul', 'layout_config',
2902 'tests/fixtures/layout-tags.yaml')
2903 self.sched.reconfigure(self.config)
2904
2905 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2906 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
2907 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2908 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2909 self.waitUntilSettled()
2910
2911 results = {'project1-merge': 'extratag merge project1',
2912 'project2-merge': 'merge'}
2913
2914 for build in self.history:
2915 self.assertEqual(results.get(build.name, ''),
2916 build.parameters.get('BUILD_TAGS'))
2917
James E. Blairec056492016-07-22 09:45:56 -07002918 @skip("Disabled for early v3 development")
James E. Blair63bb0ef2013-07-29 17:14:51 -07002919 def test_timer(self):
2920 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07002921 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08002922 self.updateConfigLayout(
2923 'tests/fixtures/layout-timer.yaml')
James E. Blair63bb0ef2013-07-29 17:14:51 -07002924 self.sched.reconfigure(self.config)
2925 self.registerJobs()
2926
Clark Boylan3ee090a2014-04-03 20:55:09 -07002927 # The pipeline triggers every second, so we should have seen
2928 # several by now.
2929 time.sleep(5)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002930 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07002931
2932 self.assertEqual(len(self.builds), 2)
2933
James E. Blair63bb0ef2013-07-29 17:14:51 -07002934 port = self.webapp.server.socket.getsockname()[1]
2935
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002936 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2937 f = urllib.request.urlopen(req)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002938 data = f.read()
2939
James E. Blair08d19992016-08-10 15:25:31 -07002940 self.launch_server.hold_jobs_in_build = False
Clark Boylan3ee090a2014-04-03 20:55:09 -07002941 # Stop queuing timer triggered jobs so that the assertions
2942 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08002943 self.updateConfigLayout(
2944 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07002945 self.sched.reconfigure(self.config)
2946 self.registerJobs()
James E. Blair08d19992016-08-10 15:25:31 -07002947 self.launch_server.release()
James E. Blair63bb0ef2013-07-29 17:14:51 -07002948 self.waitUntilSettled()
2949
2950 self.assertEqual(self.getJobFromHistory(
2951 'project-bitrot-stable-old').result, 'SUCCESS')
2952 self.assertEqual(self.getJobFromHistory(
2953 'project-bitrot-stable-older').result, 'SUCCESS')
2954
2955 data = json.loads(data)
2956 status_jobs = set()
2957 for p in data['pipelines']:
2958 for q in p['change_queues']:
2959 for head in q['heads']:
2960 for change in head:
Alex Gaynorddb9ef32013-09-16 21:04:58 -07002961 self.assertEqual(change['id'], None)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002962 for job in change['jobs']:
2963 status_jobs.add(job['name'])
2964 self.assertIn('project-bitrot-stable-old', status_jobs)
2965 self.assertIn('project-bitrot-stable-older', status_jobs)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10002966
James E. Blairec056492016-07-22 09:45:56 -07002967 @skip("Disabled for early v3 development")
James E. Blair4f6033c2014-03-27 15:49:09 -07002968 def test_idle(self):
2969 "Test that frequent periodic jobs work"
James E. Blair08d19992016-08-10 15:25:31 -07002970 self.launch_server.hold_jobs_in_build = True
James E. Blair4f6033c2014-03-27 15:49:09 -07002971
Clark Boylan3ee090a2014-04-03 20:55:09 -07002972 for x in range(1, 3):
2973 # Test that timer triggers periodic jobs even across
2974 # layout config reloads.
2975 # Start timer trigger
James E. Blairf84026c2015-12-08 16:11:46 -08002976 self.updateConfigLayout(
2977 'tests/fixtures/layout-idle.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07002978 self.sched.reconfigure(self.config)
2979 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08002980 self.waitUntilSettled()
James E. Blair4f6033c2014-03-27 15:49:09 -07002981
Clark Boylan3ee090a2014-04-03 20:55:09 -07002982 # The pipeline triggers every second, so we should have seen
2983 # several by now.
2984 time.sleep(5)
Clark Boylan3ee090a2014-04-03 20:55:09 -07002985
2986 # Stop queuing timer triggered jobs so that the assertions
2987 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08002988 self.updateConfigLayout(
2989 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07002990 self.sched.reconfigure(self.config)
2991 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08002992 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07002993
2994 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07002995 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07002996 self.waitUntilSettled()
2997 self.assertEqual(len(self.builds), 0)
2998 self.assertEqual(len(self.history), x * 2)
James E. Blair4f6033c2014-03-27 15:49:09 -07002999
James E. Blairec056492016-07-22 09:45:56 -07003000 @skip("Disabled for early v3 development")
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003001 def test_check_smtp_pool(self):
James E. Blairf84026c2015-12-08 16:11:46 -08003002 self.updateConfigLayout(
3003 'tests/fixtures/layout-smtp.yaml')
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003004 self.sched.reconfigure(self.config)
3005
3006 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3007 self.waitUntilSettled()
3008
3009 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3010 self.waitUntilSettled()
3011
James E. Blairff80a2f2013-12-27 13:24:06 -08003012 self.assertEqual(len(self.smtp_messages), 2)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003013
3014 # A.messages only holds what FakeGerrit places in it. Thus we
3015 # work on the knowledge of what the first message should be as
3016 # it is only configured to go to SMTP.
3017
3018 self.assertEqual('zuul@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003019 self.smtp_messages[0]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003020 self.assertEqual(['you@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003021 self.smtp_messages[0]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003022 self.assertEqual('Starting check jobs.',
James E. Blairff80a2f2013-12-27 13:24:06 -08003023 self.smtp_messages[0]['body'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003024
3025 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003026 self.smtp_messages[1]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003027 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003028 self.smtp_messages[1]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003029 self.assertEqual(A.messages[0],
James E. Blairff80a2f2013-12-27 13:24:06 -08003030 self.smtp_messages[1]['body'])
James E. Blairad28e912013-11-27 10:43:22 -08003031
James E. Blairec056492016-07-22 09:45:56 -07003032 @skip("Disabled for early v3 development")
James E. Blaire5910202013-12-27 09:50:31 -08003033 def test_timer_smtp(self):
3034 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003035 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003036 self.updateConfigLayout(
3037 'tests/fixtures/layout-timer-smtp.yaml')
James E. Blaire5910202013-12-27 09:50:31 -08003038 self.sched.reconfigure(self.config)
3039 self.registerJobs()
3040
Clark Boylan3ee090a2014-04-03 20:55:09 -07003041 # The pipeline triggers every second, so we should have seen
3042 # several by now.
3043 time.sleep(5)
James E. Blaire5910202013-12-27 09:50:31 -08003044 self.waitUntilSettled()
3045
Clark Boylan3ee090a2014-04-03 20:55:09 -07003046 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003047 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003048 self.waitUntilSettled()
3049 self.assertEqual(len(self.history), 2)
3050
James E. Blaire5910202013-12-27 09:50:31 -08003051 self.assertEqual(self.getJobFromHistory(
3052 'project-bitrot-stable-old').result, 'SUCCESS')
3053 self.assertEqual(self.getJobFromHistory(
3054 'project-bitrot-stable-older').result, 'SUCCESS')
3055
James E. Blairff80a2f2013-12-27 13:24:06 -08003056 self.assertEqual(len(self.smtp_messages), 1)
James E. Blaire5910202013-12-27 09:50:31 -08003057
3058 # A.messages only holds what FakeGerrit places in it. Thus we
3059 # work on the knowledge of what the first message should be as
3060 # it is only configured to go to SMTP.
3061
3062 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003063 self.smtp_messages[0]['from_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003064 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003065 self.smtp_messages[0]['to_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003066 self.assertIn('Subject: Periodic check for org/project succeeded',
James E. Blairff80a2f2013-12-27 13:24:06 -08003067 self.smtp_messages[0]['headers'])
James E. Blaire5910202013-12-27 09:50:31 -08003068
Clark Boylan3ee090a2014-04-03 20:55:09 -07003069 # Stop queuing timer triggered jobs and let any that may have
3070 # queued through so that end of test assertions pass.
James E. Blairf84026c2015-12-08 16:11:46 -08003071 self.updateConfigLayout(
3072 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003073 self.sched.reconfigure(self.config)
3074 self.registerJobs()
James E. Blairf8058972014-08-15 16:09:16 -07003075 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003076 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003077 self.waitUntilSettled()
3078
James E. Blairec056492016-07-22 09:45:56 -07003079 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003080 def test_client_enqueue_change(self):
James E. Blairad28e912013-11-27 10:43:22 -08003081 "Test that the RPC client can enqueue a change"
3082 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003083 A.addApproval('code-review', 2)
3084 A.addApproval('approved', 1)
James E. Blairad28e912013-11-27 10:43:22 -08003085
3086 client = zuul.rpcclient.RPCClient('127.0.0.1',
3087 self.gearman_server.port)
3088 r = client.enqueue(pipeline='gate',
3089 project='org/project',
3090 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003091 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003092 self.waitUntilSettled()
3093 self.assertEqual(self.getJobFromHistory('project-merge').result,
3094 'SUCCESS')
3095 self.assertEqual(self.getJobFromHistory('project-test1').result,
3096 'SUCCESS')
3097 self.assertEqual(self.getJobFromHistory('project-test2').result,
3098 'SUCCESS')
3099 self.assertEqual(A.data['status'], 'MERGED')
3100 self.assertEqual(A.reported, 2)
3101 self.assertEqual(r, True)
3102
James E. Blairec056492016-07-22 09:45:56 -07003103 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003104 def test_client_enqueue_ref(self):
3105 "Test that the RPC client can enqueue a ref"
3106
3107 client = zuul.rpcclient.RPCClient('127.0.0.1',
3108 self.gearman_server.port)
3109 r = client.enqueue_ref(
3110 pipeline='post',
3111 project='org/project',
3112 trigger='gerrit',
3113 ref='master',
3114 oldrev='90f173846e3af9154517b88543ffbd1691f31366',
3115 newrev='d479a0bfcb34da57a31adb2a595c0cf687812543')
3116 self.waitUntilSettled()
3117 job_names = [x.name for x in self.history]
3118 self.assertEqual(len(self.history), 1)
3119 self.assertIn('project-post', job_names)
3120 self.assertEqual(r, True)
3121
James E. Blairec056492016-07-22 09:45:56 -07003122 @skip("Disabled for early v3 development")
James E. Blairad28e912013-11-27 10:43:22 -08003123 def test_client_enqueue_negative(self):
3124 "Test that the RPC client returns errors"
3125 client = zuul.rpcclient.RPCClient('127.0.0.1',
3126 self.gearman_server.port)
3127 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3128 "Invalid project"):
3129 r = client.enqueue(pipeline='gate',
3130 project='project-does-not-exist',
3131 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003132 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003133 client.shutdown()
3134 self.assertEqual(r, False)
3135
3136 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3137 "Invalid pipeline"):
3138 r = client.enqueue(pipeline='pipeline-does-not-exist',
3139 project='org/project',
3140 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003141 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003142 client.shutdown()
3143 self.assertEqual(r, False)
3144
3145 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3146 "Invalid trigger"):
3147 r = client.enqueue(pipeline='gate',
3148 project='org/project',
3149 trigger='trigger-does-not-exist',
James E. Blair36658cf2013-12-06 17:53:48 -08003150 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003151 client.shutdown()
3152 self.assertEqual(r, False)
3153
3154 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3155 "Invalid change"):
3156 r = client.enqueue(pipeline='gate',
3157 project='org/project',
3158 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003159 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003160 client.shutdown()
3161 self.assertEqual(r, False)
3162
3163 self.waitUntilSettled()
3164 self.assertEqual(len(self.history), 0)
3165 self.assertEqual(len(self.builds), 0)
James E. Blair36658cf2013-12-06 17:53:48 -08003166
James E. Blairec056492016-07-22 09:45:56 -07003167 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003168 def test_client_promote(self):
3169 "Test that the RPC client can promote a change"
James E. Blair08d19992016-08-10 15:25:31 -07003170 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003171 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3172 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3173 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003174 A.addApproval('code-review', 2)
3175 B.addApproval('code-review', 2)
3176 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003177
James E. Blair8b5408c2016-08-08 15:37:46 -07003178 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3179 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3180 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003181
3182 self.waitUntilSettled()
3183
Sean Daguef39b9ca2014-01-10 21:34:35 -05003184 items = self.sched.layout.pipelines['gate'].getAllItems()
3185 enqueue_times = {}
3186 for item in items:
3187 enqueue_times[str(item.change)] = item.enqueue_time
3188
James E. Blair36658cf2013-12-06 17:53:48 -08003189 client = zuul.rpcclient.RPCClient('127.0.0.1',
3190 self.gearman_server.port)
3191 r = client.promote(pipeline='gate',
3192 change_ids=['2,1', '3,1'])
3193
Sean Daguef39b9ca2014-01-10 21:34:35 -05003194 # ensure that enqueue times are durable
3195 items = self.sched.layout.pipelines['gate'].getAllItems()
3196 for item in items:
3197 self.assertEqual(
3198 enqueue_times[str(item.change)], item.enqueue_time)
3199
James E. Blair78acec92014-02-06 07:11:32 -08003200 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003201 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003202 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003203 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003204 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003205 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003206 self.waitUntilSettled()
3207
3208 self.assertEqual(len(self.builds), 6)
3209 self.assertEqual(self.builds[0].name, 'project-test1')
3210 self.assertEqual(self.builds[1].name, 'project-test2')
3211 self.assertEqual(self.builds[2].name, 'project-test1')
3212 self.assertEqual(self.builds[3].name, 'project-test2')
3213 self.assertEqual(self.builds[4].name, 'project-test1')
3214 self.assertEqual(self.builds[5].name, 'project-test2')
3215
3216 self.assertTrue(self.job_has_changes(self.builds[0], B))
3217 self.assertFalse(self.job_has_changes(self.builds[0], A))
3218 self.assertFalse(self.job_has_changes(self.builds[0], C))
3219
3220 self.assertTrue(self.job_has_changes(self.builds[2], B))
3221 self.assertTrue(self.job_has_changes(self.builds[2], C))
3222 self.assertFalse(self.job_has_changes(self.builds[2], A))
3223
3224 self.assertTrue(self.job_has_changes(self.builds[4], B))
3225 self.assertTrue(self.job_has_changes(self.builds[4], C))
3226 self.assertTrue(self.job_has_changes(self.builds[4], A))
3227
James E. Blair08d19992016-08-10 15:25:31 -07003228 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003229 self.waitUntilSettled()
3230
3231 self.assertEqual(A.data['status'], 'MERGED')
3232 self.assertEqual(A.reported, 2)
3233 self.assertEqual(B.data['status'], 'MERGED')
3234 self.assertEqual(B.reported, 2)
3235 self.assertEqual(C.data['status'], 'MERGED')
3236 self.assertEqual(C.reported, 2)
3237
3238 client.shutdown()
3239 self.assertEqual(r, True)
3240
James E. Blairec056492016-07-22 09:45:56 -07003241 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003242 def test_client_promote_dependent(self):
3243 "Test that the RPC client can promote a dependent change"
3244 # C (depends on B) -> B -> A ; then promote C to get:
3245 # A -> C (depends on B) -> B
James E. Blair08d19992016-08-10 15:25:31 -07003246 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003247 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3248 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3249 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3250
3251 C.setDependsOn(B, 1)
3252
James E. Blair8b5408c2016-08-08 15:37:46 -07003253 A.addApproval('code-review', 2)
3254 B.addApproval('code-review', 2)
3255 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003256
James E. Blair8b5408c2016-08-08 15:37:46 -07003257 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3258 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3259 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003260
3261 self.waitUntilSettled()
3262
3263 client = zuul.rpcclient.RPCClient('127.0.0.1',
3264 self.gearman_server.port)
3265 r = client.promote(pipeline='gate',
3266 change_ids=['3,1'])
3267
James E. Blair78acec92014-02-06 07:11:32 -08003268 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003269 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003270 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003271 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003272 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003273 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003274 self.waitUntilSettled()
3275
3276 self.assertEqual(len(self.builds), 6)
3277 self.assertEqual(self.builds[0].name, 'project-test1')
3278 self.assertEqual(self.builds[1].name, 'project-test2')
3279 self.assertEqual(self.builds[2].name, 'project-test1')
3280 self.assertEqual(self.builds[3].name, 'project-test2')
3281 self.assertEqual(self.builds[4].name, 'project-test1')
3282 self.assertEqual(self.builds[5].name, 'project-test2')
3283
3284 self.assertTrue(self.job_has_changes(self.builds[0], B))
3285 self.assertFalse(self.job_has_changes(self.builds[0], A))
3286 self.assertFalse(self.job_has_changes(self.builds[0], C))
3287
3288 self.assertTrue(self.job_has_changes(self.builds[2], B))
3289 self.assertTrue(self.job_has_changes(self.builds[2], C))
3290 self.assertFalse(self.job_has_changes(self.builds[2], A))
3291
3292 self.assertTrue(self.job_has_changes(self.builds[4], B))
3293 self.assertTrue(self.job_has_changes(self.builds[4], C))
3294 self.assertTrue(self.job_has_changes(self.builds[4], A))
3295
James E. Blair08d19992016-08-10 15:25:31 -07003296 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003297 self.waitUntilSettled()
3298
3299 self.assertEqual(A.data['status'], 'MERGED')
3300 self.assertEqual(A.reported, 2)
3301 self.assertEqual(B.data['status'], 'MERGED')
3302 self.assertEqual(B.reported, 2)
3303 self.assertEqual(C.data['status'], 'MERGED')
3304 self.assertEqual(C.reported, 2)
3305
3306 client.shutdown()
3307 self.assertEqual(r, True)
3308
James E. Blairec056492016-07-22 09:45:56 -07003309 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003310 def test_client_promote_negative(self):
3311 "Test that the RPC client returns errors for promotion"
James E. Blair08d19992016-08-10 15:25:31 -07003312 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003313 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003314 A.addApproval('code-review', 2)
3315 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003316 self.waitUntilSettled()
3317
3318 client = zuul.rpcclient.RPCClient('127.0.0.1',
3319 self.gearman_server.port)
3320
3321 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3322 r = client.promote(pipeline='nonexistent',
3323 change_ids=['2,1', '3,1'])
3324 client.shutdown()
3325 self.assertEqual(r, False)
3326
3327 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3328 r = client.promote(pipeline='gate',
3329 change_ids=['4,1'])
3330 client.shutdown()
3331 self.assertEqual(r, False)
3332
James E. Blair08d19992016-08-10 15:25:31 -07003333 self.launch_server.hold_jobs_in_build = False
3334 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003335 self.waitUntilSettled()
Clark Boylan7603a372014-01-21 11:43:20 -08003336
James E. Blairec056492016-07-22 09:45:56 -07003337 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003338 def test_queue_rate_limiting(self):
3339 "Test that DependentPipelines are rate limited with dep across window"
James E. Blairf84026c2015-12-08 16:11:46 -08003340 self.updateConfigLayout(
3341 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003342 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003343 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003344 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3345 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3346 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3347
3348 C.setDependsOn(B, 1)
James E. Blair08d19992016-08-10 15:25:31 -07003349 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003350
James E. Blair8b5408c2016-08-08 15:37:46 -07003351 A.addApproval('code-review', 2)
3352 B.addApproval('code-review', 2)
3353 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003354
James E. Blair8b5408c2016-08-08 15:37:46 -07003355 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3356 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3357 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003358 self.waitUntilSettled()
3359
3360 # Only A and B will have their merge jobs queued because
3361 # window is 2.
3362 self.assertEqual(len(self.builds), 2)
3363 self.assertEqual(self.builds[0].name, 'project-merge')
3364 self.assertEqual(self.builds[1].name, 'project-merge')
3365
James E. Blair08d19992016-08-10 15:25:31 -07003366 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003367 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003368 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003369 self.waitUntilSettled()
3370
3371 # Only A and B will have their test jobs queued because
3372 # window is 2.
3373 self.assertEqual(len(self.builds), 4)
3374 self.assertEqual(self.builds[0].name, 'project-test1')
3375 self.assertEqual(self.builds[1].name, 'project-test2')
3376 self.assertEqual(self.builds[2].name, 'project-test1')
3377 self.assertEqual(self.builds[3].name, 'project-test2')
3378
James E. Blair08d19992016-08-10 15:25:31 -07003379 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003380 self.waitUntilSettled()
3381
3382 queue = self.sched.layout.pipelines['gate'].queues[0]
3383 # A failed so window is reduced by 1 to 1.
3384 self.assertEqual(queue.window, 1)
3385 self.assertEqual(queue.window_floor, 1)
3386 self.assertEqual(A.data['status'], 'NEW')
3387
3388 # Gate is reset and only B's merge job is queued because
3389 # window shrunk to 1.
3390 self.assertEqual(len(self.builds), 1)
3391 self.assertEqual(self.builds[0].name, 'project-merge')
3392
James E. Blair08d19992016-08-10 15:25:31 -07003393 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003394 self.waitUntilSettled()
3395
3396 # Only B's test jobs are queued because window is still 1.
3397 self.assertEqual(len(self.builds), 2)
3398 self.assertEqual(self.builds[0].name, 'project-test1')
3399 self.assertEqual(self.builds[1].name, 'project-test2')
3400
James E. Blair08d19992016-08-10 15:25:31 -07003401 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003402 self.waitUntilSettled()
3403
3404 # B was successfully merged so window is increased to 2.
3405 self.assertEqual(queue.window, 2)
3406 self.assertEqual(queue.window_floor, 1)
3407 self.assertEqual(B.data['status'], 'MERGED')
3408
3409 # Only C is left and its merge job is queued.
3410 self.assertEqual(len(self.builds), 1)
3411 self.assertEqual(self.builds[0].name, 'project-merge')
3412
James E. Blair08d19992016-08-10 15:25:31 -07003413 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003414 self.waitUntilSettled()
3415
3416 # After successful merge job the test jobs for C are queued.
3417 self.assertEqual(len(self.builds), 2)
3418 self.assertEqual(self.builds[0].name, 'project-test1')
3419 self.assertEqual(self.builds[1].name, 'project-test2')
3420
James E. Blair08d19992016-08-10 15:25:31 -07003421 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003422 self.waitUntilSettled()
3423
3424 # C successfully merged so window is bumped to 3.
3425 self.assertEqual(queue.window, 3)
3426 self.assertEqual(queue.window_floor, 1)
3427 self.assertEqual(C.data['status'], 'MERGED')
3428
James E. Blairec056492016-07-22 09:45:56 -07003429 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003430 def test_queue_rate_limiting_dependent(self):
3431 "Test that DependentPipelines are rate limited with dep in window"
James E. Blairf84026c2015-12-08 16:11:46 -08003432 self.updateConfigLayout(
3433 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003434 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003435 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003436 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3437 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3438 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3439
3440 B.setDependsOn(A, 1)
3441
James E. Blair08d19992016-08-10 15:25:31 -07003442 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003443
James E. Blair8b5408c2016-08-08 15:37:46 -07003444 A.addApproval('code-review', 2)
3445 B.addApproval('code-review', 2)
3446 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003447
James E. Blair8b5408c2016-08-08 15:37:46 -07003448 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3449 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3450 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003451 self.waitUntilSettled()
3452
3453 # Only A and B will have their merge jobs queued because
3454 # window is 2.
3455 self.assertEqual(len(self.builds), 2)
3456 self.assertEqual(self.builds[0].name, 'project-merge')
3457 self.assertEqual(self.builds[1].name, 'project-merge')
3458
James E. Blair08d19992016-08-10 15:25:31 -07003459 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003460 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003461 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003462 self.waitUntilSettled()
3463
3464 # Only A and B will have their test jobs queued because
3465 # window is 2.
3466 self.assertEqual(len(self.builds), 4)
3467 self.assertEqual(self.builds[0].name, 'project-test1')
3468 self.assertEqual(self.builds[1].name, 'project-test2')
3469 self.assertEqual(self.builds[2].name, 'project-test1')
3470 self.assertEqual(self.builds[3].name, 'project-test2')
3471
James E. Blair08d19992016-08-10 15:25:31 -07003472 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003473 self.waitUntilSettled()
3474
3475 queue = self.sched.layout.pipelines['gate'].queues[0]
3476 # A failed so window is reduced by 1 to 1.
3477 self.assertEqual(queue.window, 1)
3478 self.assertEqual(queue.window_floor, 1)
3479 self.assertEqual(A.data['status'], 'NEW')
3480 self.assertEqual(B.data['status'], 'NEW')
3481
3482 # Gate is reset and only C's merge job is queued because
3483 # window shrunk to 1 and A and B were dequeued.
3484 self.assertEqual(len(self.builds), 1)
3485 self.assertEqual(self.builds[0].name, 'project-merge')
3486
James E. Blair08d19992016-08-10 15:25:31 -07003487 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003488 self.waitUntilSettled()
3489
3490 # Only C's test jobs are queued because window is still 1.
3491 self.assertEqual(len(self.builds), 2)
3492 self.assertEqual(self.builds[0].name, 'project-test1')
3493 self.assertEqual(self.builds[1].name, 'project-test2')
3494
James E. Blair08d19992016-08-10 15:25:31 -07003495 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003496 self.waitUntilSettled()
3497
3498 # C was successfully merged so window is increased to 2.
3499 self.assertEqual(queue.window, 2)
3500 self.assertEqual(queue.window_floor, 1)
3501 self.assertEqual(C.data['status'], 'MERGED')
Joshua Heskethba8776a2014-01-12 14:35:40 +08003502
James E. Blairec056492016-07-22 09:45:56 -07003503 @skip("Disabled for early v3 development")
Joshua Heskethba8776a2014-01-12 14:35:40 +08003504 def test_worker_update_metadata(self):
3505 "Test if a worker can send back metadata about itself"
James E. Blair08d19992016-08-10 15:25:31 -07003506 self.launch_server.hold_jobs_in_build = True
Joshua Heskethba8776a2014-01-12 14:35:40 +08003507
3508 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003509 A.addApproval('code-review', 2)
3510 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethba8776a2014-01-12 14:35:40 +08003511 self.waitUntilSettled()
3512
3513 self.assertEqual(len(self.launcher.builds), 1)
3514
3515 self.log.debug('Current builds:')
3516 self.log.debug(self.launcher.builds)
3517
3518 start = time.time()
3519 while True:
3520 if time.time() - start > 10:
3521 raise Exception("Timeout waiting for gearman server to report "
3522 + "back to the client")
3523 build = self.launcher.builds.values()[0]
3524 if build.worker.name == "My Worker":
3525 break
3526 else:
3527 time.sleep(0)
3528
3529 self.log.debug(build)
3530 self.assertEqual("My Worker", build.worker.name)
3531 self.assertEqual("localhost", build.worker.hostname)
3532 self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips)
3533 self.assertEqual("zuul.example.org", build.worker.fqdn)
3534 self.assertEqual("FakeBuilder", build.worker.program)
3535 self.assertEqual("v1.1", build.worker.version)
3536 self.assertEqual({'something': 'else'}, build.worker.extra)
3537
James E. Blair08d19992016-08-10 15:25:31 -07003538 self.launch_server.hold_jobs_in_build = False
3539 self.launch_server.release()
Joshua Heskethba8776a2014-01-12 14:35:40 +08003540 self.waitUntilSettled()
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003541
James E. Blairec056492016-07-22 09:45:56 -07003542 @skip("Disabled for early v3 development")
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003543 def test_footer_message(self):
3544 "Test a pipeline's footer message is correctly added to the report."
James E. Blairf84026c2015-12-08 16:11:46 -08003545 self.updateConfigLayout(
3546 'tests/fixtures/layout-footer-message.yaml')
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003547 self.sched.reconfigure(self.config)
3548 self.registerJobs()
3549
3550 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003551 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003552 self.launch_server.failJob('test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003553 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003554 self.waitUntilSettled()
3555
3556 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003557 B.addApproval('code-review', 2)
3558 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003559 self.waitUntilSettled()
3560
3561 self.assertEqual(2, len(self.smtp_messages))
3562
3563 failure_body = """\
3564Build failed. For information on how to proceed, see \
3565http://wiki.example.org/Test_Failures
3566
3567- test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s
3568- test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s
3569
3570For CI problems and help debugging, contact ci@example.org"""
3571
3572 success_body = """\
3573Build succeeded.
3574
3575- test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s
3576- test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s
3577
3578For CI problems and help debugging, contact ci@example.org"""
3579
3580 self.assertEqual(failure_body, self.smtp_messages[0]['body'])
3581 self.assertEqual(success_body, self.smtp_messages[1]['body'])
Joshua Heskethb7179772014-01-30 23:30:46 +11003582
James E. Blairec056492016-07-22 09:45:56 -07003583 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003584 def test_merge_failure_reporters(self):
3585 """Check that the config is set up correctly"""
3586
James E. Blairf84026c2015-12-08 16:11:46 -08003587 self.updateConfigLayout(
3588 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003589 self.sched.reconfigure(self.config)
3590 self.registerJobs()
3591
3592 self.assertEqual(
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +00003593 "Merge Failed.\n\nThis change or one of its cross-repo "
3594 "dependencies was unable to be automatically merged with the "
3595 "current state of its repository. Please rebase the change and "
3596 "upload a new patchset.",
Joshua Heskethb7179772014-01-30 23:30:46 +11003597 self.sched.layout.pipelines['check'].merge_failure_message)
3598 self.assertEqual(
3599 "The merge failed! For more information...",
3600 self.sched.layout.pipelines['gate'].merge_failure_message)
3601
3602 self.assertEqual(
3603 len(self.sched.layout.pipelines['check'].merge_failure_actions), 1)
3604 self.assertEqual(
3605 len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2)
3606
3607 self.assertTrue(isinstance(
Joshua Heskethde958652015-11-10 19:19:50 +11003608 self.sched.layout.pipelines['check'].merge_failure_actions[0],
3609 zuul.reporter.gerrit.GerritReporter))
Joshua Heskethb7179772014-01-30 23:30:46 +11003610
3611 self.assertTrue(
3612 (
3613 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003614 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003615 zuul.reporter.smtp.SMTPReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003616 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003617 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003618 zuul.reporter.gerrit.GerritReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003619 ) or (
3620 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003621 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003622 zuul.reporter.gerrit.GerritReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003623 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003624 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003625 zuul.reporter.smtp.SMTPReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003626 )
3627 )
3628
James E. Blairec056492016-07-22 09:45:56 -07003629 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003630 def test_merge_failure_reports(self):
3631 """Check that when a change fails to merge the correct message is sent
3632 to the correct reporter"""
James E. Blairf84026c2015-12-08 16:11:46 -08003633 self.updateConfigLayout(
3634 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003635 self.sched.reconfigure(self.config)
3636 self.registerJobs()
3637
3638 # Check a test failure isn't reported to SMTP
3639 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003640 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003641 self.launch_server.failJob('project-test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003642 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003643 self.waitUntilSettled()
3644
3645 self.assertEqual(3, len(self.history)) # 3 jobs
3646 self.assertEqual(0, len(self.smtp_messages))
3647
3648 # Check a merge failure is reported to SMTP
3649 # B should be merged, but C will conflict with B
3650 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3651 B.addPatchset(['conflict'])
3652 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3653 C.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003654 B.addApproval('code-review', 2)
3655 C.addApproval('code-review', 2)
3656 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3657 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003658 self.waitUntilSettled()
3659
3660 self.assertEqual(6, len(self.history)) # A and B jobs
3661 self.assertEqual(1, len(self.smtp_messages))
3662 self.assertEqual('The merge failed! For more information...',
3663 self.smtp_messages[0]['body'])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003664
James E. Blairec056492016-07-22 09:45:56 -07003665 @skip("Disabled for early v3 development")
James E. Blairf760f0e2016-02-09 08:44:52 -08003666 def test_default_merge_failure_reports(self):
3667 """Check that the default merge failure reports are correct."""
3668
3669 # A should report success, B should report merge failure.
3670 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3671 A.addPatchset(['conflict'])
3672 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3673 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003674 A.addApproval('code-review', 2)
3675 B.addApproval('code-review', 2)
3676 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3677 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairf760f0e2016-02-09 08:44:52 -08003678 self.waitUntilSettled()
3679
3680 self.assertEqual(3, len(self.history)) # A jobs
3681 self.assertEqual(A.reported, 2)
3682 self.assertEqual(B.reported, 2)
3683 self.assertEqual(A.data['status'], 'MERGED')
3684 self.assertEqual(B.data['status'], 'NEW')
3685 self.assertIn('Build succeeded', A.messages[1])
3686 self.assertIn('Merge Failed', B.messages[1])
3687 self.assertIn('automatically merged', B.messages[1])
3688 self.assertNotIn('logs.example.com', B.messages[1])
3689 self.assertNotIn('SKIPPED', B.messages[1])
3690
James E. Blairec056492016-07-22 09:45:56 -07003691 @skip("Disabled for early v3 development")
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003692 def test_swift_instructions(self):
3693 "Test that the correct swift instructions are sent to the workers"
James E. Blairf84026c2015-12-08 16:11:46 -08003694 self.updateConfigLayout(
3695 'tests/fixtures/layout-swift.yaml')
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003696 self.sched.reconfigure(self.config)
3697 self.registerJobs()
3698
James E. Blair08d19992016-08-10 15:25:31 -07003699 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003700 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3701
James E. Blair8b5408c2016-08-08 15:37:46 -07003702 A.addApproval('code-review', 2)
3703 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003704 self.waitUntilSettled()
3705
3706 self.assertEqual(
3707 "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/"
3708 "gate/test-merge/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003709 self.builds[0].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003710 self.assertEqual(5,
3711 len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY'].
3712 split('\n')))
3713 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters)
3714
3715 self.assertEqual(
3716 "https://storage.example.org/V1/AUTH_account/logs/1/1/1/"
3717 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003718 self.builds[1].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003719 self.assertEqual(5,
3720 len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY'].
3721 split('\n')))
3722 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters)
3723
3724 self.assertEqual(
3725 "https://storage.example.org/V1/AUTH_account/stash/1/1/1/"
3726 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003727 self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003728 self.assertEqual(5,
3729 len(self.builds[1].
3730 parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n')))
3731 self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters)
3732
James E. Blair08d19992016-08-10 15:25:31 -07003733 self.launch_server.hold_jobs_in_build = False
3734 self.launch_server.release()
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003735 self.waitUntilSettled()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003736
James E. Blairec056492016-07-22 09:45:56 -07003737 @skip("Disabled for early v3 development")
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003738 def test_client_get_running_jobs(self):
3739 "Test that the RPC client can get a list of running jobs"
James E. Blair08d19992016-08-10 15:25:31 -07003740 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003741 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003742 A.addApproval('code-review', 2)
3743 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003744 self.waitUntilSettled()
3745
3746 client = zuul.rpcclient.RPCClient('127.0.0.1',
3747 self.gearman_server.port)
3748
3749 # Wait for gearman server to send the initial workData back to zuul
3750 start = time.time()
3751 while True:
3752 if time.time() - start > 10:
3753 raise Exception("Timeout waiting for gearman server to report "
3754 + "back to the client")
3755 build = self.launcher.builds.values()[0]
3756 if build.worker.name == "My Worker":
3757 break
3758 else:
3759 time.sleep(0)
3760
3761 running_items = client.get_running_jobs()
3762
3763 self.assertEqual(1, len(running_items))
3764 running_item = running_items[0]
3765 self.assertEqual([], running_item['failing_reasons'])
3766 self.assertEqual([], running_item['items_behind'])
3767 self.assertEqual('https://hostname/1', running_item['url'])
3768 self.assertEqual(None, running_item['item_ahead'])
3769 self.assertEqual('org/project', running_item['project'])
3770 self.assertEqual(None, running_item['remaining_time'])
3771 self.assertEqual(True, running_item['active'])
3772 self.assertEqual('1,1', running_item['id'])
3773
3774 self.assertEqual(3, len(running_item['jobs']))
3775 for job in running_item['jobs']:
3776 if job['name'] == 'project-merge':
3777 self.assertEqual('project-merge', job['name'])
3778 self.assertEqual('gate', job['pipeline'])
3779 self.assertEqual(False, job['retry'])
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003780 self.assertEqual('https://server/job/project-merge/0/',
3781 job['url'])
3782 self.assertEqual(7, len(job['worker']))
3783 self.assertEqual(False, job['canceled'])
3784 self.assertEqual(True, job['voting'])
3785 self.assertEqual(None, job['result'])
3786 self.assertEqual('gate', job['pipeline'])
3787 break
3788
James E. Blair08d19992016-08-10 15:25:31 -07003789 self.launch_server.hold_jobs_in_build = False
3790 self.launch_server.release()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003791 self.waitUntilSettled()
3792
3793 running_items = client.get_running_jobs()
3794 self.assertEqual(0, len(running_items))
James E. Blairbadc1ad2014-04-28 13:55:14 -07003795
James E. Blairec056492016-07-22 09:45:56 -07003796 @skip("Disabled for early v3 development")
James E. Blairbadc1ad2014-04-28 13:55:14 -07003797 def test_nonvoting_pipeline(self):
3798 "Test that a nonvoting pipeline (experimental) can still report"
3799
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003800 A = self.fake_gerrit.addFakeChange('org/experimental-project',
3801 'master', 'A')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003802 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3803 self.waitUntilSettled()
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003804 self.assertEqual(
3805 self.getJobFromHistory('experimental-project-test').result,
3806 'SUCCESS')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003807 self.assertEqual(A.reported, 1)
James E. Blair5ee24252014-12-30 10:12:29 -08003808
James E. Blairec056492016-07-22 09:45:56 -07003809 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003810 def test_crd_gate(self):
3811 "Test cross-repo dependencies"
3812 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3813 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003814 A.addApproval('code-review', 2)
3815 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003816
3817 AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2')
3818 AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1')
3819 AM2.setMerged()
3820 AM1.setMerged()
3821
3822 BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2')
3823 BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1')
3824 BM2.setMerged()
3825 BM1.setMerged()
3826
3827 # A -> AM1 -> AM2
3828 # B -> BM1 -> BM2
3829 # A Depends-On: B
3830 # M2 is here to make sure it is never queried. If it is, it
3831 # means zuul is walking down the entire history of merged
3832 # changes.
3833
3834 B.setDependsOn(BM1, 1)
3835 BM1.setDependsOn(BM2, 1)
3836
3837 A.setDependsOn(AM1, 1)
3838 AM1.setDependsOn(AM2, 1)
3839
3840 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3841 A.subject, B.data['id'])
3842
James E. Blair8b5408c2016-08-08 15:37:46 -07003843 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003844 self.waitUntilSettled()
3845
3846 self.assertEqual(A.data['status'], 'NEW')
3847 self.assertEqual(B.data['status'], 'NEW')
3848
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11003849 for connection in self.connections.values():
3850 connection.maintainCache([])
James E. Blair5ee24252014-12-30 10:12:29 -08003851
James E. Blair08d19992016-08-10 15:25:31 -07003852 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003853 B.addApproval('approved', 1)
3854 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003855 self.waitUntilSettled()
3856
James E. Blair08d19992016-08-10 15:25:31 -07003857 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003858 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003859 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003860 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003861 self.launch_server.hold_jobs_in_build = False
3862 self.launch_server.release()
James E. Blair5ee24252014-12-30 10:12:29 -08003863 self.waitUntilSettled()
3864
3865 self.assertEqual(AM2.queried, 0)
3866 self.assertEqual(BM2.queried, 0)
3867 self.assertEqual(A.data['status'], 'MERGED')
3868 self.assertEqual(B.data['status'], 'MERGED')
3869 self.assertEqual(A.reported, 2)
3870 self.assertEqual(B.reported, 2)
3871
James E. Blair8f78d882015-02-05 08:51:37 -08003872 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3873 '2,1 1,1')
3874
James E. Blairec056492016-07-22 09:45:56 -07003875 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003876 def test_crd_branch(self):
3877 "Test cross-repo dependencies in multiple branches"
3878 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3879 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3880 C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C')
3881 C.data['id'] = B.data['id']
James E. Blair8b5408c2016-08-08 15:37:46 -07003882 A.addApproval('code-review', 2)
3883 B.addApproval('code-review', 2)
3884 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003885
3886 # A Depends-On: B+C
3887 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3888 A.subject, B.data['id'])
3889
James E. Blair08d19992016-08-10 15:25:31 -07003890 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003891 B.addApproval('approved', 1)
3892 C.addApproval('approved', 1)
3893 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08003894 self.waitUntilSettled()
3895
James E. Blair08d19992016-08-10 15:25:31 -07003896 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003897 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003898 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003899 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003900 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003901 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003902 self.launch_server.hold_jobs_in_build = False
3903 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08003904 self.waitUntilSettled()
3905
3906 self.assertEqual(A.data['status'], 'MERGED')
3907 self.assertEqual(B.data['status'], 'MERGED')
3908 self.assertEqual(C.data['status'], 'MERGED')
3909 self.assertEqual(A.reported, 2)
3910 self.assertEqual(B.reported, 2)
3911 self.assertEqual(C.reported, 2)
3912
3913 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3914 '2,1 3,1 1,1')
3915
James E. Blairec056492016-07-22 09:45:56 -07003916 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003917 def test_crd_multiline(self):
3918 "Test multiple depends-on lines in commit"
3919 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3920 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3921 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003922 A.addApproval('code-review', 2)
3923 B.addApproval('code-review', 2)
3924 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003925
3926 # A Depends-On: B+C
3927 A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % (
3928 A.subject, B.data['id'], C.data['id'])
3929
James E. Blair08d19992016-08-10 15:25:31 -07003930 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003931 B.addApproval('approved', 1)
3932 C.addApproval('approved', 1)
3933 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08003934 self.waitUntilSettled()
3935
James E. Blair08d19992016-08-10 15:25:31 -07003936 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003937 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003938 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003939 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003940 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003941 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003942 self.launch_server.hold_jobs_in_build = False
3943 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08003944 self.waitUntilSettled()
3945
3946 self.assertEqual(A.data['status'], 'MERGED')
3947 self.assertEqual(B.data['status'], 'MERGED')
3948 self.assertEqual(C.data['status'], 'MERGED')
3949 self.assertEqual(A.reported, 2)
3950 self.assertEqual(B.reported, 2)
3951 self.assertEqual(C.reported, 2)
3952
3953 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3954 '2,1 3,1 1,1')
James E. Blair5ee24252014-12-30 10:12:29 -08003955
James E. Blairec056492016-07-22 09:45:56 -07003956 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003957 def test_crd_unshared_gate(self):
3958 "Test cross-repo dependencies in unshared gate queues"
3959 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3960 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003961 A.addApproval('code-review', 2)
3962 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003963
3964 # A Depends-On: B
3965 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3966 A.subject, B.data['id'])
3967
3968 # A and B do not share a queue, make sure that A is unable to
3969 # enqueue B (and therefore, A is unable to be enqueued).
James E. Blair8b5408c2016-08-08 15:37:46 -07003970 B.addApproval('approved', 1)
3971 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003972 self.waitUntilSettled()
3973
3974 self.assertEqual(A.data['status'], 'NEW')
3975 self.assertEqual(B.data['status'], 'NEW')
3976 self.assertEqual(A.reported, 0)
3977 self.assertEqual(B.reported, 0)
3978 self.assertEqual(len(self.history), 0)
3979
3980 # Enqueue and merge B alone.
James E. Blair8b5408c2016-08-08 15:37:46 -07003981 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003982 self.waitUntilSettled()
3983
3984 self.assertEqual(B.data['status'], 'MERGED')
3985 self.assertEqual(B.reported, 2)
3986
3987 # Now that B is merged, A should be able to be enqueued and
3988 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07003989 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003990 self.waitUntilSettled()
3991
3992 self.assertEqual(A.data['status'], 'MERGED')
3993 self.assertEqual(A.reported, 2)
3994
James E. Blairec056492016-07-22 09:45:56 -07003995 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07003996 def test_crd_gate_reverse(self):
3997 "Test reverse cross-repo dependencies"
3998 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3999 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004000 A.addApproval('code-review', 2)
4001 B.addApproval('code-review', 2)
James E. Blair96698e22015-04-02 07:48:21 -07004002
4003 # A Depends-On: B
4004
4005 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4006 A.subject, B.data['id'])
4007
James E. Blair8b5408c2016-08-08 15:37:46 -07004008 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004009 self.waitUntilSettled()
4010
4011 self.assertEqual(A.data['status'], 'NEW')
4012 self.assertEqual(B.data['status'], 'NEW')
4013
James E. Blair08d19992016-08-10 15:25:31 -07004014 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004015 A.addApproval('approved', 1)
4016 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004017 self.waitUntilSettled()
4018
James E. Blair08d19992016-08-10 15:25:31 -07004019 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004020 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004021 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004022 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004023 self.launch_server.hold_jobs_in_build = False
4024 self.launch_server.release()
James E. Blair96698e22015-04-02 07:48:21 -07004025 self.waitUntilSettled()
4026
4027 self.assertEqual(A.data['status'], 'MERGED')
4028 self.assertEqual(B.data['status'], 'MERGED')
4029 self.assertEqual(A.reported, 2)
4030 self.assertEqual(B.reported, 2)
4031
4032 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4033 '2,1 1,1')
4034
James E. Blairec056492016-07-22 09:45:56 -07004035 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004036 def test_crd_cycle(self):
4037 "Test cross-repo dependency cycles"
4038 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4039 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004040 A.addApproval('code-review', 2)
4041 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004042
4043 # A -> B -> A (via commit-depends)
4044
4045 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4046 A.subject, B.data['id'])
4047 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4048 B.subject, A.data['id'])
4049
James E. Blair8b5408c2016-08-08 15:37:46 -07004050 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004051 self.waitUntilSettled()
4052
4053 self.assertEqual(A.reported, 0)
4054 self.assertEqual(B.reported, 0)
4055 self.assertEqual(A.data['status'], 'NEW')
4056 self.assertEqual(B.data['status'], 'NEW')
James E. Blairbfb8e042014-12-30 17:01:44 -08004057
James E. Blairec056492016-07-22 09:45:56 -07004058 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004059 def test_crd_gate_unknown(self):
4060 "Test unknown projects in dependent pipeline"
4061 self.init_repo("org/unknown")
4062 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4063 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004064 A.addApproval('code-review', 2)
4065 B.addApproval('code-review', 2)
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004066
4067 # A Depends-On: B
4068 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4069 A.subject, B.data['id'])
4070
James E. Blair8b5408c2016-08-08 15:37:46 -07004071 B.addApproval('approved', 1)
4072 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004073 self.waitUntilSettled()
4074
4075 # Unknown projects cannot share a queue with any other
4076 # since they don't have common jobs with any other (they have no jobs).
4077 # Changes which depend on unknown project changes
4078 # should not be processed in dependent pipeline
4079 self.assertEqual(A.data['status'], 'NEW')
4080 self.assertEqual(B.data['status'], 'NEW')
4081 self.assertEqual(A.reported, 0)
4082 self.assertEqual(B.reported, 0)
4083 self.assertEqual(len(self.history), 0)
4084
4085 # Simulate change B being gated outside this layout
James E. Blair8b5408c2016-08-08 15:37:46 -07004086 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004087 B.setMerged()
4088 self.waitUntilSettled()
4089 self.assertEqual(len(self.history), 0)
4090
4091 # Now that B is merged, A should be able to be enqueued and
4092 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004093 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004094 self.waitUntilSettled()
4095
4096 self.assertEqual(A.data['status'], 'MERGED')
4097 self.assertEqual(A.reported, 2)
4098 self.assertEqual(B.data['status'], 'MERGED')
4099 self.assertEqual(B.reported, 0)
4100
James E. Blairec056492016-07-22 09:45:56 -07004101 @skip("Disabled for early v3 development")
James E. Blairbfb8e042014-12-30 17:01:44 -08004102 def test_crd_check(self):
4103 "Test cross-repo dependencies in independent pipelines"
4104
4105 self.gearman_server.hold_jobs_in_queue = True
4106 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4107 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4108
4109 # A Depends-On: B
4110 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4111 A.subject, B.data['id'])
4112
4113 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4114 self.waitUntilSettled()
4115
4116 queue = self.gearman_server.getQueue()
4117 ref = self.getParameter(queue[-1], 'ZUUL_REF')
4118 self.gearman_server.hold_jobs_in_queue = False
4119 self.gearman_server.release()
4120 self.waitUntilSettled()
4121
4122 path = os.path.join(self.git_root, "org/project1")
4123 repo = git.Repo(path)
4124 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4125 repo_messages.reverse()
4126 correct_messages = ['initial commit', 'A-1']
4127 self.assertEqual(repo_messages, correct_messages)
4128
4129 path = os.path.join(self.git_root, "org/project2")
4130 repo = git.Repo(path)
4131 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4132 repo_messages.reverse()
4133 correct_messages = ['initial commit', 'B-1']
4134 self.assertEqual(repo_messages, correct_messages)
4135
4136 self.assertEqual(A.data['status'], 'NEW')
4137 self.assertEqual(B.data['status'], 'NEW')
4138 self.assertEqual(A.reported, 1)
4139 self.assertEqual(B.reported, 0)
4140
4141 self.assertEqual(self.history[0].changes, '2,1 1,1')
4142 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair8f78d882015-02-05 08:51:37 -08004143
James E. Blairec056492016-07-22 09:45:56 -07004144 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004145 def test_crd_check_git_depends(self):
4146 "Test single-repo dependencies in independent pipelines"
James E. Blairb8c16472015-05-05 14:55:26 -07004147 self.gearman_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004148 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4149 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4150
4151 # Add two git-dependent changes and make sure they both report
4152 # success.
4153 B.setDependsOn(A, 1)
4154 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4155 self.waitUntilSettled()
4156 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4157 self.waitUntilSettled()
4158
James E. Blairb8c16472015-05-05 14:55:26 -07004159 self.orderedRelease()
4160 self.gearman_server.hold_jobs_in_build = False
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004161 self.waitUntilSettled()
4162
4163 self.assertEqual(A.data['status'], 'NEW')
4164 self.assertEqual(B.data['status'], 'NEW')
4165 self.assertEqual(A.reported, 1)
4166 self.assertEqual(B.reported, 1)
4167
4168 self.assertEqual(self.history[0].changes, '1,1')
4169 self.assertEqual(self.history[-1].changes, '1,1 2,1')
4170 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4171
4172 self.assertIn('Build succeeded', A.messages[0])
4173 self.assertIn('Build succeeded', B.messages[0])
4174
James E. Blairec056492016-07-22 09:45:56 -07004175 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004176 def test_crd_check_duplicate(self):
4177 "Test duplicate check in independent pipelines"
James E. Blair08d19992016-08-10 15:25:31 -07004178 self.launch_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004179 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4180 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4181 check_pipeline = self.sched.layout.pipelines['check']
4182
4183 # Add two git-dependent changes...
4184 B.setDependsOn(A, 1)
4185 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4186 self.waitUntilSettled()
4187 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4188
4189 # ...make sure the live one is not duplicated...
4190 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4191 self.waitUntilSettled()
4192 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4193
4194 # ...but the non-live one is able to be.
4195 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4196 self.waitUntilSettled()
4197 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4198
Clark Boylandd849822015-03-02 12:38:14 -08004199 # Release jobs in order to avoid races with change A jobs
4200 # finishing before change B jobs.
James E. Blaird7650852015-05-07 15:47:37 -07004201 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07004202 self.launch_server.hold_jobs_in_build = False
4203 self.launch_server.release()
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004204 self.waitUntilSettled()
4205
4206 self.assertEqual(A.data['status'], 'NEW')
4207 self.assertEqual(B.data['status'], 'NEW')
4208 self.assertEqual(A.reported, 1)
4209 self.assertEqual(B.reported, 1)
4210
4211 self.assertEqual(self.history[0].changes, '1,1 2,1')
4212 self.assertEqual(self.history[1].changes, '1,1')
4213 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4214
4215 self.assertIn('Build succeeded', A.messages[0])
4216 self.assertIn('Build succeeded', B.messages[0])
4217
James E. Blairec056492016-07-22 09:45:56 -07004218 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004219 def _test_crd_check_reconfiguration(self, project1, project2):
James E. Blair8f78d882015-02-05 08:51:37 -08004220 "Test cross-repo dependencies re-enqueued in independent pipelines"
4221
4222 self.gearman_server.hold_jobs_in_queue = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004223 A = self.fake_gerrit.addFakeChange(project1, 'master', 'A')
4224 B = self.fake_gerrit.addFakeChange(project2, 'master', 'B')
James E. Blair8f78d882015-02-05 08:51:37 -08004225
4226 # A Depends-On: B
4227 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4228 A.subject, B.data['id'])
4229
4230 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4231 self.waitUntilSettled()
4232
4233 self.sched.reconfigure(self.config)
4234
4235 # Make sure the items still share a change queue, and the
4236 # first one is not live.
4237 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1)
4238 queue = self.sched.layout.pipelines['check'].queues[0]
4239 first_item = queue.queue[0]
4240 for item in queue.queue:
4241 self.assertEqual(item.queue, first_item.queue)
4242 self.assertFalse(first_item.live)
4243 self.assertTrue(queue.queue[1].live)
4244
4245 self.gearman_server.hold_jobs_in_queue = False
4246 self.gearman_server.release()
4247 self.waitUntilSettled()
4248
4249 self.assertEqual(A.data['status'], 'NEW')
4250 self.assertEqual(B.data['status'], 'NEW')
4251 self.assertEqual(A.reported, 1)
4252 self.assertEqual(B.reported, 0)
4253
4254 self.assertEqual(self.history[0].changes, '2,1 1,1')
4255 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair17dd6772015-02-09 14:45:18 -08004256
James E. Blairec056492016-07-22 09:45:56 -07004257 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004258 def test_crd_check_reconfiguration(self):
4259 self._test_crd_check_reconfiguration('org/project1', 'org/project2')
4260
James E. Blairec056492016-07-22 09:45:56 -07004261 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004262 def test_crd_undefined_project(self):
4263 """Test that undefined projects in dependencies are handled for
4264 independent pipelines"""
4265 # It's a hack for fake gerrit,
4266 # as it implies repo creation upon the creation of any change
4267 self.init_repo("org/unknown")
4268 self._test_crd_check_reconfiguration('org/project1', 'org/unknown')
4269
James E. Blairec056492016-07-22 09:45:56 -07004270 @skip("Disabled for early v3 development")
James E. Blair17dd6772015-02-09 14:45:18 -08004271 def test_crd_check_ignore_dependencies(self):
4272 "Test cross-repo dependencies can be ignored"
James E. Blairf84026c2015-12-08 16:11:46 -08004273 self.updateConfigLayout(
4274 'tests/fixtures/layout-ignore-dependencies.yaml')
James E. Blair17dd6772015-02-09 14:45:18 -08004275 self.sched.reconfigure(self.config)
4276 self.registerJobs()
4277
4278 self.gearman_server.hold_jobs_in_queue = True
4279 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4280 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4281 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
4282
4283 # A Depends-On: B
4284 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4285 A.subject, B.data['id'])
4286 # C git-depends on B
4287 C.setDependsOn(B, 1)
4288 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4289 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4290 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4291 self.waitUntilSettled()
4292
4293 # Make sure none of the items share a change queue, and all
4294 # are live.
4295 check_pipeline = self.sched.layout.pipelines['check']
4296 self.assertEqual(len(check_pipeline.queues), 3)
4297 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4298 for item in check_pipeline.getAllItems():
4299 self.assertTrue(item.live)
4300
4301 self.gearman_server.hold_jobs_in_queue = False
4302 self.gearman_server.release()
4303 self.waitUntilSettled()
4304
4305 self.assertEqual(A.data['status'], 'NEW')
4306 self.assertEqual(B.data['status'], 'NEW')
4307 self.assertEqual(C.data['status'], 'NEW')
4308 self.assertEqual(A.reported, 1)
4309 self.assertEqual(B.reported, 1)
4310 self.assertEqual(C.reported, 1)
4311
4312 # Each job should have tested exactly one change
4313 for job in self.history:
4314 self.assertEqual(len(job.changes.split()), 1)
James E. Blair96698e22015-04-02 07:48:21 -07004315
James E. Blairec056492016-07-22 09:45:56 -07004316 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004317 def test_crd_check_transitive(self):
4318 "Test transitive cross-repo dependencies"
4319 # Specifically, if A -> B -> C, and C gets a new patchset and
4320 # A gets a new patchset, ensure the test of A,2 includes B,1
4321 # and C,2 (not C,1 which would indicate stale data in the
4322 # cache for B).
4323 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4324 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4325 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
4326
4327 # A Depends-On: B
4328 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4329 A.subject, B.data['id'])
4330
4331 # B Depends-On: C
4332 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4333 B.subject, C.data['id'])
4334
4335 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4336 self.waitUntilSettled()
4337 self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1')
4338
4339 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4340 self.waitUntilSettled()
4341 self.assertEqual(self.history[-1].changes, '3,1 2,1')
4342
4343 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4344 self.waitUntilSettled()
4345 self.assertEqual(self.history[-1].changes, '3,1')
4346
4347 C.addPatchset()
4348 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2))
4349 self.waitUntilSettled()
4350 self.assertEqual(self.history[-1].changes, '3,2')
4351
4352 A.addPatchset()
4353 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
4354 self.waitUntilSettled()
4355 self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004356
James E. Blairec056492016-07-22 09:45:56 -07004357 @skip("Disabled for early v3 development")
James E. Blair92464a22016-04-05 10:21:26 -07004358 def test_crd_cycle_join(self):
4359 "Test an updated change creates a cycle"
4360 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
4361
4362 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4363 self.waitUntilSettled()
4364
4365 # Create B->A
4366 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4367 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4368 B.subject, A.data['id'])
4369 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4370 self.waitUntilSettled()
4371
4372 # Update A to add A->B (a cycle).
4373 A.addPatchset()
4374 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4375 A.subject, B.data['id'])
4376 # Normally we would submit the patchset-created event for
4377 # processing here, however, we have no way of noting whether
4378 # the dependency cycle detection correctly raised an
4379 # exception, so instead, we reach into the source driver and
4380 # call the method that would ultimately be called by the event
4381 # processing.
4382
4383 source = self.sched.layout.pipelines['gate'].source
4384 with testtools.ExpectedException(
4385 Exception, "Dependency cycle detected"):
4386 source._getChange(u'1', u'2', True)
4387 self.log.debug("Got expected dependency cycle exception")
4388
4389 # Now if we update B to remove the depends-on, everything
4390 # should be okay. B; A->B
4391
4392 B.addPatchset()
4393 B.data['commitMessage'] = '%s\n' % (B.subject,)
4394 source._getChange(u'1', u'2', True)
4395 source._getChange(u'2', u'2', True)
4396
James E. Blairec056492016-07-22 09:45:56 -07004397 @skip("Disabled for early v3 development")
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004398 def test_disable_at(self):
4399 "Test a pipeline will only report to the disabled trigger when failing"
4400
James E. Blairf84026c2015-12-08 16:11:46 -08004401 self.updateConfigLayout(
4402 'tests/fixtures/layout-disable-at.yaml')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004403 self.sched.reconfigure(self.config)
4404
4405 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4406 self.assertEqual(
4407 0, self.sched.layout.pipelines['check']._consecutive_failures)
4408 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4409
4410 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4411 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
4412 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
4413 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
4414 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
4415 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
4416 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
4417 H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H')
4418 I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I')
4419 J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J')
4420 K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K')
4421
James E. Blair08d19992016-08-10 15:25:31 -07004422 self.launch_server.failJob('project-test1', A)
4423 self.launch_server.failJob('project-test1', B)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004424 # Let C pass, resetting the counter
James E. Blair08d19992016-08-10 15:25:31 -07004425 self.launch_server.failJob('project-test1', D)
4426 self.launch_server.failJob('project-test1', E)
4427 self.launch_server.failJob('project-test1', F)
4428 self.launch_server.failJob('project-test1', G)
4429 self.launch_server.failJob('project-test1', H)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004430 # I also passes but should only report to the disabled reporters
James E. Blair08d19992016-08-10 15:25:31 -07004431 self.launch_server.failJob('project-test1', J)
4432 self.launch_server.failJob('project-test1', K)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004433
4434 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4435 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4436 self.waitUntilSettled()
4437
4438 self.assertEqual(
4439 2, self.sched.layout.pipelines['check']._consecutive_failures)
4440 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4441
4442 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4443 self.waitUntilSettled()
4444
4445 self.assertEqual(
4446 0, self.sched.layout.pipelines['check']._consecutive_failures)
4447 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4448
4449 self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1))
4450 self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1))
4451 self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1))
4452 self.waitUntilSettled()
4453
4454 # We should be disabled now
4455 self.assertEqual(
4456 3, self.sched.layout.pipelines['check']._consecutive_failures)
4457 self.assertTrue(self.sched.layout.pipelines['check']._disabled)
4458
4459 # We need to wait between each of these patches to make sure the
4460 # smtp messages come back in an expected order
4461 self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1))
4462 self.waitUntilSettled()
4463 self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1))
4464 self.waitUntilSettled()
4465 self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1))
4466 self.waitUntilSettled()
4467
4468 # The first 6 (ABCDEF) jobs should have reported back to gerrt thus
4469 # leaving a message on each change
4470 self.assertEqual(1, len(A.messages))
4471 self.assertIn('Build failed.', A.messages[0])
4472 self.assertEqual(1, len(B.messages))
4473 self.assertIn('Build failed.', B.messages[0])
4474 self.assertEqual(1, len(C.messages))
4475 self.assertIn('Build succeeded.', C.messages[0])
4476 self.assertEqual(1, len(D.messages))
4477 self.assertIn('Build failed.', D.messages[0])
4478 self.assertEqual(1, len(E.messages))
4479 self.assertIn('Build failed.', E.messages[0])
4480 self.assertEqual(1, len(F.messages))
4481 self.assertIn('Build failed.', F.messages[0])
4482
4483 # The last 3 (GHI) would have only reported via smtp.
4484 self.assertEqual(3, len(self.smtp_messages))
4485 self.assertEqual(0, len(G.messages))
4486 self.assertIn('Build failed.', self.smtp_messages[0]['body'])
4487 self.assertIn('/7/1/check', self.smtp_messages[0]['body'])
4488 self.assertEqual(0, len(H.messages))
4489 self.assertIn('Build failed.', self.smtp_messages[1]['body'])
4490 self.assertIn('/8/1/check', self.smtp_messages[1]['body'])
4491 self.assertEqual(0, len(I.messages))
4492 self.assertIn('Build succeeded.', self.smtp_messages[2]['body'])
4493 self.assertIn('/9/1/check', self.smtp_messages[2]['body'])
4494
4495 # Now reload the configuration (simulate a HUP) to check the pipeline
4496 # comes out of disabled
4497 self.sched.reconfigure(self.config)
4498
4499 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4500 self.assertEqual(
4501 0, self.sched.layout.pipelines['check']._consecutive_failures)
4502 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4503
4504 self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1))
4505 self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1))
4506 self.waitUntilSettled()
4507
4508 self.assertEqual(
4509 2, self.sched.layout.pipelines['check']._consecutive_failures)
4510 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4511
4512 # J and K went back to gerrit
4513 self.assertEqual(1, len(J.messages))
4514 self.assertIn('Build failed.', J.messages[0])
4515 self.assertEqual(1, len(K.messages))
4516 self.assertIn('Build failed.', K.messages[0])
4517 # No more messages reported via smtp
4518 self.assertEqual(3, len(self.smtp_messages))
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004519
James E. Blairec056492016-07-22 09:45:56 -07004520 @skip("Disabled for early v3 development")
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004521 def test_success_pattern(self):
4522 "Ensure bad build params are ignored"
4523
4524 # Use SMTP reporter to grab the result message easier
4525 self.init_repo("org/docs")
4526 self.config.set('zuul', 'layout_config',
4527 'tests/fixtures/layout-success-pattern.yaml')
4528 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07004529 self.launch_server.hold_jobs_in_build = True
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004530 self.registerJobs()
4531
4532 A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A')
4533 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4534 self.waitUntilSettled()
4535
4536 # Grab build id
4537 self.assertEqual(len(self.builds), 1)
4538 uuid = self.builds[0].unique[:7]
4539
James E. Blair08d19992016-08-10 15:25:31 -07004540 self.launch_server.hold_jobs_in_build = False
4541 self.launch_server.release()
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004542 self.waitUntilSettled()
4543
4544 self.assertEqual(len(self.smtp_messages), 1)
4545 body = self.smtp_messages[0]['body'].splitlines()
4546 self.assertEqual('Build succeeded.', body[0])
4547
4548 self.assertIn(
4549 '- docs-draft-test http://docs-draft.example.org/1/1/1/check/'
4550 'docs-draft-test/%s/publish-docs/' % uuid,
4551 body[2])
4552 self.assertIn(
4553 '- docs-draft-test2 https://server/job/docs-draft-test2/1/',
4554 body[3])