blob: 02ae910983ea65c52a0ac0806e23093e8110f2c6 [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
Antoine Musso45dd2cb2014-01-29 17:17:43 +010022
23import git
24
25import zuul.lib.cloner
26
27from tests.base import ZuulTestCase
Antoine Musso45dd2cb2014-01-29 17:17:43 +010028
Antoine Musso45dd2cb2014-01-29 17:17:43 +010029
30class TestCloner(ZuulTestCase):
31
32 log = logging.getLogger("zuul.test.cloner")
33 workspace_root = None
34
35 def setUp(self):
James E. Blair509cada2015-12-08 16:31:16 -080036 self.skip("Disabled for early v3 development")
37
Antoine Musso45dd2cb2014-01-29 17:17:43 +010038 super(TestCloner, self).setUp()
39 self.workspace_root = os.path.join(self.test_root, 'workspace')
40
James E. Blairf84026c2015-12-08 16:11:46 -080041 self.updateConfigLayout(
42 'tests/fixtures/layout-cloner.yaml')
Antoine Musso45dd2cb2014-01-29 17:17:43 +010043 self.sched.reconfigure(self.config)
44 self.registerJobs()
45
James E. Blair97d902e2014-08-21 13:25:56 -070046 def getWorkspaceRepos(self, projects):
47 repos = {}
48 for project in projects:
49 repos[project] = git.Repo(
50 os.path.join(self.workspace_root, project))
51 return repos
52
53 def getUpstreamRepos(self, projects):
54 repos = {}
55 for project in projects:
56 repos[project] = git.Repo(
57 os.path.join(self.upstream_root, project))
58 return repos
59
James E. Blair48ff4d52014-08-25 15:07:21 -070060 def test_cache_dir(self):
61 projects = ['org/project1', 'org/project2']
62 cache_root = os.path.join(self.test_root, "cache")
63 for project in projects:
64 upstream_repo_path = os.path.join(self.upstream_root, project)
65 cache_repo_path = os.path.join(cache_root, project)
66 git.Repo.clone_from(upstream_repo_path, cache_repo_path)
67
68 self.worker.hold_jobs_in_build = True
69 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
70 A.addApproval('CRVW', 2)
71 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
72
73 self.waitUntilSettled()
74
75 self.assertEquals(1, len(self.builds), "One build is running")
76
77 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
78 B.setMerged()
79
80 upstream = self.getUpstreamRepos(projects)
Joshua Hesketh29d99b72014-08-19 16:27:42 +100081 states = [{
82 'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
83 'org/project2': str(upstream['org/project2'].commit('master')),
84 }]
James E. Blair48ff4d52014-08-25 15:07:21 -070085
86 for number, build in enumerate(self.builds):
87 self.log.debug("Build parameters: %s", build.parameters)
88 cloner = zuul.lib.cloner.Cloner(
89 git_base_url=self.upstream_root,
90 projects=projects,
91 workspace=self.workspace_root,
92 zuul_branch=build.parameters['ZUUL_BRANCH'],
93 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -050094 zuul_url=self.src_root,
James E. Blair48ff4d52014-08-25 15:07:21 -070095 cache_dir=cache_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +100096 )
James E. Blair48ff4d52014-08-25 15:07:21 -070097 cloner.execute()
98 work = self.getWorkspaceRepos(projects)
99 state = states[number]
100
101 for project in projects:
102 self.assertEquals(state[project],
103 str(work[project].commit('HEAD')),
104 'Project %s commit for build %s should '
105 'be correct' % (project, number))
106
107 work = self.getWorkspaceRepos(projects)
108 upstream_repo_path = os.path.join(self.upstream_root, 'org/project1')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000109 self.assertEquals(
110 work['org/project1'].remotes.origin.url,
111 upstream_repo_path,
112 'workspace repo origin should be upstream, not cache'
113 )
James E. Blair48ff4d52014-08-25 15:07:21 -0700114
115 self.worker.hold_jobs_in_build = False
116 self.worker.release()
117 self.waitUntilSettled()
118
James E. Blair97d902e2014-08-21 13:25:56 -0700119 def test_one_branch(self):
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100120 self.worker.hold_jobs_in_build = True
121
James E. Blair97d902e2014-08-21 13:25:56 -0700122 projects = ['org/project1', 'org/project2']
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100123 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
124 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100125 A.addApproval('CRVW', 2)
126 B.addApproval('CRVW', 2)
127 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
128 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
129
130 self.waitUntilSettled()
131
132 self.assertEquals(2, len(self.builds), "Two builds are running")
133
James E. Blair97d902e2014-08-21 13:25:56 -0700134 upstream = self.getUpstreamRepos(projects)
135 states = [
136 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
137 'org/project2': str(upstream['org/project2'].commit('master')),
138 },
139 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
140 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
141 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000142 ]
James E. Blair97d902e2014-08-21 13:25:56 -0700143
144 for number, build in enumerate(self.builds):
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100145 self.log.debug("Build parameters: %s", build.parameters)
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100146 cloner = zuul.lib.cloner.Cloner(
147 git_base_url=self.upstream_root,
James E. Blair97d902e2014-08-21 13:25:56 -0700148 projects=projects,
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100149 workspace=self.workspace_root,
James E. Blair97d902e2014-08-21 13:25:56 -0700150 zuul_branch=build.parameters['ZUUL_BRANCH'],
James E. Blair82318922014-08-21 11:05:32 -0700151 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500152 zuul_url=self.src_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000153 )
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100154 cloner.execute()
James E. Blair97d902e2014-08-21 13:25:56 -0700155 work = self.getWorkspaceRepos(projects)
156 state = states[number]
157
158 for project in projects:
159 self.assertEquals(state[project],
160 str(work[project].commit('HEAD')),
161 'Project %s commit for build %s should '
162 'be correct' % (project, number))
163
164 shutil.rmtree(self.workspace_root)
165
166 self.worker.hold_jobs_in_build = False
167 self.worker.release()
168 self.waitUntilSettled()
169
170 def test_multi_branch(self):
171 self.worker.hold_jobs_in_build = True
172 projects = ['org/project1', 'org/project2',
173 'org/project3', 'org/project4']
174
175 self.create_branch('org/project2', 'stable/havana')
176 self.create_branch('org/project4', 'stable/havana')
177 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000178 B = self.fake_gerrit.addFakeChange('org/project2', 'stable/havana',
179 'B')
James E. Blair97d902e2014-08-21 13:25:56 -0700180 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
181 A.addApproval('CRVW', 2)
182 B.addApproval('CRVW', 2)
183 C.addApproval('CRVW', 2)
184 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
185 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
186 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
187
188 self.waitUntilSettled()
189
190 self.assertEquals(3, len(self.builds), "Three builds are running")
191
192 upstream = self.getUpstreamRepos(projects)
193 states = [
194 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
195 'org/project2': str(upstream['org/project2'].commit('master')),
196 'org/project3': str(upstream['org/project3'].commit('master')),
197 'org/project4': str(upstream['org/project4'].
198 commit('master')),
199 },
200 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
201 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
202 'org/project3': str(upstream['org/project3'].commit('master')),
203 'org/project4': str(upstream['org/project4'].
204 commit('stable/havana')),
205 },
206 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
207 'org/project2': str(upstream['org/project2'].commit('master')),
208 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
209 'org/project4': str(upstream['org/project4'].
210 commit('master')),
211 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000212 ]
James E. Blair97d902e2014-08-21 13:25:56 -0700213
214 for number, build in enumerate(self.builds):
215 self.log.debug("Build parameters: %s", build.parameters)
216 cloner = zuul.lib.cloner.Cloner(
217 git_base_url=self.upstream_root,
218 projects=projects,
219 workspace=self.workspace_root,
220 zuul_branch=build.parameters['ZUUL_BRANCH'],
221 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500222 zuul_url=self.src_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000223 )
James E. Blair97d902e2014-08-21 13:25:56 -0700224 cloner.execute()
225 work = self.getWorkspaceRepos(projects)
226 state = states[number]
227
228 for project in projects:
229 self.assertEquals(state[project],
230 str(work[project].commit('HEAD')),
231 'Project %s commit for build %s should '
232 'be correct' % (project, number))
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100233 shutil.rmtree(self.workspace_root)
James E. Blair82318922014-08-21 11:05:32 -0700234
235 self.worker.hold_jobs_in_build = False
236 self.worker.release()
237 self.waitUntilSettled()
James E. Blairbce35e12014-08-21 14:31:17 -0700238
239 def test_upgrade(self):
240 # Simulates an upgrade test
241 self.worker.hold_jobs_in_build = True
242 projects = ['org/project1', 'org/project2', 'org/project3',
243 'org/project4', 'org/project5', 'org/project6']
244
245 self.create_branch('org/project2', 'stable/havana')
246 self.create_branch('org/project3', 'stable/havana')
247 self.create_branch('org/project4', 'stable/havana')
248 self.create_branch('org/project5', 'stable/havana')
249 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
250 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000251 C = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
252 'C')
James E. Blairbce35e12014-08-21 14:31:17 -0700253 D = self.fake_gerrit.addFakeChange('org/project3', 'master', 'D')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000254 E = self.fake_gerrit.addFakeChange('org/project4', 'stable/havana',
255 'E')
James E. Blairbce35e12014-08-21 14:31:17 -0700256 A.addApproval('CRVW', 2)
257 B.addApproval('CRVW', 2)
258 C.addApproval('CRVW', 2)
259 D.addApproval('CRVW', 2)
260 E.addApproval('CRVW', 2)
261 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
262 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
263 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
264 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
265 self.fake_gerrit.addEvent(E.addApproval('APRV', 1))
266
267 self.waitUntilSettled()
268
269 self.assertEquals(5, len(self.builds), "Five builds are running")
270
271 # Check the old side of the upgrade first
272 upstream = self.getUpstreamRepos(projects)
273 states = [
274 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000275 'org/project2': str(upstream['org/project2'].commit(
276 'stable/havana')),
277 'org/project3': str(upstream['org/project3'].commit(
278 'stable/havana')),
279 'org/project4': str(upstream['org/project4'].commit(
280 'stable/havana')),
281 'org/project5': str(upstream['org/project5'].commit(
282 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700283 'org/project6': str(upstream['org/project6'].commit('master')),
284 },
285 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000286 'org/project2': str(upstream['org/project2'].commit(
287 'stable/havana')),
288 'org/project3': str(upstream['org/project3'].commit(
289 'stable/havana')),
290 'org/project4': str(upstream['org/project4'].commit(
291 'stable/havana')),
292 'org/project5': str(upstream['org/project5'].commit(
293 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700294 'org/project6': str(upstream['org/project6'].commit('master')),
295 },
296 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000297 'org/project2': str(upstream['org/project2'].commit(
298 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700299 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000300 'org/project4': str(upstream['org/project4'].commit(
301 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700302
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000303 'org/project5': str(upstream['org/project5'].commit(
304 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700305 'org/project6': str(upstream['org/project6'].commit('master')),
306 },
307 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000308 'org/project2': str(upstream['org/project2'].commit(
309 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700310 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000311 'org/project4': str(upstream['org/project4'].commit(
312 'stable/havana')),
313 'org/project5': str(upstream['org/project5'].commit(
314 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700315 'org/project6': str(upstream['org/project6'].commit('master')),
316 },
317 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000318 'org/project2': str(upstream['org/project2'].commit(
319 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700320 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
321 'org/project4': self.builds[4].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000322 'org/project5': str(upstream['org/project5'].commit(
323 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700324 'org/project6': str(upstream['org/project6'].commit('master')),
325 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000326 ]
James E. Blairbce35e12014-08-21 14:31:17 -0700327
328 for number, build in enumerate(self.builds):
329 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairbce35e12014-08-21 14:31:17 -0700330 cloner = zuul.lib.cloner.Cloner(
331 git_base_url=self.upstream_root,
332 projects=projects,
333 workspace=self.workspace_root,
334 zuul_branch=build.parameters['ZUUL_BRANCH'],
335 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500336 zuul_url=self.src_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000337 branch='stable/havana', # Old branch for upgrade
338 )
James E. Blairbce35e12014-08-21 14:31:17 -0700339 cloner.execute()
340 work = self.getWorkspaceRepos(projects)
341 state = states[number]
342
343 for project in projects:
344 self.assertEquals(state[project],
345 str(work[project].commit('HEAD')),
346 'Project %s commit for build %s should '
347 'be correct on old side of upgrade' %
348 (project, number))
349 shutil.rmtree(self.workspace_root)
350
351 # Check the new side of the upgrade
352 states = [
353 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
354 'org/project2': str(upstream['org/project2'].commit('master')),
355 'org/project3': str(upstream['org/project3'].commit('master')),
356 'org/project4': str(upstream['org/project4'].commit('master')),
357 'org/project5': str(upstream['org/project5'].commit('master')),
358 'org/project6': str(upstream['org/project6'].commit('master')),
359 },
360 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
361 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
362 'org/project3': str(upstream['org/project3'].commit('master')),
363 'org/project4': str(upstream['org/project4'].commit('master')),
364 'org/project5': str(upstream['org/project5'].commit('master')),
365 'org/project6': str(upstream['org/project6'].commit('master')),
366 },
367 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
368 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
369 'org/project3': str(upstream['org/project3'].commit('master')),
370 'org/project4': str(upstream['org/project4'].commit('master')),
371 'org/project5': str(upstream['org/project5'].commit('master')),
372 'org/project6': str(upstream['org/project6'].commit('master')),
373 },
374 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
375 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
376 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
377 'org/project4': str(upstream['org/project4'].commit('master')),
378 'org/project5': str(upstream['org/project5'].commit('master')),
379 'org/project6': str(upstream['org/project6'].commit('master')),
380 },
381 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
382 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
383 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
384 'org/project4': str(upstream['org/project4'].commit('master')),
385 'org/project5': str(upstream['org/project5'].commit('master')),
386 'org/project6': str(upstream['org/project6'].commit('master')),
387 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000388 ]
James E. Blairbce35e12014-08-21 14:31:17 -0700389
390 for number, build in enumerate(self.builds):
391 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairbce35e12014-08-21 14:31:17 -0700392 cloner = zuul.lib.cloner.Cloner(
393 git_base_url=self.upstream_root,
394 projects=projects,
395 workspace=self.workspace_root,
396 zuul_branch=build.parameters['ZUUL_BRANCH'],
397 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500398 zuul_url=self.src_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000399 branch='master', # New branch for upgrade
400 )
James E. Blairbce35e12014-08-21 14:31:17 -0700401 cloner.execute()
402 work = self.getWorkspaceRepos(projects)
403 state = states[number]
404
405 for project in projects:
406 self.assertEquals(state[project],
407 str(work[project].commit('HEAD')),
408 'Project %s commit for build %s should '
409 'be correct on old side of upgrade' %
410 (project, number))
411 shutil.rmtree(self.workspace_root)
412
413 self.worker.hold_jobs_in_build = False
414 self.worker.release()
415 self.waitUntilSettled()
James E. Blairf0420222014-08-21 16:02:17 -0700416
417 def test_project_override(self):
418 self.worker.hold_jobs_in_build = True
419 projects = ['org/project1', 'org/project2', 'org/project3',
420 'org/project4', 'org/project5', 'org/project6']
421
422 self.create_branch('org/project3', 'stable/havana')
423 self.create_branch('org/project4', 'stable/havana')
424 self.create_branch('org/project6', 'stable/havana')
425 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
426 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
427 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000428 D = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
429 'D')
James E. Blairf0420222014-08-21 16:02:17 -0700430 A.addApproval('CRVW', 2)
431 B.addApproval('CRVW', 2)
432 C.addApproval('CRVW', 2)
433 D.addApproval('CRVW', 2)
434 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
435 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
436 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
437 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
438
439 self.waitUntilSettled()
440
441 self.assertEquals(4, len(self.builds), "Four builds are running")
442
443 upstream = self.getUpstreamRepos(projects)
444 states = [
445 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
446 'org/project2': str(upstream['org/project2'].commit('master')),
447 'org/project3': str(upstream['org/project3'].commit('master')),
448 'org/project4': str(upstream['org/project4'].commit('master')),
449 'org/project5': str(upstream['org/project5'].commit('master')),
450 'org/project6': str(upstream['org/project6'].commit('master')),
451 },
452 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
453 'org/project2': str(upstream['org/project2'].commit('master')),
454 'org/project3': str(upstream['org/project3'].commit('master')),
455 'org/project4': str(upstream['org/project4'].commit('master')),
456 'org/project5': str(upstream['org/project5'].commit('master')),
457 'org/project6': str(upstream['org/project6'].commit('master')),
458 },
459 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
460 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'],
461 'org/project3': str(upstream['org/project3'].commit('master')),
462 'org/project4': str(upstream['org/project4'].commit('master')),
463 'org/project5': str(upstream['org/project5'].commit('master')),
464 'org/project6': str(upstream['org/project6'].commit('master')),
465 },
466 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
467 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'],
468 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
469 'org/project4': str(upstream['org/project4'].commit('master')),
470 'org/project5': str(upstream['org/project5'].commit('master')),
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000471 'org/project6': str(upstream['org/project6'].commit(
472 'stable/havana')),
James E. Blairf0420222014-08-21 16:02:17 -0700473 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000474 ]
James E. Blairf0420222014-08-21 16:02:17 -0700475
476 for number, build in enumerate(self.builds):
477 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairf0420222014-08-21 16:02:17 -0700478 cloner = zuul.lib.cloner.Cloner(
479 git_base_url=self.upstream_root,
480 projects=projects,
481 workspace=self.workspace_root,
482 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
502 def test_periodic(self):
503 self.worker.hold_jobs_in_build = True
504 self.create_branch('org/project', 'stable/havana')
James E. Blairf84026c2015-12-08 16:11:46 -0800505 self.updateConfigLayout(
506 'tests/fixtures/layout-timer.yaml')
James E. Blair217b10d2015-01-08 16:25:28 -0800507 self.sched.reconfigure(self.config)
508 self.registerJobs()
509
510 # The pipeline triggers every second, so we should have seen
511 # several by now.
512 time.sleep(5)
513 self.waitUntilSettled()
514
515 builds = self.builds[:]
516
517 self.worker.hold_jobs_in_build = False
518 # Stop queuing timer triggered jobs so that the assertions
519 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -0800520 self.updateConfigLayout(
521 'tests/fixtures/layout-no-timer.yaml')
James E. Blair217b10d2015-01-08 16:25:28 -0800522 self.sched.reconfigure(self.config)
523 self.registerJobs()
524 self.worker.release()
525 self.waitUntilSettled()
526
527 projects = ['org/project']
528
529 self.assertEquals(2, len(builds), "Two builds are running")
530
531 upstream = self.getUpstreamRepos(projects)
532 states = [
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000533 {'org/project':
534 str(upstream['org/project'].commit('stable/havana')),
James E. Blair217b10d2015-01-08 16:25:28 -0800535 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000536 {'org/project':
537 str(upstream['org/project'].commit('stable/havana')),
James E. Blair217b10d2015-01-08 16:25:28 -0800538 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000539 ]
James E. Blair217b10d2015-01-08 16:25:28 -0800540
541 for number, build in enumerate(builds):
542 self.log.debug("Build parameters: %s", build.parameters)
543 cloner = zuul.lib.cloner.Cloner(
544 git_base_url=self.upstream_root,
545 projects=projects,
546 workspace=self.workspace_root,
547 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
548 zuul_ref=build.parameters.get('ZUUL_REF', None),
Monty Taylord642d852017-02-23 14:05:42 -0500549 zuul_url=self.src_root,
James E. Blair217b10d2015-01-08 16:25:28 -0800550 branch='stable/havana',
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000551 )
James E. Blair217b10d2015-01-08 16:25:28 -0800552 cloner.execute()
553 work = self.getWorkspaceRepos(projects)
554 state = states[number]
555
556 for project in projects:
557 self.assertEquals(state[project],
558 str(work[project].commit('HEAD')),
559 'Project %s commit for build %s should '
560 'be correct' % (project, number))
561
562 shutil.rmtree(self.workspace_root)
563
564 self.worker.hold_jobs_in_build = False
565 self.worker.release()
566 self.waitUntilSettled()
Sachi King9f16d522016-03-16 12:20:45 +1100567
568 def test_post_checkout(self):
569 project = "org/project"
570 path = os.path.join(self.upstream_root, project)
571 repo = git.Repo(path)
572 repo.head.reference = repo.heads['master']
573 commits = []
574 for i in range(0, 3):
575 commits.append(self.create_commit(project))
576 newRev = commits[1]
577
578 cloner = zuul.lib.cloner.Cloner(
579 git_base_url=self.upstream_root,
580 projects=[project],
581 workspace=self.workspace_root,
582 zuul_branch=None,
583 zuul_ref='master',
Monty Taylord642d852017-02-23 14:05:42 -0500584 zuul_url=self.src_root,
Sachi King9f16d522016-03-16 12:20:45 +1100585 zuul_project=project,
586 zuul_newrev=newRev,
587 )
588 cloner.execute()
589 repos = self.getWorkspaceRepos([project])
590 cloned_sha = repos[project].rev_parse('HEAD').hexsha
591 self.assertEqual(newRev, cloned_sha)
592
593 def test_post_and_master_checkout(self):
594 project = "org/project1"
595 master_project = "org/project2"
596 path = os.path.join(self.upstream_root, project)
597 repo = git.Repo(path)
598 repo.head.reference = repo.heads['master']
599 commits = []
600 for i in range(0, 3):
601 commits.append(self.create_commit(project))
602 newRev = commits[1]
603
604 cloner = zuul.lib.cloner.Cloner(
605 git_base_url=self.upstream_root,
606 projects=[project, master_project],
607 workspace=self.workspace_root,
608 zuul_branch=None,
609 zuul_ref='master',
Monty Taylord642d852017-02-23 14:05:42 -0500610 zuul_url=self.src_root,
Sachi King9f16d522016-03-16 12:20:45 +1100611 zuul_project=project,
612 zuul_newrev=newRev
613 )
614 cloner.execute()
615 repos = self.getWorkspaceRepos([project, master_project])
616 cloned_sha = repos[project].rev_parse('HEAD').hexsha
617 self.assertEqual(newRev, cloned_sha)
618 self.assertEqual(
619 repos[master_project].rev_parse('HEAD').hexsha,
620 repos[master_project].rev_parse('master').hexsha)