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