blob: e3576bdad8f4f1401cc3afb7797738e62d6960b6 [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
29logging.basicConfig(level=logging.DEBUG,
30 format='%(asctime)s %(name)-32s '
31 '%(levelname)-8s %(message)s')
32
33
34class TestCloner(ZuulTestCase):
35
36 log = logging.getLogger("zuul.test.cloner")
37 workspace_root = None
38
39 def setUp(self):
40 super(TestCloner, self).setUp()
41 self.workspace_root = os.path.join(self.test_root, 'workspace')
42
43 self.config.set('zuul', 'layout_config',
James E. Blair97d902e2014-08-21 13:25:56 -070044 'tests/fixtures/layout-cloner.yaml')
Antoine Musso45dd2cb2014-01-29 17:17:43 +010045 self.sched.reconfigure(self.config)
46 self.registerJobs()
47
James E. Blair97d902e2014-08-21 13:25:56 -070048 def getWorkspaceRepos(self, projects):
49 repos = {}
50 for project in projects:
51 repos[project] = git.Repo(
52 os.path.join(self.workspace_root, project))
53 return repos
54
55 def getUpstreamRepos(self, projects):
56 repos = {}
57 for project in projects:
58 repos[project] = git.Repo(
59 os.path.join(self.upstream_root, project))
60 return repos
61
James E. Blair48ff4d52014-08-25 15:07:21 -070062 def test_cache_dir(self):
63 projects = ['org/project1', 'org/project2']
64 cache_root = os.path.join(self.test_root, "cache")
65 for project in projects:
66 upstream_repo_path = os.path.join(self.upstream_root, project)
67 cache_repo_path = os.path.join(cache_root, project)
68 git.Repo.clone_from(upstream_repo_path, cache_repo_path)
69
70 self.worker.hold_jobs_in_build = True
71 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
72 A.addApproval('CRVW', 2)
73 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
74
75 self.waitUntilSettled()
76
77 self.assertEquals(1, len(self.builds), "One build is running")
78
79 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
80 B.setMerged()
81
82 upstream = self.getUpstreamRepos(projects)
Joshua Hesketh29d99b72014-08-19 16:27:42 +100083 states = [{
84 'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
85 'org/project2': str(upstream['org/project2'].commit('master')),
86 }]
James E. Blair48ff4d52014-08-25 15:07:21 -070087
88 for number, build in enumerate(self.builds):
89 self.log.debug("Build parameters: %s", build.parameters)
90 cloner = zuul.lib.cloner.Cloner(
91 git_base_url=self.upstream_root,
92 projects=projects,
93 workspace=self.workspace_root,
94 zuul_branch=build.parameters['ZUUL_BRANCH'],
95 zuul_ref=build.parameters['ZUUL_REF'],
96 zuul_url=self.git_root,
97 cache_dir=cache_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +100098 )
James E. Blair48ff4d52014-08-25 15:07:21 -070099 cloner.execute()
100 work = self.getWorkspaceRepos(projects)
101 state = states[number]
102
103 for project in projects:
104 self.assertEquals(state[project],
105 str(work[project].commit('HEAD')),
106 'Project %s commit for build %s should '
107 'be correct' % (project, number))
108
109 work = self.getWorkspaceRepos(projects)
110 upstream_repo_path = os.path.join(self.upstream_root, 'org/project1')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000111 self.assertEquals(
112 work['org/project1'].remotes.origin.url,
113 upstream_repo_path,
114 'workspace repo origin should be upstream, not cache'
115 )
James E. Blair48ff4d52014-08-25 15:07:21 -0700116
117 self.worker.hold_jobs_in_build = False
118 self.worker.release()
119 self.waitUntilSettled()
120
James E. Blair97d902e2014-08-21 13:25:56 -0700121 def test_one_branch(self):
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100122 self.worker.hold_jobs_in_build = True
123
James E. Blair97d902e2014-08-21 13:25:56 -0700124 projects = ['org/project1', 'org/project2']
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100125 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
126 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100127 A.addApproval('CRVW', 2)
128 B.addApproval('CRVW', 2)
129 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
130 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
131
132 self.waitUntilSettled()
133
134 self.assertEquals(2, len(self.builds), "Two builds are running")
135
James E. Blair97d902e2014-08-21 13:25:56 -0700136 upstream = self.getUpstreamRepos(projects)
137 states = [
138 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
139 'org/project2': str(upstream['org/project2'].commit('master')),
140 },
141 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
142 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
143 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000144 ]
James E. Blair97d902e2014-08-21 13:25:56 -0700145
146 for number, build in enumerate(self.builds):
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100147 self.log.debug("Build parameters: %s", build.parameters)
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100148 cloner = zuul.lib.cloner.Cloner(
149 git_base_url=self.upstream_root,
James E. Blair97d902e2014-08-21 13:25:56 -0700150 projects=projects,
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100151 workspace=self.workspace_root,
James E. Blair97d902e2014-08-21 13:25:56 -0700152 zuul_branch=build.parameters['ZUUL_BRANCH'],
James E. Blair82318922014-08-21 11:05:32 -0700153 zuul_ref=build.parameters['ZUUL_REF'],
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100154 zuul_url=self.git_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000155 )
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100156 cloner.execute()
James E. Blair97d902e2014-08-21 13:25:56 -0700157 work = self.getWorkspaceRepos(projects)
158 state = states[number]
159
160 for project in projects:
161 self.assertEquals(state[project],
162 str(work[project].commit('HEAD')),
163 'Project %s commit for build %s should '
164 'be correct' % (project, number))
165
166 shutil.rmtree(self.workspace_root)
167
168 self.worker.hold_jobs_in_build = False
169 self.worker.release()
170 self.waitUntilSettled()
171
172 def test_multi_branch(self):
173 self.worker.hold_jobs_in_build = True
174 projects = ['org/project1', 'org/project2',
175 'org/project3', 'org/project4']
176
177 self.create_branch('org/project2', 'stable/havana')
178 self.create_branch('org/project4', 'stable/havana')
179 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000180 B = self.fake_gerrit.addFakeChange('org/project2', 'stable/havana',
181 'B')
James E. Blair97d902e2014-08-21 13:25:56 -0700182 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
183 A.addApproval('CRVW', 2)
184 B.addApproval('CRVW', 2)
185 C.addApproval('CRVW', 2)
186 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
187 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
188 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
189
190 self.waitUntilSettled()
191
192 self.assertEquals(3, len(self.builds), "Three builds are running")
193
194 upstream = self.getUpstreamRepos(projects)
195 states = [
196 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
197 'org/project2': str(upstream['org/project2'].commit('master')),
198 'org/project3': str(upstream['org/project3'].commit('master')),
199 'org/project4': str(upstream['org/project4'].
200 commit('master')),
201 },
202 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
203 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
204 'org/project3': str(upstream['org/project3'].commit('master')),
205 'org/project4': str(upstream['org/project4'].
206 commit('stable/havana')),
207 },
208 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
209 'org/project2': str(upstream['org/project2'].commit('master')),
210 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
211 'org/project4': str(upstream['org/project4'].
212 commit('master')),
213 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000214 ]
James E. Blair97d902e2014-08-21 13:25:56 -0700215
216 for number, build in enumerate(self.builds):
217 self.log.debug("Build parameters: %s", build.parameters)
218 cloner = zuul.lib.cloner.Cloner(
219 git_base_url=self.upstream_root,
220 projects=projects,
221 workspace=self.workspace_root,
222 zuul_branch=build.parameters['ZUUL_BRANCH'],
223 zuul_ref=build.parameters['ZUUL_REF'],
224 zuul_url=self.git_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000225 )
James E. Blair97d902e2014-08-21 13:25:56 -0700226 cloner.execute()
227 work = self.getWorkspaceRepos(projects)
228 state = states[number]
229
230 for project in projects:
231 self.assertEquals(state[project],
232 str(work[project].commit('HEAD')),
233 'Project %s commit for build %s should '
234 'be correct' % (project, number))
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100235 shutil.rmtree(self.workspace_root)
James E. Blair82318922014-08-21 11:05:32 -0700236
237 self.worker.hold_jobs_in_build = False
238 self.worker.release()
239 self.waitUntilSettled()
James E. Blairbce35e12014-08-21 14:31:17 -0700240
241 def test_upgrade(self):
242 # Simulates an upgrade test
243 self.worker.hold_jobs_in_build = True
244 projects = ['org/project1', 'org/project2', 'org/project3',
245 'org/project4', 'org/project5', 'org/project6']
246
247 self.create_branch('org/project2', 'stable/havana')
248 self.create_branch('org/project3', 'stable/havana')
249 self.create_branch('org/project4', 'stable/havana')
250 self.create_branch('org/project5', 'stable/havana')
251 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
252 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000253 C = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
254 'C')
James E. Blairbce35e12014-08-21 14:31:17 -0700255 D = self.fake_gerrit.addFakeChange('org/project3', 'master', 'D')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000256 E = self.fake_gerrit.addFakeChange('org/project4', 'stable/havana',
257 'E')
James E. Blairbce35e12014-08-21 14:31:17 -0700258 A.addApproval('CRVW', 2)
259 B.addApproval('CRVW', 2)
260 C.addApproval('CRVW', 2)
261 D.addApproval('CRVW', 2)
262 E.addApproval('CRVW', 2)
263 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
264 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
265 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
266 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
267 self.fake_gerrit.addEvent(E.addApproval('APRV', 1))
268
269 self.waitUntilSettled()
270
271 self.assertEquals(5, len(self.builds), "Five builds are running")
272
273 # Check the old side of the upgrade first
274 upstream = self.getUpstreamRepos(projects)
275 states = [
276 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000277 'org/project2': str(upstream['org/project2'].commit(
278 'stable/havana')),
279 'org/project3': str(upstream['org/project3'].commit(
280 'stable/havana')),
281 'org/project4': str(upstream['org/project4'].commit(
282 'stable/havana')),
283 'org/project5': str(upstream['org/project5'].commit(
284 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700285 'org/project6': str(upstream['org/project6'].commit('master')),
286 },
287 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000288 'org/project2': str(upstream['org/project2'].commit(
289 'stable/havana')),
290 'org/project3': str(upstream['org/project3'].commit(
291 'stable/havana')),
292 'org/project4': str(upstream['org/project4'].commit(
293 'stable/havana')),
294 'org/project5': str(upstream['org/project5'].commit(
295 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700296 'org/project6': str(upstream['org/project6'].commit('master')),
297 },
298 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000299 'org/project2': str(upstream['org/project2'].commit(
300 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700301 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000302 'org/project4': str(upstream['org/project4'].commit(
303 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700304
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000305 'org/project5': str(upstream['org/project5'].commit(
306 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700307 'org/project6': str(upstream['org/project6'].commit('master')),
308 },
309 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000310 'org/project2': str(upstream['org/project2'].commit(
311 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700312 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000313 'org/project4': str(upstream['org/project4'].commit(
314 'stable/havana')),
315 'org/project5': str(upstream['org/project5'].commit(
316 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700317 'org/project6': str(upstream['org/project6'].commit('master')),
318 },
319 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000320 'org/project2': str(upstream['org/project2'].commit(
321 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700322 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
323 'org/project4': self.builds[4].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000324 'org/project5': str(upstream['org/project5'].commit(
325 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700326 'org/project6': str(upstream['org/project6'].commit('master')),
327 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000328 ]
James E. Blairbce35e12014-08-21 14:31:17 -0700329
330 for number, build in enumerate(self.builds):
331 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairbce35e12014-08-21 14:31:17 -0700332 cloner = zuul.lib.cloner.Cloner(
333 git_base_url=self.upstream_root,
334 projects=projects,
335 workspace=self.workspace_root,
336 zuul_branch=build.parameters['ZUUL_BRANCH'],
337 zuul_ref=build.parameters['ZUUL_REF'],
338 zuul_url=self.git_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000339 branch='stable/havana', # Old branch for upgrade
340 )
James E. Blairbce35e12014-08-21 14:31:17 -0700341 cloner.execute()
342 work = self.getWorkspaceRepos(projects)
343 state = states[number]
344
345 for project in projects:
346 self.assertEquals(state[project],
347 str(work[project].commit('HEAD')),
348 'Project %s commit for build %s should '
349 'be correct on old side of upgrade' %
350 (project, number))
351 shutil.rmtree(self.workspace_root)
352
353 # Check the new side of the upgrade
354 states = [
355 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
356 'org/project2': str(upstream['org/project2'].commit('master')),
357 'org/project3': str(upstream['org/project3'].commit('master')),
358 'org/project4': str(upstream['org/project4'].commit('master')),
359 'org/project5': str(upstream['org/project5'].commit('master')),
360 'org/project6': str(upstream['org/project6'].commit('master')),
361 },
362 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
363 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
364 'org/project3': str(upstream['org/project3'].commit('master')),
365 'org/project4': str(upstream['org/project4'].commit('master')),
366 'org/project5': str(upstream['org/project5'].commit('master')),
367 'org/project6': str(upstream['org/project6'].commit('master')),
368 },
369 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
370 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
371 'org/project3': str(upstream['org/project3'].commit('master')),
372 'org/project4': str(upstream['org/project4'].commit('master')),
373 'org/project5': str(upstream['org/project5'].commit('master')),
374 'org/project6': str(upstream['org/project6'].commit('master')),
375 },
376 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
377 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
378 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
379 'org/project4': str(upstream['org/project4'].commit('master')),
380 'org/project5': str(upstream['org/project5'].commit('master')),
381 'org/project6': str(upstream['org/project6'].commit('master')),
382 },
383 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
384 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
385 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
386 'org/project4': str(upstream['org/project4'].commit('master')),
387 'org/project5': str(upstream['org/project5'].commit('master')),
388 'org/project6': str(upstream['org/project6'].commit('master')),
389 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000390 ]
James E. Blairbce35e12014-08-21 14:31:17 -0700391
392 for number, build in enumerate(self.builds):
393 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairbce35e12014-08-21 14:31:17 -0700394 cloner = zuul.lib.cloner.Cloner(
395 git_base_url=self.upstream_root,
396 projects=projects,
397 workspace=self.workspace_root,
398 zuul_branch=build.parameters['ZUUL_BRANCH'],
399 zuul_ref=build.parameters['ZUUL_REF'],
400 zuul_url=self.git_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000401 branch='master', # New branch for upgrade
402 )
James E. Blairbce35e12014-08-21 14:31:17 -0700403 cloner.execute()
404 work = self.getWorkspaceRepos(projects)
405 state = states[number]
406
407 for project in projects:
408 self.assertEquals(state[project],
409 str(work[project].commit('HEAD')),
410 'Project %s commit for build %s should '
411 'be correct on old side of upgrade' %
412 (project, number))
413 shutil.rmtree(self.workspace_root)
414
415 self.worker.hold_jobs_in_build = False
416 self.worker.release()
417 self.waitUntilSettled()
James E. Blairf0420222014-08-21 16:02:17 -0700418
419 def test_project_override(self):
420 self.worker.hold_jobs_in_build = True
421 projects = ['org/project1', 'org/project2', 'org/project3',
422 'org/project4', 'org/project5', 'org/project6']
423
424 self.create_branch('org/project3', 'stable/havana')
425 self.create_branch('org/project4', 'stable/havana')
426 self.create_branch('org/project6', 'stable/havana')
427 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
428 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
429 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000430 D = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
431 'D')
James E. Blairf0420222014-08-21 16:02:17 -0700432 A.addApproval('CRVW', 2)
433 B.addApproval('CRVW', 2)
434 C.addApproval('CRVW', 2)
435 D.addApproval('CRVW', 2)
436 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
437 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
438 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
439 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
440
441 self.waitUntilSettled()
442
443 self.assertEquals(4, len(self.builds), "Four builds are running")
444
445 upstream = self.getUpstreamRepos(projects)
446 states = [
447 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
448 'org/project2': str(upstream['org/project2'].commit('master')),
449 'org/project3': str(upstream['org/project3'].commit('master')),
450 'org/project4': str(upstream['org/project4'].commit('master')),
451 'org/project5': str(upstream['org/project5'].commit('master')),
452 'org/project6': str(upstream['org/project6'].commit('master')),
453 },
454 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
455 'org/project2': str(upstream['org/project2'].commit('master')),
456 'org/project3': str(upstream['org/project3'].commit('master')),
457 'org/project4': str(upstream['org/project4'].commit('master')),
458 'org/project5': str(upstream['org/project5'].commit('master')),
459 'org/project6': str(upstream['org/project6'].commit('master')),
460 },
461 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
462 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'],
463 'org/project3': str(upstream['org/project3'].commit('master')),
464 'org/project4': str(upstream['org/project4'].commit('master')),
465 'org/project5': str(upstream['org/project5'].commit('master')),
466 'org/project6': str(upstream['org/project6'].commit('master')),
467 },
468 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
469 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'],
470 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
471 'org/project4': str(upstream['org/project4'].commit('master')),
472 'org/project5': str(upstream['org/project5'].commit('master')),
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000473 'org/project6': str(upstream['org/project6'].commit(
474 'stable/havana')),
James E. Blairf0420222014-08-21 16:02:17 -0700475 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000476 ]
James E. Blairf0420222014-08-21 16:02:17 -0700477
478 for number, build in enumerate(self.builds):
479 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairf0420222014-08-21 16:02:17 -0700480 cloner = zuul.lib.cloner.Cloner(
481 git_base_url=self.upstream_root,
482 projects=projects,
483 workspace=self.workspace_root,
484 zuul_branch=build.parameters['ZUUL_BRANCH'],
485 zuul_ref=build.parameters['ZUUL_REF'],
486 zuul_url=self.git_root,
487 project_branches={'org/project4': 'master'},
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000488 )
James E. Blairf0420222014-08-21 16:02:17 -0700489 cloner.execute()
490 work = self.getWorkspaceRepos(projects)
491 state = states[number]
492
493 for project in projects:
494 self.assertEquals(state[project],
495 str(work[project].commit('HEAD')),
496 'Project %s commit for build %s should '
497 'be correct' % (project, number))
498 shutil.rmtree(self.workspace_root)
499
500 self.worker.hold_jobs_in_build = False
501 self.worker.release()
502 self.waitUntilSettled()
James E. Blair217b10d2015-01-08 16:25:28 -0800503
504 def test_periodic(self):
505 self.worker.hold_jobs_in_build = True
506 self.create_branch('org/project', 'stable/havana')
507 self.config.set('zuul', 'layout_config',
508 'tests/fixtures/layout-timer.yaml')
509 self.sched.reconfigure(self.config)
510 self.registerJobs()
511
512 # The pipeline triggers every second, so we should have seen
513 # several by now.
514 time.sleep(5)
515 self.waitUntilSettled()
516
517 builds = self.builds[:]
518
519 self.worker.hold_jobs_in_build = False
520 # Stop queuing timer triggered jobs so that the assertions
521 # below don't race against more jobs being queued.
522 self.config.set('zuul', 'layout_config',
523 'tests/fixtures/layout-no-timer.yaml')
524 self.sched.reconfigure(self.config)
525 self.registerJobs()
526 self.worker.release()
527 self.waitUntilSettled()
528
529 projects = ['org/project']
530
531 self.assertEquals(2, len(builds), "Two builds are running")
532
533 upstream = self.getUpstreamRepos(projects)
534 states = [
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000535 {'org/project':
536 str(upstream['org/project'].commit('stable/havana')),
James E. Blair217b10d2015-01-08 16:25:28 -0800537 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000538 {'org/project':
539 str(upstream['org/project'].commit('stable/havana')),
James E. Blair217b10d2015-01-08 16:25:28 -0800540 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000541 ]
James E. Blair217b10d2015-01-08 16:25:28 -0800542
543 for number, build in enumerate(builds):
544 self.log.debug("Build parameters: %s", build.parameters)
545 cloner = zuul.lib.cloner.Cloner(
546 git_base_url=self.upstream_root,
547 projects=projects,
548 workspace=self.workspace_root,
549 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
550 zuul_ref=build.parameters.get('ZUUL_REF', None),
551 zuul_url=self.git_root,
552 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
570 def test_post_checkout(self):
571 project = "org/project"
572 path = os.path.join(self.upstream_root, project)
573 repo = git.Repo(path)
574 repo.head.reference = repo.heads['master']
575 commits = []
576 for i in range(0, 3):
577 commits.append(self.create_commit(project))
578 newRev = commits[1]
579
580 cloner = zuul.lib.cloner.Cloner(
581 git_base_url=self.upstream_root,
582 projects=[project],
583 workspace=self.workspace_root,
584 zuul_branch=None,
585 zuul_ref='master',
586 zuul_url=self.git_root,
587 zuul_project=project,
588 zuul_newrev=newRev,
589 )
590 cloner.execute()
591 repos = self.getWorkspaceRepos([project])
592 cloned_sha = repos[project].rev_parse('HEAD').hexsha
593 self.assertEqual(newRev, cloned_sha)
594
595 def test_post_and_master_checkout(self):
596 project = "org/project1"
597 master_project = "org/project2"
598 path = os.path.join(self.upstream_root, project)
599 repo = git.Repo(path)
600 repo.head.reference = repo.heads['master']
601 commits = []
602 for i in range(0, 3):
603 commits.append(self.create_commit(project))
604 newRev = commits[1]
605
606 cloner = zuul.lib.cloner.Cloner(
607 git_base_url=self.upstream_root,
608 projects=[project, master_project],
609 workspace=self.workspace_root,
610 zuul_branch=None,
611 zuul_ref='master',
612 zuul_url=self.git_root,
613 zuul_project=project,
614 zuul_newrev=newRev
615 )
616 cloner.execute()
617 repos = self.getWorkspaceRepos([project, master_project])
618 cloned_sha = repos[project].rev_parse('HEAD').hexsha
619 self.assertEqual(newRev, cloned_sha)
620 self.assertEqual(
621 repos[master_project].rev_parse('HEAD').hexsha,
622 repos[master_project].rev_parse('master').hexsha)