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 |
| 21 | |
| 22 | import git |
| 23 | |
| 24 | import zuul.lib.cloner |
| 25 | |
| 26 | from tests.base import ZuulTestCase |
| 27 | from tests.base import FIXTURE_DIR |
| 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): |
| 40 | super(TestCloner, self).setUp() |
| 41 | self.workspace_root = os.path.join(self.test_root, 'workspace') |
| 42 | |
| 43 | self.config.set('zuul', 'layout_config', |
| 44 | 'tests/fixtures/layout-gating.yaml') |
| 45 | self.sched.reconfigure(self.config) |
| 46 | self.registerJobs() |
| 47 | |
| 48 | def test_cloner(self): |
| 49 | self.worker.hold_jobs_in_build = True |
| 50 | |
| 51 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 52 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 53 | A.addApproval('CRVW', 2) |
| 54 | B.addApproval('CRVW', 2) |
| 55 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 56 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 57 | |
| 58 | self.waitUntilSettled() |
| 59 | |
| 60 | self.assertEquals(2, len(self.builds), "Two builds are running") |
| 61 | |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 62 | for build in self.builds: |
| 63 | self.log.debug("Build parameters: %s", build.parameters) |
James E. Blair | 8231892 | 2014-08-21 11:05:32 -0700 | [diff] [blame^] | 64 | change_number = int(build.parameters['ZUUL_CHANGE']) |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 65 | cloner = zuul.lib.cloner.Cloner( |
| 66 | git_base_url=self.upstream_root, |
| 67 | projects=['org/project1', 'org/project2'], |
| 68 | workspace=self.workspace_root, |
| 69 | zuul_branch='master', |
James E. Blair | 8231892 | 2014-08-21 11:05:32 -0700 | [diff] [blame^] | 70 | zuul_ref=build.parameters['ZUUL_REF'], |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 71 | zuul_url=self.git_root, |
| 72 | branch='master', |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 73 | ) |
| 74 | cloner.execute() |
| 75 | work_repo1 = git.Repo(os.path.join(self.workspace_root, |
| 76 | 'org/project1')) |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 77 | work_repo2 = git.Repo(os.path.join(self.workspace_root, |
| 78 | 'org/project2')) |
James E. Blair | 8231892 | 2014-08-21 11:05:32 -0700 | [diff] [blame^] | 79 | if change_number >= 1: |
| 80 | self.assertEquals( |
| 81 | self.builds[0].parameters['ZUUL_COMMIT'], |
| 82 | str(work_repo1.commit('HEAD'))) |
| 83 | if change_number >= 2: |
| 84 | self.assertEquals( |
| 85 | self.builds[1].parameters['ZUUL_COMMIT'], |
| 86 | str(work_repo2.commit('HEAD'))) |
| 87 | else: |
| 88 | self.assertEquals(str(work_repo2.commit('master')), |
| 89 | str(work_repo2.commit('HEAD'))) |
Antoine Musso | 45dd2cb | 2014-01-29 17:17:43 +0100 | [diff] [blame] | 90 | shutil.rmtree(self.workspace_root) |
James E. Blair | 8231892 | 2014-08-21 11:05:32 -0700 | [diff] [blame^] | 91 | |
| 92 | self.worker.hold_jobs_in_build = False |
| 93 | self.worker.release() |
| 94 | self.waitUntilSettled() |