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