blob: f0e606ac5ae274d514ceec7e5308d1ad99b634d1 [file] [log] [blame]
James E. Blairac180ce2017-06-07 19:31:02 -07001# Copyright 2017 Red Hat, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Tristan Cacqueray829e6172017-06-13 06:49:36 +000015import textwrap
James E. Blairac180ce2017-06-07 19:31:02 -070016
17from tests.base import ZuulTestCase
18
19
20class TenantParserTestCase(ZuulTestCase):
21 create_project_keys = True
22
23 CONFIG_SET = set(['pipeline', 'job', 'semaphore', 'project',
24 'project-template', 'nodeset', 'secret'])
25 UNTRUSTED_SET = CONFIG_SET - set(['pipeline'])
26
27 def setupAllProjectKeys(self):
28 for project in ['common-config', 'org/project1', 'org/project2']:
29 self.setupProjectKeys('gerrit', project)
30
31
32class TestTenantSimple(TenantParserTestCase):
33 tenant_config_file = 'config/tenant-parser/simple.yaml'
34
35 def test_tenant_simple(self):
36 tenant = self.sched.abide.tenants.get('tenant-one')
37 self.assertEqual(['common-config'],
38 [x.name for x in tenant.config_projects])
39 self.assertEqual(['org/project1', 'org/project2'],
40 [x.name for x in tenant.untrusted_projects])
41 self.assertEqual(self.CONFIG_SET,
42 tenant.config_projects[0].load_classes)
43 self.assertEqual(self.UNTRUSTED_SET,
44 tenant.untrusted_projects[0].load_classes)
45 self.assertEqual(self.UNTRUSTED_SET,
46 tenant.untrusted_projects[1].load_classes)
47 self.assertTrue('common-config-job' in tenant.layout.jobs)
48 self.assertTrue('project1-job' in tenant.layout.jobs)
49 self.assertTrue('project2-job' in tenant.layout.jobs)
50 project1_config = tenant.layout.project_configs.get(
51 'review.example.com/org/project1')
52 self.assertTrue('common-config-job' in
53 project1_config.pipelines['check'].job_list.jobs)
54 self.assertTrue('project1-job' in
55 project1_config.pipelines['check'].job_list.jobs)
56 project2_config = tenant.layout.project_configs.get(
57 'review.example.com/org/project2')
58 self.assertTrue('common-config-job' in
59 project2_config.pipelines['check'].job_list.jobs)
60 self.assertTrue('project2-job' in
61 project2_config.pipelines['check'].job_list.jobs)
62
63
64class TestTenantOverride(TenantParserTestCase):
65 tenant_config_file = 'config/tenant-parser/override.yaml'
66
67 def test_tenant_override(self):
68 tenant = self.sched.abide.tenants.get('tenant-one')
69 self.assertEqual(['common-config'],
70 [x.name for x in tenant.config_projects])
71 self.assertEqual(['org/project1', 'org/project2'],
72 [x.name for x in tenant.untrusted_projects])
73 self.assertEqual(self.CONFIG_SET,
74 tenant.config_projects[0].load_classes)
75 self.assertEqual(self.UNTRUSTED_SET - set(['project']),
76 tenant.untrusted_projects[0].load_classes)
77 self.assertEqual(set(['job']),
78 tenant.untrusted_projects[1].load_classes)
79 self.assertTrue('common-config-job' in tenant.layout.jobs)
80 self.assertTrue('project1-job' in tenant.layout.jobs)
81 self.assertTrue('project2-job' in tenant.layout.jobs)
82 project1_config = tenant.layout.project_configs.get(
83 'review.example.com/org/project1')
84 self.assertTrue('common-config-job' in
85 project1_config.pipelines['check'].job_list.jobs)
86 self.assertFalse('project1-job' in
87 project1_config.pipelines['check'].job_list.jobs)
88 project2_config = tenant.layout.project_configs.get(
89 'review.example.com/org/project2')
90 self.assertTrue('common-config-job' in
91 project2_config.pipelines['check'].job_list.jobs)
92 self.assertFalse('project2-job' in
93 project2_config.pipelines['check'].job_list.jobs)
94
95
96class TestTenantGroups(TenantParserTestCase):
97 tenant_config_file = 'config/tenant-parser/groups.yaml'
98
99 def test_tenant_groups(self):
100 tenant = self.sched.abide.tenants.get('tenant-one')
101 self.assertEqual(['common-config'],
102 [x.name for x in tenant.config_projects])
103 self.assertEqual(['org/project1', 'org/project2'],
104 [x.name for x in tenant.untrusted_projects])
105 self.assertEqual(self.CONFIG_SET,
106 tenant.config_projects[0].load_classes)
107 self.assertEqual(self.UNTRUSTED_SET - set(['project']),
108 tenant.untrusted_projects[0].load_classes)
109 self.assertEqual(self.UNTRUSTED_SET - set(['project']),
110 tenant.untrusted_projects[1].load_classes)
111 self.assertTrue('common-config-job' in tenant.layout.jobs)
112 self.assertTrue('project1-job' in tenant.layout.jobs)
113 self.assertTrue('project2-job' in tenant.layout.jobs)
114 project1_config = tenant.layout.project_configs.get(
115 'review.example.com/org/project1')
116 self.assertTrue('common-config-job' in
117 project1_config.pipelines['check'].job_list.jobs)
118 self.assertFalse('project1-job' in
119 project1_config.pipelines['check'].job_list.jobs)
120 project2_config = tenant.layout.project_configs.get(
121 'review.example.com/org/project2')
122 self.assertTrue('common-config-job' in
123 project2_config.pipelines['check'].job_list.jobs)
124 self.assertFalse('project2-job' in
125 project2_config.pipelines['check'].job_list.jobs)
126
127
128class TestTenantGroups2(TenantParserTestCase):
129 tenant_config_file = 'config/tenant-parser/groups2.yaml'
130
131 def test_tenant_groups2(self):
132 tenant = self.sched.abide.tenants.get('tenant-one')
133 self.assertEqual(['common-config'],
134 [x.name for x in tenant.config_projects])
135 self.assertEqual(['org/project1', 'org/project2'],
136 [x.name for x in tenant.untrusted_projects])
137 self.assertEqual(self.CONFIG_SET,
138 tenant.config_projects[0].load_classes)
139 self.assertEqual(self.UNTRUSTED_SET - set(['project']),
140 tenant.untrusted_projects[0].load_classes)
141 self.assertEqual(self.UNTRUSTED_SET - set(['project', 'job']),
142 tenant.untrusted_projects[1].load_classes)
143 self.assertTrue('common-config-job' in tenant.layout.jobs)
144 self.assertTrue('project1-job' in tenant.layout.jobs)
145 self.assertFalse('project2-job' in tenant.layout.jobs)
146 project1_config = tenant.layout.project_configs.get(
147 'review.example.com/org/project1')
148 self.assertTrue('common-config-job' in
149 project1_config.pipelines['check'].job_list.jobs)
150 self.assertFalse('project1-job' in
151 project1_config.pipelines['check'].job_list.jobs)
152 project2_config = tenant.layout.project_configs.get(
153 'review.example.com/org/project2')
154 self.assertTrue('common-config-job' in
155 project2_config.pipelines['check'].job_list.jobs)
156 self.assertFalse('project2-job' in
157 project2_config.pipelines['check'].job_list.jobs)
158
159
160class TestTenantGroups3(TenantParserTestCase):
161 tenant_config_file = 'config/tenant-parser/groups3.yaml'
162
163 def test_tenant_groups3(self):
164 tenant = self.sched.abide.tenants.get('tenant-one')
165 self.assertEqual(['common-config'],
166 [x.name for x in tenant.config_projects])
167 self.assertEqual(['org/project1', 'org/project2'],
168 [x.name for x in tenant.untrusted_projects])
169 self.assertEqual(self.CONFIG_SET,
170 tenant.config_projects[0].load_classes)
171 self.assertEqual(set(['job']),
172 tenant.untrusted_projects[0].load_classes)
173 self.assertEqual(set(['project', 'job']),
174 tenant.untrusted_projects[1].load_classes)
175 self.assertTrue('common-config-job' in tenant.layout.jobs)
176 self.assertTrue('project1-job' in tenant.layout.jobs)
177 self.assertTrue('project2-job' in tenant.layout.jobs)
178 project1_config = tenant.layout.project_configs.get(
179 'review.example.com/org/project1')
180 self.assertTrue('common-config-job' in
181 project1_config.pipelines['check'].job_list.jobs)
182 self.assertFalse('project1-job' in
183 project1_config.pipelines['check'].job_list.jobs)
184 project2_config = tenant.layout.project_configs.get(
185 'review.example.com/org/project2')
186 self.assertTrue('common-config-job' in
187 project2_config.pipelines['check'].job_list.jobs)
188 self.assertTrue('project2-job' in
189 project2_config.pipelines['check'].job_list.jobs)
Tristan Cacqueray829e6172017-06-13 06:49:36 +0000190
191
192class TestSplitConfig(ZuulTestCase):
193 tenant_config_file = 'config/split-config/main.yaml'
194
195 def setup_config(self):
196 super(TestSplitConfig, self).setup_config()
197
198 def test_split_config(self):
199 tenant = self.sched.abide.tenants.get('tenant-one')
200 self.assertIn('project-test1', tenant.layout.jobs)
201 project_config = tenant.layout.project_configs.get(
202 'review.example.com/org/project')
203 self.assertIn('project-test1',
204 project_config.pipelines['check'].job_list.jobs)
205 project1_config = tenant.layout.project_configs.get(
206 'review.example.com/org/project1')
207 self.assertIn('project1-project2-integration',
208 project1_config.pipelines['check'].job_list.jobs)
209
210 def test_dynamic_split_config(self):
211 in_repo_conf = textwrap.dedent(
212 """
213 - project:
214 name: org/project1
215 check:
216 jobs:
217 - project-test1
218 """)
219 file_dict = {'.zuul.d/gate.yaml': in_repo_conf}
220 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A',
221 files=file_dict)
222 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
223 self.waitUntilSettled()
224 # project1-project2-integration test removed, only want project-test1
225 self.assertHistory([
226 dict(name='project-test1', result='SUCCESS', changes='1,1')])