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 | |
| 29 | logging.basicConfig(level=logging.DEBUG, |
| 30 | format='%(asctime)s %(name)-32s ' |
| 31 | '%(levelname)-8s %(message)s') |
| 32 | |
| 33 | |
| 34 | class TestCloner(ZuulTestCase): |
| 35 | |
| 36 | log = logging.getLogger("zuul.test.cloner") |
| 37 | workspace_root = None |
| 38 | |
| 39 | def setUp(self): |
James E. Blair | 509cada | 2015-12-08 16:31:16 -0800 | [diff] [blame] | 40 | self.skip("Disabled for early v3 development") |
| 41 | |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 42 | super(TestCloner, self).setUp() |
| 43 | self.workspace_root = os.path.join(self.test_root, 'workspace') |
| 44 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 45 | self.updateConfigLayout( |
| 46 | 'tests/fixtures/layout-cloner.yaml') |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 47 | self.sched.reconfigure(self.config) |
| 48 | self.registerJobs() |
| 49 | |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 50 | def getWorkspaceRepos(self, projects): |
| 51 | repos = {} |
| 52 | for project in projects: |
| 53 | repos[project] = git.Repo( |
| 54 | os.path.join(self.workspace_root, project)) |
| 55 | return repos |
| 56 | |
| 57 | def getUpstreamRepos(self, projects): |
| 58 | repos = {} |
| 59 | for project in projects: |
| 60 | repos[project] = git.Repo( |
| 61 | os.path.join(self.upstream_root, project)) |
| 62 | return repos |
| 63 | |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 64 | def test_cache_dir(self): |
| 65 | projects = ['org/project1', 'org/project2'] |
| 66 | cache_root = os.path.join(self.test_root, "cache") |
| 67 | for project in projects: |
| 68 | upstream_repo_path = os.path.join(self.upstream_root, project) |
| 69 | cache_repo_path = os.path.join(cache_root, project) |
| 70 | git.Repo.clone_from(upstream_repo_path, cache_repo_path) |
| 71 | |
| 72 | self.worker.hold_jobs_in_build = True |
| 73 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 74 | A.addApproval('CRVW', 2) |
| 75 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 76 | |
| 77 | self.waitUntilSettled() |
| 78 | |
| 79 | self.assertEquals(1, len(self.builds), "One build is running") |
| 80 | |
| 81 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 82 | B.setMerged() |
| 83 | |
| 84 | upstream = self.getUpstreamRepos(projects) |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 85 | states = [{ |
| 86 | 'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 87 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 88 | }] |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 89 | |
| 90 | for number, build in enumerate(self.builds): |
| 91 | self.log.debug("Build parameters: %s", build.parameters) |
| 92 | cloner = zuul.lib.cloner.Cloner( |
| 93 | git_base_url=self.upstream_root, |
| 94 | projects=projects, |
| 95 | workspace=self.workspace_root, |
| 96 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 97 | zuul_ref=build.parameters['ZUUL_REF'], |
| 98 | zuul_url=self.git_root, |
| 99 | cache_dir=cache_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 100 | ) |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 101 | cloner.execute() |
| 102 | work = self.getWorkspaceRepos(projects) |
| 103 | state = states[number] |
| 104 | |
| 105 | for project in projects: |
| 106 | self.assertEquals(state[project], |
| 107 | str(work[project].commit('HEAD')), |
| 108 | 'Project %s commit for build %s should ' |
| 109 | 'be correct' % (project, number)) |
| 110 | |
| 111 | work = self.getWorkspaceRepos(projects) |
| 112 | upstream_repo_path = os.path.join(self.upstream_root, 'org/project1') |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 113 | self.assertEquals( |
| 114 | work['org/project1'].remotes.origin.url, |
| 115 | upstream_repo_path, |
| 116 | 'workspace repo origin should be upstream, not cache' |
| 117 | ) |
James E. Blair | 48ff4d5 | 2014-08-25 15:07:21 -0700 | [diff] [blame] | 118 | |
| 119 | self.worker.hold_jobs_in_build = False |
| 120 | self.worker.release() |
| 121 | self.waitUntilSettled() |
| 122 | |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 123 | def test_one_branch(self): |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 124 | self.worker.hold_jobs_in_build = True |
| 125 | |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 126 | projects = ['org/project1', 'org/project2'] |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 127 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 128 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 129 | A.addApproval('CRVW', 2) |
| 130 | B.addApproval('CRVW', 2) |
| 131 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 132 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 133 | |
| 134 | self.waitUntilSettled() |
| 135 | |
| 136 | self.assertEquals(2, len(self.builds), "Two builds are running") |
| 137 | |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 138 | upstream = self.getUpstreamRepos(projects) |
| 139 | states = [ |
| 140 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 141 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 142 | }, |
| 143 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 144 | 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'], |
| 145 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 146 | ] |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 147 | |
| 148 | for number, build in enumerate(self.builds): |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 149 | self.log.debug("Build parameters: %s", build.parameters) |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 150 | cloner = zuul.lib.cloner.Cloner( |
| 151 | git_base_url=self.upstream_root, |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 152 | projects=projects, |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 153 | workspace=self.workspace_root, |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 154 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
James E. Blair | 8231892 | 2014-08-21 11:05:32 -0700 | [diff] [blame] | 155 | zuul_ref=build.parameters['ZUUL_REF'], |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 156 | zuul_url=self.git_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 157 | ) |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 158 | cloner.execute() |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 159 | work = self.getWorkspaceRepos(projects) |
| 160 | state = states[number] |
| 161 | |
| 162 | for project in projects: |
| 163 | self.assertEquals(state[project], |
| 164 | str(work[project].commit('HEAD')), |
| 165 | 'Project %s commit for build %s should ' |
| 166 | 'be correct' % (project, number)) |
| 167 | |
| 168 | shutil.rmtree(self.workspace_root) |
| 169 | |
| 170 | self.worker.hold_jobs_in_build = False |
| 171 | self.worker.release() |
| 172 | self.waitUntilSettled() |
| 173 | |
| 174 | def test_multi_branch(self): |
| 175 | self.worker.hold_jobs_in_build = True |
| 176 | projects = ['org/project1', 'org/project2', |
| 177 | 'org/project3', 'org/project4'] |
| 178 | |
| 179 | self.create_branch('org/project2', 'stable/havana') |
| 180 | self.create_branch('org/project4', 'stable/havana') |
| 181 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 182 | B = self.fake_gerrit.addFakeChange('org/project2', 'stable/havana', |
| 183 | 'B') |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 184 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 185 | A.addApproval('CRVW', 2) |
| 186 | B.addApproval('CRVW', 2) |
| 187 | C.addApproval('CRVW', 2) |
| 188 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 189 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 190 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 191 | |
| 192 | self.waitUntilSettled() |
| 193 | |
| 194 | self.assertEquals(3, len(self.builds), "Three builds are running") |
| 195 | |
| 196 | upstream = self.getUpstreamRepos(projects) |
| 197 | states = [ |
| 198 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 199 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 200 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 201 | 'org/project4': str(upstream['org/project4']. |
| 202 | commit('master')), |
| 203 | }, |
| 204 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 205 | 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'], |
| 206 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 207 | 'org/project4': str(upstream['org/project4']. |
| 208 | commit('stable/havana')), |
| 209 | }, |
| 210 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 211 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 212 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
| 213 | 'org/project4': str(upstream['org/project4']. |
| 214 | commit('master')), |
| 215 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 216 | ] |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 217 | |
| 218 | for number, build in enumerate(self.builds): |
| 219 | self.log.debug("Build parameters: %s", build.parameters) |
| 220 | cloner = zuul.lib.cloner.Cloner( |
| 221 | git_base_url=self.upstream_root, |
| 222 | projects=projects, |
| 223 | workspace=self.workspace_root, |
| 224 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 225 | zuul_ref=build.parameters['ZUUL_REF'], |
| 226 | zuul_url=self.git_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 227 | ) |
James E. Blair | 97d902e | 2014-08-21 13:25:56 -0700 | [diff] [blame] | 228 | cloner.execute() |
| 229 | work = self.getWorkspaceRepos(projects) |
| 230 | state = states[number] |
| 231 | |
| 232 | for project in projects: |
| 233 | self.assertEquals(state[project], |
| 234 | str(work[project].commit('HEAD')), |
| 235 | 'Project %s commit for build %s should ' |
| 236 | 'be correct' % (project, number)) |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 237 | shutil.rmtree(self.workspace_root) |
James E. Blair | 8231892 | 2014-08-21 11:05:32 -0700 | [diff] [blame] | 238 | |
| 239 | self.worker.hold_jobs_in_build = False |
| 240 | self.worker.release() |
| 241 | self.waitUntilSettled() |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 242 | |
| 243 | def test_upgrade(self): |
| 244 | # Simulates an upgrade test |
| 245 | self.worker.hold_jobs_in_build = True |
| 246 | projects = ['org/project1', 'org/project2', 'org/project3', |
| 247 | 'org/project4', 'org/project5', 'org/project6'] |
| 248 | |
| 249 | self.create_branch('org/project2', 'stable/havana') |
| 250 | self.create_branch('org/project3', 'stable/havana') |
| 251 | self.create_branch('org/project4', 'stable/havana') |
| 252 | self.create_branch('org/project5', 'stable/havana') |
| 253 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 254 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 255 | C = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana', |
| 256 | 'C') |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 257 | D = self.fake_gerrit.addFakeChange('org/project3', 'master', 'D') |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 258 | E = self.fake_gerrit.addFakeChange('org/project4', 'stable/havana', |
| 259 | 'E') |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 260 | A.addApproval('CRVW', 2) |
| 261 | B.addApproval('CRVW', 2) |
| 262 | C.addApproval('CRVW', 2) |
| 263 | D.addApproval('CRVW', 2) |
| 264 | E.addApproval('CRVW', 2) |
| 265 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 266 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 267 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 268 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 269 | self.fake_gerrit.addEvent(E.addApproval('APRV', 1)) |
| 270 | |
| 271 | self.waitUntilSettled() |
| 272 | |
| 273 | self.assertEquals(5, len(self.builds), "Five builds are running") |
| 274 | |
| 275 | # Check the old side of the upgrade first |
| 276 | upstream = self.getUpstreamRepos(projects) |
| 277 | states = [ |
| 278 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 279 | 'org/project2': str(upstream['org/project2'].commit( |
| 280 | 'stable/havana')), |
| 281 | 'org/project3': str(upstream['org/project3'].commit( |
| 282 | 'stable/havana')), |
| 283 | 'org/project4': str(upstream['org/project4'].commit( |
| 284 | 'stable/havana')), |
| 285 | 'org/project5': str(upstream['org/project5'].commit( |
| 286 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 287 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 288 | }, |
| 289 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 290 | 'org/project2': str(upstream['org/project2'].commit( |
| 291 | 'stable/havana')), |
| 292 | 'org/project3': str(upstream['org/project3'].commit( |
| 293 | 'stable/havana')), |
| 294 | 'org/project4': str(upstream['org/project4'].commit( |
| 295 | 'stable/havana')), |
| 296 | 'org/project5': str(upstream['org/project5'].commit( |
| 297 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 298 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 299 | }, |
| 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')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 303 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 304 | 'org/project4': str(upstream['org/project4'].commit( |
| 305 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 306 | |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 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')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 314 | 'org/project3': self.builds[2].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 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'], |
| 325 | 'org/project4': self.builds[4].parameters['ZUUL_COMMIT'], |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 326 | 'org/project5': str(upstream['org/project5'].commit( |
| 327 | 'stable/havana')), |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 328 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 329 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 330 | ] |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 331 | |
| 332 | for number, build in enumerate(self.builds): |
| 333 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 334 | cloner = zuul.lib.cloner.Cloner( |
| 335 | git_base_url=self.upstream_root, |
| 336 | projects=projects, |
| 337 | workspace=self.workspace_root, |
| 338 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 339 | zuul_ref=build.parameters['ZUUL_REF'], |
| 340 | zuul_url=self.git_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 341 | branch='stable/havana', # Old branch for upgrade |
| 342 | ) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 343 | cloner.execute() |
| 344 | work = self.getWorkspaceRepos(projects) |
| 345 | state = states[number] |
| 346 | |
| 347 | for project in projects: |
| 348 | self.assertEquals(state[project], |
| 349 | str(work[project].commit('HEAD')), |
| 350 | 'Project %s commit for build %s should ' |
| 351 | 'be correct on old side of upgrade' % |
| 352 | (project, number)) |
| 353 | shutil.rmtree(self.workspace_root) |
| 354 | |
| 355 | # Check the new side of the upgrade |
| 356 | states = [ |
| 357 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 358 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 359 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 360 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 361 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 362 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 363 | }, |
| 364 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 365 | 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'], |
| 366 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 367 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 368 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 369 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 370 | }, |
| 371 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 372 | 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'], |
| 373 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 374 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 375 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 376 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 377 | }, |
| 378 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 379 | 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'], |
| 380 | 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'], |
| 381 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 382 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 383 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 384 | }, |
| 385 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 386 | 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'], |
| 387 | 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'], |
| 388 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 389 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 390 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 391 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 392 | ] |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 393 | |
| 394 | for number, build in enumerate(self.builds): |
| 395 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 396 | cloner = zuul.lib.cloner.Cloner( |
| 397 | git_base_url=self.upstream_root, |
| 398 | projects=projects, |
| 399 | workspace=self.workspace_root, |
| 400 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 401 | zuul_ref=build.parameters['ZUUL_REF'], |
| 402 | zuul_url=self.git_root, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 403 | branch='master', # New branch for upgrade |
| 404 | ) |
James E. Blair | bce35e1 | 2014-08-21 14:31:17 -0700 | [diff] [blame] | 405 | cloner.execute() |
| 406 | work = self.getWorkspaceRepos(projects) |
| 407 | state = states[number] |
| 408 | |
| 409 | for project in projects: |
| 410 | self.assertEquals(state[project], |
| 411 | str(work[project].commit('HEAD')), |
| 412 | 'Project %s commit for build %s should ' |
| 413 | 'be correct on old side of upgrade' % |
| 414 | (project, number)) |
| 415 | shutil.rmtree(self.workspace_root) |
| 416 | |
| 417 | self.worker.hold_jobs_in_build = False |
| 418 | self.worker.release() |
| 419 | self.waitUntilSettled() |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 420 | |
| 421 | def test_project_override(self): |
| 422 | self.worker.hold_jobs_in_build = True |
| 423 | projects = ['org/project1', 'org/project2', 'org/project3', |
| 424 | 'org/project4', 'org/project5', 'org/project6'] |
| 425 | |
| 426 | self.create_branch('org/project3', 'stable/havana') |
| 427 | self.create_branch('org/project4', 'stable/havana') |
| 428 | self.create_branch('org/project6', 'stable/havana') |
| 429 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 430 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 431 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 432 | D = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana', |
| 433 | 'D') |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 434 | A.addApproval('CRVW', 2) |
| 435 | B.addApproval('CRVW', 2) |
| 436 | C.addApproval('CRVW', 2) |
| 437 | D.addApproval('CRVW', 2) |
| 438 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 439 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 440 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 441 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 442 | |
| 443 | self.waitUntilSettled() |
| 444 | |
| 445 | self.assertEquals(4, len(self.builds), "Four builds are running") |
| 446 | |
| 447 | upstream = self.getUpstreamRepos(projects) |
| 448 | states = [ |
| 449 | {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'], |
| 450 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 451 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 452 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 453 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 454 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 455 | }, |
| 456 | {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'], |
| 457 | 'org/project2': str(upstream['org/project2'].commit('master')), |
| 458 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 459 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 460 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 461 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 462 | }, |
| 463 | {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'], |
| 464 | 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'], |
| 465 | 'org/project3': str(upstream['org/project3'].commit('master')), |
| 466 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 467 | 'org/project5': str(upstream['org/project5'].commit('master')), |
| 468 | 'org/project6': str(upstream['org/project6'].commit('master')), |
| 469 | }, |
| 470 | {'org/project1': self.builds[1].parameters['ZUUL_COMMIT'], |
| 471 | 'org/project2': self.builds[2].parameters['ZUUL_COMMIT'], |
| 472 | 'org/project3': self.builds[3].parameters['ZUUL_COMMIT'], |
| 473 | 'org/project4': str(upstream['org/project4'].commit('master')), |
| 474 | 'org/project5': str(upstream['org/project5'].commit('master')), |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 475 | 'org/project6': str(upstream['org/project6'].commit( |
| 476 | 'stable/havana')), |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 477 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 478 | ] |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 479 | |
| 480 | for number, build in enumerate(self.builds): |
| 481 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 482 | cloner = zuul.lib.cloner.Cloner( |
| 483 | git_base_url=self.upstream_root, |
| 484 | projects=projects, |
| 485 | workspace=self.workspace_root, |
| 486 | zuul_branch=build.parameters['ZUUL_BRANCH'], |
| 487 | zuul_ref=build.parameters['ZUUL_REF'], |
| 488 | zuul_url=self.git_root, |
| 489 | project_branches={'org/project4': 'master'}, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 490 | ) |
James E. Blair | f042022 | 2014-08-21 16:02:17 -0700 | [diff] [blame] | 491 | cloner.execute() |
| 492 | work = self.getWorkspaceRepos(projects) |
| 493 | state = states[number] |
| 494 | |
| 495 | for project in projects: |
| 496 | self.assertEquals(state[project], |
| 497 | str(work[project].commit('HEAD')), |
| 498 | 'Project %s commit for build %s should ' |
| 499 | 'be correct' % (project, number)) |
| 500 | shutil.rmtree(self.workspace_root) |
| 501 | |
| 502 | self.worker.hold_jobs_in_build = False |
| 503 | self.worker.release() |
| 504 | self.waitUntilSettled() |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 505 | |
| 506 | def test_periodic(self): |
| 507 | self.worker.hold_jobs_in_build = True |
| 508 | self.create_branch('org/project', 'stable/havana') |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 509 | self.updateConfigLayout( |
| 510 | 'tests/fixtures/layout-timer.yaml') |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 511 | self.sched.reconfigure(self.config) |
| 512 | self.registerJobs() |
| 513 | |
| 514 | # The pipeline triggers every second, so we should have seen |
| 515 | # several by now. |
| 516 | time.sleep(5) |
| 517 | self.waitUntilSettled() |
| 518 | |
| 519 | builds = self.builds[:] |
| 520 | |
| 521 | self.worker.hold_jobs_in_build = False |
| 522 | # Stop queuing timer triggered jobs so that the assertions |
| 523 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 524 | self.updateConfigLayout( |
| 525 | 'tests/fixtures/layout-no-timer.yaml') |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 526 | self.sched.reconfigure(self.config) |
| 527 | self.registerJobs() |
| 528 | self.worker.release() |
| 529 | self.waitUntilSettled() |
| 530 | |
| 531 | projects = ['org/project'] |
| 532 | |
| 533 | self.assertEquals(2, len(builds), "Two builds are running") |
| 534 | |
| 535 | upstream = self.getUpstreamRepos(projects) |
| 536 | states = [ |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 537 | {'org/project': |
| 538 | str(upstream['org/project'].commit('stable/havana')), |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 539 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 540 | {'org/project': |
| 541 | str(upstream['org/project'].commit('stable/havana')), |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 542 | }, |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 543 | ] |
James E. Blair | 217b10d | 2015-01-08 16:25:28 -0800 | [diff] [blame] | 544 | |
| 545 | for number, build in enumerate(builds): |
| 546 | self.log.debug("Build parameters: %s", build.parameters) |
| 547 | cloner = zuul.lib.cloner.Cloner( |
| 548 | git_base_url=self.upstream_root, |
| 549 | projects=projects, |
| 550 | workspace=self.workspace_root, |
| 551 | zuul_branch=build.parameters.get('ZUUL_BRANCH', None), |
| 552 | zuul_ref=build.parameters.get('ZUUL_REF', None), |
| 553 | zuul_url=self.git_root, |
| 554 | branch='stable/havana', |
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 | cloner.execute() |
| 557 | work = self.getWorkspaceRepos(projects) |
| 558 | state = states[number] |
| 559 | |
| 560 | for project in projects: |
| 561 | self.assertEquals(state[project], |
| 562 | str(work[project].commit('HEAD')), |
| 563 | 'Project %s commit for build %s should ' |
| 564 | 'be correct' % (project, number)) |
| 565 | |
| 566 | shutil.rmtree(self.workspace_root) |
| 567 | |
| 568 | self.worker.hold_jobs_in_build = False |
| 569 | self.worker.release() |
| 570 | self.waitUntilSettled() |
Sachi King | 9f16d52 | 2016-03-16 12:20:45 +1100 | [diff] [blame] | 571 | |
| 572 | def test_post_checkout(self): |
| 573 | project = "org/project" |
| 574 | path = os.path.join(self.upstream_root, project) |
| 575 | repo = git.Repo(path) |
| 576 | repo.head.reference = repo.heads['master'] |
| 577 | commits = [] |
| 578 | for i in range(0, 3): |
| 579 | commits.append(self.create_commit(project)) |
| 580 | newRev = commits[1] |
| 581 | |
| 582 | cloner = zuul.lib.cloner.Cloner( |
| 583 | git_base_url=self.upstream_root, |
| 584 | projects=[project], |
| 585 | workspace=self.workspace_root, |
| 586 | zuul_branch=None, |
| 587 | zuul_ref='master', |
| 588 | zuul_url=self.git_root, |
| 589 | zuul_project=project, |
| 590 | zuul_newrev=newRev, |
| 591 | ) |
| 592 | cloner.execute() |
| 593 | repos = self.getWorkspaceRepos([project]) |
| 594 | cloned_sha = repos[project].rev_parse('HEAD').hexsha |
| 595 | self.assertEqual(newRev, cloned_sha) |
| 596 | |
| 597 | def test_post_and_master_checkout(self): |
| 598 | project = "org/project1" |
| 599 | master_project = "org/project2" |
| 600 | path = os.path.join(self.upstream_root, project) |
| 601 | repo = git.Repo(path) |
| 602 | repo.head.reference = repo.heads['master'] |
| 603 | commits = [] |
| 604 | for i in range(0, 3): |
| 605 | commits.append(self.create_commit(project)) |
| 606 | newRev = commits[1] |
| 607 | |
| 608 | cloner = zuul.lib.cloner.Cloner( |
| 609 | git_base_url=self.upstream_root, |
| 610 | projects=[project, master_project], |
| 611 | workspace=self.workspace_root, |
| 612 | zuul_branch=None, |
| 613 | zuul_ref='master', |
| 614 | zuul_url=self.git_root, |
| 615 | zuul_project=project, |
| 616 | zuul_newrev=newRev |
| 617 | ) |
| 618 | cloner.execute() |
| 619 | repos = self.getWorkspaceRepos([project, master_project]) |
| 620 | cloned_sha = repos[project].rev_parse('HEAD').hexsha |
| 621 | self.assertEqual(newRev, cloned_sha) |
| 622 | self.assertEqual( |
| 623 | repos[master_project].rev_parse('HEAD').hexsha, |
| 624 | repos[master_project].rev_parse('master').hexsha) |