blob: 430f24ef63d7bc65ef881bdce0ead0754a4e905b [file] [log] [blame]
Antoine Musso45dd2cb2014-01-29 17:17:43 +01001#!/usr/bin/env python
2
3# Copyright 2012 Hewlett-Packard Development Company, L.P.
4# Copyright 2014 Wikimedia Foundation Inc.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import logging
19import os
20import shutil
James E. Blair217b10d2015-01-08 16:25:28 -080021import time
James E. Blaird8af5422017-05-24 13:59:40 -070022from unittest import skip
Antoine Musso45dd2cb2014-01-29 17:17:43 +010023
24import git
25
26import zuul.lib.cloner
27
James E. Blaird8af5422017-05-24 13:59:40 -070028from tests.base import ZuulTestCase, simple_layout
Antoine Musso45dd2cb2014-01-29 17:17:43 +010029
Antoine Musso45dd2cb2014-01-29 17:17:43 +010030
31class TestCloner(ZuulTestCase):
James E. Blaird8af5422017-05-24 13:59:40 -070032 tenant_config_file = 'config/single-tenant/main.yaml'
Antoine Musso45dd2cb2014-01-29 17:17:43 +010033
34 log = logging.getLogger("zuul.test.cloner")
Antoine Musso45dd2cb2014-01-29 17:17:43 +010035
James E. Blaird8af5422017-05-24 13:59:40 -070036 @skip("Disabled for early v3 development")
James E. Blair48ff4d52014-08-25 15:07:21 -070037 def test_cache_dir(self):
38 projects = ['org/project1', 'org/project2']
39 cache_root = os.path.join(self.test_root, "cache")
40 for project in projects:
41 upstream_repo_path = os.path.join(self.upstream_root, project)
42 cache_repo_path = os.path.join(cache_root, project)
43 git.Repo.clone_from(upstream_repo_path, cache_repo_path)
44
45 self.worker.hold_jobs_in_build = True
46 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
47 A.addApproval('CRVW', 2)
48 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
49
50 self.waitUntilSettled()
51
52 self.assertEquals(1, len(self.builds), "One build is running")
53
54 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
55 B.setMerged()
56
57 upstream = self.getUpstreamRepos(projects)
Joshua Hesketh29d99b72014-08-19 16:27:42 +100058 states = [{
59 'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
60 'org/project2': str(upstream['org/project2'].commit('master')),
61 }]
James E. Blair48ff4d52014-08-25 15:07:21 -070062
63 for number, build in enumerate(self.builds):
64 self.log.debug("Build parameters: %s", build.parameters)
65 cloner = zuul.lib.cloner.Cloner(
66 git_base_url=self.upstream_root,
67 projects=projects,
68 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -070069 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blair48ff4d52014-08-25 15:07:21 -070070 zuul_branch=build.parameters['ZUUL_BRANCH'],
71 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -050072 zuul_url=self.src_root,
James E. Blair48ff4d52014-08-25 15:07:21 -070073 cache_dir=cache_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +100074 )
James E. Blair48ff4d52014-08-25 15:07:21 -070075 cloner.execute()
76 work = self.getWorkspaceRepos(projects)
77 state = states[number]
78
79 for project in projects:
80 self.assertEquals(state[project],
81 str(work[project].commit('HEAD')),
82 'Project %s commit for build %s should '
83 'be correct' % (project, number))
84
85 work = self.getWorkspaceRepos(projects)
James E. Blair8cce42e2016-10-18 08:18:36 -070086 # project1 is the zuul_project so the origin should be set to the
87 # zuul_url since that is the most up to date.
88 cache_repo_path = os.path.join(cache_root, 'org/project1')
89 self.assertNotEqual(
Joshua Hesketh29d99b72014-08-19 16:27:42 +100090 work['org/project1'].remotes.origin.url,
James E. Blair8cce42e2016-10-18 08:18:36 -070091 cache_repo_path,
92 'workspace repo origin should not be the cache'
93 )
94 zuul_url_repo_path = os.path.join(self.git_root, 'org/project1')
95 self.assertEqual(
96 work['org/project1'].remotes.origin.url,
97 zuul_url_repo_path,
98 'workspace repo origin should be the zuul url'
99 )
100
101 # project2 is not the zuul_project so the origin should be set
102 # to upstream since that is the best we can do
103 cache_repo_path = os.path.join(cache_root, 'org/project2')
104 self.assertNotEqual(
105 work['org/project2'].remotes.origin.url,
106 cache_repo_path,
107 'workspace repo origin should not be the cache'
108 )
109 upstream_repo_path = os.path.join(self.upstream_root, 'org/project2')
110 self.assertEqual(
111 work['org/project2'].remotes.origin.url,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000112 upstream_repo_path,
James E. Blair8cce42e2016-10-18 08:18:36 -0700113 'workspace repo origin should be the upstream url'
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000114 )
James E. Blair48ff4d52014-08-25 15:07:21 -0700115
116 self.worker.hold_jobs_in_build = False
117 self.worker.release()
118 self.waitUntilSettled()
119
James E. Blaird8af5422017-05-24 13:59:40 -0700120 @simple_layout('layouts/repo-checkout-two-project.yaml')
James E. Blair97d902e2014-08-21 13:25:56 -0700121 def test_one_branch(self):
James E. Blaird8af5422017-05-24 13:59:40 -0700122 self.executor_server.hold_jobs_in_build = True
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100123
James E. Blaird8af5422017-05-24 13:59:40 -0700124 p1 = 'review.example.com/org/project1'
125 p2 = 'review.example.com/org/project2'
126 projects = [p1, p2]
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100127 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
128 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blaird8af5422017-05-24 13:59:40 -0700129 A.addApproval('code-review', 2)
130 B.addApproval('code-review', 2)
131 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
132 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100133
134 self.waitUntilSettled()
135
136 self.assertEquals(2, len(self.builds), "Two builds are running")
137
James E. Blair97d902e2014-08-21 13:25:56 -0700138 upstream = self.getUpstreamRepos(projects)
139 states = [
James E. Blaird8af5422017-05-24 13:59:40 -0700140 {p1: self.builds[0].parameters['ZUUL_COMMIT'],
141 p2: str(upstream[p2].commit('master')),
James E. Blair97d902e2014-08-21 13:25:56 -0700142 },
James E. Blaird8af5422017-05-24 13:59:40 -0700143 {p1: self.builds[0].parameters['ZUUL_COMMIT'],
144 p2: self.builds[1].parameters['ZUUL_COMMIT'],
James E. Blair97d902e2014-08-21 13:25:56 -0700145 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000146 ]
James E. Blair97d902e2014-08-21 13:25:56 -0700147
148 for number, build in enumerate(self.builds):
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100149 self.log.debug("Build parameters: %s", build.parameters)
James E. Blaird8af5422017-05-24 13:59:40 -0700150 work = build.getWorkspaceRepos(projects)
James E. Blair97d902e2014-08-21 13:25:56 -0700151 state = states[number]
152
153 for project in projects:
154 self.assertEquals(state[project],
155 str(work[project].commit('HEAD')),
156 'Project %s commit for build %s should '
157 'be correct' % (project, number))
158
James E. Blaird8af5422017-05-24 13:59:40 -0700159 self.executor_server.hold_jobs_in_build = False
160 self.executor_server.release()
James E. Blair97d902e2014-08-21 13:25:56 -0700161 self.waitUntilSettled()
162
James E. Blaird8af5422017-05-24 13:59:40 -0700163 @skip("Disabled for early v3 development")
James E. Blair97d902e2014-08-21 13:25:56 -0700164 def test_multi_branch(self):
165 self.worker.hold_jobs_in_build = True
166 projects = ['org/project1', 'org/project2',
167 'org/project3', 'org/project4']
168
169 self.create_branch('org/project2', 'stable/havana')
170 self.create_branch('org/project4', 'stable/havana')
171 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000172 B = self.fake_gerrit.addFakeChange('org/project2', 'stable/havana',
173 'B')
James E. Blair97d902e2014-08-21 13:25:56 -0700174 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
175 A.addApproval('CRVW', 2)
176 B.addApproval('CRVW', 2)
177 C.addApproval('CRVW', 2)
178 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
179 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
180 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
181
182 self.waitUntilSettled()
183
184 self.assertEquals(3, len(self.builds), "Three builds are running")
185
186 upstream = self.getUpstreamRepos(projects)
187 states = [
188 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
189 'org/project2': str(upstream['org/project2'].commit('master')),
190 'org/project3': str(upstream['org/project3'].commit('master')),
191 'org/project4': str(upstream['org/project4'].
192 commit('master')),
193 },
194 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
195 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
196 'org/project3': str(upstream['org/project3'].commit('master')),
197 'org/project4': str(upstream['org/project4'].
198 commit('stable/havana')),
199 },
200 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
201 'org/project2': str(upstream['org/project2'].commit('master')),
202 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
203 'org/project4': str(upstream['org/project4'].
204 commit('master')),
205 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000206 ]
James E. Blair97d902e2014-08-21 13:25:56 -0700207
208 for number, build in enumerate(self.builds):
209 self.log.debug("Build parameters: %s", build.parameters)
210 cloner = zuul.lib.cloner.Cloner(
211 git_base_url=self.upstream_root,
212 projects=projects,
213 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700214 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blair97d902e2014-08-21 13:25:56 -0700215 zuul_branch=build.parameters['ZUUL_BRANCH'],
216 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500217 zuul_url=self.src_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000218 )
James E. Blair97d902e2014-08-21 13:25:56 -0700219 cloner.execute()
220 work = self.getWorkspaceRepos(projects)
221 state = states[number]
222
223 for project in projects:
224 self.assertEquals(state[project],
225 str(work[project].commit('HEAD')),
226 'Project %s commit for build %s should '
227 'be correct' % (project, number))
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100228 shutil.rmtree(self.workspace_root)
James E. Blair82318922014-08-21 11:05:32 -0700229
230 self.worker.hold_jobs_in_build = False
231 self.worker.release()
232 self.waitUntilSettled()
James E. Blairbce35e12014-08-21 14:31:17 -0700233
James E. Blaird8af5422017-05-24 13:59:40 -0700234 @skip("Disabled for early v3 development")
James E. Blairbce35e12014-08-21 14:31:17 -0700235 def test_upgrade(self):
236 # Simulates an upgrade test
237 self.worker.hold_jobs_in_build = True
238 projects = ['org/project1', 'org/project2', 'org/project3',
239 'org/project4', 'org/project5', 'org/project6']
240
241 self.create_branch('org/project2', 'stable/havana')
242 self.create_branch('org/project3', 'stable/havana')
243 self.create_branch('org/project4', 'stable/havana')
244 self.create_branch('org/project5', 'stable/havana')
245 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
246 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000247 C = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
248 'C')
James E. Blairbce35e12014-08-21 14:31:17 -0700249 D = self.fake_gerrit.addFakeChange('org/project3', 'master', 'D')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000250 E = self.fake_gerrit.addFakeChange('org/project4', 'stable/havana',
251 'E')
James E. Blairbce35e12014-08-21 14:31:17 -0700252 A.addApproval('CRVW', 2)
253 B.addApproval('CRVW', 2)
254 C.addApproval('CRVW', 2)
255 D.addApproval('CRVW', 2)
256 E.addApproval('CRVW', 2)
257 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
258 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
259 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
260 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
261 self.fake_gerrit.addEvent(E.addApproval('APRV', 1))
262
263 self.waitUntilSettled()
264
265 self.assertEquals(5, len(self.builds), "Five builds are running")
266
267 # Check the old side of the upgrade first
268 upstream = self.getUpstreamRepos(projects)
269 states = [
270 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000271 'org/project2': str(upstream['org/project2'].commit(
272 'stable/havana')),
273 'org/project3': str(upstream['org/project3'].commit(
274 'stable/havana')),
275 'org/project4': str(upstream['org/project4'].commit(
276 'stable/havana')),
277 'org/project5': str(upstream['org/project5'].commit(
278 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700279 'org/project6': str(upstream['org/project6'].commit('master')),
280 },
281 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000282 'org/project2': str(upstream['org/project2'].commit(
283 'stable/havana')),
284 'org/project3': str(upstream['org/project3'].commit(
285 'stable/havana')),
286 'org/project4': str(upstream['org/project4'].commit(
287 'stable/havana')),
288 'org/project5': str(upstream['org/project5'].commit(
289 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700290 'org/project6': str(upstream['org/project6'].commit('master')),
291 },
292 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000293 'org/project2': str(upstream['org/project2'].commit(
294 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700295 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000296 'org/project4': str(upstream['org/project4'].commit(
297 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700298
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000299 'org/project5': str(upstream['org/project5'].commit(
300 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700301 'org/project6': str(upstream['org/project6'].commit('master')),
302 },
303 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000304 'org/project2': str(upstream['org/project2'].commit(
305 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700306 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000307 'org/project4': str(upstream['org/project4'].commit(
308 'stable/havana')),
309 'org/project5': str(upstream['org/project5'].commit(
310 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700311 'org/project6': str(upstream['org/project6'].commit('master')),
312 },
313 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000314 'org/project2': str(upstream['org/project2'].commit(
315 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700316 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
317 'org/project4': self.builds[4].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000318 'org/project5': str(upstream['org/project5'].commit(
319 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700320 'org/project6': str(upstream['org/project6'].commit('master')),
321 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000322 ]
James E. Blairbce35e12014-08-21 14:31:17 -0700323
324 for number, build in enumerate(self.builds):
325 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairbce35e12014-08-21 14:31:17 -0700326 cloner = zuul.lib.cloner.Cloner(
327 git_base_url=self.upstream_root,
328 projects=projects,
329 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700330 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blairbce35e12014-08-21 14:31:17 -0700331 zuul_branch=build.parameters['ZUUL_BRANCH'],
332 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500333 zuul_url=self.src_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000334 branch='stable/havana', # Old branch for upgrade
335 )
James E. Blairbce35e12014-08-21 14:31:17 -0700336 cloner.execute()
337 work = self.getWorkspaceRepos(projects)
338 state = states[number]
339
340 for project in projects:
341 self.assertEquals(state[project],
342 str(work[project].commit('HEAD')),
343 'Project %s commit for build %s should '
344 'be correct on old side of upgrade' %
345 (project, number))
346 shutil.rmtree(self.workspace_root)
347
348 # Check the new side of the upgrade
349 states = [
350 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
351 'org/project2': str(upstream['org/project2'].commit('master')),
352 'org/project3': str(upstream['org/project3'].commit('master')),
353 'org/project4': str(upstream['org/project4'].commit('master')),
354 'org/project5': str(upstream['org/project5'].commit('master')),
355 'org/project6': str(upstream['org/project6'].commit('master')),
356 },
357 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
358 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
359 'org/project3': str(upstream['org/project3'].commit('master')),
360 'org/project4': str(upstream['org/project4'].commit('master')),
361 'org/project5': str(upstream['org/project5'].commit('master')),
362 'org/project6': str(upstream['org/project6'].commit('master')),
363 },
364 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
365 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
366 'org/project3': str(upstream['org/project3'].commit('master')),
367 'org/project4': str(upstream['org/project4'].commit('master')),
368 'org/project5': str(upstream['org/project5'].commit('master')),
369 'org/project6': str(upstream['org/project6'].commit('master')),
370 },
371 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
372 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
373 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
374 'org/project4': str(upstream['org/project4'].commit('master')),
375 'org/project5': str(upstream['org/project5'].commit('master')),
376 'org/project6': str(upstream['org/project6'].commit('master')),
377 },
378 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
379 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
380 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
381 'org/project4': str(upstream['org/project4'].commit('master')),
382 'org/project5': str(upstream['org/project5'].commit('master')),
383 'org/project6': str(upstream['org/project6'].commit('master')),
384 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000385 ]
James E. Blairbce35e12014-08-21 14:31:17 -0700386
387 for number, build in enumerate(self.builds):
388 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairbce35e12014-08-21 14:31:17 -0700389 cloner = zuul.lib.cloner.Cloner(
390 git_base_url=self.upstream_root,
391 projects=projects,
392 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700393 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blairbce35e12014-08-21 14:31:17 -0700394 zuul_branch=build.parameters['ZUUL_BRANCH'],
395 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500396 zuul_url=self.src_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000397 branch='master', # New branch for upgrade
398 )
James E. Blairbce35e12014-08-21 14:31:17 -0700399 cloner.execute()
400 work = self.getWorkspaceRepos(projects)
401 state = states[number]
402
403 for project in projects:
404 self.assertEquals(state[project],
405 str(work[project].commit('HEAD')),
406 'Project %s commit for build %s should '
407 'be correct on old side of upgrade' %
408 (project, number))
409 shutil.rmtree(self.workspace_root)
410
411 self.worker.hold_jobs_in_build = False
412 self.worker.release()
413 self.waitUntilSettled()
James E. Blairf0420222014-08-21 16:02:17 -0700414
James E. Blaird8af5422017-05-24 13:59:40 -0700415 @skip("Disabled for early v3 development")
James E. Blairf0420222014-08-21 16:02:17 -0700416 def test_project_override(self):
417 self.worker.hold_jobs_in_build = True
418 projects = ['org/project1', 'org/project2', 'org/project3',
419 'org/project4', 'org/project5', 'org/project6']
420
421 self.create_branch('org/project3', 'stable/havana')
422 self.create_branch('org/project4', 'stable/havana')
423 self.create_branch('org/project6', 'stable/havana')
424 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
425 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
426 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000427 D = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
428 'D')
James E. Blairf0420222014-08-21 16:02:17 -0700429 A.addApproval('CRVW', 2)
430 B.addApproval('CRVW', 2)
431 C.addApproval('CRVW', 2)
432 D.addApproval('CRVW', 2)
433 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
434 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
435 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
436 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
437
438 self.waitUntilSettled()
439
440 self.assertEquals(4, len(self.builds), "Four builds are running")
441
442 upstream = self.getUpstreamRepos(projects)
443 states = [
444 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
445 'org/project2': str(upstream['org/project2'].commit('master')),
446 'org/project3': str(upstream['org/project3'].commit('master')),
447 'org/project4': str(upstream['org/project4'].commit('master')),
448 'org/project5': str(upstream['org/project5'].commit('master')),
449 'org/project6': str(upstream['org/project6'].commit('master')),
450 },
451 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
452 'org/project2': str(upstream['org/project2'].commit('master')),
453 'org/project3': str(upstream['org/project3'].commit('master')),
454 'org/project4': str(upstream['org/project4'].commit('master')),
455 'org/project5': str(upstream['org/project5'].commit('master')),
456 'org/project6': str(upstream['org/project6'].commit('master')),
457 },
458 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
459 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'],
460 'org/project3': str(upstream['org/project3'].commit('master')),
461 'org/project4': str(upstream['org/project4'].commit('master')),
462 'org/project5': str(upstream['org/project5'].commit('master')),
463 'org/project6': str(upstream['org/project6'].commit('master')),
464 },
465 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
466 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'],
467 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
468 'org/project4': str(upstream['org/project4'].commit('master')),
469 'org/project5': str(upstream['org/project5'].commit('master')),
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000470 'org/project6': str(upstream['org/project6'].commit(
471 'stable/havana')),
James E. Blairf0420222014-08-21 16:02:17 -0700472 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000473 ]
James E. Blairf0420222014-08-21 16:02:17 -0700474
475 for number, build in enumerate(self.builds):
476 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairf0420222014-08-21 16:02:17 -0700477 cloner = zuul.lib.cloner.Cloner(
478 git_base_url=self.upstream_root,
479 projects=projects,
480 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700481 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blairf0420222014-08-21 16:02:17 -0700482 zuul_branch=build.parameters['ZUUL_BRANCH'],
483 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500484 zuul_url=self.src_root,
James E. Blairf0420222014-08-21 16:02:17 -0700485 project_branches={'org/project4': 'master'},
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000486 )
James E. Blairf0420222014-08-21 16:02:17 -0700487 cloner.execute()
488 work = self.getWorkspaceRepos(projects)
489 state = states[number]
490
491 for project in projects:
492 self.assertEquals(state[project],
493 str(work[project].commit('HEAD')),
494 'Project %s commit for build %s should '
495 'be correct' % (project, number))
496 shutil.rmtree(self.workspace_root)
497
498 self.worker.hold_jobs_in_build = False
499 self.worker.release()
500 self.waitUntilSettled()
James E. Blair217b10d2015-01-08 16:25:28 -0800501
James E. Blaird8af5422017-05-24 13:59:40 -0700502 @skip("Disabled for early v3 development")
James E. Blair217b10d2015-01-08 16:25:28 -0800503 def test_periodic(self):
504 self.worker.hold_jobs_in_build = True
505 self.create_branch('org/project', 'stable/havana')
James E. Blairf84026c2015-12-08 16:11:46 -0800506 self.updateConfigLayout(
507 'tests/fixtures/layout-timer.yaml')
James E. Blair217b10d2015-01-08 16:25:28 -0800508 self.sched.reconfigure(self.config)
509 self.registerJobs()
510
511 # The pipeline triggers every second, so we should have seen
512 # several by now.
513 time.sleep(5)
514 self.waitUntilSettled()
515
516 builds = self.builds[:]
517
518 self.worker.hold_jobs_in_build = False
519 # Stop queuing timer triggered jobs so that the assertions
520 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -0800521 self.updateConfigLayout(
522 'tests/fixtures/layout-no-timer.yaml')
James E. Blair217b10d2015-01-08 16:25:28 -0800523 self.sched.reconfigure(self.config)
524 self.registerJobs()
525 self.worker.release()
526 self.waitUntilSettled()
527
528 projects = ['org/project']
529
530 self.assertEquals(2, len(builds), "Two builds are running")
531
532 upstream = self.getUpstreamRepos(projects)
533 states = [
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000534 {'org/project':
535 str(upstream['org/project'].commit('stable/havana')),
James E. Blair217b10d2015-01-08 16:25:28 -0800536 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000537 {'org/project':
538 str(upstream['org/project'].commit('stable/havana')),
James E. Blair217b10d2015-01-08 16:25:28 -0800539 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000540 ]
James E. Blair217b10d2015-01-08 16:25:28 -0800541
542 for number, build in enumerate(builds):
543 self.log.debug("Build parameters: %s", build.parameters)
544 cloner = zuul.lib.cloner.Cloner(
545 git_base_url=self.upstream_root,
546 projects=projects,
547 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700548 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blair217b10d2015-01-08 16:25:28 -0800549 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
550 zuul_ref=build.parameters.get('ZUUL_REF', None),
Monty Taylord642d852017-02-23 14:05:42 -0500551 zuul_url=self.src_root,
James E. Blair217b10d2015-01-08 16:25:28 -0800552 branch='stable/havana',
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000553 )
James E. Blair217b10d2015-01-08 16:25:28 -0800554 cloner.execute()
555 work = self.getWorkspaceRepos(projects)
556 state = states[number]
557
558 for project in projects:
559 self.assertEquals(state[project],
560 str(work[project].commit('HEAD')),
561 'Project %s commit for build %s should '
562 'be correct' % (project, number))
563
564 shutil.rmtree(self.workspace_root)
565
566 self.worker.hold_jobs_in_build = False
567 self.worker.release()
568 self.waitUntilSettled()
Sachi King9f16d522016-03-16 12:20:45 +1100569
James E. Blaird8af5422017-05-24 13:59:40 -0700570 @skip("Disabled for early v3 development")
James E. Blairbfd85fd2016-10-21 14:18:11 -0700571 def test_periodic_update(self):
572 # Test that the merger correctly updates its local repository
573 # before running a periodic job.
574
575 # Prime the merger with the current state
576 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
577 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
578 self.waitUntilSettled()
579
580 # Merge a different change
581 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
582 B.setMerged()
583
584 # Start a periodic job
585 self.worker.hold_jobs_in_build = True
Paul Belanger174a8272017-03-14 13:20:10 -0400586 self.executor.negative_function_cache_ttl = 0
James E. Blairbfd85fd2016-10-21 14:18:11 -0700587 self.config.set('zuul', 'layout_config',
588 'tests/fixtures/layout-timer.yaml')
589 self.sched.reconfigure(self.config)
590 self.registerJobs()
591
592 # The pipeline triggers every second, so we should have seen
593 # several by now.
594 time.sleep(5)
595 self.waitUntilSettled()
596
597 builds = self.builds[:]
598
599 self.worker.hold_jobs_in_build = False
600 # Stop queuing timer triggered jobs so that the assertions
601 # below don't race against more jobs being queued.
602 self.config.set('zuul', 'layout_config',
603 'tests/fixtures/layout-no-timer.yaml')
604 self.sched.reconfigure(self.config)
605 self.registerJobs()
606 self.worker.release()
607 self.waitUntilSettled()
608
609 projects = ['org/project']
610
611 self.assertEquals(2, len(builds), "Two builds are running")
612
613 upstream = self.getUpstreamRepos(projects)
614 self.assertEqual(upstream['org/project'].commit('master').hexsha,
615 B.patchsets[0]['revision'])
616 states = [
617 {'org/project':
618 str(upstream['org/project'].commit('master')),
619 },
620 {'org/project':
621 str(upstream['org/project'].commit('master')),
622 },
623 ]
624
625 for number, build in enumerate(builds):
626 self.log.debug("Build parameters: %s", build.parameters)
627 cloner = zuul.lib.cloner.Cloner(
628 git_base_url=self.upstream_root,
629 projects=projects,
630 workspace=self.workspace_root,
631 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
632 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
633 zuul_ref=build.parameters.get('ZUUL_REF', None),
634 zuul_url=self.git_root,
635 )
636 cloner.execute()
637 work = self.getWorkspaceRepos(projects)
638 state = states[number]
639
640 for project in projects:
641 self.assertEquals(state[project],
642 str(work[project].commit('HEAD')),
643 'Project %s commit for build %s should '
644 'be correct' % (project, number))
645
646 shutil.rmtree(self.workspace_root)
647
648 self.worker.hold_jobs_in_build = False
649 self.worker.release()
650 self.waitUntilSettled()
651
James E. Blaird8af5422017-05-24 13:59:40 -0700652 @skip("Disabled for early v3 development")
Sachi King9f16d522016-03-16 12:20:45 +1100653 def test_post_checkout(self):
James E. Blair8cce42e2016-10-18 08:18:36 -0700654 self.worker.hold_jobs_in_build = True
655 project = "org/project1"
656
657 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
658 event = A.getRefUpdatedEvent()
659 A.setMerged()
660 self.fake_gerrit.addEvent(event)
661 self.waitUntilSettled()
662
663 build = self.builds[0]
664 state = {'org/project1': build.parameters['ZUUL_COMMIT']}
665
666 build.release()
667 self.waitUntilSettled()
Sachi King9f16d522016-03-16 12:20:45 +1100668
669 cloner = zuul.lib.cloner.Cloner(
670 git_base_url=self.upstream_root,
671 projects=[project],
672 workspace=self.workspace_root,
James E. Blair8cce42e2016-10-18 08:18:36 -0700673 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
674 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
675 zuul_ref=build.parameters.get('ZUUL_REF', None),
676 zuul_newrev=build.parameters.get('ZUUL_NEWREV', None),
Sachi King9f16d522016-03-16 12:20:45 +1100677 zuul_url=self.git_root,
Sachi King9f16d522016-03-16 12:20:45 +1100678 )
679 cloner.execute()
James E. Blair8cce42e2016-10-18 08:18:36 -0700680 work = self.getWorkspaceRepos([project])
681 self.assertEquals(state[project],
682 str(work[project].commit('HEAD')),
683 'Project %s commit for build %s should '
684 'be correct' % (project, 0))
685 shutil.rmtree(self.workspace_root)
Sachi King9f16d522016-03-16 12:20:45 +1100686
James E. Blaird8af5422017-05-24 13:59:40 -0700687 @skip("Disabled for early v3 development")
Sachi King9f16d522016-03-16 12:20:45 +1100688 def test_post_and_master_checkout(self):
James E. Blair8cce42e2016-10-18 08:18:36 -0700689 self.worker.hold_jobs_in_build = True
690 projects = ["org/project1", "org/project2"]
691
692 A = self.fake_gerrit.addFakeChange(projects[0], 'master', 'A')
693 event = A.getRefUpdatedEvent()
694 A.setMerged()
695 self.fake_gerrit.addEvent(event)
696 self.waitUntilSettled()
697
698 build = self.builds[0]
699 upstream = self.getUpstreamRepos(projects)
700 state = {'org/project1':
701 build.parameters['ZUUL_COMMIT'],
702 'org/project2':
703 str(upstream['org/project2'].commit('master')),
704 }
705
706 build.release()
707 self.waitUntilSettled()
Sachi King9f16d522016-03-16 12:20:45 +1100708
709 cloner = zuul.lib.cloner.Cloner(
710 git_base_url=self.upstream_root,
James E. Blair8cce42e2016-10-18 08:18:36 -0700711 projects=projects,
Sachi King9f16d522016-03-16 12:20:45 +1100712 workspace=self.workspace_root,
James E. Blair8cce42e2016-10-18 08:18:36 -0700713 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
714 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
715 zuul_ref=build.parameters.get('ZUUL_REF', None),
716 zuul_newrev=build.parameters.get('ZUUL_NEWREV', None),
Sachi King9f16d522016-03-16 12:20:45 +1100717 zuul_url=self.git_root,
Sachi King9f16d522016-03-16 12:20:45 +1100718 )
719 cloner.execute()
James E. Blair8cce42e2016-10-18 08:18:36 -0700720 work = self.getWorkspaceRepos(projects)
721
722 for project in projects:
723 self.assertEquals(state[project],
724 str(work[project].commit('HEAD')),
725 'Project %s commit for build %s should '
726 'be correct' % (project, 0))
727 shutil.rmtree(self.workspace_root)