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 |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 23 | import six |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 24 | |
| 25 | import git |
| 26 | |
| 27 | import zuul.lib.cloner |
| 28 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 29 | from tests.base import ZuulTestCase, simple_layout |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 30 | |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 31 | |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 32 | def make_state(present, absent): |
| 33 | return (present, absent) |
| 34 | |
| 35 | |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 36 | class TestCloner(ZuulTestCase): |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 37 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 38 | |
| 39 | log = logging.getLogger("zuul.test.cloner") |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 40 | |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 41 | 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. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 65 | @skip("Disabled for early v3 development") |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 66 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 87 | states = [{ |
| 88 | 'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 89 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 90 | }] |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 91 | |
| 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. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 98 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 99 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 100 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 101 | zuul_url=self.src_root, |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 102 | cache_dir=cache_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 103 | ) |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 104 | 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. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 115 | # 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 119 | work['org/project1'].remotes.origin.url, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 120 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 141 | upstream_repo_path, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 142 | 'workspace repo origin should be the upstream url' |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 143 | ) |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 144 | |
| 145 | self.worker.hold_jobs_in_build = False |
| 146 | self.worker.release() |
| 147 | self.waitUntilSettled() |
| 148 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 149 | @simple_layout('layouts/repo-checkout-two-project.yaml') |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 150 | def test_one_branch(self): |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 151 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 152 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 153 | p1 = 'review.example.com/org/project1' |
| 154 | p2 = 'review.example.com/org/project2' |
| 155 | projects = [p1, p2] |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 156 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 157 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 158 | 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 Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 162 | |
| 163 | self.waitUntilSettled() |
| 164 | |
| 165 | self.assertEquals(2, len(self.builds), "Two builds are running") |
| 166 | |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 167 | upstream = self.getUpstreamRepos(projects) |
| 168 | states = [ |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 169 | {p1: make_state(present=[A], absent=[B]), |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 170 | p2: str(upstream[p2].commit('master')), |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 171 | }, |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 172 | {p1: make_state(present=[A], absent=[B]), |
| 173 | p2: make_state(present=[B], absent=[A]), |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 174 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 175 | ] |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 176 | |
| 177 | for number, build in enumerate(self.builds): |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 178 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 179 | work = build.getWorkspaceRepos(projects) |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 180 | state = states[number] |
| 181 | |
| 182 | for project in projects: |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 183 | self.assertRepoState(work[project], state[project], |
| 184 | project, build, number) |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 185 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 186 | self.executor_server.hold_jobs_in_build = False |
| 187 | self.executor_server.release() |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 188 | self.waitUntilSettled() |
| 189 | |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 190 | @simple_layout('layouts/repo-checkout-four-project.yaml') |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 191 | def test_multi_branch(self): |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 192 | 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. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 199 | |
| 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 203 | B = self.fake_gerrit.addFakeChange('org/project2', 'stable/havana', |
| 204 | 'B') |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 205 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 206 | 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. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 212 | |
| 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. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 219 | {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. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 223 | }, |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 224 | {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. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 228 | }, |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 229 | {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. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 233 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 234 | ] |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 235 | |
| 236 | for number, build in enumerate(self.builds): |
| 237 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 238 | work = build.getWorkspaceRepos(projects) |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 239 | state = states[number] |
| 240 | |
| 241 | for project in projects: |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 242 | self.assertRepoState(work[project], state[project], |
| 243 | project, build, number) |
James E. Blair | 8231892 | 2014-08-21 11:05:32 -0700 | [diff] [blame] | 244 | |
James E. Blair | af3d01e | 2017-05-26 14:30:18 -0700 | [diff] [blame^] | 245 | self.executor_server.hold_jobs_in_build = False |
| 246 | self.executor_server.release() |
James E. Blair | 8231892 | 2014-08-21 11:05:32 -0700 | [diff] [blame] | 247 | self.waitUntilSettled() |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 248 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 249 | @skip("Disabled for early v3 development") |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 250 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 262 | C = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana', |
| 263 | 'C') |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 264 | D = self.fake_gerrit.addFakeChange('org/project3', 'master', 'D') |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 265 | E = self.fake_gerrit.addFakeChange('org/project4', 'stable/havana', |
| 266 | 'E') |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 267 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 286 | '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. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 294 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 295 | }, |
| 296 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 297 | '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. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 305 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 306 | }, |
| 307 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 308 | 'org/project2': str(upstream['org/project2'].commit( |
| 309 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 310 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 311 | 'org/project4': str(upstream['org/project4'].commit( |
| 312 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 313 | |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 314 | 'org/project5': str(upstream['org/project5'].commit( |
| 315 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 316 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 317 | }, |
| 318 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 319 | 'org/project2': str(upstream['org/project2'].commit( |
| 320 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 321 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 322 | 'org/project4': str(upstream['org/project4'].commit( |
| 323 | 'stable/havana')), |
| 324 | 'org/project5': str(upstream['org/project5'].commit( |
| 325 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 326 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 327 | }, |
| 328 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 329 | 'org/project2': str(upstream['org/project2'].commit( |
| 330 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 331 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
| 332 | 'org/project4': self.builds[4].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 333 | 'org/project5': str(upstream['org/project5'].commit( |
| 334 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 335 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 336 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 337 | ] |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 338 | |
| 339 | for number, build in enumerate(self.builds): |
| 340 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 341 | cloner = zuul.lib.cloner.Cloner( |
| 342 | git_base_url=self.upstream_root, |
| 343 | projects=projects, |
| 344 | workspace=self.workspace_root, |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 345 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 346 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 347 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 348 | zuul_url=self.src_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 349 | branch='stable/havana', # Old branch for upgrade |
| 350 | ) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 351 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 400 | ] |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 401 | |
| 402 | for number, build in enumerate(self.builds): |
| 403 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 404 | cloner = zuul.lib.cloner.Cloner( |
| 405 | git_base_url=self.upstream_root, |
| 406 | projects=projects, |
| 407 | workspace=self.workspace_root, |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 408 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 409 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 410 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 411 | zuul_url=self.src_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 412 | branch='master', # New branch for upgrade |
| 413 | ) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 414 | 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. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 429 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 430 | @skip("Disabled for early v3 development") |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 431 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 442 | D = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana', |
| 443 | 'D') |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 444 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 485 | 'org/project6': str(upstream['org/project6'].commit( |
| 486 | 'stable/havana')), |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 487 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 488 | ] |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 489 | |
| 490 | for number, build in enumerate(self.builds): |
| 491 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 492 | cloner = zuul.lib.cloner.Cloner( |
| 493 | git_base_url=self.upstream_root, |
| 494 | projects=projects, |
| 495 | workspace=self.workspace_root, |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 496 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 497 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 498 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 499 | zuul_url=self.src_root, |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 500 | project_branches={'org/project4': 'master'}, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 501 | ) |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 502 | 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. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 516 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 517 | @skip("Disabled for early v3 development") |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 518 | def test_periodic(self): |
| 519 | self.worker.hold_jobs_in_build = True |
| 520 | self.create_branch('org/project', 'stable/havana') |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 521 | self.updateConfigLayout( |
| 522 | 'tests/fixtures/layout-timer.yaml') |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 523 | 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. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 536 | self.updateConfigLayout( |
| 537 | 'tests/fixtures/layout-no-timer.yaml') |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 538 | 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 Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 549 | {'org/project': |
| 550 | str(upstream['org/project'].commit('stable/havana')), |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 551 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 552 | {'org/project': |
| 553 | str(upstream['org/project'].commit('stable/havana')), |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 554 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 555 | ] |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 556 | |
| 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. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 563 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 564 | zuul_branch=build.parameters.get('ZUUL_BRANCH', None), |
| 565 | zuul_ref=build.parameters.get('ZUUL_REF', None), |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 566 | zuul_url=self.src_root, |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 567 | branch='stable/havana', |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 568 | ) |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 569 | 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 King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 584 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 585 | @skip("Disabled for early v3 development") |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 586 | 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 Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 601 | self.executor.negative_function_cache_ttl = 0 |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 602 | 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. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 667 | @skip("Disabled for early v3 development") |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 668 | def test_post_checkout(self): |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 669 | 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 King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 683 | |
| 684 | cloner = zuul.lib.cloner.Cloner( |
| 685 | git_base_url=self.upstream_root, |
| 686 | projects=[project], |
| 687 | workspace=self.workspace_root, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 688 | 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 King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 692 | zuul_url=self.git_root, |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 693 | ) |
| 694 | cloner.execute() |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 695 | 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 King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 701 | |
James E. Blair | d8af542 | 2017-05-24 13:59:40 -0700 | [diff] [blame] | 702 | @skip("Disabled for early v3 development") |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 703 | def test_post_and_master_checkout(self): |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 704 | 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 King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 723 | |
| 724 | cloner = zuul.lib.cloner.Cloner( |
| 725 | git_base_url=self.upstream_root, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 726 | projects=projects, |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 727 | workspace=self.workspace_root, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 728 | 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 King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 732 | zuul_url=self.git_root, |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 733 | ) |
| 734 | cloner.execute() |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 735 | 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) |