blob: 181cb155878b5bd68cc6c08346a0dc20c6c8013b [file] [log] [blame]
Don Garrettbe3608b2018-06-05 17:10:09 -07001# -*- coding: utf-8 -*-
2# Copyright 2018 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Test gen_luci_scheduler."""
7from __future__ import print_function
8
Don Garrett8dace272018-07-19 14:07:42 -07009from chromite.config import chromeos_config
Don Garrettbe3608b2018-06-05 17:10:09 -070010from chromite.lib import cros_test_lib
11from chromite.lib import config_lib
12from chromite.lib import config_lib_unittest
13from chromite.scripts import gen_luci_scheduler
14
15# It's reasonable for unittests to look at internals.
16# pylint: disable=protected-access
17
18
19class GenLuciSchedulerTest(cros_test_lib.MockTestCase):
20 """Tests for cbuildbot_launch script."""
21 def testSanityAgainstProd(self):
22 """Test we can generate a luci scheduler config with live data."""
23 # If it runs without crashing, we pass.
Don Garrett8dace272018-07-19 14:07:42 -070024 gen_luci_scheduler.genLuciSchedulerConfig(
25 config_lib.GetConfig(), chromeos_config.BranchScheduleConfig())
Don Garrettbe3608b2018-06-05 17:10:09 -070026
27 def testGenSchedulerJob(self):
28 """Test the job creation helper."""
29 build_config = config_lib_unittest.MockBuildConfig().apply(
30 schedule='funky schedule'
31 )
32
33 expected = '''
34job {
35 id: "amd64-generic-paladin"
36 acl_sets: "default"
37 schedule: "funky schedule"
38 buildbucket: {
39 server: "cr-buildbucket.appspot.com"
40 bucket: "luci.chromeos.general"
41 builder: "Prod"
42 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -070043 tags: "cbb_config:amd64-generic-paladin"
Don Garrett73148e52018-08-17 16:54:46 -070044 tags: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -070045 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -070046 properties: "cbb_config:amd64-generic-paladin"
Don Garrett73148e52018-08-17 16:54:46 -070047 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -070048 properties: "cbb_extra_args:[\\"--buildbot\\"]"
49 }
50}
51'''
52
53 result = gen_luci_scheduler.genSchedulerJob(build_config)
54 self.assertEqual(result, expected)
55
56 def testGenSchedulerTriggerSimple(self):
57 """Test the trigger creation helper."""
58 trigger_name = 'simple'
59 repo = 'url://repo'
60 refs = ['refs/path']
61 builds = ['test_build']
62
63 expected = '''
64trigger {
65 id: "simple"
66 acl_sets: "default"
67 schedule: "with 5m interval"
68 gitiles: {
69 repo: "url://repo"
70 refs: "refs/path"
71 }
72 triggers: "test_build"
73}
74'''
75
76 result = gen_luci_scheduler.genSchedulerTrigger(
77 trigger_name, repo, refs, builds)
78
79 self.assertEqual(result, expected)
80
81 def testGenSchedulerTriggerComplex(self):
82 """Test the trigger creation helper."""
83 trigger_name = 'complex'
84 repo = 'url://repo'
85 refs = ['refs/path', 'refs/other_path']
86 builds = ['test_build_a', 'test_build_b']
87
88 expected = '''
89trigger {
90 id: "complex"
91 acl_sets: "default"
92 schedule: "with 5m interval"
93 gitiles: {
94 repo: "url://repo"
95 refs: "refs/path"
96 refs: "refs/other_path"
97 }
98 triggers: "test_build_a"
99 triggers: "test_build_b"
100}
101'''
102
103 result = gen_luci_scheduler.genSchedulerTrigger(
104 trigger_name, repo, refs, builds)
105
106 self.assertEqual(result, expected)
107
Don Garrett8dace272018-07-19 14:07:42 -0700108
109 def testGenSchedulerBranched(self):
110 """Test the job creation helper."""
111 build_config = config_lib_unittest.MockBuildConfig().apply(
112 schedule_branch='mock_branch',
113 schedule='funky schedule',
114 )
115
116 expected = '''
117job {
118 id: "mock_branch-amd64-generic-paladin"
119 acl_sets: "default"
120 schedule: "funky schedule"
121 buildbucket: {
122 server: "cr-buildbucket.appspot.com"
123 bucket: "luci.chromeos.general"
124 builder: "Prod"
125 tags: "cbb_branch:mock_branch"
Don Garrett8dace272018-07-19 14:07:42 -0700126 tags: "cbb_config:amd64-generic-paladin"
Don Garrett73148e52018-08-17 16:54:46 -0700127 tags: "cbb_display_label:MockLabel"
Don Garrett8dace272018-07-19 14:07:42 -0700128 properties: "cbb_branch:mock_branch"
Don Garrett8dace272018-07-19 14:07:42 -0700129 properties: "cbb_config:amd64-generic-paladin"
Don Garrett73148e52018-08-17 16:54:46 -0700130 properties: "cbb_display_label:MockLabel"
131 properties: "cbb_extra_args:[\\"--buildbot\\"]"
132 }
133}
134'''
135
136 result = gen_luci_scheduler.genSchedulerJob(build_config)
137 self.assertEqual(result, expected)
138
139 def testGenSchedulerWorkspaceBranch(self):
140 """Test the job creation helper."""
141 build_config = config_lib_unittest.MockBuildConfig().apply(
142 workspace_branch='work_branch',
143 schedule='funky schedule',
144 )
145
146 expected = '''
147job {
148 id: "amd64-generic-paladin"
149 acl_sets: "default"
150 schedule: "funky schedule"
151 buildbucket: {
152 server: "cr-buildbucket.appspot.com"
153 bucket: "luci.chromeos.general"
154 builder: "Prod"
155 tags: "cbb_branch:master"
156 tags: "cbb_config:amd64-generic-paladin"
157 tags: "cbb_display_label:MockLabel"
158 tags: "cbb_workspace_branch:work_branch"
159 properties: "cbb_branch:master"
160 properties: "cbb_config:amd64-generic-paladin"
161 properties: "cbb_display_label:MockLabel"
162 properties: "cbb_workspace_branch:work_branch"
Don Garrett8dace272018-07-19 14:07:42 -0700163 properties: "cbb_extra_args:[\\"--buildbot\\"]"
164 }
165}
166'''
167
168 result = gen_luci_scheduler.genSchedulerJob(build_config)
169 self.assertEqual(result, expected)
170
Yoshisato Yanagisawa16285b42018-09-19 14:00:58 +0900171 def testGenSchedulerGomaClientType(self):
172 """Test the job creation helper."""
173 build_config = config_lib_unittest.MockBuildConfig().apply(
174 goma_client_type='client_type',
175 schedule='funky schedule',
176 )
177
178 expected = '''
179job {
180 id: "amd64-generic-paladin"
181 acl_sets: "default"
182 schedule: "funky schedule"
183 buildbucket: {
184 server: "cr-buildbucket.appspot.com"
185 bucket: "luci.chromeos.general"
186 builder: "Prod"
187 tags: "cbb_branch:master"
188 tags: "cbb_config:amd64-generic-paladin"
189 tags: "cbb_display_label:MockLabel"
190 tags: "cbb_goma_client_type:client_type"
191 properties: "cbb_branch:master"
192 properties: "cbb_config:amd64-generic-paladin"
193 properties: "cbb_display_label:MockLabel"
194 properties: "cbb_goma_client_type:client_type"
195 properties: "cbb_extra_args:[\\"--buildbot\\"]"
196 }
197}
198'''
199
200 result = gen_luci_scheduler.genSchedulerJob(build_config)
201 self.assertEqual(result, expected)
202
Don Garrettbe3608b2018-06-05 17:10:09 -0700203 def testGenLuciSchedulerConfig(self):
204 """Test a full LUCI Scheduler config file."""
205 site_config = config_lib.SiteConfig()
206
207 site_config.Add(
208 'not_scheduled',
209 luci_builder='ProdBuilder',
210 display_label='MockLabel',
211 )
212
213 site_config.Add(
214 'build_prod',
215 luci_builder='ProdBuilder',
216 display_label='MockLabel',
217 schedule='run once in a while',
218 )
219
220 site_config.Add(
221 'build_tester',
222 luci_builder='TestBuilder',
223 display_label='TestLabel',
224 schedule='run daily',
225 )
226
227 site_config.Add(
228 'build_triggered_a',
229 luci_builder='ProdBuilder',
230 display_label='MockLabel',
231 schedule='triggered',
232 triggered_gitiles=[[
233 'gitiles_url_a',
234 ['ref_a', 'ref_b'],
235 ], [
236 'gitiles_url_b',
237 ['ref_c'],
238 ]],
239 )
240
241 site_config.Add(
242 'build_triggered_b',
243 luci_builder='ProdBuilder',
244 display_label='MockLabel',
245 schedule='triggered',
246 triggered_gitiles=[[
247 'gitiles_url_b',
248 ['ref_c'],
249 ]],
250 )
251
Don Garrett8dace272018-07-19 14:07:42 -0700252 default_config = config_lib.GetConfig().GetDefault()
253
254 branch_configs = [
255 default_config.derive(
256 name='branch_tester',
257 luci_builder='TestBuilder',
258 display_label='TestLabel',
259 schedule='run daily',
260 schedule_branch='test-branch',
261 ),
262 ]
263
264
Don Garrettbe3608b2018-06-05 17:10:09 -0700265 expected = '''# Defines buckets on luci-scheduler.appspot.com.
266#
267# For schema of this file and documentation see ProjectConfig message in
268# https://github.com/luci/luci-go/blob/master/scheduler/appengine/messages/config.proto
269
270# Generated with chromite/scripts/gen_luci_scheduler
271
Don Garrettff45f4b2018-10-04 09:08:01 -0700272# Autodeployed with:
273# http://cros-goldeneye/chromeos/legoland/builderHistory?buildConfig=luci-scheduler-updater
274
Don Garrettbe3608b2018-06-05 17:10:09 -0700275acl_sets {
276 name: "default"
277 acls {
278 role: READER
279 granted_to: "group:googlers"
280 }
281 acls {
282 role: OWNER
283 granted_to: "group:project-chromeos-admins"
284 }
Jason D. Clintona9e374a2018-10-18 18:41:00 -0600285 acls {
286 role: TRIGGERER
287 granted_to: "group:mdb/chromeos-build-access"
288 }
Don Garrettbe3608b2018-06-05 17:10:09 -0700289}
290
291trigger {
292 id: "trigger_0"
293 acl_sets: "default"
294 schedule: "with 5m interval"
295 gitiles: {
296 repo: "gitiles_url_a"
297 refs: "ref_a"
298 refs: "ref_b"
299 }
300 triggers: "build_triggered_a"
301}
302
303trigger {
304 id: "trigger_1"
305 acl_sets: "default"
306 schedule: "with 5m interval"
307 gitiles: {
308 repo: "gitiles_url_b"
309 refs: "ref_c"
310 }
311 triggers: "build_triggered_a"
312 triggers: "build_triggered_b"
313}
314
315job {
316 id: "build_prod"
317 acl_sets: "default"
318 schedule: "run once in a while"
319 buildbucket: {
320 server: "cr-buildbucket.appspot.com"
321 bucket: "luci.chromeos.general"
322 builder: "ProdBuilder"
323 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700324 tags: "cbb_config:build_prod"
Don Garrett73148e52018-08-17 16:54:46 -0700325 tags: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700326 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700327 properties: "cbb_config:build_prod"
Don Garrett73148e52018-08-17 16:54:46 -0700328 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700329 properties: "cbb_extra_args:[\\"--buildbot\\"]"
330 }
331}
332
333job {
334 id: "build_tester"
335 acl_sets: "default"
336 schedule: "run daily"
337 buildbucket: {
338 server: "cr-buildbucket.appspot.com"
339 bucket: "luci.chromeos.general"
340 builder: "TestBuilder"
341 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700342 tags: "cbb_config:build_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700343 tags: "cbb_display_label:TestLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700344 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700345 properties: "cbb_config:build_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700346 properties: "cbb_display_label:TestLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700347 properties: "cbb_extra_args:[\\"--buildbot\\"]"
348 }
349}
350
351job {
352 id: "build_triggered_a"
353 acl_sets: "default"
354 schedule: "triggered"
355 buildbucket: {
356 server: "cr-buildbucket.appspot.com"
357 bucket: "luci.chromeos.general"
358 builder: "ProdBuilder"
359 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700360 tags: "cbb_config:build_triggered_a"
Don Garrett73148e52018-08-17 16:54:46 -0700361 tags: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700362 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700363 properties: "cbb_config:build_triggered_a"
Don Garrett73148e52018-08-17 16:54:46 -0700364 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700365 properties: "cbb_extra_args:[\\"--buildbot\\"]"
366 }
367}
368
369job {
370 id: "build_triggered_b"
371 acl_sets: "default"
372 schedule: "triggered"
373 buildbucket: {
374 server: "cr-buildbucket.appspot.com"
375 bucket: "luci.chromeos.general"
376 builder: "ProdBuilder"
377 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700378 tags: "cbb_config:build_triggered_b"
Don Garrett73148e52018-08-17 16:54:46 -0700379 tags: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700380 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700381 properties: "cbb_config:build_triggered_b"
Don Garrett73148e52018-08-17 16:54:46 -0700382 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700383 properties: "cbb_extra_args:[\\"--buildbot\\"]"
384 }
385}
Don Garrett8dace272018-07-19 14:07:42 -0700386
387job {
388 id: "test-branch-branch_tester"
389 acl_sets: "default"
390 schedule: "run daily"
391 buildbucket: {
392 server: "cr-buildbucket.appspot.com"
393 bucket: "luci.chromeos.general"
394 builder: "TestBuilder"
395 tags: "cbb_branch:test-branch"
Don Garrett8dace272018-07-19 14:07:42 -0700396 tags: "cbb_config:branch_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700397 tags: "cbb_display_label:TestLabel"
Don Garrett8dace272018-07-19 14:07:42 -0700398 properties: "cbb_branch:test-branch"
Don Garrett8dace272018-07-19 14:07:42 -0700399 properties: "cbb_config:branch_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700400 properties: "cbb_display_label:TestLabel"
Don Garrett8dace272018-07-19 14:07:42 -0700401 properties: "cbb_extra_args:[\\"--buildbot\\"]"
402 }
403}
Don Garrettbe3608b2018-06-05 17:10:09 -0700404'''
Don Garrett8dace272018-07-19 14:07:42 -0700405 result = gen_luci_scheduler.genLuciSchedulerConfig(
406 site_config, branch_configs)
Don Garrettbe3608b2018-06-05 17:10:09 -0700407
408 self.assertEqual(result, expected)