blob: a9223c4db1c8bebcade67c22d3fa4c4a57d65ca3 [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
James E. Blairaf3d01e2017-05-26 14:30:18 -070023import six
Antoine Musso45dd2cb2014-01-29 17:17:43 +010024
25import git
26
27import zuul.lib.cloner
28
James E. Blaird8af5422017-05-24 13:59:40 -070029from tests.base import ZuulTestCase, simple_layout
Antoine Musso45dd2cb2014-01-29 17:17:43 +010030
Antoine Musso45dd2cb2014-01-29 17:17:43 +010031
James E. Blairaf3d01e2017-05-26 14:30:18 -070032def make_state(present, absent):
33 return (present, absent)
34
35
Antoine Musso45dd2cb2014-01-29 17:17:43 +010036class TestCloner(ZuulTestCase):
James E. Blaird8af5422017-05-24 13:59:40 -070037 tenant_config_file = 'config/single-tenant/main.yaml'
Antoine Musso45dd2cb2014-01-29 17:17:43 +010038
39 log = logging.getLogger("zuul.test.cloner")
Antoine Musso45dd2cb2014-01-29 17:17:43 +010040
James E. Blairaf3d01e2017-05-26 14:30:18 -070041 def assertRepoState(self, repo, state, project, build, number):
42 if isinstance(state, six.string_types):
43 self.assertEquals(state,
44 str(repo.commit('HEAD')),
45 'Project %s commit for build %s #%s should '
46 'be correct' % (
47 project, build, number))
48 else:
49 ref = repo.commit('HEAD')
50 repo_messages = set(
51 [c.message.strip() for c in repo.iter_commits(ref)])
52 for change in state[0]:
53 msg = '%s-1' % change.subject
54 self.assertTrue(msg in repo_messages,
55 'Project %s for build %s #%s should '
56 'have change %s' % (
57 project, build, number, change.subject))
58 for change in state[1]:
59 msg = '%s-1' % change.subject
60 self.assertTrue(msg not in repo_messages,
61 'Project %s for build %s #%s should '
62 'not have change %s' % (
63 project, build, number, change.subject))
64
James E. Blaird8af5422017-05-24 13:59:40 -070065 @skip("Disabled for early v3 development")
James E. Blair48ff4d52014-08-25 15:07:21 -070066 def test_cache_dir(self):
67 projects = ['org/project1', 'org/project2']
68 cache_root = os.path.join(self.test_root, "cache")
69 for project in projects:
70 upstream_repo_path = os.path.join(self.upstream_root, project)
71 cache_repo_path = os.path.join(cache_root, project)
72 git.Repo.clone_from(upstream_repo_path, cache_repo_path)
73
74 self.worker.hold_jobs_in_build = True
75 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
76 A.addApproval('CRVW', 2)
77 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
78
79 self.waitUntilSettled()
80
81 self.assertEquals(1, len(self.builds), "One build is running")
82
83 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
84 B.setMerged()
85
86 upstream = self.getUpstreamRepos(projects)
Joshua Hesketh29d99b72014-08-19 16:27:42 +100087 states = [{
88 'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
89 'org/project2': str(upstream['org/project2'].commit('master')),
90 }]
James E. Blair48ff4d52014-08-25 15:07:21 -070091
92 for number, build in enumerate(self.builds):
93 self.log.debug("Build parameters: %s", build.parameters)
94 cloner = zuul.lib.cloner.Cloner(
95 git_base_url=self.upstream_root,
96 projects=projects,
97 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -070098 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blair48ff4d52014-08-25 15:07:21 -070099 zuul_branch=build.parameters['ZUUL_BRANCH'],
100 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500101 zuul_url=self.src_root,
James E. Blair48ff4d52014-08-25 15:07:21 -0700102 cache_dir=cache_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000103 )
James E. Blair48ff4d52014-08-25 15:07:21 -0700104 cloner.execute()
105 work = self.getWorkspaceRepos(projects)
106 state = states[number]
107
108 for project in projects:
109 self.assertEquals(state[project],
110 str(work[project].commit('HEAD')),
111 'Project %s commit for build %s should '
112 'be correct' % (project, number))
113
114 work = self.getWorkspaceRepos(projects)
James E. Blair8cce42e2016-10-18 08:18:36 -0700115 # project1 is the zuul_project so the origin should be set to the
116 # zuul_url since that is the most up to date.
117 cache_repo_path = os.path.join(cache_root, 'org/project1')
118 self.assertNotEqual(
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000119 work['org/project1'].remotes.origin.url,
James E. Blair8cce42e2016-10-18 08:18:36 -0700120 cache_repo_path,
121 'workspace repo origin should not be the cache'
122 )
123 zuul_url_repo_path = os.path.join(self.git_root, 'org/project1')
124 self.assertEqual(
125 work['org/project1'].remotes.origin.url,
126 zuul_url_repo_path,
127 'workspace repo origin should be the zuul url'
128 )
129
130 # project2 is not the zuul_project so the origin should be set
131 # to upstream since that is the best we can do
132 cache_repo_path = os.path.join(cache_root, 'org/project2')
133 self.assertNotEqual(
134 work['org/project2'].remotes.origin.url,
135 cache_repo_path,
136 'workspace repo origin should not be the cache'
137 )
138 upstream_repo_path = os.path.join(self.upstream_root, 'org/project2')
139 self.assertEqual(
140 work['org/project2'].remotes.origin.url,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000141 upstream_repo_path,
James E. Blair8cce42e2016-10-18 08:18:36 -0700142 'workspace repo origin should be the upstream url'
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000143 )
James E. Blair48ff4d52014-08-25 15:07:21 -0700144
145 self.worker.hold_jobs_in_build = False
146 self.worker.release()
147 self.waitUntilSettled()
148
James E. Blaird8af5422017-05-24 13:59:40 -0700149 @simple_layout('layouts/repo-checkout-two-project.yaml')
James E. Blair97d902e2014-08-21 13:25:56 -0700150 def test_one_branch(self):
James E. Blaird8af5422017-05-24 13:59:40 -0700151 self.executor_server.hold_jobs_in_build = True
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100152
James E. Blaird8af5422017-05-24 13:59:40 -0700153 p1 = 'review.example.com/org/project1'
154 p2 = 'review.example.com/org/project2'
155 projects = [p1, p2]
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100156 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
157 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blaird8af5422017-05-24 13:59:40 -0700158 A.addApproval('code-review', 2)
159 B.addApproval('code-review', 2)
160 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
161 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100162
163 self.waitUntilSettled()
164
165 self.assertEquals(2, len(self.builds), "Two builds are running")
166
James E. Blair97d902e2014-08-21 13:25:56 -0700167 upstream = self.getUpstreamRepos(projects)
168 states = [
James E. Blairaf3d01e2017-05-26 14:30:18 -0700169 {p1: make_state(present=[A], absent=[B]),
James E. Blaird8af5422017-05-24 13:59:40 -0700170 p2: str(upstream[p2].commit('master')),
James E. Blair97d902e2014-08-21 13:25:56 -0700171 },
James E. Blairaf3d01e2017-05-26 14:30:18 -0700172 {p1: make_state(present=[A], absent=[B]),
173 p2: make_state(present=[B], absent=[A]),
James E. Blair97d902e2014-08-21 13:25:56 -0700174 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000175 ]
James E. Blair97d902e2014-08-21 13:25:56 -0700176
177 for number, build in enumerate(self.builds):
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100178 self.log.debug("Build parameters: %s", build.parameters)
James E. Blaird8af5422017-05-24 13:59:40 -0700179 work = build.getWorkspaceRepos(projects)
James E. Blair97d902e2014-08-21 13:25:56 -0700180 state = states[number]
181
182 for project in projects:
James E. Blairaf3d01e2017-05-26 14:30:18 -0700183 self.assertRepoState(work[project], state[project],
184 project, build, number)
James E. Blair97d902e2014-08-21 13:25:56 -0700185
James E. Blaird8af5422017-05-24 13:59:40 -0700186 self.executor_server.hold_jobs_in_build = False
187 self.executor_server.release()
James E. Blair97d902e2014-08-21 13:25:56 -0700188 self.waitUntilSettled()
189
James E. Blairaf3d01e2017-05-26 14:30:18 -0700190 @simple_layout('layouts/repo-checkout-four-project.yaml')
James E. Blair97d902e2014-08-21 13:25:56 -0700191 def test_multi_branch(self):
James E. Blairaf3d01e2017-05-26 14:30:18 -0700192 self.executor_server.hold_jobs_in_build = True
193
194 p1 = 'review.example.com/org/project1'
195 p2 = 'review.example.com/org/project2'
196 p3 = 'review.example.com/org/project3'
197 p4 = 'review.example.com/org/project4'
198 projects = [p1, p2, p3, p4]
James E. Blair97d902e2014-08-21 13:25:56 -0700199
200 self.create_branch('org/project2', 'stable/havana')
201 self.create_branch('org/project4', 'stable/havana')
202 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000203 B = self.fake_gerrit.addFakeChange('org/project2', 'stable/havana',
204 'B')
James E. Blair97d902e2014-08-21 13:25:56 -0700205 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
James E. Blairaf3d01e2017-05-26 14:30:18 -0700206 A.addApproval('code-review', 2)
207 B.addApproval('code-review', 2)
208 C.addApproval('code-review', 2)
209 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
210 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
211 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair97d902e2014-08-21 13:25:56 -0700212
213 self.waitUntilSettled()
214
215 self.assertEquals(3, len(self.builds), "Three builds are running")
216
217 upstream = self.getUpstreamRepos(projects)
218 states = [
James E. Blairaf3d01e2017-05-26 14:30:18 -0700219 {p1: make_state(present=[A], absent=[B, C]),
220 p2: str(upstream[p2].commit('master')),
221 p3: str(upstream[p3].commit('master')),
222 p4: str(upstream[p4].commit('master')),
James E. Blair97d902e2014-08-21 13:25:56 -0700223 },
James E. Blairaf3d01e2017-05-26 14:30:18 -0700224 {p1: make_state(present=[A], absent=[B, C]),
225 p2: make_state(present=[B], absent=[A, C]),
226 p3: str(upstream[p3].commit('master')),
227 p4: str(upstream[p4].commit('stable/havana')),
James E. Blair97d902e2014-08-21 13:25:56 -0700228 },
James E. Blairaf3d01e2017-05-26 14:30:18 -0700229 {p1: make_state(present=[A], absent=[B, C]),
230 p2: str(upstream[p2].commit('master')),
231 p3: make_state(present=[C], absent=[A, B]),
232 p4: str(upstream[p4].commit('master')),
James E. Blair97d902e2014-08-21 13:25:56 -0700233 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000234 ]
James E. Blair97d902e2014-08-21 13:25:56 -0700235
236 for number, build in enumerate(self.builds):
237 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairaf3d01e2017-05-26 14:30:18 -0700238 work = build.getWorkspaceRepos(projects)
James E. Blair97d902e2014-08-21 13:25:56 -0700239 state = states[number]
240
241 for project in projects:
James E. Blairaf3d01e2017-05-26 14:30:18 -0700242 self.assertRepoState(work[project], state[project],
243 project, build, number)
James E. Blair82318922014-08-21 11:05:32 -0700244
James E. Blairaf3d01e2017-05-26 14:30:18 -0700245 self.executor_server.hold_jobs_in_build = False
246 self.executor_server.release()
James E. Blair82318922014-08-21 11:05:32 -0700247 self.waitUntilSettled()
James E. Blairbce35e12014-08-21 14:31:17 -0700248
James E. Blaird8af5422017-05-24 13:59:40 -0700249 @skip("Disabled for early v3 development")
James E. Blairbce35e12014-08-21 14:31:17 -0700250 def test_upgrade(self):
251 # Simulates an upgrade test
252 self.worker.hold_jobs_in_build = True
253 projects = ['org/project1', 'org/project2', 'org/project3',
254 'org/project4', 'org/project5', 'org/project6']
255
256 self.create_branch('org/project2', 'stable/havana')
257 self.create_branch('org/project3', 'stable/havana')
258 self.create_branch('org/project4', 'stable/havana')
259 self.create_branch('org/project5', 'stable/havana')
260 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
261 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000262 C = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
263 'C')
James E. Blairbce35e12014-08-21 14:31:17 -0700264 D = self.fake_gerrit.addFakeChange('org/project3', 'master', 'D')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000265 E = self.fake_gerrit.addFakeChange('org/project4', 'stable/havana',
266 'E')
James E. Blairbce35e12014-08-21 14:31:17 -0700267 A.addApproval('CRVW', 2)
268 B.addApproval('CRVW', 2)
269 C.addApproval('CRVW', 2)
270 D.addApproval('CRVW', 2)
271 E.addApproval('CRVW', 2)
272 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
273 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
274 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
275 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
276 self.fake_gerrit.addEvent(E.addApproval('APRV', 1))
277
278 self.waitUntilSettled()
279
280 self.assertEquals(5, len(self.builds), "Five builds are running")
281
282 # Check the old side of the upgrade first
283 upstream = self.getUpstreamRepos(projects)
284 states = [
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')),
299 'org/project3': str(upstream['org/project3'].commit(
300 'stable/havana')),
301 'org/project4': str(upstream['org/project4'].commit(
302 'stable/havana')),
303 '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')),
James E. Blairbce35e12014-08-21 14:31:17 -0700313
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000314 'org/project5': str(upstream['org/project5'].commit(
315 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700316 'org/project6': str(upstream['org/project6'].commit('master')),
317 },
318 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000319 'org/project2': str(upstream['org/project2'].commit(
320 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700321 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000322 'org/project4': str(upstream['org/project4'].commit(
323 'stable/havana')),
324 '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 },
328 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000329 'org/project2': str(upstream['org/project2'].commit(
330 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700331 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
332 'org/project4': self.builds[4].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000333 'org/project5': str(upstream['org/project5'].commit(
334 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700335 'org/project6': str(upstream['org/project6'].commit('master')),
336 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000337 ]
James E. Blairbce35e12014-08-21 14:31:17 -0700338
339 for number, build in enumerate(self.builds):
340 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairbce35e12014-08-21 14:31:17 -0700341 cloner = zuul.lib.cloner.Cloner(
342 git_base_url=self.upstream_root,
343 projects=projects,
344 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700345 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blairbce35e12014-08-21 14:31:17 -0700346 zuul_branch=build.parameters['ZUUL_BRANCH'],
347 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500348 zuul_url=self.src_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000349 branch='stable/havana', # Old branch for upgrade
350 )
James E. Blairbce35e12014-08-21 14:31:17 -0700351 cloner.execute()
352 work = self.getWorkspaceRepos(projects)
353 state = states[number]
354
355 for project in projects:
356 self.assertEquals(state[project],
357 str(work[project].commit('HEAD')),
358 'Project %s commit for build %s should '
359 'be correct on old side of upgrade' %
360 (project, number))
361 shutil.rmtree(self.workspace_root)
362
363 # Check the new side of the upgrade
364 states = [
365 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
366 'org/project2': str(upstream['org/project2'].commit('master')),
367 'org/project3': str(upstream['org/project3'].commit('master')),
368 'org/project4': str(upstream['org/project4'].commit('master')),
369 'org/project5': str(upstream['org/project5'].commit('master')),
370 'org/project6': str(upstream['org/project6'].commit('master')),
371 },
372 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
373 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
374 'org/project3': str(upstream['org/project3'].commit('master')),
375 'org/project4': str(upstream['org/project4'].commit('master')),
376 'org/project5': str(upstream['org/project5'].commit('master')),
377 'org/project6': str(upstream['org/project6'].commit('master')),
378 },
379 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
380 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
381 'org/project3': str(upstream['org/project3'].commit('master')),
382 'org/project4': str(upstream['org/project4'].commit('master')),
383 'org/project5': str(upstream['org/project5'].commit('master')),
384 'org/project6': str(upstream['org/project6'].commit('master')),
385 },
386 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
387 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
388 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
389 'org/project4': str(upstream['org/project4'].commit('master')),
390 'org/project5': str(upstream['org/project5'].commit('master')),
391 'org/project6': str(upstream['org/project6'].commit('master')),
392 },
393 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
394 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
395 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
396 'org/project4': str(upstream['org/project4'].commit('master')),
397 'org/project5': str(upstream['org/project5'].commit('master')),
398 'org/project6': str(upstream['org/project6'].commit('master')),
399 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000400 ]
James E. Blairbce35e12014-08-21 14:31:17 -0700401
402 for number, build in enumerate(self.builds):
403 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairbce35e12014-08-21 14:31:17 -0700404 cloner = zuul.lib.cloner.Cloner(
405 git_base_url=self.upstream_root,
406 projects=projects,
407 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700408 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blairbce35e12014-08-21 14:31:17 -0700409 zuul_branch=build.parameters['ZUUL_BRANCH'],
410 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500411 zuul_url=self.src_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000412 branch='master', # New branch for upgrade
413 )
James E. Blairbce35e12014-08-21 14:31:17 -0700414 cloner.execute()
415 work = self.getWorkspaceRepos(projects)
416 state = states[number]
417
418 for project in projects:
419 self.assertEquals(state[project],
420 str(work[project].commit('HEAD')),
421 'Project %s commit for build %s should '
422 'be correct on old side of upgrade' %
423 (project, number))
424 shutil.rmtree(self.workspace_root)
425
426 self.worker.hold_jobs_in_build = False
427 self.worker.release()
428 self.waitUntilSettled()
James E. Blairf0420222014-08-21 16:02:17 -0700429
James E. Blaird8af5422017-05-24 13:59:40 -0700430 @skip("Disabled for early v3 development")
James E. Blairf0420222014-08-21 16:02:17 -0700431 def test_project_override(self):
432 self.worker.hold_jobs_in_build = True
433 projects = ['org/project1', 'org/project2', 'org/project3',
434 'org/project4', 'org/project5', 'org/project6']
435
436 self.create_branch('org/project3', 'stable/havana')
437 self.create_branch('org/project4', 'stable/havana')
438 self.create_branch('org/project6', 'stable/havana')
439 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
440 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
441 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000442 D = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
443 'D')
James E. Blairf0420222014-08-21 16:02:17 -0700444 A.addApproval('CRVW', 2)
445 B.addApproval('CRVW', 2)
446 C.addApproval('CRVW', 2)
447 D.addApproval('CRVW', 2)
448 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
449 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
450 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
451 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
452
453 self.waitUntilSettled()
454
455 self.assertEquals(4, len(self.builds), "Four builds are running")
456
457 upstream = self.getUpstreamRepos(projects)
458 states = [
459 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
460 'org/project2': str(upstream['org/project2'].commit('master')),
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': str(upstream['org/project2'].commit('master')),
468 'org/project3': str(upstream['org/project3'].commit('master')),
469 'org/project4': str(upstream['org/project4'].commit('master')),
470 'org/project5': str(upstream['org/project5'].commit('master')),
471 'org/project6': str(upstream['org/project6'].commit('master')),
472 },
473 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
474 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'],
475 'org/project3': str(upstream['org/project3'].commit('master')),
476 'org/project4': str(upstream['org/project4'].commit('master')),
477 'org/project5': str(upstream['org/project5'].commit('master')),
478 'org/project6': str(upstream['org/project6'].commit('master')),
479 },
480 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
481 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'],
482 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
483 'org/project4': str(upstream['org/project4'].commit('master')),
484 'org/project5': str(upstream['org/project5'].commit('master')),
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000485 'org/project6': str(upstream['org/project6'].commit(
486 'stable/havana')),
James E. Blairf0420222014-08-21 16:02:17 -0700487 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000488 ]
James E. Blairf0420222014-08-21 16:02:17 -0700489
490 for number, build in enumerate(self.builds):
491 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairf0420222014-08-21 16:02:17 -0700492 cloner = zuul.lib.cloner.Cloner(
493 git_base_url=self.upstream_root,
494 projects=projects,
495 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700496 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blairf0420222014-08-21 16:02:17 -0700497 zuul_branch=build.parameters['ZUUL_BRANCH'],
498 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500499 zuul_url=self.src_root,
James E. Blairf0420222014-08-21 16:02:17 -0700500 project_branches={'org/project4': 'master'},
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000501 )
James E. Blairf0420222014-08-21 16:02:17 -0700502 cloner.execute()
503 work = self.getWorkspaceRepos(projects)
504 state = states[number]
505
506 for project in projects:
507 self.assertEquals(state[project],
508 str(work[project].commit('HEAD')),
509 'Project %s commit for build %s should '
510 'be correct' % (project, number))
511 shutil.rmtree(self.workspace_root)
512
513 self.worker.hold_jobs_in_build = False
514 self.worker.release()
515 self.waitUntilSettled()
James E. Blair217b10d2015-01-08 16:25:28 -0800516
James E. Blaird8af5422017-05-24 13:59:40 -0700517 @skip("Disabled for early v3 development")
James E. Blair217b10d2015-01-08 16:25:28 -0800518 def test_periodic(self):
519 self.worker.hold_jobs_in_build = True
520 self.create_branch('org/project', 'stable/havana')
James E. Blairf84026c2015-12-08 16:11:46 -0800521 self.updateConfigLayout(
522 'tests/fixtures/layout-timer.yaml')
James E. Blair217b10d2015-01-08 16:25:28 -0800523 self.sched.reconfigure(self.config)
524 self.registerJobs()
525
526 # The pipeline triggers every second, so we should have seen
527 # several by now.
528 time.sleep(5)
529 self.waitUntilSettled()
530
531 builds = self.builds[:]
532
533 self.worker.hold_jobs_in_build = False
534 # Stop queuing timer triggered jobs so that the assertions
535 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -0800536 self.updateConfigLayout(
537 'tests/fixtures/layout-no-timer.yaml')
James E. Blair217b10d2015-01-08 16:25:28 -0800538 self.sched.reconfigure(self.config)
539 self.registerJobs()
540 self.worker.release()
541 self.waitUntilSettled()
542
543 projects = ['org/project']
544
545 self.assertEquals(2, len(builds), "Two builds are running")
546
547 upstream = self.getUpstreamRepos(projects)
548 states = [
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000549 {'org/project':
550 str(upstream['org/project'].commit('stable/havana')),
James E. Blair217b10d2015-01-08 16:25:28 -0800551 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000552 {'org/project':
553 str(upstream['org/project'].commit('stable/havana')),
James E. Blair217b10d2015-01-08 16:25:28 -0800554 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000555 ]
James E. Blair217b10d2015-01-08 16:25:28 -0800556
557 for number, build in enumerate(builds):
558 self.log.debug("Build parameters: %s", build.parameters)
559 cloner = zuul.lib.cloner.Cloner(
560 git_base_url=self.upstream_root,
561 projects=projects,
562 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700563 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blair217b10d2015-01-08 16:25:28 -0800564 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
565 zuul_ref=build.parameters.get('ZUUL_REF', None),
Monty Taylord642d852017-02-23 14:05:42 -0500566 zuul_url=self.src_root,
James E. Blair217b10d2015-01-08 16:25:28 -0800567 branch='stable/havana',
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000568 )
James E. Blair217b10d2015-01-08 16:25:28 -0800569 cloner.execute()
570 work = self.getWorkspaceRepos(projects)
571 state = states[number]
572
573 for project in projects:
574 self.assertEquals(state[project],
575 str(work[project].commit('HEAD')),
576 'Project %s commit for build %s should '
577 'be correct' % (project, number))
578
579 shutil.rmtree(self.workspace_root)
580
581 self.worker.hold_jobs_in_build = False
582 self.worker.release()
583 self.waitUntilSettled()
Sachi King9f16d522016-03-16 12:20:45 +1100584
James E. Blaird8af5422017-05-24 13:59:40 -0700585 @skip("Disabled for early v3 development")
James E. Blairbfd85fd2016-10-21 14:18:11 -0700586 def test_periodic_update(self):
587 # Test that the merger correctly updates its local repository
588 # before running a periodic job.
589
590 # Prime the merger with the current state
591 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
592 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
593 self.waitUntilSettled()
594
595 # Merge a different change
596 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
597 B.setMerged()
598
599 # Start a periodic job
600 self.worker.hold_jobs_in_build = True
Paul Belanger174a8272017-03-14 13:20:10 -0400601 self.executor.negative_function_cache_ttl = 0
James E. Blairbfd85fd2016-10-21 14:18:11 -0700602 self.config.set('zuul', 'layout_config',
603 'tests/fixtures/layout-timer.yaml')
604 self.sched.reconfigure(self.config)
605 self.registerJobs()
606
607 # The pipeline triggers every second, so we should have seen
608 # several by now.
609 time.sleep(5)
610 self.waitUntilSettled()
611
612 builds = self.builds[:]
613
614 self.worker.hold_jobs_in_build = False
615 # Stop queuing timer triggered jobs so that the assertions
616 # below don't race against more jobs being queued.
617 self.config.set('zuul', 'layout_config',
618 'tests/fixtures/layout-no-timer.yaml')
619 self.sched.reconfigure(self.config)
620 self.registerJobs()
621 self.worker.release()
622 self.waitUntilSettled()
623
624 projects = ['org/project']
625
626 self.assertEquals(2, len(builds), "Two builds are running")
627
628 upstream = self.getUpstreamRepos(projects)
629 self.assertEqual(upstream['org/project'].commit('master').hexsha,
630 B.patchsets[0]['revision'])
631 states = [
632 {'org/project':
633 str(upstream['org/project'].commit('master')),
634 },
635 {'org/project':
636 str(upstream['org/project'].commit('master')),
637 },
638 ]
639
640 for number, build in enumerate(builds):
641 self.log.debug("Build parameters: %s", build.parameters)
642 cloner = zuul.lib.cloner.Cloner(
643 git_base_url=self.upstream_root,
644 projects=projects,
645 workspace=self.workspace_root,
646 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
647 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
648 zuul_ref=build.parameters.get('ZUUL_REF', None),
649 zuul_url=self.git_root,
650 )
651 cloner.execute()
652 work = self.getWorkspaceRepos(projects)
653 state = states[number]
654
655 for project in projects:
656 self.assertEquals(state[project],
657 str(work[project].commit('HEAD')),
658 'Project %s commit for build %s should '
659 'be correct' % (project, number))
660
661 shutil.rmtree(self.workspace_root)
662
663 self.worker.hold_jobs_in_build = False
664 self.worker.release()
665 self.waitUntilSettled()
666
James E. Blaird8af5422017-05-24 13:59:40 -0700667 @skip("Disabled for early v3 development")
Sachi King9f16d522016-03-16 12:20:45 +1100668 def test_post_checkout(self):
James E. Blair8cce42e2016-10-18 08:18:36 -0700669 self.worker.hold_jobs_in_build = True
670 project = "org/project1"
671
672 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
673 event = A.getRefUpdatedEvent()
674 A.setMerged()
675 self.fake_gerrit.addEvent(event)
676 self.waitUntilSettled()
677
678 build = self.builds[0]
679 state = {'org/project1': build.parameters['ZUUL_COMMIT']}
680
681 build.release()
682 self.waitUntilSettled()
Sachi King9f16d522016-03-16 12:20:45 +1100683
684 cloner = zuul.lib.cloner.Cloner(
685 git_base_url=self.upstream_root,
686 projects=[project],
687 workspace=self.workspace_root,
James E. Blair8cce42e2016-10-18 08:18:36 -0700688 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
689 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
690 zuul_ref=build.parameters.get('ZUUL_REF', None),
691 zuul_newrev=build.parameters.get('ZUUL_NEWREV', None),
Sachi King9f16d522016-03-16 12:20:45 +1100692 zuul_url=self.git_root,
Sachi King9f16d522016-03-16 12:20:45 +1100693 )
694 cloner.execute()
James E. Blair8cce42e2016-10-18 08:18:36 -0700695 work = self.getWorkspaceRepos([project])
696 self.assertEquals(state[project],
697 str(work[project].commit('HEAD')),
698 'Project %s commit for build %s should '
699 'be correct' % (project, 0))
700 shutil.rmtree(self.workspace_root)
Sachi King9f16d522016-03-16 12:20:45 +1100701
James E. Blaird8af5422017-05-24 13:59:40 -0700702 @skip("Disabled for early v3 development")
Sachi King9f16d522016-03-16 12:20:45 +1100703 def test_post_and_master_checkout(self):
James E. Blair8cce42e2016-10-18 08:18:36 -0700704 self.worker.hold_jobs_in_build = True
705 projects = ["org/project1", "org/project2"]
706
707 A = self.fake_gerrit.addFakeChange(projects[0], 'master', 'A')
708 event = A.getRefUpdatedEvent()
709 A.setMerged()
710 self.fake_gerrit.addEvent(event)
711 self.waitUntilSettled()
712
713 build = self.builds[0]
714 upstream = self.getUpstreamRepos(projects)
715 state = {'org/project1':
716 build.parameters['ZUUL_COMMIT'],
717 'org/project2':
718 str(upstream['org/project2'].commit('master')),
719 }
720
721 build.release()
722 self.waitUntilSettled()
Sachi King9f16d522016-03-16 12:20:45 +1100723
724 cloner = zuul.lib.cloner.Cloner(
725 git_base_url=self.upstream_root,
James E. Blair8cce42e2016-10-18 08:18:36 -0700726 projects=projects,
Sachi King9f16d522016-03-16 12:20:45 +1100727 workspace=self.workspace_root,
James E. Blair8cce42e2016-10-18 08:18:36 -0700728 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
729 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
730 zuul_ref=build.parameters.get('ZUUL_REF', None),
731 zuul_newrev=build.parameters.get('ZUUL_NEWREV', None),
Sachi King9f16d522016-03-16 12:20:45 +1100732 zuul_url=self.git_root,
Sachi King9f16d522016-03-16 12:20:45 +1100733 )
734 cloner.execute()
James E. Blair8cce42e2016-10-18 08:18:36 -0700735 work = self.getWorkspaceRepos(projects)
736
737 for project in projects:
738 self.assertEquals(state[project],
739 str(work[project].commit('HEAD')),
740 'Project %s commit for build %s should '
741 'be correct' % (project, 0))
742 shutil.rmtree(self.workspace_root)