blob: 82d1812ea21f9f3432dd66f19b501be70cc65f0b [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):
James E. Blair509cada2015-12-08 16:31:16 -080040 self.skip("Disabled for early v3 development")
41
Antoine Musso45dd2cb2014-01-29 17:17:43 +010042 super(TestCloner, self).setUp()
43 self.workspace_root = os.path.join(self.test_root, 'workspace')
44
James E. Blairf84026c2015-12-08 16:11:46 -080045 self.updateConfigLayout(
46 'tests/fixtures/layout-cloner.yaml')
Antoine Musso45dd2cb2014-01-29 17:17:43 +010047 self.sched.reconfigure(self.config)
48 self.registerJobs()
49
James E. Blair97d902e2014-08-21 13:25:56 -070050 def getWorkspaceRepos(self, projects):
51 repos = {}
52 for project in projects:
53 repos[project] = git.Repo(
54 os.path.join(self.workspace_root, project))
55 return repos
56
57 def getUpstreamRepos(self, projects):
58 repos = {}
59 for project in projects:
60 repos[project] = git.Repo(
61 os.path.join(self.upstream_root, project))
62 return repos
63
James E. Blair48ff4d52014-08-25 15:07:21 -070064 def test_cache_dir(self):
65 projects = ['org/project1', 'org/project2']
66 cache_root = os.path.join(self.test_root, "cache")
67 for project in projects:
68 upstream_repo_path = os.path.join(self.upstream_root, project)
69 cache_repo_path = os.path.join(cache_root, project)
70 git.Repo.clone_from(upstream_repo_path, cache_repo_path)
71
72 self.worker.hold_jobs_in_build = True
73 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
74 A.addApproval('CRVW', 2)
75 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
76
77 self.waitUntilSettled()
78
79 self.assertEquals(1, len(self.builds), "One build is running")
80
81 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
82 B.setMerged()
83
84 upstream = self.getUpstreamRepos(projects)
Joshua Hesketh29d99b72014-08-19 16:27:42 +100085 states = [{
86 'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
87 'org/project2': str(upstream['org/project2'].commit('master')),
88 }]
James E. Blair48ff4d52014-08-25 15:07:21 -070089
90 for number, build in enumerate(self.builds):
91 self.log.debug("Build parameters: %s", build.parameters)
92 cloner = zuul.lib.cloner.Cloner(
93 git_base_url=self.upstream_root,
94 projects=projects,
95 workspace=self.workspace_root,
96 zuul_branch=build.parameters['ZUUL_BRANCH'],
97 zuul_ref=build.parameters['ZUUL_REF'],
98 zuul_url=self.git_root,
99 cache_dir=cache_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000100 )
James E. Blair48ff4d52014-08-25 15:07:21 -0700101 cloner.execute()
102 work = self.getWorkspaceRepos(projects)
103 state = states[number]
104
105 for project in projects:
106 self.assertEquals(state[project],
107 str(work[project].commit('HEAD')),
108 'Project %s commit for build %s should '
109 'be correct' % (project, number))
110
111 work = self.getWorkspaceRepos(projects)
112 upstream_repo_path = os.path.join(self.upstream_root, 'org/project1')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000113 self.assertEquals(
114 work['org/project1'].remotes.origin.url,
115 upstream_repo_path,
116 'workspace repo origin should be upstream, not cache'
117 )
James E. Blair48ff4d52014-08-25 15:07:21 -0700118
119 self.worker.hold_jobs_in_build = False
120 self.worker.release()
121 self.waitUntilSettled()
122
James E. Blair97d902e2014-08-21 13:25:56 -0700123 def test_one_branch(self):
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100124 self.worker.hold_jobs_in_build = True
125
James E. Blair97d902e2014-08-21 13:25:56 -0700126 projects = ['org/project1', 'org/project2']
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')
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100129 A.addApproval('CRVW', 2)
130 B.addApproval('CRVW', 2)
131 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
132 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
133
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 = [
140 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
141 'org/project2': str(upstream['org/project2'].commit('master')),
142 },
143 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
144 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
145 },
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)
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100150 cloner = zuul.lib.cloner.Cloner(
151 git_base_url=self.upstream_root,
James E. Blair97d902e2014-08-21 13:25:56 -0700152 projects=projects,
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100153 workspace=self.workspace_root,
James E. Blair97d902e2014-08-21 13:25:56 -0700154 zuul_branch=build.parameters['ZUUL_BRANCH'],
James E. Blair82318922014-08-21 11:05:32 -0700155 zuul_ref=build.parameters['ZUUL_REF'],
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100156 zuul_url=self.git_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000157 )
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100158 cloner.execute()
James E. Blair97d902e2014-08-21 13:25:56 -0700159 work = self.getWorkspaceRepos(projects)
160 state = states[number]
161
162 for project in projects:
163 self.assertEquals(state[project],
164 str(work[project].commit('HEAD')),
165 'Project %s commit for build %s should '
166 'be correct' % (project, number))
167
168 shutil.rmtree(self.workspace_root)
169
170 self.worker.hold_jobs_in_build = False
171 self.worker.release()
172 self.waitUntilSettled()
173
174 def test_multi_branch(self):
175 self.worker.hold_jobs_in_build = True
176 projects = ['org/project1', 'org/project2',
177 'org/project3', 'org/project4']
178
179 self.create_branch('org/project2', 'stable/havana')
180 self.create_branch('org/project4', 'stable/havana')
181 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000182 B = self.fake_gerrit.addFakeChange('org/project2', 'stable/havana',
183 'B')
James E. Blair97d902e2014-08-21 13:25:56 -0700184 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
185 A.addApproval('CRVW', 2)
186 B.addApproval('CRVW', 2)
187 C.addApproval('CRVW', 2)
188 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
189 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
190 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
191
192 self.waitUntilSettled()
193
194 self.assertEquals(3, len(self.builds), "Three builds are running")
195
196 upstream = self.getUpstreamRepos(projects)
197 states = [
198 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
199 'org/project2': str(upstream['org/project2'].commit('master')),
200 'org/project3': str(upstream['org/project3'].commit('master')),
201 'org/project4': str(upstream['org/project4'].
202 commit('master')),
203 },
204 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
205 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
206 'org/project3': str(upstream['org/project3'].commit('master')),
207 'org/project4': str(upstream['org/project4'].
208 commit('stable/havana')),
209 },
210 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
211 'org/project2': str(upstream['org/project2'].commit('master')),
212 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
213 'org/project4': str(upstream['org/project4'].
214 commit('master')),
215 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000216 ]
James E. Blair97d902e2014-08-21 13:25:56 -0700217
218 for number, build in enumerate(self.builds):
219 self.log.debug("Build parameters: %s", build.parameters)
220 cloner = zuul.lib.cloner.Cloner(
221 git_base_url=self.upstream_root,
222 projects=projects,
223 workspace=self.workspace_root,
224 zuul_branch=build.parameters['ZUUL_BRANCH'],
225 zuul_ref=build.parameters['ZUUL_REF'],
226 zuul_url=self.git_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000227 )
James E. Blair97d902e2014-08-21 13:25:56 -0700228 cloner.execute()
229 work = self.getWorkspaceRepos(projects)
230 state = states[number]
231
232 for project in projects:
233 self.assertEquals(state[project],
234 str(work[project].commit('HEAD')),
235 'Project %s commit for build %s should '
236 'be correct' % (project, number))
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100237 shutil.rmtree(self.workspace_root)
James E. Blair82318922014-08-21 11:05:32 -0700238
239 self.worker.hold_jobs_in_build = False
240 self.worker.release()
241 self.waitUntilSettled()
James E. Blairbce35e12014-08-21 14:31:17 -0700242
243 def test_upgrade(self):
244 # Simulates an upgrade test
245 self.worker.hold_jobs_in_build = True
246 projects = ['org/project1', 'org/project2', 'org/project3',
247 'org/project4', 'org/project5', 'org/project6']
248
249 self.create_branch('org/project2', 'stable/havana')
250 self.create_branch('org/project3', 'stable/havana')
251 self.create_branch('org/project4', 'stable/havana')
252 self.create_branch('org/project5', 'stable/havana')
253 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
254 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000255 C = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
256 'C')
James E. Blairbce35e12014-08-21 14:31:17 -0700257 D = self.fake_gerrit.addFakeChange('org/project3', 'master', 'D')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000258 E = self.fake_gerrit.addFakeChange('org/project4', 'stable/havana',
259 'E')
James E. Blairbce35e12014-08-21 14:31:17 -0700260 A.addApproval('CRVW', 2)
261 B.addApproval('CRVW', 2)
262 C.addApproval('CRVW', 2)
263 D.addApproval('CRVW', 2)
264 E.addApproval('CRVW', 2)
265 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
266 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
267 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
268 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
269 self.fake_gerrit.addEvent(E.addApproval('APRV', 1))
270
271 self.waitUntilSettled()
272
273 self.assertEquals(5, len(self.builds), "Five builds are running")
274
275 # Check the old side of the upgrade first
276 upstream = self.getUpstreamRepos(projects)
277 states = [
278 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000279 'org/project2': str(upstream['org/project2'].commit(
280 'stable/havana')),
281 'org/project3': str(upstream['org/project3'].commit(
282 'stable/havana')),
283 'org/project4': str(upstream['org/project4'].commit(
284 'stable/havana')),
285 'org/project5': str(upstream['org/project5'].commit(
286 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700287 'org/project6': str(upstream['org/project6'].commit('master')),
288 },
289 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000290 'org/project2': str(upstream['org/project2'].commit(
291 'stable/havana')),
292 'org/project3': str(upstream['org/project3'].commit(
293 'stable/havana')),
294 'org/project4': str(upstream['org/project4'].commit(
295 'stable/havana')),
296 'org/project5': str(upstream['org/project5'].commit(
297 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700298 'org/project6': str(upstream['org/project6'].commit('master')),
299 },
300 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000301 'org/project2': str(upstream['org/project2'].commit(
302 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700303 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000304 'org/project4': str(upstream['org/project4'].commit(
305 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700306
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000307 'org/project5': str(upstream['org/project5'].commit(
308 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700309 'org/project6': str(upstream['org/project6'].commit('master')),
310 },
311 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000312 'org/project2': str(upstream['org/project2'].commit(
313 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700314 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000315 'org/project4': str(upstream['org/project4'].commit(
316 'stable/havana')),
317 'org/project5': str(upstream['org/project5'].commit(
318 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700319 'org/project6': str(upstream['org/project6'].commit('master')),
320 },
321 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000322 'org/project2': str(upstream['org/project2'].commit(
323 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700324 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
325 'org/project4': self.builds[4].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000326 'org/project5': str(upstream['org/project5'].commit(
327 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700328 'org/project6': str(upstream['org/project6'].commit('master')),
329 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000330 ]
James E. Blairbce35e12014-08-21 14:31:17 -0700331
332 for number, build in enumerate(self.builds):
333 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairbce35e12014-08-21 14:31:17 -0700334 cloner = zuul.lib.cloner.Cloner(
335 git_base_url=self.upstream_root,
336 projects=projects,
337 workspace=self.workspace_root,
338 zuul_branch=build.parameters['ZUUL_BRANCH'],
339 zuul_ref=build.parameters['ZUUL_REF'],
340 zuul_url=self.git_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000341 branch='stable/havana', # Old branch for upgrade
342 )
James E. Blairbce35e12014-08-21 14:31:17 -0700343 cloner.execute()
344 work = self.getWorkspaceRepos(projects)
345 state = states[number]
346
347 for project in projects:
348 self.assertEquals(state[project],
349 str(work[project].commit('HEAD')),
350 'Project %s commit for build %s should '
351 'be correct on old side of upgrade' %
352 (project, number))
353 shutil.rmtree(self.workspace_root)
354
355 # Check the new side of the upgrade
356 states = [
357 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
358 'org/project2': str(upstream['org/project2'].commit('master')),
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': str(upstream['org/project3'].commit('master')),
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 },
385 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
386 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
387 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
388 'org/project4': str(upstream['org/project4'].commit('master')),
389 'org/project5': str(upstream['org/project5'].commit('master')),
390 'org/project6': str(upstream['org/project6'].commit('master')),
391 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000392 ]
James E. Blairbce35e12014-08-21 14:31:17 -0700393
394 for number, build in enumerate(self.builds):
395 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairbce35e12014-08-21 14:31:17 -0700396 cloner = zuul.lib.cloner.Cloner(
397 git_base_url=self.upstream_root,
398 projects=projects,
399 workspace=self.workspace_root,
400 zuul_branch=build.parameters['ZUUL_BRANCH'],
401 zuul_ref=build.parameters['ZUUL_REF'],
402 zuul_url=self.git_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000403 branch='master', # New branch for upgrade
404 )
James E. Blairbce35e12014-08-21 14:31:17 -0700405 cloner.execute()
406 work = self.getWorkspaceRepos(projects)
407 state = states[number]
408
409 for project in projects:
410 self.assertEquals(state[project],
411 str(work[project].commit('HEAD')),
412 'Project %s commit for build %s should '
413 'be correct on old side of upgrade' %
414 (project, number))
415 shutil.rmtree(self.workspace_root)
416
417 self.worker.hold_jobs_in_build = False
418 self.worker.release()
419 self.waitUntilSettled()
James E. Blairf0420222014-08-21 16:02:17 -0700420
421 def test_project_override(self):
422 self.worker.hold_jobs_in_build = True
423 projects = ['org/project1', 'org/project2', 'org/project3',
424 'org/project4', 'org/project5', 'org/project6']
425
426 self.create_branch('org/project3', 'stable/havana')
427 self.create_branch('org/project4', 'stable/havana')
428 self.create_branch('org/project6', 'stable/havana')
429 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
430 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
431 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000432 D = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
433 'D')
James E. Blairf0420222014-08-21 16:02:17 -0700434 A.addApproval('CRVW', 2)
435 B.addApproval('CRVW', 2)
436 C.addApproval('CRVW', 2)
437 D.addApproval('CRVW', 2)
438 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
439 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
440 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
441 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
442
443 self.waitUntilSettled()
444
445 self.assertEquals(4, len(self.builds), "Four builds are running")
446
447 upstream = self.getUpstreamRepos(projects)
448 states = [
449 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
450 'org/project2': str(upstream['org/project2'].commit('master')),
451 'org/project3': str(upstream['org/project3'].commit('master')),
452 'org/project4': str(upstream['org/project4'].commit('master')),
453 'org/project5': str(upstream['org/project5'].commit('master')),
454 'org/project6': str(upstream['org/project6'].commit('master')),
455 },
456 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
457 'org/project2': str(upstream['org/project2'].commit('master')),
458 'org/project3': str(upstream['org/project3'].commit('master')),
459 'org/project4': str(upstream['org/project4'].commit('master')),
460 'org/project5': str(upstream['org/project5'].commit('master')),
461 'org/project6': str(upstream['org/project6'].commit('master')),
462 },
463 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
464 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'],
465 'org/project3': str(upstream['org/project3'].commit('master')),
466 'org/project4': str(upstream['org/project4'].commit('master')),
467 'org/project5': str(upstream['org/project5'].commit('master')),
468 'org/project6': str(upstream['org/project6'].commit('master')),
469 },
470 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
471 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'],
472 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
473 'org/project4': str(upstream['org/project4'].commit('master')),
474 'org/project5': str(upstream['org/project5'].commit('master')),
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000475 'org/project6': str(upstream['org/project6'].commit(
476 'stable/havana')),
James E. Blairf0420222014-08-21 16:02:17 -0700477 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000478 ]
James E. Blairf0420222014-08-21 16:02:17 -0700479
480 for number, build in enumerate(self.builds):
481 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairf0420222014-08-21 16:02:17 -0700482 cloner = zuul.lib.cloner.Cloner(
483 git_base_url=self.upstream_root,
484 projects=projects,
485 workspace=self.workspace_root,
486 zuul_branch=build.parameters['ZUUL_BRANCH'],
487 zuul_ref=build.parameters['ZUUL_REF'],
488 zuul_url=self.git_root,
489 project_branches={'org/project4': 'master'},
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000490 )
James E. Blairf0420222014-08-21 16:02:17 -0700491 cloner.execute()
492 work = self.getWorkspaceRepos(projects)
493 state = states[number]
494
495 for project in projects:
496 self.assertEquals(state[project],
497 str(work[project].commit('HEAD')),
498 'Project %s commit for build %s should '
499 'be correct' % (project, number))
500 shutil.rmtree(self.workspace_root)
501
502 self.worker.hold_jobs_in_build = False
503 self.worker.release()
504 self.waitUntilSettled()
James E. Blair217b10d2015-01-08 16:25:28 -0800505
506 def test_periodic(self):
507 self.worker.hold_jobs_in_build = True
508 self.create_branch('org/project', 'stable/havana')
James E. Blairf84026c2015-12-08 16:11:46 -0800509 self.updateConfigLayout(
510 'tests/fixtures/layout-timer.yaml')
James E. Blair217b10d2015-01-08 16:25:28 -0800511 self.sched.reconfigure(self.config)
512 self.registerJobs()
513
514 # The pipeline triggers every second, so we should have seen
515 # several by now.
516 time.sleep(5)
517 self.waitUntilSettled()
518
519 builds = self.builds[:]
520
521 self.worker.hold_jobs_in_build = False
522 # Stop queuing timer triggered jobs so that the assertions
523 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -0800524 self.updateConfigLayout(
525 'tests/fixtures/layout-no-timer.yaml')
James E. Blair217b10d2015-01-08 16:25:28 -0800526 self.sched.reconfigure(self.config)
527 self.registerJobs()
528 self.worker.release()
529 self.waitUntilSettled()
530
531 projects = ['org/project']
532
533 self.assertEquals(2, len(builds), "Two builds are running")
534
535 upstream = self.getUpstreamRepos(projects)
536 states = [
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 {'org/project':
541 str(upstream['org/project'].commit('stable/havana')),
James E. Blair217b10d2015-01-08 16:25:28 -0800542 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000543 ]
James E. Blair217b10d2015-01-08 16:25:28 -0800544
545 for number, build in enumerate(builds):
546 self.log.debug("Build parameters: %s", build.parameters)
547 cloner = zuul.lib.cloner.Cloner(
548 git_base_url=self.upstream_root,
549 projects=projects,
550 workspace=self.workspace_root,
551 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
552 zuul_ref=build.parameters.get('ZUUL_REF', None),
553 zuul_url=self.git_root,
554 branch='stable/havana',
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000555 )
James E. Blair217b10d2015-01-08 16:25:28 -0800556 cloner.execute()
557 work = self.getWorkspaceRepos(projects)
558 state = states[number]
559
560 for project in projects:
561 self.assertEquals(state[project],
562 str(work[project].commit('HEAD')),
563 'Project %s commit for build %s should '
564 'be correct' % (project, number))
565
566 shutil.rmtree(self.workspace_root)
567
568 self.worker.hold_jobs_in_build = False
569 self.worker.release()
570 self.waitUntilSettled()