blob: 1f543b32694eb9b0ead981cabbc013acdfd05f88 [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
Mike Frysinger74a6cc82020-02-14 14:16:22 -05009import sys
10
Don Garrett8dace272018-07-19 14:07:42 -070011from chromite.config import chromeos_config
Don Garrettbe3608b2018-06-05 17:10:09 -070012from chromite.lib import cros_test_lib
13from chromite.lib import config_lib
14from chromite.lib import config_lib_unittest
15from chromite.scripts import gen_luci_scheduler
16
Mike Frysinger74a6cc82020-02-14 14:16:22 -050017
18assert sys.version_info >= (3, 6), 'This module requires Python 3.6+'
19
20
Don Garrettbe3608b2018-06-05 17:10:09 -070021# It's reasonable for unittests to look at internals.
22# pylint: disable=protected-access
23
24
25class GenLuciSchedulerTest(cros_test_lib.MockTestCase):
26 """Tests for cbuildbot_launch script."""
27 def testSanityAgainstProd(self):
28 """Test we can generate a luci scheduler config with live data."""
29 # If it runs without crashing, we pass.
Don Garrett8dace272018-07-19 14:07:42 -070030 gen_luci_scheduler.genLuciSchedulerConfig(
31 config_lib.GetConfig(), chromeos_config.BranchScheduleConfig())
Don Garrettbe3608b2018-06-05 17:10:09 -070032
33 def testGenSchedulerJob(self):
34 """Test the job creation helper."""
35 build_config = config_lib_unittest.MockBuildConfig().apply(
36 schedule='funky schedule'
37 )
38
Mike Frysinger80de5012019-08-01 14:10:53 -040039 expected = """
Don Garrettbe3608b2018-06-05 17:10:09 -070040job {
41 id: "amd64-generic-paladin"
42 acl_sets: "default"
43 schedule: "funky schedule"
44 buildbucket: {
45 server: "cr-buildbucket.appspot.com"
46 bucket: "luci.chromeos.general"
47 builder: "Prod"
48 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -070049 tags: "cbb_config:amd64-generic-paladin"
Don Garrett73148e52018-08-17 16:54:46 -070050 tags: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -070051 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -070052 properties: "cbb_config:amd64-generic-paladin"
Don Garrett73148e52018-08-17 16:54:46 -070053 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -070054 properties: "cbb_extra_args:[\\"--buildbot\\"]"
55 }
56}
Mike Frysinger80de5012019-08-01 14:10:53 -040057"""
Don Garrettbe3608b2018-06-05 17:10:09 -070058
59 result = gen_luci_scheduler.genSchedulerJob(build_config)
60 self.assertEqual(result, expected)
61
62 def testGenSchedulerTriggerSimple(self):
63 """Test the trigger creation helper."""
64 trigger_name = 'simple'
65 repo = 'url://repo'
66 refs = ['refs/path']
David Burgercba0d272020-06-24 16:21:26 -060067 path_regexps = ['path/regexps']
Don Garrettbe3608b2018-06-05 17:10:09 -070068 builds = ['test_build']
69
Mike Frysinger80de5012019-08-01 14:10:53 -040070 expected = """
Don Garrettbe3608b2018-06-05 17:10:09 -070071trigger {
72 id: "simple"
73 acl_sets: "default"
74 schedule: "with 5m interval"
75 gitiles: {
76 repo: "url://repo"
77 refs: "refs/path"
David Burgercba0d272020-06-24 16:21:26 -060078 path_regexps: "path/regexps"
Don Garrettbe3608b2018-06-05 17:10:09 -070079 }
80 triggers: "test_build"
81}
Mike Frysinger80de5012019-08-01 14:10:53 -040082"""
Don Garrettbe3608b2018-06-05 17:10:09 -070083
84 result = gen_luci_scheduler.genSchedulerTrigger(
David Burgercba0d272020-06-24 16:21:26 -060085 trigger_name, repo, refs, path_regexps, builds)
Don Garrettbe3608b2018-06-05 17:10:09 -070086
87 self.assertEqual(result, expected)
88
89 def testGenSchedulerTriggerComplex(self):
90 """Test the trigger creation helper."""
91 trigger_name = 'complex'
92 repo = 'url://repo'
93 refs = ['refs/path', 'refs/other_path']
94 builds = ['test_build_a', 'test_build_b']
95
Mike Frysinger80de5012019-08-01 14:10:53 -040096 expected = """
Don Garrettbe3608b2018-06-05 17:10:09 -070097trigger {
98 id: "complex"
99 acl_sets: "default"
100 schedule: "with 5m interval"
101 gitiles: {
102 repo: "url://repo"
103 refs: "refs/path"
104 refs: "refs/other_path"
105 }
106 triggers: "test_build_a"
107 triggers: "test_build_b"
108}
Mike Frysinger80de5012019-08-01 14:10:53 -0400109"""
Don Garrettbe3608b2018-06-05 17:10:09 -0700110
111 result = gen_luci_scheduler.genSchedulerTrigger(
David Burgercba0d272020-06-24 16:21:26 -0600112 trigger_name, repo, refs, None, builds)
Don Garrettbe3608b2018-06-05 17:10:09 -0700113
114 self.assertEqual(result, expected)
115
Don Garrett8dace272018-07-19 14:07:42 -0700116
117 def testGenSchedulerBranched(self):
118 """Test the job creation helper."""
119 build_config = config_lib_unittest.MockBuildConfig().apply(
120 schedule_branch='mock_branch',
121 schedule='funky schedule',
122 )
123
Mike Frysinger80de5012019-08-01 14:10:53 -0400124 expected = """
Don Garrett8dace272018-07-19 14:07:42 -0700125job {
126 id: "mock_branch-amd64-generic-paladin"
127 acl_sets: "default"
128 schedule: "funky schedule"
129 buildbucket: {
130 server: "cr-buildbucket.appspot.com"
131 bucket: "luci.chromeos.general"
132 builder: "Prod"
133 tags: "cbb_branch:mock_branch"
Don Garrett8dace272018-07-19 14:07:42 -0700134 tags: "cbb_config:amd64-generic-paladin"
Don Garrett73148e52018-08-17 16:54:46 -0700135 tags: "cbb_display_label:MockLabel"
Don Garrett8dace272018-07-19 14:07:42 -0700136 properties: "cbb_branch:mock_branch"
Don Garrett8dace272018-07-19 14:07:42 -0700137 properties: "cbb_config:amd64-generic-paladin"
Don Garrett73148e52018-08-17 16:54:46 -0700138 properties: "cbb_display_label:MockLabel"
139 properties: "cbb_extra_args:[\\"--buildbot\\"]"
140 }
141}
Mike Frysinger80de5012019-08-01 14:10:53 -0400142"""
Don Garrett73148e52018-08-17 16:54:46 -0700143
144 result = gen_luci_scheduler.genSchedulerJob(build_config)
145 self.assertEqual(result, expected)
146
147 def testGenSchedulerWorkspaceBranch(self):
148 """Test the job creation helper."""
149 build_config = config_lib_unittest.MockBuildConfig().apply(
150 workspace_branch='work_branch',
151 schedule='funky schedule',
152 )
153
Mike Frysinger80de5012019-08-01 14:10:53 -0400154 expected = """
Don Garrett73148e52018-08-17 16:54:46 -0700155job {
156 id: "amd64-generic-paladin"
157 acl_sets: "default"
158 schedule: "funky schedule"
159 buildbucket: {
160 server: "cr-buildbucket.appspot.com"
161 bucket: "luci.chromeos.general"
162 builder: "Prod"
163 tags: "cbb_branch:master"
164 tags: "cbb_config:amd64-generic-paladin"
165 tags: "cbb_display_label:MockLabel"
166 tags: "cbb_workspace_branch:work_branch"
167 properties: "cbb_branch:master"
168 properties: "cbb_config:amd64-generic-paladin"
169 properties: "cbb_display_label:MockLabel"
170 properties: "cbb_workspace_branch:work_branch"
Don Garrett8dace272018-07-19 14:07:42 -0700171 properties: "cbb_extra_args:[\\"--buildbot\\"]"
172 }
173}
Mike Frysinger80de5012019-08-01 14:10:53 -0400174"""
Don Garrett8dace272018-07-19 14:07:42 -0700175
176 result = gen_luci_scheduler.genSchedulerJob(build_config)
177 self.assertEqual(result, expected)
178
Yoshisato Yanagisawa16285b42018-09-19 14:00:58 +0900179 def testGenSchedulerGomaClientType(self):
180 """Test the job creation helper."""
181 build_config = config_lib_unittest.MockBuildConfig().apply(
182 goma_client_type='client_type',
183 schedule='funky schedule',
184 )
185
Mike Frysinger80de5012019-08-01 14:10:53 -0400186 expected = """
Yoshisato Yanagisawa16285b42018-09-19 14:00:58 +0900187job {
188 id: "amd64-generic-paladin"
189 acl_sets: "default"
190 schedule: "funky schedule"
191 buildbucket: {
192 server: "cr-buildbucket.appspot.com"
193 bucket: "luci.chromeos.general"
194 builder: "Prod"
195 tags: "cbb_branch:master"
196 tags: "cbb_config:amd64-generic-paladin"
197 tags: "cbb_display_label:MockLabel"
198 tags: "cbb_goma_client_type:client_type"
199 properties: "cbb_branch:master"
200 properties: "cbb_config:amd64-generic-paladin"
201 properties: "cbb_display_label:MockLabel"
202 properties: "cbb_goma_client_type:client_type"
203 properties: "cbb_extra_args:[\\"--buildbot\\"]"
204 }
205}
Mike Frysinger80de5012019-08-01 14:10:53 -0400206"""
Yoshisato Yanagisawa16285b42018-09-19 14:00:58 +0900207
208 result = gen_luci_scheduler.genSchedulerJob(build_config)
209 self.assertEqual(result, expected)
210
Don Garrettbe3608b2018-06-05 17:10:09 -0700211 def testGenLuciSchedulerConfig(self):
212 """Test a full LUCI Scheduler config file."""
213 site_config = config_lib.SiteConfig()
214
215 site_config.Add(
216 'not_scheduled',
217 luci_builder='ProdBuilder',
218 display_label='MockLabel',
219 )
220
221 site_config.Add(
222 'build_prod',
223 luci_builder='ProdBuilder',
224 display_label='MockLabel',
225 schedule='run once in a while',
226 )
227
228 site_config.Add(
229 'build_tester',
230 luci_builder='TestBuilder',
231 display_label='TestLabel',
232 schedule='run daily',
233 )
234
235 site_config.Add(
236 'build_triggered_a',
237 luci_builder='ProdBuilder',
238 display_label='MockLabel',
239 schedule='triggered',
240 triggered_gitiles=[[
241 'gitiles_url_a',
242 ['ref_a', 'ref_b'],
243 ], [
244 'gitiles_url_b',
245 ['ref_c'],
246 ]],
247 )
248
249 site_config.Add(
250 'build_triggered_b',
251 luci_builder='ProdBuilder',
252 display_label='MockLabel',
253 schedule='triggered',
254 triggered_gitiles=[[
255 'gitiles_url_b',
256 ['ref_c'],
257 ]],
258 )
259
Don Garrett8dace272018-07-19 14:07:42 -0700260 default_config = config_lib.GetConfig().GetDefault()
261
262 branch_configs = [
263 default_config.derive(
264 name='branch_tester',
265 luci_builder='TestBuilder',
266 display_label='TestLabel',
267 schedule='run daily',
268 schedule_branch='test-branch',
269 ),
Don Garrett9a0d90c2018-10-30 12:47:14 -0700270 default_config.derive(
271 name='branch_tester_triggered',
272 luci_builder='TestBuilder',
273 display_label='TestLabel',
274 schedule='run daily',
275 schedule_branch='test-branch',
276 triggered_gitiles=[[
277 'gitiles_url_a',
278 ['ref_a', 'ref_b'],
279 ]],
280 ),
Don Garrett8dace272018-07-19 14:07:42 -0700281 ]
282
Mike Frysinger80de5012019-08-01 14:10:53 -0400283 expected = """# Defines buckets on luci-scheduler.appspot.com.
Don Garrettbe3608b2018-06-05 17:10:09 -0700284#
285# For schema of this file and documentation see ProjectConfig message in
286# https://github.com/luci/luci-go/blob/master/scheduler/appengine/messages/config.proto
287
288# Generated with chromite/scripts/gen_luci_scheduler
289
Don Garrettff45f4b2018-10-04 09:08:01 -0700290# Autodeployed with:
291# http://cros-goldeneye/chromeos/legoland/builderHistory?buildConfig=luci-scheduler-updater
292
Don Garrettbe3608b2018-06-05 17:10:09 -0700293acl_sets {
294 name: "default"
295 acls {
296 role: READER
297 granted_to: "group:googlers"
298 }
299 acls {
300 role: OWNER
301 granted_to: "group:project-chromeos-admins"
302 }
Jason D. Clintona9e374a2018-10-18 18:41:00 -0600303 acls {
304 role: TRIGGERER
305 granted_to: "group:mdb/chromeos-build-access"
306 }
Don Garrettbe3608b2018-06-05 17:10:09 -0700307}
308
309trigger {
310 id: "trigger_0"
311 acl_sets: "default"
312 schedule: "with 5m interval"
313 gitiles: {
314 repo: "gitiles_url_a"
315 refs: "ref_a"
316 refs: "ref_b"
317 }
318 triggers: "build_triggered_a"
Don Garrett9a0d90c2018-10-30 12:47:14 -0700319 triggers: "test-branch-branch_tester_triggered"
Don Garrettbe3608b2018-06-05 17:10:09 -0700320}
321
322trigger {
323 id: "trigger_1"
324 acl_sets: "default"
325 schedule: "with 5m interval"
326 gitiles: {
327 repo: "gitiles_url_b"
328 refs: "ref_c"
329 }
330 triggers: "build_triggered_a"
331 triggers: "build_triggered_b"
332}
333
334job {
335 id: "build_prod"
336 acl_sets: "default"
337 schedule: "run once in a while"
338 buildbucket: {
339 server: "cr-buildbucket.appspot.com"
340 bucket: "luci.chromeos.general"
341 builder: "ProdBuilder"
342 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700343 tags: "cbb_config:build_prod"
Don Garrett73148e52018-08-17 16:54:46 -0700344 tags: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700345 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700346 properties: "cbb_config:build_prod"
Don Garrett73148e52018-08-17 16:54:46 -0700347 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700348 properties: "cbb_extra_args:[\\"--buildbot\\"]"
349 }
350}
351
352job {
353 id: "build_tester"
354 acl_sets: "default"
355 schedule: "run daily"
356 buildbucket: {
357 server: "cr-buildbucket.appspot.com"
358 bucket: "luci.chromeos.general"
359 builder: "TestBuilder"
360 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700361 tags: "cbb_config:build_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700362 tags: "cbb_display_label:TestLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700363 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700364 properties: "cbb_config:build_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700365 properties: "cbb_display_label:TestLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700366 properties: "cbb_extra_args:[\\"--buildbot\\"]"
367 }
368}
369
370job {
371 id: "build_triggered_a"
372 acl_sets: "default"
373 schedule: "triggered"
374 buildbucket: {
375 server: "cr-buildbucket.appspot.com"
376 bucket: "luci.chromeos.general"
377 builder: "ProdBuilder"
378 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700379 tags: "cbb_config:build_triggered_a"
Don Garrett73148e52018-08-17 16:54:46 -0700380 tags: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700381 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700382 properties: "cbb_config:build_triggered_a"
Don Garrett73148e52018-08-17 16:54:46 -0700383 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700384 properties: "cbb_extra_args:[\\"--buildbot\\"]"
385 }
386}
387
388job {
389 id: "build_triggered_b"
390 acl_sets: "default"
391 schedule: "triggered"
392 buildbucket: {
393 server: "cr-buildbucket.appspot.com"
394 bucket: "luci.chromeos.general"
395 builder: "ProdBuilder"
396 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700397 tags: "cbb_config:build_triggered_b"
Don Garrett73148e52018-08-17 16:54:46 -0700398 tags: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700399 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700400 properties: "cbb_config:build_triggered_b"
Don Garrett73148e52018-08-17 16:54:46 -0700401 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700402 properties: "cbb_extra_args:[\\"--buildbot\\"]"
403 }
404}
Don Garrett8dace272018-07-19 14:07:42 -0700405
406job {
407 id: "test-branch-branch_tester"
408 acl_sets: "default"
409 schedule: "run daily"
410 buildbucket: {
411 server: "cr-buildbucket.appspot.com"
412 bucket: "luci.chromeos.general"
413 builder: "TestBuilder"
414 tags: "cbb_branch:test-branch"
Don Garrett8dace272018-07-19 14:07:42 -0700415 tags: "cbb_config:branch_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700416 tags: "cbb_display_label:TestLabel"
Don Garrett8dace272018-07-19 14:07:42 -0700417 properties: "cbb_branch:test-branch"
Don Garrett8dace272018-07-19 14:07:42 -0700418 properties: "cbb_config:branch_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700419 properties: "cbb_display_label:TestLabel"
Don Garrett8dace272018-07-19 14:07:42 -0700420 properties: "cbb_extra_args:[\\"--buildbot\\"]"
421 }
422}
Don Garrett9a0d90c2018-10-30 12:47:14 -0700423
424job {
425 id: "test-branch-branch_tester_triggered"
426 acl_sets: "default"
427 schedule: "run daily"
428 buildbucket: {
429 server: "cr-buildbucket.appspot.com"
430 bucket: "luci.chromeos.general"
431 builder: "TestBuilder"
432 tags: "cbb_branch:test-branch"
433 tags: "cbb_config:branch_tester_triggered"
434 tags: "cbb_display_label:TestLabel"
435 properties: "cbb_branch:test-branch"
436 properties: "cbb_config:branch_tester_triggered"
437 properties: "cbb_display_label:TestLabel"
438 properties: "cbb_extra_args:[\\"--buildbot\\"]"
439 }
440}
Mike Frysinger80de5012019-08-01 14:10:53 -0400441"""
Don Garrett8dace272018-07-19 14:07:42 -0700442 result = gen_luci_scheduler.genLuciSchedulerConfig(
443 site_config, branch_configs)
Don Garrettbe3608b2018-06-05 17:10:09 -0700444
445 self.assertEqual(result, expected)