blob: dffe49d80c536a32111c94f3d9133974b54c3913 [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 {
Mike Nichols9e47e842020-08-11 15:23:56 -060041 id: "amd64-generic-release"
Don Garrettbe3608b2018-06-05 17:10:09 -070042 acl_sets: "default"
43 schedule: "funky schedule"
44 buildbucket: {
45 server: "cr-buildbucket.appspot.com"
46 bucket: "luci.chromeos.general"
Mike Nichols9e47e842020-08-11 15:23:56 -060047 builder: "LegacyRelease"
Don Garrettbe3608b2018-06-05 17:10:09 -070048 tags: "cbb_branch:master"
Mike Nichols9e47e842020-08-11 15:23:56 -060049 tags: "cbb_config:amd64-generic-release"
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"
Mike Nichols9e47e842020-08-11 15:23:56 -060052 properties: "cbb_config:amd64-generic-release"
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 {
Mike Nichols9e47e842020-08-11 15:23:56 -0600126 id: "mock_branch-amd64-generic-release"
Don Garrett8dace272018-07-19 14:07:42 -0700127 acl_sets: "default"
128 schedule: "funky schedule"
129 buildbucket: {
130 server: "cr-buildbucket.appspot.com"
131 bucket: "luci.chromeos.general"
Mike Nichols9e47e842020-08-11 15:23:56 -0600132 builder: "LegacyRelease"
Don Garrett8dace272018-07-19 14:07:42 -0700133 tags: "cbb_branch:mock_branch"
Mike Nichols9e47e842020-08-11 15:23:56 -0600134 tags: "cbb_config:amd64-generic-release"
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"
Mike Nichols9e47e842020-08-11 15:23:56 -0600137 properties: "cbb_config:amd64-generic-release"
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 {
Mike Nichols9e47e842020-08-11 15:23:56 -0600156 id: "amd64-generic-release"
Don Garrett73148e52018-08-17 16:54:46 -0700157 acl_sets: "default"
158 schedule: "funky schedule"
159 buildbucket: {
160 server: "cr-buildbucket.appspot.com"
161 bucket: "luci.chromeos.general"
Mike Nichols9e47e842020-08-11 15:23:56 -0600162 builder: "LegacyRelease"
Don Garrett73148e52018-08-17 16:54:46 -0700163 tags: "cbb_branch:master"
Mike Nichols9e47e842020-08-11 15:23:56 -0600164 tags: "cbb_config:amd64-generic-release"
Don Garrett73148e52018-08-17 16:54:46 -0700165 tags: "cbb_display_label:MockLabel"
166 tags: "cbb_workspace_branch:work_branch"
167 properties: "cbb_branch:master"
Mike Nichols9e47e842020-08-11 15:23:56 -0600168 properties: "cbb_config:amd64-generic-release"
Don Garrett73148e52018-08-17 16:54:46 -0700169 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 {
Mike Nichols9e47e842020-08-11 15:23:56 -0600188 id: "amd64-generic-release"
Yoshisato Yanagisawa16285b42018-09-19 14:00:58 +0900189 acl_sets: "default"
190 schedule: "funky schedule"
191 buildbucket: {
192 server: "cr-buildbucket.appspot.com"
193 bucket: "luci.chromeos.general"
Mike Nichols9e47e842020-08-11 15:23:56 -0600194 builder: "LegacyRelease"
Yoshisato Yanagisawa16285b42018-09-19 14:00:58 +0900195 tags: "cbb_branch:master"
Mike Nichols9e47e842020-08-11 15:23:56 -0600196 tags: "cbb_config:amd64-generic-release"
Yoshisato Yanagisawa16285b42018-09-19 14:00:58 +0900197 tags: "cbb_display_label:MockLabel"
198 tags: "cbb_goma_client_type:client_type"
199 properties: "cbb_branch:master"
Mike Nichols9e47e842020-08-11 15:23:56 -0600200 properties: "cbb_config:amd64-generic-release"
Yoshisato Yanagisawa16285b42018-09-19 14:00:58 +0900201 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',
Mike Nichols9e47e842020-08-11 15:23:56 -0600217 luci_builder='ReleaseBuilder',
Don Garrettbe3608b2018-06-05 17:10:09 -0700218 display_label='MockLabel',
219 )
220
221 site_config.Add(
222 'build_prod',
Mike Nichols9e47e842020-08-11 15:23:56 -0600223 luci_builder='ReleaseBuilder',
Don Garrettbe3608b2018-06-05 17:10:09 -0700224 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',
Mike Nichols9e47e842020-08-11 15:23:56 -0600237 luci_builder='ReleaseBuilder',
Don Garrettbe3608b2018-06-05 17:10:09 -0700238 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"
LaMont Jonesd1bb0002020-09-16 09:35:10 -0600306 granted_to: "group:project-chromeos-buildbucket-schedulers"
Jason D. Clintona9e374a2018-10-18 18:41:00 -0600307 }
Don Garrettbe3608b2018-06-05 17:10:09 -0700308}
309
310trigger {
311 id: "trigger_0"
312 acl_sets: "default"
313 schedule: "with 5m interval"
314 gitiles: {
315 repo: "gitiles_url_a"
316 refs: "ref_a"
317 refs: "ref_b"
318 }
319 triggers: "build_triggered_a"
Don Garrett9a0d90c2018-10-30 12:47:14 -0700320 triggers: "test-branch-branch_tester_triggered"
Don Garrettbe3608b2018-06-05 17:10:09 -0700321}
322
323trigger {
324 id: "trigger_1"
325 acl_sets: "default"
326 schedule: "with 5m interval"
327 gitiles: {
328 repo: "gitiles_url_b"
329 refs: "ref_c"
330 }
331 triggers: "build_triggered_a"
332 triggers: "build_triggered_b"
333}
334
335job {
336 id: "build_prod"
337 acl_sets: "default"
338 schedule: "run once in a while"
339 buildbucket: {
340 server: "cr-buildbucket.appspot.com"
341 bucket: "luci.chromeos.general"
Mike Nichols9e47e842020-08-11 15:23:56 -0600342 builder: "ReleaseBuilder"
Don Garrettbe3608b2018-06-05 17:10:09 -0700343 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700344 tags: "cbb_config:build_prod"
Don Garrett73148e52018-08-17 16:54:46 -0700345 tags: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700346 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700347 properties: "cbb_config:build_prod"
Don Garrett73148e52018-08-17 16:54:46 -0700348 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700349 properties: "cbb_extra_args:[\\"--buildbot\\"]"
350 }
351}
352
353job {
354 id: "build_tester"
355 acl_sets: "default"
356 schedule: "run daily"
357 buildbucket: {
358 server: "cr-buildbucket.appspot.com"
359 bucket: "luci.chromeos.general"
360 builder: "TestBuilder"
361 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700362 tags: "cbb_config:build_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700363 tags: "cbb_display_label:TestLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700364 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700365 properties: "cbb_config:build_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700366 properties: "cbb_display_label:TestLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700367 properties: "cbb_extra_args:[\\"--buildbot\\"]"
368 }
369}
370
371job {
372 id: "build_triggered_a"
373 acl_sets: "default"
374 schedule: "triggered"
375 buildbucket: {
376 server: "cr-buildbucket.appspot.com"
377 bucket: "luci.chromeos.general"
Mike Nichols9e47e842020-08-11 15:23:56 -0600378 builder: "ReleaseBuilder"
Don Garrettbe3608b2018-06-05 17:10:09 -0700379 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700380 tags: "cbb_config:build_triggered_a"
Don Garrett73148e52018-08-17 16:54:46 -0700381 tags: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700382 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700383 properties: "cbb_config:build_triggered_a"
Don Garrett73148e52018-08-17 16:54:46 -0700384 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700385 properties: "cbb_extra_args:[\\"--buildbot\\"]"
386 }
387}
388
389job {
390 id: "build_triggered_b"
391 acl_sets: "default"
392 schedule: "triggered"
393 buildbucket: {
394 server: "cr-buildbucket.appspot.com"
395 bucket: "luci.chromeos.general"
396 builder: "ProdBuilder"
397 tags: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700398 tags: "cbb_config:build_triggered_b"
Don Garrett73148e52018-08-17 16:54:46 -0700399 tags: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700400 properties: "cbb_branch:master"
Don Garrettbe3608b2018-06-05 17:10:09 -0700401 properties: "cbb_config:build_triggered_b"
Don Garrett73148e52018-08-17 16:54:46 -0700402 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700403 properties: "cbb_extra_args:[\\"--buildbot\\"]"
404 }
405}
Don Garrett8dace272018-07-19 14:07:42 -0700406
407job {
408 id: "test-branch-branch_tester"
409 acl_sets: "default"
410 schedule: "run daily"
411 buildbucket: {
412 server: "cr-buildbucket.appspot.com"
413 bucket: "luci.chromeos.general"
414 builder: "TestBuilder"
415 tags: "cbb_branch:test-branch"
Don Garrett8dace272018-07-19 14:07:42 -0700416 tags: "cbb_config:branch_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700417 tags: "cbb_display_label:TestLabel"
Don Garrett8dace272018-07-19 14:07:42 -0700418 properties: "cbb_branch:test-branch"
Don Garrett8dace272018-07-19 14:07:42 -0700419 properties: "cbb_config:branch_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700420 properties: "cbb_display_label:TestLabel"
Don Garrett8dace272018-07-19 14:07:42 -0700421 properties: "cbb_extra_args:[\\"--buildbot\\"]"
422 }
423}
Don Garrett9a0d90c2018-10-30 12:47:14 -0700424
425job {
426 id: "test-branch-branch_tester_triggered"
427 acl_sets: "default"
428 schedule: "run daily"
429 buildbucket: {
430 server: "cr-buildbucket.appspot.com"
431 bucket: "luci.chromeos.general"
432 builder: "TestBuilder"
433 tags: "cbb_branch:test-branch"
434 tags: "cbb_config:branch_tester_triggered"
435 tags: "cbb_display_label:TestLabel"
436 properties: "cbb_branch:test-branch"
437 properties: "cbb_config:branch_tester_triggered"
438 properties: "cbb_display_label:TestLabel"
439 properties: "cbb_extra_args:[\\"--buildbot\\"]"
440 }
441}
Mike Frysinger80de5012019-08-01 14:10:53 -0400442"""
Don Garrett8dace272018-07-19 14:07:42 -0700443 result = gen_luci_scheduler.genLuciSchedulerConfig(
444 site_config, branch_configs)
Don Garrettbe3608b2018-06-05 17:10:09 -0700445
446 self.assertEqual(result, expected)