blob: 8edfea773be1f48b9a97cc4d0eb37d6941120740 [file] [log] [blame]
Antoine Musso45dd2cb2014-01-29 17:17:43 +01001#!/usr/bin/env python
2
3# Copyright 2012 Hewlett-Packard Development Company, L.P.
4# Copyright 2014 Wikimedia Foundation Inc.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import logging
19import os
20import shutil
James E. Blair217b10d2015-01-08 16:25:28 -080021import time
James E. Blaird8af5422017-05-24 13:59:40 -070022from unittest import skip
Antoine Musso45dd2cb2014-01-29 17:17:43 +010023
24import git
25
26import zuul.lib.cloner
27
James E. Blaird8af5422017-05-24 13:59:40 -070028from tests.base import ZuulTestCase, simple_layout
Antoine Musso45dd2cb2014-01-29 17:17:43 +010029
Antoine Musso45dd2cb2014-01-29 17:17:43 +010030
31class TestCloner(ZuulTestCase):
James E. Blaird8af5422017-05-24 13:59:40 -070032 tenant_config_file = 'config/single-tenant/main.yaml'
Antoine Musso45dd2cb2014-01-29 17:17:43 +010033
34 log = logging.getLogger("zuul.test.cloner")
Antoine Musso45dd2cb2014-01-29 17:17:43 +010035
James E. Blairaf3d01e2017-05-26 14:30:18 -070036 def assertRepoState(self, repo, state, project, build, number):
James E. Blairbcaa2d42017-05-26 15:44:23 -070037 if 'branch' in state:
38 self.assertFalse(repo.head.is_detached,
39 'Project %s commit for build %s #%s should '
40 'not have a detached HEAD' % (
41 project, build, number))
42 self.assertEquals(repo.active_branch.name,
43 state['branch'],
44 'Project %s commit for build %s #%s should '
45 'be on the correct branch' % (
46 project, build, number))
47 if 'commit' in state:
48 self.assertEquals(state['commit'],
James E. Blairaf3d01e2017-05-26 14:30:18 -070049 str(repo.commit('HEAD')),
50 'Project %s commit for build %s #%s should '
51 'be correct' % (
52 project, build, number))
James E. Blairbcaa2d42017-05-26 15:44:23 -070053 ref = repo.commit('HEAD')
54 repo_messages = set(
55 [c.message.strip() for c in repo.iter_commits(ref)])
56 if 'present' in state:
57 for change in state['present']:
James E. Blairaf3d01e2017-05-26 14:30:18 -070058 msg = '%s-1' % change.subject
59 self.assertTrue(msg in repo_messages,
60 'Project %s for build %s #%s should '
61 'have change %s' % (
62 project, build, number, change.subject))
James E. Blairbcaa2d42017-05-26 15:44:23 -070063 if 'absent' in state:
64 for change in state['absent']:
James E. Blairaf3d01e2017-05-26 14:30:18 -070065 msg = '%s-1' % change.subject
66 self.assertTrue(msg not in repo_messages,
67 'Project %s for build %s #%s should '
68 'not have change %s' % (
69 project, build, number, change.subject))
70
James E. Blaird8af5422017-05-24 13:59:40 -070071 @skip("Disabled for early v3 development")
James E. Blair48ff4d52014-08-25 15:07:21 -070072 def test_cache_dir(self):
73 projects = ['org/project1', 'org/project2']
74 cache_root = os.path.join(self.test_root, "cache")
75 for project in projects:
76 upstream_repo_path = os.path.join(self.upstream_root, project)
77 cache_repo_path = os.path.join(cache_root, project)
78 git.Repo.clone_from(upstream_repo_path, cache_repo_path)
79
80 self.worker.hold_jobs_in_build = True
81 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
82 A.addApproval('CRVW', 2)
83 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
84
85 self.waitUntilSettled()
86
87 self.assertEquals(1, len(self.builds), "One build is running")
88
89 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
90 B.setMerged()
91
92 upstream = self.getUpstreamRepos(projects)
Joshua Hesketh29d99b72014-08-19 16:27:42 +100093 states = [{
94 'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
95 'org/project2': str(upstream['org/project2'].commit('master')),
96 }]
James E. Blair48ff4d52014-08-25 15:07:21 -070097
98 for number, build in enumerate(self.builds):
99 self.log.debug("Build parameters: %s", build.parameters)
100 cloner = zuul.lib.cloner.Cloner(
101 git_base_url=self.upstream_root,
102 projects=projects,
103 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700104 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blair48ff4d52014-08-25 15:07:21 -0700105 zuul_branch=build.parameters['ZUUL_BRANCH'],
106 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500107 zuul_url=self.src_root,
James E. Blair48ff4d52014-08-25 15:07:21 -0700108 cache_dir=cache_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000109 )
James E. Blair48ff4d52014-08-25 15:07:21 -0700110 cloner.execute()
111 work = self.getWorkspaceRepos(projects)
112 state = states[number]
113
114 for project in projects:
115 self.assertEquals(state[project],
116 str(work[project].commit('HEAD')),
117 'Project %s commit for build %s should '
118 'be correct' % (project, number))
119
120 work = self.getWorkspaceRepos(projects)
James E. Blair8cce42e2016-10-18 08:18:36 -0700121 # project1 is the zuul_project so the origin should be set to the
122 # zuul_url since that is the most up to date.
123 cache_repo_path = os.path.join(cache_root, 'org/project1')
124 self.assertNotEqual(
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000125 work['org/project1'].remotes.origin.url,
James E. Blair8cce42e2016-10-18 08:18:36 -0700126 cache_repo_path,
127 'workspace repo origin should not be the cache'
128 )
129 zuul_url_repo_path = os.path.join(self.git_root, 'org/project1')
130 self.assertEqual(
131 work['org/project1'].remotes.origin.url,
132 zuul_url_repo_path,
133 'workspace repo origin should be the zuul url'
134 )
135
136 # project2 is not the zuul_project so the origin should be set
137 # to upstream since that is the best we can do
138 cache_repo_path = os.path.join(cache_root, 'org/project2')
139 self.assertNotEqual(
140 work['org/project2'].remotes.origin.url,
141 cache_repo_path,
142 'workspace repo origin should not be the cache'
143 )
144 upstream_repo_path = os.path.join(self.upstream_root, 'org/project2')
145 self.assertEqual(
146 work['org/project2'].remotes.origin.url,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000147 upstream_repo_path,
James E. Blair8cce42e2016-10-18 08:18:36 -0700148 'workspace repo origin should be the upstream url'
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000149 )
James E. Blair48ff4d52014-08-25 15:07:21 -0700150
151 self.worker.hold_jobs_in_build = False
152 self.worker.release()
153 self.waitUntilSettled()
154
James E. Blaird8af5422017-05-24 13:59:40 -0700155 @simple_layout('layouts/repo-checkout-two-project.yaml')
James E. Blair97d902e2014-08-21 13:25:56 -0700156 def test_one_branch(self):
James E. Blaird8af5422017-05-24 13:59:40 -0700157 self.executor_server.hold_jobs_in_build = True
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100158
James E. Blaird8af5422017-05-24 13:59:40 -0700159 p1 = 'review.example.com/org/project1'
160 p2 = 'review.example.com/org/project2'
161 projects = [p1, p2]
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100162 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
163 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blaird8af5422017-05-24 13:59:40 -0700164 A.addApproval('code-review', 2)
165 B.addApproval('code-review', 2)
166 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
167 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100168
169 self.waitUntilSettled()
170
171 self.assertEquals(2, len(self.builds), "Two builds are running")
172
James E. Blair97d902e2014-08-21 13:25:56 -0700173 upstream = self.getUpstreamRepos(projects)
174 states = [
James E. Blairbcaa2d42017-05-26 15:44:23 -0700175 {p1: dict(present=[A], absent=[B], branch='master'),
176 p2: dict(commit=str(upstream[p2].commit('master')),
177 branch='master'),
James E. Blair97d902e2014-08-21 13:25:56 -0700178 },
James E. Blairbcaa2d42017-05-26 15:44:23 -0700179 {p1: dict(present=[A], absent=[B], branch='master'),
180 p2: dict(present=[B], absent=[A], branch='master'),
James E. Blair97d902e2014-08-21 13:25:56 -0700181 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000182 ]
James E. Blair97d902e2014-08-21 13:25:56 -0700183
184 for number, build in enumerate(self.builds):
Antoine Musso45dd2cb2014-01-29 17:17:43 +0100185 self.log.debug("Build parameters: %s", build.parameters)
James E. Blaird8af5422017-05-24 13:59:40 -0700186 work = build.getWorkspaceRepos(projects)
James E. Blair97d902e2014-08-21 13:25:56 -0700187 state = states[number]
188
189 for project in projects:
James E. Blairaf3d01e2017-05-26 14:30:18 -0700190 self.assertRepoState(work[project], state[project],
191 project, build, number)
James E. Blair97d902e2014-08-21 13:25:56 -0700192
James E. Blaird8af5422017-05-24 13:59:40 -0700193 self.executor_server.hold_jobs_in_build = False
194 self.executor_server.release()
James E. Blair97d902e2014-08-21 13:25:56 -0700195 self.waitUntilSettled()
196
James E. Blairaf3d01e2017-05-26 14:30:18 -0700197 @simple_layout('layouts/repo-checkout-four-project.yaml')
James E. Blair97d902e2014-08-21 13:25:56 -0700198 def test_multi_branch(self):
James E. Blairaf3d01e2017-05-26 14:30:18 -0700199 self.executor_server.hold_jobs_in_build = True
200
201 p1 = 'review.example.com/org/project1'
202 p2 = 'review.example.com/org/project2'
203 p3 = 'review.example.com/org/project3'
204 p4 = 'review.example.com/org/project4'
205 projects = [p1, p2, p3, p4]
James E. Blair97d902e2014-08-21 13:25:56 -0700206
207 self.create_branch('org/project2', 'stable/havana')
208 self.create_branch('org/project4', 'stable/havana')
209 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000210 B = self.fake_gerrit.addFakeChange('org/project2', 'stable/havana',
211 'B')
James E. Blair97d902e2014-08-21 13:25:56 -0700212 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
James E. Blairaf3d01e2017-05-26 14:30:18 -0700213 A.addApproval('code-review', 2)
214 B.addApproval('code-review', 2)
215 C.addApproval('code-review', 2)
216 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
217 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
218 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair97d902e2014-08-21 13:25:56 -0700219
220 self.waitUntilSettled()
221
222 self.assertEquals(3, len(self.builds), "Three builds are running")
223
224 upstream = self.getUpstreamRepos(projects)
225 states = [
James E. Blairbcaa2d42017-05-26 15:44:23 -0700226 {p1: dict(present=[A], absent=[B, C], branch='master'),
227 p2: dict(commit=str(upstream[p2].commit('master')),
228 branch='master'),
229 p3: dict(commit=str(upstream[p3].commit('master')),
230 branch='master'),
231 p4: dict(commit=str(upstream[p4].commit('master')),
232 branch='master'),
James E. Blair97d902e2014-08-21 13:25:56 -0700233 },
James E. Blairbcaa2d42017-05-26 15:44:23 -0700234 {p1: dict(present=[A], absent=[B, C], branch='master'),
235 p2: dict(present=[B], absent=[A, C], branch='stable/havana'),
236 p3: dict(commit=str(upstream[p3].commit('master')),
237 branch='master'),
238 p4: dict(commit=str(upstream[p4].commit('stable/havana')),
239 branch='stable/havana'),
James E. Blair97d902e2014-08-21 13:25:56 -0700240 },
James E. Blairbcaa2d42017-05-26 15:44:23 -0700241 {p1: dict(present=[A], absent=[B, C], branch='master'),
242 p2: dict(commit=str(upstream[p2].commit('master')),
243 branch='master'),
244 p3: dict(present=[C], absent=[A, B], branch='master'),
245 p4: dict(commit=str(upstream[p4].commit('master')),
246 branch='master'),
James E. Blair97d902e2014-08-21 13:25:56 -0700247 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000248 ]
James E. Blair97d902e2014-08-21 13:25:56 -0700249
250 for number, build in enumerate(self.builds):
251 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairaf3d01e2017-05-26 14:30:18 -0700252 work = build.getWorkspaceRepos(projects)
James E. Blair97d902e2014-08-21 13:25:56 -0700253 state = states[number]
254
255 for project in projects:
James E. Blairaf3d01e2017-05-26 14:30:18 -0700256 self.assertRepoState(work[project], state[project],
257 project, build, number)
James E. Blair82318922014-08-21 11:05:32 -0700258
James E. Blairaf3d01e2017-05-26 14:30:18 -0700259 self.executor_server.hold_jobs_in_build = False
260 self.executor_server.release()
James E. Blair82318922014-08-21 11:05:32 -0700261 self.waitUntilSettled()
James E. Blairbce35e12014-08-21 14:31:17 -0700262
James E. Blaird8af5422017-05-24 13:59:40 -0700263 @skip("Disabled for early v3 development")
James E. Blairbce35e12014-08-21 14:31:17 -0700264 def test_upgrade(self):
265 # Simulates an upgrade test
266 self.worker.hold_jobs_in_build = True
267 projects = ['org/project1', 'org/project2', 'org/project3',
268 'org/project4', 'org/project5', 'org/project6']
269
270 self.create_branch('org/project2', 'stable/havana')
271 self.create_branch('org/project3', 'stable/havana')
272 self.create_branch('org/project4', 'stable/havana')
273 self.create_branch('org/project5', 'stable/havana')
274 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
275 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000276 C = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
277 'C')
James E. Blairbce35e12014-08-21 14:31:17 -0700278 D = self.fake_gerrit.addFakeChange('org/project3', 'master', 'D')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000279 E = self.fake_gerrit.addFakeChange('org/project4', 'stable/havana',
280 'E')
James E. Blairbce35e12014-08-21 14:31:17 -0700281 A.addApproval('CRVW', 2)
282 B.addApproval('CRVW', 2)
283 C.addApproval('CRVW', 2)
284 D.addApproval('CRVW', 2)
285 E.addApproval('CRVW', 2)
286 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
287 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
288 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
289 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
290 self.fake_gerrit.addEvent(E.addApproval('APRV', 1))
291
292 self.waitUntilSettled()
293
294 self.assertEquals(5, len(self.builds), "Five builds are running")
295
296 # Check the old side of the upgrade first
297 upstream = self.getUpstreamRepos(projects)
298 states = [
299 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000300 'org/project2': str(upstream['org/project2'].commit(
301 'stable/havana')),
302 'org/project3': str(upstream['org/project3'].commit(
303 'stable/havana')),
304 'org/project4': str(upstream['org/project4'].commit(
305 'stable/havana')),
306 'org/project5': str(upstream['org/project5'].commit(
307 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700308 'org/project6': str(upstream['org/project6'].commit('master')),
309 },
310 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000311 'org/project2': str(upstream['org/project2'].commit(
312 'stable/havana')),
313 'org/project3': str(upstream['org/project3'].commit(
314 'stable/havana')),
315 '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'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000325 'org/project4': str(upstream['org/project4'].commit(
326 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700327
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000328 'org/project5': str(upstream['org/project5'].commit(
329 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700330 'org/project6': str(upstream['org/project6'].commit('master')),
331 },
332 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000333 'org/project2': str(upstream['org/project2'].commit(
334 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700335 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000336 'org/project4': str(upstream['org/project4'].commit(
337 'stable/havana')),
338 'org/project5': str(upstream['org/project5'].commit(
339 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700340 'org/project6': str(upstream['org/project6'].commit('master')),
341 },
342 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000343 'org/project2': str(upstream['org/project2'].commit(
344 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700345 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
346 'org/project4': self.builds[4].parameters['ZUUL_COMMIT'],
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000347 'org/project5': str(upstream['org/project5'].commit(
348 'stable/havana')),
James E. Blairbce35e12014-08-21 14:31:17 -0700349 'org/project6': str(upstream['org/project6'].commit('master')),
350 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000351 ]
James E. Blairbce35e12014-08-21 14:31:17 -0700352
353 for number, build in enumerate(self.builds):
354 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairbce35e12014-08-21 14:31:17 -0700355 cloner = zuul.lib.cloner.Cloner(
356 git_base_url=self.upstream_root,
357 projects=projects,
358 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700359 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blairbce35e12014-08-21 14:31:17 -0700360 zuul_branch=build.parameters['ZUUL_BRANCH'],
361 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500362 zuul_url=self.src_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000363 branch='stable/havana', # Old branch for upgrade
364 )
James E. Blairbce35e12014-08-21 14:31:17 -0700365 cloner.execute()
366 work = self.getWorkspaceRepos(projects)
367 state = states[number]
368
369 for project in projects:
370 self.assertEquals(state[project],
371 str(work[project].commit('HEAD')),
372 'Project %s commit for build %s should '
373 'be correct on old side of upgrade' %
374 (project, number))
375 shutil.rmtree(self.workspace_root)
376
377 # Check the new side of the upgrade
378 states = [
379 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
380 'org/project2': str(upstream['org/project2'].commit('master')),
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': str(upstream['org/project3'].commit('master')),
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': str(upstream['org/project3'].commit('master')),
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 },
400 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
401 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
402 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
403 'org/project4': str(upstream['org/project4'].commit('master')),
404 'org/project5': str(upstream['org/project5'].commit('master')),
405 'org/project6': str(upstream['org/project6'].commit('master')),
406 },
407 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
408 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
409 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
410 'org/project4': str(upstream['org/project4'].commit('master')),
411 'org/project5': str(upstream['org/project5'].commit('master')),
412 'org/project6': str(upstream['org/project6'].commit('master')),
413 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000414 ]
James E. Blairbce35e12014-08-21 14:31:17 -0700415
416 for number, build in enumerate(self.builds):
417 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairbce35e12014-08-21 14:31:17 -0700418 cloner = zuul.lib.cloner.Cloner(
419 git_base_url=self.upstream_root,
420 projects=projects,
421 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700422 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blairbce35e12014-08-21 14:31:17 -0700423 zuul_branch=build.parameters['ZUUL_BRANCH'],
424 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500425 zuul_url=self.src_root,
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000426 branch='master', # New branch for upgrade
427 )
James E. Blairbce35e12014-08-21 14:31:17 -0700428 cloner.execute()
429 work = self.getWorkspaceRepos(projects)
430 state = states[number]
431
432 for project in projects:
433 self.assertEquals(state[project],
434 str(work[project].commit('HEAD')),
435 'Project %s commit for build %s should '
436 'be correct on old side of upgrade' %
437 (project, number))
438 shutil.rmtree(self.workspace_root)
439
440 self.worker.hold_jobs_in_build = False
441 self.worker.release()
442 self.waitUntilSettled()
James E. Blairf0420222014-08-21 16:02:17 -0700443
James E. Blaird8af5422017-05-24 13:59:40 -0700444 @skip("Disabled for early v3 development")
James E. Blairf0420222014-08-21 16:02:17 -0700445 def test_project_override(self):
446 self.worker.hold_jobs_in_build = True
447 projects = ['org/project1', 'org/project2', 'org/project3',
448 'org/project4', 'org/project5', 'org/project6']
449
450 self.create_branch('org/project3', 'stable/havana')
451 self.create_branch('org/project4', 'stable/havana')
452 self.create_branch('org/project6', 'stable/havana')
453 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
454 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
455 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000456 D = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
457 'D')
James E. Blairf0420222014-08-21 16:02:17 -0700458 A.addApproval('CRVW', 2)
459 B.addApproval('CRVW', 2)
460 C.addApproval('CRVW', 2)
461 D.addApproval('CRVW', 2)
462 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
463 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
464 self.fake_gerrit.addEvent(C.addApproval('APRV', 1))
465 self.fake_gerrit.addEvent(D.addApproval('APRV', 1))
466
467 self.waitUntilSettled()
468
469 self.assertEquals(4, len(self.builds), "Four builds are running")
470
471 upstream = self.getUpstreamRepos(projects)
472 states = [
473 {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
474 'org/project2': str(upstream['org/project2'].commit('master')),
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': str(upstream['org/project2'].commit('master')),
482 'org/project3': str(upstream['org/project3'].commit('master')),
483 'org/project4': str(upstream['org/project4'].commit('master')),
484 'org/project5': str(upstream['org/project5'].commit('master')),
485 'org/project6': str(upstream['org/project6'].commit('master')),
486 },
487 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
488 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'],
489 'org/project3': str(upstream['org/project3'].commit('master')),
490 'org/project4': str(upstream['org/project4'].commit('master')),
491 'org/project5': str(upstream['org/project5'].commit('master')),
492 'org/project6': str(upstream['org/project6'].commit('master')),
493 },
494 {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'],
495 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'],
496 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
497 'org/project4': str(upstream['org/project4'].commit('master')),
498 'org/project5': str(upstream['org/project5'].commit('master')),
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000499 'org/project6': str(upstream['org/project6'].commit(
500 'stable/havana')),
James E. Blairf0420222014-08-21 16:02:17 -0700501 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000502 ]
James E. Blairf0420222014-08-21 16:02:17 -0700503
504 for number, build in enumerate(self.builds):
505 self.log.debug("Build parameters: %s", build.parameters)
James E. Blairf0420222014-08-21 16:02:17 -0700506 cloner = zuul.lib.cloner.Cloner(
507 git_base_url=self.upstream_root,
508 projects=projects,
509 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700510 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blairf0420222014-08-21 16:02:17 -0700511 zuul_branch=build.parameters['ZUUL_BRANCH'],
512 zuul_ref=build.parameters['ZUUL_REF'],
Monty Taylord642d852017-02-23 14:05:42 -0500513 zuul_url=self.src_root,
James E. Blairf0420222014-08-21 16:02:17 -0700514 project_branches={'org/project4': 'master'},
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000515 )
James E. Blairf0420222014-08-21 16:02:17 -0700516 cloner.execute()
517 work = self.getWorkspaceRepos(projects)
518 state = states[number]
519
520 for project in projects:
521 self.assertEquals(state[project],
522 str(work[project].commit('HEAD')),
523 'Project %s commit for build %s should '
524 'be correct' % (project, number))
525 shutil.rmtree(self.workspace_root)
526
527 self.worker.hold_jobs_in_build = False
528 self.worker.release()
529 self.waitUntilSettled()
James E. Blair217b10d2015-01-08 16:25:28 -0800530
James E. Blaird8af5422017-05-24 13:59:40 -0700531 @skip("Disabled for early v3 development")
James E. Blair217b10d2015-01-08 16:25:28 -0800532 def test_periodic(self):
533 self.worker.hold_jobs_in_build = True
534 self.create_branch('org/project', 'stable/havana')
James E. Blairf84026c2015-12-08 16:11:46 -0800535 self.updateConfigLayout(
536 'tests/fixtures/layout-timer.yaml')
James E. Blair217b10d2015-01-08 16:25:28 -0800537 self.sched.reconfigure(self.config)
538 self.registerJobs()
539
540 # The pipeline triggers every second, so we should have seen
541 # several by now.
542 time.sleep(5)
543 self.waitUntilSettled()
544
545 builds = self.builds[:]
546
547 self.worker.hold_jobs_in_build = False
548 # Stop queuing timer triggered jobs so that the assertions
549 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -0800550 self.updateConfigLayout(
551 'tests/fixtures/layout-no-timer.yaml')
James E. Blair217b10d2015-01-08 16:25:28 -0800552 self.sched.reconfigure(self.config)
553 self.registerJobs()
554 self.worker.release()
555 self.waitUntilSettled()
556
557 projects = ['org/project']
558
559 self.assertEquals(2, len(builds), "Two builds are running")
560
561 upstream = self.getUpstreamRepos(projects)
562 states = [
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000563 {'org/project':
564 str(upstream['org/project'].commit('stable/havana')),
James E. Blair217b10d2015-01-08 16:25:28 -0800565 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000566 {'org/project':
567 str(upstream['org/project'].commit('stable/havana')),
James E. Blair217b10d2015-01-08 16:25:28 -0800568 },
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000569 ]
James E. Blair217b10d2015-01-08 16:25:28 -0800570
571 for number, build in enumerate(builds):
572 self.log.debug("Build parameters: %s", build.parameters)
573 cloner = zuul.lib.cloner.Cloner(
574 git_base_url=self.upstream_root,
575 projects=projects,
576 workspace=self.workspace_root,
James E. Blairbfd85fd2016-10-21 14:18:11 -0700577 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
James E. Blair217b10d2015-01-08 16:25:28 -0800578 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
579 zuul_ref=build.parameters.get('ZUUL_REF', None),
Monty Taylord642d852017-02-23 14:05:42 -0500580 zuul_url=self.src_root,
James E. Blair217b10d2015-01-08 16:25:28 -0800581 branch='stable/havana',
Joshua Hesketh29d99b72014-08-19 16:27:42 +1000582 )
James E. Blair217b10d2015-01-08 16:25:28 -0800583 cloner.execute()
584 work = self.getWorkspaceRepos(projects)
585 state = states[number]
586
587 for project in projects:
588 self.assertEquals(state[project],
589 str(work[project].commit('HEAD')),
590 'Project %s commit for build %s should '
591 'be correct' % (project, number))
592
593 shutil.rmtree(self.workspace_root)
594
595 self.worker.hold_jobs_in_build = False
596 self.worker.release()
597 self.waitUntilSettled()
Sachi King9f16d522016-03-16 12:20:45 +1100598
James E. Blaird8af5422017-05-24 13:59:40 -0700599 @skip("Disabled for early v3 development")
James E. Blairbfd85fd2016-10-21 14:18:11 -0700600 def test_periodic_update(self):
601 # Test that the merger correctly updates its local repository
602 # before running a periodic job.
603
604 # Prime the merger with the current state
605 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
606 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
607 self.waitUntilSettled()
608
609 # Merge a different change
610 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
611 B.setMerged()
612
613 # Start a periodic job
614 self.worker.hold_jobs_in_build = True
Paul Belanger174a8272017-03-14 13:20:10 -0400615 self.executor.negative_function_cache_ttl = 0
James E. Blairbfd85fd2016-10-21 14:18:11 -0700616 self.config.set('zuul', 'layout_config',
617 'tests/fixtures/layout-timer.yaml')
618 self.sched.reconfigure(self.config)
619 self.registerJobs()
620
621 # The pipeline triggers every second, so we should have seen
622 # several by now.
623 time.sleep(5)
624 self.waitUntilSettled()
625
626 builds = self.builds[:]
627
628 self.worker.hold_jobs_in_build = False
629 # Stop queuing timer triggered jobs so that the assertions
630 # below don't race against more jobs being queued.
631 self.config.set('zuul', 'layout_config',
632 'tests/fixtures/layout-no-timer.yaml')
633 self.sched.reconfigure(self.config)
634 self.registerJobs()
635 self.worker.release()
636 self.waitUntilSettled()
637
638 projects = ['org/project']
639
640 self.assertEquals(2, len(builds), "Two builds are running")
641
642 upstream = self.getUpstreamRepos(projects)
643 self.assertEqual(upstream['org/project'].commit('master').hexsha,
644 B.patchsets[0]['revision'])
645 states = [
646 {'org/project':
647 str(upstream['org/project'].commit('master')),
648 },
649 {'org/project':
650 str(upstream['org/project'].commit('master')),
651 },
652 ]
653
654 for number, build in enumerate(builds):
655 self.log.debug("Build parameters: %s", build.parameters)
656 cloner = zuul.lib.cloner.Cloner(
657 git_base_url=self.upstream_root,
658 projects=projects,
659 workspace=self.workspace_root,
660 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
661 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
662 zuul_ref=build.parameters.get('ZUUL_REF', None),
663 zuul_url=self.git_root,
664 )
665 cloner.execute()
666 work = self.getWorkspaceRepos(projects)
667 state = states[number]
668
669 for project in projects:
670 self.assertEquals(state[project],
671 str(work[project].commit('HEAD')),
672 'Project %s commit for build %s should '
673 'be correct' % (project, number))
674
675 shutil.rmtree(self.workspace_root)
676
677 self.worker.hold_jobs_in_build = False
678 self.worker.release()
679 self.waitUntilSettled()
680
James E. Blaird8af5422017-05-24 13:59:40 -0700681 @skip("Disabled for early v3 development")
Sachi King9f16d522016-03-16 12:20:45 +1100682 def test_post_checkout(self):
James E. Blair8cce42e2016-10-18 08:18:36 -0700683 self.worker.hold_jobs_in_build = True
684 project = "org/project1"
685
686 A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
687 event = A.getRefUpdatedEvent()
688 A.setMerged()
689 self.fake_gerrit.addEvent(event)
690 self.waitUntilSettled()
691
692 build = self.builds[0]
693 state = {'org/project1': build.parameters['ZUUL_COMMIT']}
694
695 build.release()
696 self.waitUntilSettled()
Sachi King9f16d522016-03-16 12:20:45 +1100697
698 cloner = zuul.lib.cloner.Cloner(
699 git_base_url=self.upstream_root,
700 projects=[project],
701 workspace=self.workspace_root,
James E. Blair8cce42e2016-10-18 08:18:36 -0700702 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
703 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
704 zuul_ref=build.parameters.get('ZUUL_REF', None),
705 zuul_newrev=build.parameters.get('ZUUL_NEWREV', None),
Sachi King9f16d522016-03-16 12:20:45 +1100706 zuul_url=self.git_root,
Sachi King9f16d522016-03-16 12:20:45 +1100707 )
708 cloner.execute()
James E. Blair8cce42e2016-10-18 08:18:36 -0700709 work = self.getWorkspaceRepos([project])
710 self.assertEquals(state[project],
711 str(work[project].commit('HEAD')),
712 'Project %s commit for build %s should '
713 'be correct' % (project, 0))
714 shutil.rmtree(self.workspace_root)
Sachi King9f16d522016-03-16 12:20:45 +1100715
James E. Blaird8af5422017-05-24 13:59:40 -0700716 @skip("Disabled for early v3 development")
Sachi King9f16d522016-03-16 12:20:45 +1100717 def test_post_and_master_checkout(self):
James E. Blair8cce42e2016-10-18 08:18:36 -0700718 self.worker.hold_jobs_in_build = True
719 projects = ["org/project1", "org/project2"]
720
721 A = self.fake_gerrit.addFakeChange(projects[0], 'master', 'A')
722 event = A.getRefUpdatedEvent()
723 A.setMerged()
724 self.fake_gerrit.addEvent(event)
725 self.waitUntilSettled()
726
727 build = self.builds[0]
728 upstream = self.getUpstreamRepos(projects)
729 state = {'org/project1':
730 build.parameters['ZUUL_COMMIT'],
731 'org/project2':
732 str(upstream['org/project2'].commit('master')),
733 }
734
735 build.release()
736 self.waitUntilSettled()
Sachi King9f16d522016-03-16 12:20:45 +1100737
738 cloner = zuul.lib.cloner.Cloner(
739 git_base_url=self.upstream_root,
James E. Blair8cce42e2016-10-18 08:18:36 -0700740 projects=projects,
Sachi King9f16d522016-03-16 12:20:45 +1100741 workspace=self.workspace_root,
James E. Blair8cce42e2016-10-18 08:18:36 -0700742 zuul_project=build.parameters.get('ZUUL_PROJECT', None),
743 zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
744 zuul_ref=build.parameters.get('ZUUL_REF', None),
745 zuul_newrev=build.parameters.get('ZUUL_NEWREV', None),
Sachi King9f16d522016-03-16 12:20:45 +1100746 zuul_url=self.git_root,
Sachi King9f16d522016-03-16 12:20:45 +1100747 )
748 cloner.execute()
James E. Blair8cce42e2016-10-18 08:18:36 -0700749 work = self.getWorkspaceRepos(projects)
750
751 for project in projects:
752 self.assertEquals(state[project],
753 str(work[project].commit('HEAD')),
754 'Project %s commit for build %s should '
755 'be correct' % (project, 0))
756 shutil.rmtree(self.workspace_root)