Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 1 | #!/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 | |
| 18 | import logging |
| 19 | import os |
| 20 | import shutil |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 21 | import time |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 22 | from unittest import skip |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 23 | |
| 24 | import git |
| 25 | |
| 26 | import zuul.lib.cloner |
| 27 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 28 | from tests.base import ZuulTestCase, simple_layout |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 29 | |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 30 | |
| 31 | class TestCloner(ZuulTestCase): |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 32 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 33 | |
| 34 | log = logging.getLogger("zuul.test.cloner") |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 35 | |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame] | 36 | def assertRepoState(self, repo, state, project, build, number): |
James E. Blair | bcaa2d4 | 2017-05-26 15:44:23 -0700 | [diff] [blame^] | 37 | 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. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame] | 49 | str(repo.commit('HEAD')), |
| 50 | 'Project %s commit for build %s #%s should ' |
| 51 | 'be correct' % ( |
| 52 | project, build, number)) |
James E. Blair | bcaa2d4 | 2017-05-26 15:44:23 -0700 | [diff] [blame^] | 53 | 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. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame] | 58 | 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. Blair | bcaa2d4 | 2017-05-26 15:44:23 -0700 | [diff] [blame^] | 63 | if 'absent' in state: |
| 64 | for change in state['absent']: |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame] | 65 | 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. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 71 | @skip("Disabled for early v3 development") |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 72 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 93 | states = [{ |
| 94 | 'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 95 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 96 | }] |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 97 | |
| 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. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 104 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 105 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 106 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 107 | zuul_url=self.src_root, |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 108 | cache_dir=cache_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 109 | ) |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 110 | 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. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 121 | # 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 125 | work['org/project1'].remotes.origin.url, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 126 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 147 | upstream_repo_path, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 148 | 'workspace repo origin should be the upstream url' |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 149 | ) |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 150 | |
| 151 | self.worker.hold_jobs_in_build = False |
| 152 | self.worker.release() |
| 153 | self.waitUntilSettled() |
| 154 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 155 | @simple_layout('layouts/repo-checkout-two-project.yaml') |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 156 | def test_one_branch(self): |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 157 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 158 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 159 | p1 = 'review.example.com/org/project1' |
| 160 | p2 = 'review.example.com/org/project2' |
| 161 | projects = [p1, p2] |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 162 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 163 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 164 | 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 Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 168 | |
| 169 | self.waitUntilSettled() |
| 170 | |
| 171 | self.assertEquals(2, len(self.builds), "Two builds are running") |
| 172 | |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 173 | upstream = self.getUpstreamRepos(projects) |
| 174 | states = [ |
James E. Blair | bcaa2d4 | 2017-05-26 15:44:23 -0700 | [diff] [blame^] | 175 | {p1: dict(present=[A], absent=[B], branch='master'), |
| 176 | p2: dict(commit=str(upstream[p2].commit('master')), |
| 177 | branch='master'), |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 178 | }, |
James E. Blair | bcaa2d4 | 2017-05-26 15:44:23 -0700 | [diff] [blame^] | 179 | {p1: dict(present=[A], absent=[B], branch='master'), |
| 180 | p2: dict(present=[B], absent=[A], branch='master'), |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 181 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 182 | ] |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 183 | |
| 184 | for number, build in enumerate(self.builds): |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 185 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 186 | work = build.getWorkspaceRepos(projects) |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 187 | state = states[number] |
| 188 | |
| 189 | for project in projects: |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame] | 190 | self.assertRepoState(work[project], state[project], |
| 191 | project, build, number) |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 192 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 193 | self.executor_server.hold_jobs_in_build = False |
| 194 | self.executor_server.release() |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 195 | self.waitUntilSettled() |
| 196 | |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame] | 197 | @simple_layout('layouts/repo-checkout-four-project.yaml') |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 198 | def test_multi_branch(self): |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame] | 199 | 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. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 206 | |
| 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 210 | B = self.fake_gerrit.addFakeChange('org/project2', 'stable/havana', |
| 211 | 'B') |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 212 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame] | 213 | 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. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 219 | |
| 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. Blair | bcaa2d4 | 2017-05-26 15:44:23 -0700 | [diff] [blame^] | 226 | {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. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 233 | }, |
James E. Blair | bcaa2d4 | 2017-05-26 15:44:23 -0700 | [diff] [blame^] | 234 | {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. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 240 | }, |
James E. Blair | bcaa2d4 | 2017-05-26 15:44:23 -0700 | [diff] [blame^] | 241 | {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. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 247 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 248 | ] |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 249 | |
| 250 | for number, build in enumerate(self.builds): |
| 251 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame] | 252 | work = build.getWorkspaceRepos(projects) |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 253 | state = states[number] |
| 254 | |
| 255 | for project in projects: |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame] | 256 | self.assertRepoState(work[project], state[project], |
| 257 | project, build, number) |
James E. Blair | 8231892 | 2014-08-21 11:05:32 -0700 | [diff] [blame] | 258 | |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame] | 259 | self.executor_server.hold_jobs_in_build = False |
| 260 | self.executor_server.release() |
James E. Blair | 8231892 | 2014-08-21 11:05:32 -0700 | [diff] [blame] | 261 | self.waitUntilSettled() |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 262 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 263 | @skip("Disabled for early v3 development") |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 264 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 276 | C = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana', |
| 277 | 'C') |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 278 | D = self.fake_gerrit.addFakeChange('org/project3', 'master', 'D') |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 279 | E = self.fake_gerrit.addFakeChange('org/project4', 'stable/havana', |
| 280 | 'E') |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 281 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 300 | '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. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 308 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 309 | }, |
| 310 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 311 | '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. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 319 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 320 | }, |
| 321 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 322 | 'org/project2': str(upstream['org/project2'].commit( |
| 323 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 324 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 325 | 'org/project4': str(upstream['org/project4'].commit( |
| 326 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 327 | |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 328 | 'org/project5': str(upstream['org/project5'].commit( |
| 329 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 330 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 331 | }, |
| 332 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 333 | 'org/project2': str(upstream['org/project2'].commit( |
| 334 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 335 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 336 | 'org/project4': str(upstream['org/project4'].commit( |
| 337 | 'stable/havana')), |
| 338 | 'org/project5': str(upstream['org/project5'].commit( |
| 339 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 340 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 341 | }, |
| 342 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 343 | 'org/project2': str(upstream['org/project2'].commit( |
| 344 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 345 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
| 346 | 'org/project4': self.builds[4].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 347 | 'org/project5': str(upstream['org/project5'].commit( |
| 348 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 349 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 350 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 351 | ] |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 352 | |
| 353 | for number, build in enumerate(self.builds): |
| 354 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 355 | cloner = zuul.lib.cloner.Cloner( |
| 356 | git_base_url=self.upstream_root, |
| 357 | projects=projects, |
| 358 | workspace=self.workspace_root, |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 359 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 360 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 361 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 362 | zuul_url=self.src_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 363 | branch='stable/havana', # Old branch for upgrade |
| 364 | ) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 365 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 414 | ] |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 415 | |
| 416 | for number, build in enumerate(self.builds): |
| 417 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 418 | cloner = zuul.lib.cloner.Cloner( |
| 419 | git_base_url=self.upstream_root, |
| 420 | projects=projects, |
| 421 | workspace=self.workspace_root, |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 422 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 423 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 424 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 425 | zuul_url=self.src_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 426 | branch='master', # New branch for upgrade |
| 427 | ) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 428 | 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. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 443 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 444 | @skip("Disabled for early v3 development") |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 445 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 456 | D = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana', |
| 457 | 'D') |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 458 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 499 | 'org/project6': str(upstream['org/project6'].commit( |
| 500 | 'stable/havana')), |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 501 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 502 | ] |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 503 | |
| 504 | for number, build in enumerate(self.builds): |
| 505 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 506 | cloner = zuul.lib.cloner.Cloner( |
| 507 | git_base_url=self.upstream_root, |
| 508 | projects=projects, |
| 509 | workspace=self.workspace_root, |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 510 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 511 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 512 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 513 | zuul_url=self.src_root, |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 514 | project_branches={'org/project4': 'master'}, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 515 | ) |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 516 | 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. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 530 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 531 | @skip("Disabled for early v3 development") |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 532 | def test_periodic(self): |
| 533 | self.worker.hold_jobs_in_build = True |
| 534 | self.create_branch('org/project', 'stable/havana') |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 535 | self.updateConfigLayout( |
| 536 | 'tests/fixtures/layout-timer.yaml') |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 537 | 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. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 550 | self.updateConfigLayout( |
| 551 | 'tests/fixtures/layout-no-timer.yaml') |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 552 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 563 | {'org/project': |
| 564 | str(upstream['org/project'].commit('stable/havana')), |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 565 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 566 | {'org/project': |
| 567 | str(upstream['org/project'].commit('stable/havana')), |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 568 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 569 | ] |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 570 | |
| 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. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 577 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 578 | zuul_branch=build.parameters.get('ZUUL_BRANCH', None), |
| 579 | zuul_ref=build.parameters.get('ZUUL_REF', None), |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 580 | zuul_url=self.src_root, |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 581 | branch='stable/havana', |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 582 | ) |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 583 | 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 King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 598 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 599 | @skip("Disabled for early v3 development") |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 600 | 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 Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 615 | self.executor.negative_function_cache_ttl = 0 |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 616 | 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. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 681 | @skip("Disabled for early v3 development") |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 682 | def test_post_checkout(self): |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 683 | 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 King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 697 | |
| 698 | cloner = zuul.lib.cloner.Cloner( |
| 699 | git_base_url=self.upstream_root, |
| 700 | projects=[project], |
| 701 | workspace=self.workspace_root, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 702 | 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 King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 706 | zuul_url=self.git_root, |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 707 | ) |
| 708 | cloner.execute() |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 709 | 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 King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 715 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 716 | @skip("Disabled for early v3 development") |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 717 | def test_post_and_master_checkout(self): |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 718 | 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 King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 737 | |
| 738 | cloner = zuul.lib.cloner.Cloner( |
| 739 | git_base_url=self.upstream_root, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 740 | projects=projects, |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 741 | workspace=self.workspace_root, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 742 | 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 King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 746 | zuul_url=self.git_root, |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 747 | ) |
| 748 | cloner.execute() |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 749 | 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) |