blob: 1a4ce88c15f7c0d9a4531563e434ac3e546985f9 [file] [log] [blame]
Antoine Musso45dd2cb2014-01-29 17:17:43 +01001#!/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
18import logging
19import os
20import shutil
21
22import git
23
24import zuul.lib.cloner
25
26from tests.base import ZuulTestCase
27from tests.base import FIXTURE_DIR
28
29logging.basicConfig(level=logging.DEBUG,
30 format='%(asctime)s %(name)-32s '
31 '%(levelname)-8s %(message)s')
32
33
34class 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 Musso45dd2cb2014-01-29 17:17:43 +010053 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 Musso45dd2cb2014-01-29 17:17:43 +010062 for build in self.builds:
63 self.log.debug("Build parameters: %s", build.parameters)
James E. Blair82318922014-08-21 11:05:32 -070064 change_number = int(build.parameters['ZUUL_CHANGE'])
Antoine Musso45dd2cb2014-01-29 17:17:43 +010065 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. Blair82318922014-08-21 11:05:32 -070070 zuul_ref=build.parameters['ZUUL_REF'],
Antoine Musso45dd2cb2014-01-29 17:17:43 +010071 zuul_url=self.git_root,
72 branch='master',
Antoine Musso45dd2cb2014-01-29 17:17:43 +010073 )
74 cloner.execute()
75 work_repo1 = git.Repo(os.path.join(self.workspace_root,
76 'org/project1'))
Antoine Musso45dd2cb2014-01-29 17:17:43 +010077 work_repo2 = git.Repo(os.path.join(self.workspace_root,
78 'org/project2'))
James E. Blair82318922014-08-21 11:05:32 -070079 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 Musso45dd2cb2014-01-29 17:17:43 +010090 shutil.rmtree(self.workspace_root)
James E. Blair82318922014-08-21 11:05:32 -070091
92 self.worker.hold_jobs_in_build = False
93 self.worker.release()
94 self.waitUntilSettled()