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 |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 22 | |
| 23 | import git |
| 24 | |
| 25 | import zuul.lib.cloner |
| 26 | |
| 27 | from tests.base import ZuulTestCase |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 28 | |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 29 | |
| 30 | class TestCloner(ZuulTestCase): |
| 31 | |
| 32 | log = logging.getLogger("zuul.test.cloner") |
| 33 | workspace_root = None |
| 34 | |
| 35 | def setUp(self): |
James E. Blair | 509cada | 2015-12-08 16:31:16 -0800 | [diff] [blame] | 36 | self.skip("Disabled for early v3 development") |
| 37 | |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 38 | super(TestCloner, self).setUp() |
| 39 | self.workspace_root = os.path.join(self.test_root, 'workspace') |
| 40 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 41 | self.updateConfigLayout( |
| 42 | 'tests/fixtures/layout-cloner.yaml') |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 43 | self.sched.reconfigure(self.config) |
| 44 | self.registerJobs() |
| 45 | |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 46 | def getWorkspaceRepos(self, projects): |
| 47 | repos = {} |
| 48 | for project in projects: |
| 49 | repos[project] = git.Repo( |
| 50 | os.path.join(self.workspace_root, project)) |
| 51 | return repos |
| 52 | |
| 53 | def getUpstreamRepos(self, projects): |
| 54 | repos = {} |
| 55 | for project in projects: |
| 56 | repos[project] = git.Repo( |
| 57 | os.path.join(self.upstream_root, project)) |
| 58 | return repos |
| 59 | |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 60 | def test_cache_dir(self): |
| 61 | projects = ['org/project1', 'org/project2'] |
| 62 | cache_root = os.path.join(self.test_root, "cache") |
| 63 | for project in projects: |
| 64 | upstream_repo_path = os.path.join(self.upstream_root, project) |
| 65 | cache_repo_path = os.path.join(cache_root, project) |
| 66 | git.Repo.clone_from(upstream_repo_path, cache_repo_path) |
| 67 | |
| 68 | self.worker.hold_jobs_in_build = True |
| 69 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 70 | A.addApproval('CRVW', 2) |
| 71 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 72 | |
| 73 | self.waitUntilSettled() |
| 74 | |
| 75 | self.assertEquals(1, len(self.builds), "One build is running") |
| 76 | |
| 77 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 78 | B.setMerged() |
| 79 | |
| 80 | upstream = self.getUpstreamRepos(projects) |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 81 | states = [{ |
| 82 | 'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 83 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 84 | }] |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 85 | |
| 86 | for number, build in enumerate(self.builds): |
| 87 | self.log.debug("Build parameters: %s", build.parameters) |
| 88 | cloner = zuul.lib.cloner.Cloner( |
| 89 | git_base_url=self.upstream_root, |
| 90 | projects=projects, |
| 91 | workspace=self.workspace_root, |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 92 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 93 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 94 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 95 | zuul_url=self.src_root, |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 96 | cache_dir=cache_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 97 | ) |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 98 | cloner.execute() |
| 99 | work = self.getWorkspaceRepos(projects) |
| 100 | state = states[number] |
| 101 | |
| 102 | for project in projects: |
| 103 | self.assertEquals(state[project], |
| 104 | str(work[project].commit('HEAD')), |
| 105 | 'Project %s commit for build %s should ' |
| 106 | 'be correct' % (project, number)) |
| 107 | |
| 108 | work = self.getWorkspaceRepos(projects) |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 109 | # project1 is the zuul_project so the origin should be set to the |
| 110 | # zuul_url since that is the most up to date. |
| 111 | cache_repo_path = os.path.join(cache_root, 'org/project1') |
| 112 | self.assertNotEqual( |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 113 | work['org/project1'].remotes.origin.url, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 114 | cache_repo_path, |
| 115 | 'workspace repo origin should not be the cache' |
| 116 | ) |
| 117 | zuul_url_repo_path = os.path.join(self.git_root, 'org/project1') |
| 118 | self.assertEqual( |
| 119 | work['org/project1'].remotes.origin.url, |
| 120 | zuul_url_repo_path, |
| 121 | 'workspace repo origin should be the zuul url' |
| 122 | ) |
| 123 | |
| 124 | # project2 is not the zuul_project so the origin should be set |
| 125 | # to upstream since that is the best we can do |
| 126 | cache_repo_path = os.path.join(cache_root, 'org/project2') |
| 127 | self.assertNotEqual( |
| 128 | work['org/project2'].remotes.origin.url, |
| 129 | cache_repo_path, |
| 130 | 'workspace repo origin should not be the cache' |
| 131 | ) |
| 132 | upstream_repo_path = os.path.join(self.upstream_root, 'org/project2') |
| 133 | self.assertEqual( |
| 134 | work['org/project2'].remotes.origin.url, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 135 | upstream_repo_path, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 136 | 'workspace repo origin should be the upstream url' |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 137 | ) |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 138 | |
| 139 | self.worker.hold_jobs_in_build = False |
| 140 | self.worker.release() |
| 141 | self.waitUntilSettled() |
| 142 | |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 143 | def test_one_branch(self): |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 144 | self.worker.hold_jobs_in_build = True |
| 145 | |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 146 | projects = ['org/project1', 'org/project2'] |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 147 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 148 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 149 | A.addApproval('CRVW', 2) |
| 150 | B.addApproval('CRVW', 2) |
| 151 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 152 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 153 | |
| 154 | self.waitUntilSettled() |
| 155 | |
| 156 | self.assertEquals(2, len(self.builds), "Two builds are running") |
| 157 | |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 158 | upstream = self.getUpstreamRepos(projects) |
| 159 | states = [ |
| 160 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 161 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 162 | }, |
| 163 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 164 | 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'], |
| 165 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 166 | ] |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 167 | |
| 168 | for number, build in enumerate(self.builds): |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 169 | self.log.debug("Build parameters: %s", build.parameters) |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 170 | cloner = zuul.lib.cloner.Cloner( |
| 171 | git_base_url=self.upstream_root, |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 172 | projects=projects, |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 173 | workspace=self.workspace_root, |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 174 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 175 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
James E. Blair | 8231892 | 2014-08-21 11:05:32 -0700 | [diff] [blame] | 176 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 177 | zuul_url=self.src_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 178 | ) |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 179 | cloner.execute() |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 180 | work = self.getWorkspaceRepos(projects) |
| 181 | state = states[number] |
| 182 | |
| 183 | for project in projects: |
| 184 | self.assertEquals(state[project], |
| 185 | str(work[project].commit('HEAD')), |
| 186 | 'Project %s commit for build %s should ' |
| 187 | 'be correct' % (project, number)) |
| 188 | |
| 189 | shutil.rmtree(self.workspace_root) |
| 190 | |
| 191 | self.worker.hold_jobs_in_build = False |
| 192 | self.worker.release() |
| 193 | self.waitUntilSettled() |
| 194 | |
| 195 | def test_multi_branch(self): |
| 196 | self.worker.hold_jobs_in_build = True |
| 197 | projects = ['org/project1', 'org/project2', |
| 198 | 'org/project3', 'org/project4'] |
| 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') |
| 206 | A.addApproval('CRVW', 2) |
| 207 | B.addApproval('CRVW', 2) |
| 208 | C.addApproval('CRVW', 2) |
| 209 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 210 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 211 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 212 | |
| 213 | self.waitUntilSettled() |
| 214 | |
| 215 | self.assertEquals(3, len(self.builds), "Three builds are running") |
| 216 | |
| 217 | upstream = self.getUpstreamRepos(projects) |
| 218 | states = [ |
| 219 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 220 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 221 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 222 | 'org/project4': str(upstream['org/project4']. |
| 223 | commit('master')), |
| 224 | }, |
| 225 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 226 | 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'], |
| 227 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 228 | 'org/project4': str(upstream['org/project4']. |
| 229 | commit('stable/havana')), |
| 230 | }, |
| 231 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 232 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 233 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
| 234 | 'org/project4': str(upstream['org/project4']. |
| 235 | commit('master')), |
| 236 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 237 | ] |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 238 | |
| 239 | for number, build in enumerate(self.builds): |
| 240 | self.log.debug("Build parameters: %s", build.parameters) |
| 241 | cloner = zuul.lib.cloner.Cloner( |
| 242 | git_base_url=self.upstream_root, |
| 243 | projects=projects, |
| 244 | workspace=self.workspace_root, |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 245 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 246 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 247 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 248 | zuul_url=self.src_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 249 | ) |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 250 | cloner.execute() |
| 251 | work = self.getWorkspaceRepos(projects) |
| 252 | state = states[number] |
| 253 | |
| 254 | for project in projects: |
| 255 | self.assertEquals(state[project], |
| 256 | str(work[project].commit('HEAD')), |
| 257 | 'Project %s commit for build %s should ' |
| 258 | 'be correct' % (project, number)) |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 259 | shutil.rmtree(self.workspace_root) |
James E. Blair | 8231892 | 2014-08-21 11:05:32 -0700 | [diff] [blame] | 260 | |
| 261 | self.worker.hold_jobs_in_build = False |
| 262 | self.worker.release() |
| 263 | self.waitUntilSettled() |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 264 | |
| 265 | def test_upgrade(self): |
| 266 | # Simulates an upgrade test |
| 267 | self.worker.hold_jobs_in_build = True |
| 268 | projects = ['org/project1', 'org/project2', 'org/project3', |
| 269 | 'org/project4', 'org/project5', 'org/project6'] |
| 270 | |
| 271 | self.create_branch('org/project2', 'stable/havana') |
| 272 | self.create_branch('org/project3', 'stable/havana') |
| 273 | self.create_branch('org/project4', 'stable/havana') |
| 274 | self.create_branch('org/project5', 'stable/havana') |
| 275 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 276 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 277 | C = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana', |
| 278 | 'C') |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 279 | D = self.fake_gerrit.addFakeChange('org/project3', 'master', 'D') |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 280 | E = self.fake_gerrit.addFakeChange('org/project4', 'stable/havana', |
| 281 | 'E') |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 282 | A.addApproval('CRVW', 2) |
| 283 | B.addApproval('CRVW', 2) |
| 284 | C.addApproval('CRVW', 2) |
| 285 | D.addApproval('CRVW', 2) |
| 286 | E.addApproval('CRVW', 2) |
| 287 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 288 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 289 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 290 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 291 | self.fake_gerrit.addEvent(E.addApproval('APRV', 1)) |
| 292 | |
| 293 | self.waitUntilSettled() |
| 294 | |
| 295 | self.assertEquals(5, len(self.builds), "Five builds are running") |
| 296 | |
| 297 | # Check the old side of the upgrade first |
| 298 | upstream = self.getUpstreamRepos(projects) |
| 299 | states = [ |
| 300 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 301 | 'org/project2': str(upstream['org/project2'].commit( |
| 302 | 'stable/havana')), |
| 303 | 'org/project3': str(upstream['org/project3'].commit( |
| 304 | 'stable/havana')), |
| 305 | 'org/project4': str(upstream['org/project4'].commit( |
| 306 | 'stable/havana')), |
| 307 | 'org/project5': str(upstream['org/project5'].commit( |
| 308 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 309 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 310 | }, |
| 311 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 312 | 'org/project2': str(upstream['org/project2'].commit( |
| 313 | 'stable/havana')), |
| 314 | 'org/project3': str(upstream['org/project3'].commit( |
| 315 | 'stable/havana')), |
| 316 | 'org/project4': str(upstream['org/project4'].commit( |
| 317 | 'stable/havana')), |
| 318 | 'org/project5': str(upstream['org/project5'].commit( |
| 319 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 320 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 321 | }, |
| 322 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 323 | 'org/project2': str(upstream['org/project2'].commit( |
| 324 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 325 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 326 | 'org/project4': str(upstream['org/project4'].commit( |
| 327 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 328 | |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 329 | 'org/project5': str(upstream['org/project5'].commit( |
| 330 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 331 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 332 | }, |
| 333 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 334 | 'org/project2': str(upstream['org/project2'].commit( |
| 335 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 336 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 337 | 'org/project4': str(upstream['org/project4'].commit( |
| 338 | 'stable/havana')), |
| 339 | 'org/project5': str(upstream['org/project5'].commit( |
| 340 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 341 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 342 | }, |
| 343 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 344 | 'org/project2': str(upstream['org/project2'].commit( |
| 345 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 346 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
| 347 | 'org/project4': self.builds[4].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 348 | 'org/project5': str(upstream['org/project5'].commit( |
| 349 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 350 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 351 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 352 | ] |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 353 | |
| 354 | for number, build in enumerate(self.builds): |
| 355 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 356 | cloner = zuul.lib.cloner.Cloner( |
| 357 | git_base_url=self.upstream_root, |
| 358 | projects=projects, |
| 359 | workspace=self.workspace_root, |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 360 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 361 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 362 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 363 | zuul_url=self.src_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 364 | branch='stable/havana', # Old branch for upgrade |
| 365 | ) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 366 | cloner.execute() |
| 367 | work = self.getWorkspaceRepos(projects) |
| 368 | state = states[number] |
| 369 | |
| 370 | for project in projects: |
| 371 | self.assertEquals(state[project], |
| 372 | str(work[project].commit('HEAD')), |
| 373 | 'Project %s commit for build %s should ' |
| 374 | 'be correct on old side of upgrade' % |
| 375 | (project, number)) |
| 376 | shutil.rmtree(self.workspace_root) |
| 377 | |
| 378 | # Check the new side of the upgrade |
| 379 | states = [ |
| 380 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 381 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 382 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 383 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 384 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 385 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 386 | }, |
| 387 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 388 | 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'], |
| 389 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 390 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 391 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 392 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 393 | }, |
| 394 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 395 | 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'], |
| 396 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 397 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 398 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 399 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 400 | }, |
| 401 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 402 | 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'], |
| 403 | 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'], |
| 404 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 405 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 406 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 407 | }, |
| 408 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 409 | 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'], |
| 410 | 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'], |
| 411 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 412 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 413 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 414 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 415 | ] |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 416 | |
| 417 | for number, build in enumerate(self.builds): |
| 418 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 419 | cloner = zuul.lib.cloner.Cloner( |
| 420 | git_base_url=self.upstream_root, |
| 421 | projects=projects, |
| 422 | workspace=self.workspace_root, |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 423 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 424 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 425 | zuul_ref=build.parameters['ZUUL_REF'], |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 426 | zuul_url=self.src_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 427 | branch='master', # New branch for upgrade |
| 428 | ) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 429 | cloner.execute() |
| 430 | work = self.getWorkspaceRepos(projects) |
| 431 | state = states[number] |
| 432 | |
| 433 | for project in projects: |
| 434 | self.assertEquals(state[project], |
| 435 | str(work[project].commit('HEAD')), |
| 436 | 'Project %s commit for build %s should ' |
| 437 | 'be correct on old side of upgrade' % |
| 438 | (project, number)) |
| 439 | shutil.rmtree(self.workspace_root) |
| 440 | |
| 441 | self.worker.hold_jobs_in_build = False |
| 442 | self.worker.release() |
| 443 | self.waitUntilSettled() |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 444 | |
| 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 | |
| 531 | def test_periodic(self): |
| 532 | self.worker.hold_jobs_in_build = True |
| 533 | self.create_branch('org/project', 'stable/havana') |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 534 | self.updateConfigLayout( |
| 535 | 'tests/fixtures/layout-timer.yaml') |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 536 | self.sched.reconfigure(self.config) |
| 537 | self.registerJobs() |
| 538 | |
| 539 | # The pipeline triggers every second, so we should have seen |
| 540 | # several by now. |
| 541 | time.sleep(5) |
| 542 | self.waitUntilSettled() |
| 543 | |
| 544 | builds = self.builds[:] |
| 545 | |
| 546 | self.worker.hold_jobs_in_build = False |
| 547 | # Stop queuing timer triggered jobs so that the assertions |
| 548 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 549 | self.updateConfigLayout( |
| 550 | 'tests/fixtures/layout-no-timer.yaml') |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 551 | self.sched.reconfigure(self.config) |
| 552 | self.registerJobs() |
| 553 | self.worker.release() |
| 554 | self.waitUntilSettled() |
| 555 | |
| 556 | projects = ['org/project'] |
| 557 | |
| 558 | self.assertEquals(2, len(builds), "Two builds are running") |
| 559 | |
| 560 | upstream = self.getUpstreamRepos(projects) |
| 561 | states = [ |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 562 | {'org/project': |
| 563 | str(upstream['org/project'].commit('stable/havana')), |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 564 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 565 | {'org/project': |
| 566 | str(upstream['org/project'].commit('stable/havana')), |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 567 | }, |
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 | |
| 570 | for number, build in enumerate(builds): |
| 571 | self.log.debug("Build parameters: %s", build.parameters) |
| 572 | cloner = zuul.lib.cloner.Cloner( |
| 573 | git_base_url=self.upstream_root, |
| 574 | projects=projects, |
| 575 | workspace=self.workspace_root, |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 576 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 577 | zuul_branch=build.parameters.get('ZUUL_BRANCH', None), |
| 578 | zuul_ref=build.parameters.get('ZUUL_REF', None), |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 579 | zuul_url=self.src_root, |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 580 | branch='stable/havana', |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 581 | ) |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 582 | cloner.execute() |
| 583 | work = self.getWorkspaceRepos(projects) |
| 584 | state = states[number] |
| 585 | |
| 586 | for project in projects: |
| 587 | self.assertEquals(state[project], |
| 588 | str(work[project].commit('HEAD')), |
| 589 | 'Project %s commit for build %s should ' |
| 590 | 'be correct' % (project, number)) |
| 591 | |
| 592 | shutil.rmtree(self.workspace_root) |
| 593 | |
| 594 | self.worker.hold_jobs_in_build = False |
| 595 | self.worker.release() |
| 596 | self.waitUntilSettled() |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 597 | |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 598 | def test_periodic_update(self): |
| 599 | # Test that the merger correctly updates its local repository |
| 600 | # before running a periodic job. |
| 601 | |
| 602 | # Prime the merger with the current state |
| 603 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 604 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 605 | self.waitUntilSettled() |
| 606 | |
| 607 | # Merge a different change |
| 608 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 609 | B.setMerged() |
| 610 | |
| 611 | # Start a periodic job |
| 612 | self.worker.hold_jobs_in_build = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame^] | 613 | self.executor.negative_function_cache_ttl = 0 |
James E. Blair | bfd85fd | 2016-10-21 14:18:11 -0700 | [diff] [blame] | 614 | self.config.set('zuul', 'layout_config', |
| 615 | 'tests/fixtures/layout-timer.yaml') |
| 616 | self.sched.reconfigure(self.config) |
| 617 | self.registerJobs() |
| 618 | |
| 619 | # The pipeline triggers every second, so we should have seen |
| 620 | # several by now. |
| 621 | time.sleep(5) |
| 622 | self.waitUntilSettled() |
| 623 | |
| 624 | builds = self.builds[:] |
| 625 | |
| 626 | self.worker.hold_jobs_in_build = False |
| 627 | # Stop queuing timer triggered jobs so that the assertions |
| 628 | # below don't race against more jobs being queued. |
| 629 | self.config.set('zuul', 'layout_config', |
| 630 | 'tests/fixtures/layout-no-timer.yaml') |
| 631 | self.sched.reconfigure(self.config) |
| 632 | self.registerJobs() |
| 633 | self.worker.release() |
| 634 | self.waitUntilSettled() |
| 635 | |
| 636 | projects = ['org/project'] |
| 637 | |
| 638 | self.assertEquals(2, len(builds), "Two builds are running") |
| 639 | |
| 640 | upstream = self.getUpstreamRepos(projects) |
| 641 | self.assertEqual(upstream['org/project'].commit('master').hexsha, |
| 642 | B.patchsets[0]['revision']) |
| 643 | states = [ |
| 644 | {'org/project': |
| 645 | str(upstream['org/project'].commit('master')), |
| 646 | }, |
| 647 | {'org/project': |
| 648 | str(upstream['org/project'].commit('master')), |
| 649 | }, |
| 650 | ] |
| 651 | |
| 652 | for number, build in enumerate(builds): |
| 653 | self.log.debug("Build parameters: %s", build.parameters) |
| 654 | cloner = zuul.lib.cloner.Cloner( |
| 655 | git_base_url=self.upstream_root, |
| 656 | projects=projects, |
| 657 | workspace=self.workspace_root, |
| 658 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
| 659 | zuul_branch=build.parameters.get('ZUUL_BRANCH', None), |
| 660 | zuul_ref=build.parameters.get('ZUUL_REF', None), |
| 661 | zuul_url=self.git_root, |
| 662 | ) |
| 663 | cloner.execute() |
| 664 | work = self.getWorkspaceRepos(projects) |
| 665 | state = states[number] |
| 666 | |
| 667 | for project in projects: |
| 668 | self.assertEquals(state[project], |
| 669 | str(work[project].commit('HEAD')), |
| 670 | 'Project %s commit for build %s should ' |
| 671 | 'be correct' % (project, number)) |
| 672 | |
| 673 | shutil.rmtree(self.workspace_root) |
| 674 | |
| 675 | self.worker.hold_jobs_in_build = False |
| 676 | self.worker.release() |
| 677 | self.waitUntilSettled() |
| 678 | |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 679 | def test_post_checkout(self): |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 680 | self.worker.hold_jobs_in_build = True |
| 681 | project = "org/project1" |
| 682 | |
| 683 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 684 | event = A.getRefUpdatedEvent() |
| 685 | A.setMerged() |
| 686 | self.fake_gerrit.addEvent(event) |
| 687 | self.waitUntilSettled() |
| 688 | |
| 689 | build = self.builds[0] |
| 690 | state = {'org/project1': build.parameters['ZUUL_COMMIT']} |
| 691 | |
| 692 | build.release() |
| 693 | self.waitUntilSettled() |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 694 | |
| 695 | cloner = zuul.lib.cloner.Cloner( |
| 696 | git_base_url=self.upstream_root, |
| 697 | projects=[project], |
| 698 | workspace=self.workspace_root, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 699 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
| 700 | zuul_branch=build.parameters.get('ZUUL_BRANCH', None), |
| 701 | zuul_ref=build.parameters.get('ZUUL_REF', None), |
| 702 | zuul_newrev=build.parameters.get('ZUUL_NEWREV', None), |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 703 | zuul_url=self.git_root, |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 704 | ) |
| 705 | cloner.execute() |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 706 | work = self.getWorkspaceRepos([project]) |
| 707 | self.assertEquals(state[project], |
| 708 | str(work[project].commit('HEAD')), |
| 709 | 'Project %s commit for build %s should ' |
| 710 | 'be correct' % (project, 0)) |
| 711 | shutil.rmtree(self.workspace_root) |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 712 | |
| 713 | def test_post_and_master_checkout(self): |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 714 | self.worker.hold_jobs_in_build = True |
| 715 | projects = ["org/project1", "org/project2"] |
| 716 | |
| 717 | A = self.fake_gerrit.addFakeChange(projects[0], 'master', 'A') |
| 718 | event = A.getRefUpdatedEvent() |
| 719 | A.setMerged() |
| 720 | self.fake_gerrit.addEvent(event) |
| 721 | self.waitUntilSettled() |
| 722 | |
| 723 | build = self.builds[0] |
| 724 | upstream = self.getUpstreamRepos(projects) |
| 725 | state = {'org/project1': |
| 726 | build.parameters['ZUUL_COMMIT'], |
| 727 | 'org/project2': |
| 728 | str(upstream['org/project2'].commit('master')), |
| 729 | } |
| 730 | |
| 731 | build.release() |
| 732 | self.waitUntilSettled() |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 733 | |
| 734 | cloner = zuul.lib.cloner.Cloner( |
| 735 | git_base_url=self.upstream_root, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 736 | projects=projects, |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 737 | workspace=self.workspace_root, |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 738 | zuul_project=build.parameters.get('ZUUL_PROJECT', None), |
| 739 | zuul_branch=build.parameters.get('ZUUL_BRANCH', None), |
| 740 | zuul_ref=build.parameters.get('ZUUL_REF', None), |
| 741 | zuul_newrev=build.parameters.get('ZUUL_NEWREV', None), |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 742 | zuul_url=self.git_root, |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 743 | ) |
| 744 | cloner.execute() |
James E. Blair | 8cce42e | 2016-10-18 08:18:36 -0700 | [diff] [blame] | 745 | work = self.getWorkspaceRepos(projects) |
| 746 | |
| 747 | for project in projects: |
| 748 | self.assertEquals(state[project], |
| 749 | str(work[project].commit('HEAD')), |
| 750 | 'Project %s commit for build %s should ' |
| 751 | 'be correct' % (project, 0)) |
| 752 | shutil.rmtree(self.workspace_root) |