blob: 36eca465eeda4705dd642c2f7e9215ce577f862f [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2018 The ChromiumOS Authors
Don Garrettbe3608b2018-06-05 17:10:09 -07002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Test gen_luci_scheduler."""
Don Garrettbe3608b2018-06-05 17:10:09 -07006
Don Garrettbe3608b2018-06-05 17:10:09 -07007from chromite.lib import config_lib
8from chromite.lib import config_lib_unittest
Mike Frysinger807d8282022-04-28 22:45:17 -04009from chromite.lib import cros_test_lib
Don Garrettbe3608b2018-06-05 17:10:09 -070010from chromite.scripts import gen_luci_scheduler
11
Mike Frysinger74a6cc82020-02-14 14:16:22 -050012
Don Garrettbe3608b2018-06-05 17:10:09 -070013# It's reasonable for unittests to look at internals.
14# pylint: disable=protected-access
15
16
17class GenLuciSchedulerTest(cros_test_lib.MockTestCase):
Alex Klein1699fab2022-09-08 08:46:06 -060018 """Tests for cbuildbot_launch script."""
Don Garrettbe3608b2018-06-05 17:10:09 -070019
Alex Klein1699fab2022-09-08 08:46:06 -060020 def testSanityAgainstProd(self):
21 """Test we can generate a luci scheduler config with live data."""
22 # If it runs without crashing, we pass.
George Burgess IV3b98be72023-09-12 14:20:43 -060023 gen_luci_scheduler.genLuciSchedulerConfig(config_lib.GetConfig())
Don Garrettbe3608b2018-06-05 17:10:09 -070024
Alex Klein1699fab2022-09-08 08:46:06 -060025 def testGenSchedulerJob(self):
26 """Test the job creation helper."""
27 build_config = config_lib_unittest.MockBuildConfig().apply(
28 schedule="funky schedule"
29 )
30
31 expected = """
Don Garrettbe3608b2018-06-05 17:10:09 -070032job {
Mike Nichols9e47e842020-08-11 15:23:56 -060033 id: "amd64-generic-release"
Vadim Shtayura6398e002021-01-11 12:02:11 -080034 realm: "cbb-jobs"
Don Garrettbe3608b2018-06-05 17:10:09 -070035 acl_sets: "default"
36 schedule: "funky schedule"
37 buildbucket: {
38 server: "cr-buildbucket.appspot.com"
Vadim Shtayura959cb0f2022-02-03 12:45:58 -080039 bucket: "general"
Mike Nichols9e47e842020-08-11 15:23:56 -060040 builder: "LegacyRelease"
Mike Frysinger62a02452021-03-16 03:48:34 -040041 tags: "cbb_branch:main"
Mike Nichols9e47e842020-08-11 15:23:56 -060042 tags: "cbb_config:amd64-generic-release"
Don Garrett73148e52018-08-17 16:54:46 -070043 tags: "cbb_display_label:MockLabel"
Mike Frysinger62a02452021-03-16 03:48:34 -040044 properties: "cbb_branch:main"
Mike Nichols9e47e842020-08-11 15:23:56 -060045 properties: "cbb_config:amd64-generic-release"
Don Garrett73148e52018-08-17 16:54:46 -070046 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -070047 properties: "cbb_extra_args:[\\"--buildbot\\"]"
48 }
49}
Mike Frysinger80de5012019-08-01 14:10:53 -040050"""
Don Garrettbe3608b2018-06-05 17:10:09 -070051
Alex Klein1699fab2022-09-08 08:46:06 -060052 result = gen_luci_scheduler.genSchedulerJob(build_config)
53 self.assertEqual(result, expected)
Don Garrettbe3608b2018-06-05 17:10:09 -070054
Alex Klein1699fab2022-09-08 08:46:06 -060055 def testGenSchedulerTriggerSimple(self):
56 """Test the trigger creation helper."""
57 trigger_name = "simple"
58 repo = "url://repo"
59 refs = ["refs/path"]
60 path_regexps = ["path/regexps"]
61 builds = ["test_build"]
Don Garrettbe3608b2018-06-05 17:10:09 -070062
Alex Klein1699fab2022-09-08 08:46:06 -060063 expected = """
Don Garrettbe3608b2018-06-05 17:10:09 -070064trigger {
65 id: "simple"
Vadim Shtayura6398e002021-01-11 12:02:11 -080066 realm: "cbb-jobs"
Don Garrettbe3608b2018-06-05 17:10:09 -070067 acl_sets: "default"
68 schedule: "with 5m interval"
69 gitiles: {
70 repo: "url://repo"
71 refs: "refs/path"
David Burgercba0d272020-06-24 16:21:26 -060072 path_regexps: "path/regexps"
Don Garrettbe3608b2018-06-05 17:10:09 -070073 }
74 triggers: "test_build"
75}
Mike Frysinger80de5012019-08-01 14:10:53 -040076"""
Don Garrettbe3608b2018-06-05 17:10:09 -070077
Alex Klein1699fab2022-09-08 08:46:06 -060078 result = gen_luci_scheduler.genSchedulerTrigger(
79 trigger_name, repo, refs, path_regexps, builds
80 )
Don Garrettbe3608b2018-06-05 17:10:09 -070081
Alex Klein1699fab2022-09-08 08:46:06 -060082 self.assertEqual(result, expected)
Don Garrettbe3608b2018-06-05 17:10:09 -070083
Alex Klein1699fab2022-09-08 08:46:06 -060084 def testGenSchedulerTriggerComplex(self):
85 """Test the trigger creation helper."""
86 trigger_name = "complex"
87 repo = "url://repo"
88 refs = ["refs/path", "refs/other_path"]
89 builds = ["test_build_a", "test_build_b"]
Don Garrettbe3608b2018-06-05 17:10:09 -070090
Alex Klein1699fab2022-09-08 08:46:06 -060091 expected = """
Don Garrettbe3608b2018-06-05 17:10:09 -070092trigger {
93 id: "complex"
Vadim Shtayura6398e002021-01-11 12:02:11 -080094 realm: "cbb-jobs"
Don Garrettbe3608b2018-06-05 17:10:09 -070095 acl_sets: "default"
96 schedule: "with 5m interval"
97 gitiles: {
98 repo: "url://repo"
99 refs: "refs/path"
100 refs: "refs/other_path"
101 }
102 triggers: "test_build_a"
103 triggers: "test_build_b"
104}
Mike Frysinger80de5012019-08-01 14:10:53 -0400105"""
Don Garrettbe3608b2018-06-05 17:10:09 -0700106
Alex Klein1699fab2022-09-08 08:46:06 -0600107 result = gen_luci_scheduler.genSchedulerTrigger(
108 trigger_name, repo, refs, None, builds
109 )
Don Garrettbe3608b2018-06-05 17:10:09 -0700110
Alex Klein1699fab2022-09-08 08:46:06 -0600111 self.assertEqual(result, expected)
Don Garrettbe3608b2018-06-05 17:10:09 -0700112
Alex Klein1699fab2022-09-08 08:46:06 -0600113 def testGenSchedulerBranched(self):
114 """Test the job creation helper."""
115 build_config = config_lib_unittest.MockBuildConfig().apply(
116 schedule_branch="mock_branch",
117 schedule="funky schedule",
118 )
Don Garrett8dace272018-07-19 14:07:42 -0700119
Alex Klein1699fab2022-09-08 08:46:06 -0600120 expected = """
Don Garrett8dace272018-07-19 14:07:42 -0700121job {
Mike Nichols9e47e842020-08-11 15:23:56 -0600122 id: "mock_branch-amd64-generic-release"
Vadim Shtayura6398e002021-01-11 12:02:11 -0800123 realm: "cbb-jobs"
Don Garrett8dace272018-07-19 14:07:42 -0700124 acl_sets: "default"
125 schedule: "funky schedule"
126 buildbucket: {
127 server: "cr-buildbucket.appspot.com"
Vadim Shtayura959cb0f2022-02-03 12:45:58 -0800128 bucket: "general"
Mike Nichols9e47e842020-08-11 15:23:56 -0600129 builder: "LegacyRelease"
Don Garrett8dace272018-07-19 14:07:42 -0700130 tags: "cbb_branch:mock_branch"
Mike Nichols9e47e842020-08-11 15:23:56 -0600131 tags: "cbb_config:amd64-generic-release"
Don Garrett73148e52018-08-17 16:54:46 -0700132 tags: "cbb_display_label:MockLabel"
Don Garrett8dace272018-07-19 14:07:42 -0700133 properties: "cbb_branch:mock_branch"
Mike Nichols9e47e842020-08-11 15:23:56 -0600134 properties: "cbb_config:amd64-generic-release"
Don Garrett73148e52018-08-17 16:54:46 -0700135 properties: "cbb_display_label:MockLabel"
136 properties: "cbb_extra_args:[\\"--buildbot\\"]"
137 }
138}
Mike Frysinger80de5012019-08-01 14:10:53 -0400139"""
Don Garrett73148e52018-08-17 16:54:46 -0700140
Alex Klein1699fab2022-09-08 08:46:06 -0600141 result = gen_luci_scheduler.genSchedulerJob(build_config)
142 self.assertEqual(result, expected)
Don Garrett73148e52018-08-17 16:54:46 -0700143
Alex Klein1699fab2022-09-08 08:46:06 -0600144 def testGenSchedulerWorkspaceBranch(self):
145 """Test the job creation helper."""
146 build_config = config_lib_unittest.MockBuildConfig().apply(
147 workspace_branch="work_branch",
148 schedule="funky schedule",
149 )
Don Garrett73148e52018-08-17 16:54:46 -0700150
Alex Klein1699fab2022-09-08 08:46:06 -0600151 expected = """
Don Garrett73148e52018-08-17 16:54:46 -0700152job {
Mike Nichols9e47e842020-08-11 15:23:56 -0600153 id: "amd64-generic-release"
Vadim Shtayura6398e002021-01-11 12:02:11 -0800154 realm: "cbb-jobs"
Don Garrett73148e52018-08-17 16:54:46 -0700155 acl_sets: "default"
156 schedule: "funky schedule"
157 buildbucket: {
158 server: "cr-buildbucket.appspot.com"
Vadim Shtayura959cb0f2022-02-03 12:45:58 -0800159 bucket: "general"
Mike Nichols9e47e842020-08-11 15:23:56 -0600160 builder: "LegacyRelease"
Mike Frysinger62a02452021-03-16 03:48:34 -0400161 tags: "cbb_branch:main"
Mike Nichols9e47e842020-08-11 15:23:56 -0600162 tags: "cbb_config:amd64-generic-release"
Don Garrett73148e52018-08-17 16:54:46 -0700163 tags: "cbb_display_label:MockLabel"
164 tags: "cbb_workspace_branch:work_branch"
Mike Frysinger62a02452021-03-16 03:48:34 -0400165 properties: "cbb_branch:main"
Mike Nichols9e47e842020-08-11 15:23:56 -0600166 properties: "cbb_config:amd64-generic-release"
Don Garrett73148e52018-08-17 16:54:46 -0700167 properties: "cbb_display_label:MockLabel"
168 properties: "cbb_workspace_branch:work_branch"
Don Garrett8dace272018-07-19 14:07:42 -0700169 properties: "cbb_extra_args:[\\"--buildbot\\"]"
170 }
171}
Mike Frysinger80de5012019-08-01 14:10:53 -0400172"""
Don Garrett8dace272018-07-19 14:07:42 -0700173
Alex Klein1699fab2022-09-08 08:46:06 -0600174 result = gen_luci_scheduler.genSchedulerJob(build_config)
175 self.assertEqual(result, expected)
Don Garrett8dace272018-07-19 14:07:42 -0700176
Alex Klein1699fab2022-09-08 08:46:06 -0600177 def testGenLuciSchedulerConfig(self):
178 """Test a full LUCI Scheduler config file."""
179 site_config = config_lib.SiteConfig()
Don Garrettbe3608b2018-06-05 17:10:09 -0700180
Alex Klein1699fab2022-09-08 08:46:06 -0600181 site_config.Add(
182 "not_scheduled",
183 luci_builder="ReleaseBuilder",
184 display_label="MockLabel",
185 )
Don Garrettbe3608b2018-06-05 17:10:09 -0700186
Alex Klein1699fab2022-09-08 08:46:06 -0600187 site_config.Add(
188 "build_prod",
189 luci_builder="ReleaseBuilder",
190 display_label="MockLabel",
191 schedule="run once in a while",
192 )
Don Garrettbe3608b2018-06-05 17:10:09 -0700193
Alex Klein1699fab2022-09-08 08:46:06 -0600194 site_config.Add(
195 "build_tester",
196 luci_builder="TestBuilder",
197 display_label="TestLabel",
198 schedule="run daily",
199 )
Don Garrettbe3608b2018-06-05 17:10:09 -0700200
Alex Klein1699fab2022-09-08 08:46:06 -0600201 site_config.Add(
202 "build_triggered_a",
203 luci_builder="ReleaseBuilder",
204 display_label="MockLabel",
205 schedule="triggered",
206 triggered_gitiles=[
207 [
208 "gitiles_url_a",
209 ["ref_a", "ref_b"],
210 ],
211 [
212 "gitiles_url_b",
213 ["ref_c"],
214 ],
215 ],
216 )
Don Garrettbe3608b2018-06-05 17:10:09 -0700217
Alex Klein1699fab2022-09-08 08:46:06 -0600218 site_config.Add(
219 "build_triggered_b",
220 luci_builder="ProdBuilder",
221 display_label="MockLabel",
222 schedule="triggered",
223 triggered_gitiles=[
224 [
225 "gitiles_url_b",
226 ["ref_c"],
227 ]
228 ],
229 )
Don Garrettbe3608b2018-06-05 17:10:09 -0700230
Alex Klein1699fab2022-09-08 08:46:06 -0600231 expected = """# Defines buckets on luci-scheduler.appspot.com.
Don Garrettbe3608b2018-06-05 17:10:09 -0700232#
233# For schema of this file and documentation see ProjectConfig message in
Mike Frysinger92dc6492021-02-17 16:01:09 -0500234# https://github.com/luci/luci-go/blob/HEAD/scheduler/appengine/messages/config.proto
Don Garrettbe3608b2018-06-05 17:10:09 -0700235
236# Generated with chromite/scripts/gen_luci_scheduler
237
Don Garrettff45f4b2018-10-04 09:08:01 -0700238# Autodeployed with:
Mike Nicholsb575c612021-04-09 10:04:43 -0600239# https://data.corp.google.com/sites/chromeos_ci_cros_ci_builds/utility/?f=board_name:in:luci-scheduler-updater
Don Garrettff45f4b2018-10-04 09:08:01 -0700240
Don Garrettbe3608b2018-06-05 17:10:09 -0700241acl_sets {
242 name: "default"
243 acls {
244 role: READER
245 granted_to: "group:googlers"
246 }
247 acls {
248 role: OWNER
249 granted_to: "group:project-chromeos-admins"
250 }
Jason D. Clintona9e374a2018-10-18 18:41:00 -0600251 acls {
252 role: TRIGGERER
253 granted_to: "group:mdb/chromeos-build-access"
LaMont Jones48ddfd92020-09-16 13:46:41 -0600254 }
255 acls {
256 role: TRIGGERER
LaMont Jonesd1bb0002020-09-16 09:35:10 -0600257 granted_to: "group:project-chromeos-buildbucket-schedulers"
Jason D. Clintona9e374a2018-10-18 18:41:00 -0600258 }
Don Garrettbe3608b2018-06-05 17:10:09 -0700259}
260
261trigger {
262 id: "trigger_0"
Vadim Shtayura6398e002021-01-11 12:02:11 -0800263 realm: "cbb-jobs"
Don Garrettbe3608b2018-06-05 17:10:09 -0700264 acl_sets: "default"
265 schedule: "with 5m interval"
266 gitiles: {
267 repo: "gitiles_url_a"
268 refs: "ref_a"
269 refs: "ref_b"
270 }
271 triggers: "build_triggered_a"
272}
273
274trigger {
275 id: "trigger_1"
Vadim Shtayura6398e002021-01-11 12:02:11 -0800276 realm: "cbb-jobs"
Don Garrettbe3608b2018-06-05 17:10:09 -0700277 acl_sets: "default"
278 schedule: "with 5m interval"
279 gitiles: {
280 repo: "gitiles_url_b"
281 refs: "ref_c"
282 }
283 triggers: "build_triggered_a"
284 triggers: "build_triggered_b"
285}
286
287job {
288 id: "build_prod"
Vadim Shtayura6398e002021-01-11 12:02:11 -0800289 realm: "cbb-jobs"
Don Garrettbe3608b2018-06-05 17:10:09 -0700290 acl_sets: "default"
291 schedule: "run once in a while"
292 buildbucket: {
293 server: "cr-buildbucket.appspot.com"
Vadim Shtayura959cb0f2022-02-03 12:45:58 -0800294 bucket: "general"
Mike Nichols9e47e842020-08-11 15:23:56 -0600295 builder: "ReleaseBuilder"
Mike Frysinger62a02452021-03-16 03:48:34 -0400296 tags: "cbb_branch:main"
Don Garrettbe3608b2018-06-05 17:10:09 -0700297 tags: "cbb_config:build_prod"
Don Garrett73148e52018-08-17 16:54:46 -0700298 tags: "cbb_display_label:MockLabel"
Mike Frysinger62a02452021-03-16 03:48:34 -0400299 properties: "cbb_branch:main"
Don Garrettbe3608b2018-06-05 17:10:09 -0700300 properties: "cbb_config:build_prod"
Don Garrett73148e52018-08-17 16:54:46 -0700301 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700302 properties: "cbb_extra_args:[\\"--buildbot\\"]"
303 }
304}
305
306job {
307 id: "build_tester"
Vadim Shtayura6398e002021-01-11 12:02:11 -0800308 realm: "cbb-jobs"
Don Garrettbe3608b2018-06-05 17:10:09 -0700309 acl_sets: "default"
310 schedule: "run daily"
311 buildbucket: {
312 server: "cr-buildbucket.appspot.com"
Vadim Shtayura959cb0f2022-02-03 12:45:58 -0800313 bucket: "general"
Don Garrettbe3608b2018-06-05 17:10:09 -0700314 builder: "TestBuilder"
Mike Frysinger62a02452021-03-16 03:48:34 -0400315 tags: "cbb_branch:main"
Don Garrettbe3608b2018-06-05 17:10:09 -0700316 tags: "cbb_config:build_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700317 tags: "cbb_display_label:TestLabel"
Mike Frysinger62a02452021-03-16 03:48:34 -0400318 properties: "cbb_branch:main"
Don Garrettbe3608b2018-06-05 17:10:09 -0700319 properties: "cbb_config:build_tester"
Don Garrett73148e52018-08-17 16:54:46 -0700320 properties: "cbb_display_label:TestLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700321 properties: "cbb_extra_args:[\\"--buildbot\\"]"
322 }
323}
324
325job {
326 id: "build_triggered_a"
Vadim Shtayura6398e002021-01-11 12:02:11 -0800327 realm: "cbb-jobs"
Don Garrettbe3608b2018-06-05 17:10:09 -0700328 acl_sets: "default"
329 schedule: "triggered"
330 buildbucket: {
331 server: "cr-buildbucket.appspot.com"
Vadim Shtayura959cb0f2022-02-03 12:45:58 -0800332 bucket: "general"
Mike Nichols9e47e842020-08-11 15:23:56 -0600333 builder: "ReleaseBuilder"
Mike Frysinger62a02452021-03-16 03:48:34 -0400334 tags: "cbb_branch:main"
Don Garrettbe3608b2018-06-05 17:10:09 -0700335 tags: "cbb_config:build_triggered_a"
Don Garrett73148e52018-08-17 16:54:46 -0700336 tags: "cbb_display_label:MockLabel"
Mike Frysinger62a02452021-03-16 03:48:34 -0400337 properties: "cbb_branch:main"
Don Garrettbe3608b2018-06-05 17:10:09 -0700338 properties: "cbb_config:build_triggered_a"
Don Garrett73148e52018-08-17 16:54:46 -0700339 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700340 properties: "cbb_extra_args:[\\"--buildbot\\"]"
341 }
342}
343
344job {
345 id: "build_triggered_b"
Vadim Shtayura6398e002021-01-11 12:02:11 -0800346 realm: "cbb-jobs"
Don Garrettbe3608b2018-06-05 17:10:09 -0700347 acl_sets: "default"
348 schedule: "triggered"
349 buildbucket: {
350 server: "cr-buildbucket.appspot.com"
Vadim Shtayura959cb0f2022-02-03 12:45:58 -0800351 bucket: "general"
Don Garrettbe3608b2018-06-05 17:10:09 -0700352 builder: "ProdBuilder"
Mike Frysinger62a02452021-03-16 03:48:34 -0400353 tags: "cbb_branch:main"
Don Garrettbe3608b2018-06-05 17:10:09 -0700354 tags: "cbb_config:build_triggered_b"
Don Garrett73148e52018-08-17 16:54:46 -0700355 tags: "cbb_display_label:MockLabel"
Mike Frysinger62a02452021-03-16 03:48:34 -0400356 properties: "cbb_branch:main"
Don Garrettbe3608b2018-06-05 17:10:09 -0700357 properties: "cbb_config:build_triggered_b"
Don Garrett73148e52018-08-17 16:54:46 -0700358 properties: "cbb_display_label:MockLabel"
Don Garrettbe3608b2018-06-05 17:10:09 -0700359 properties: "cbb_extra_args:[\\"--buildbot\\"]"
360 }
361}
Mike Frysinger80de5012019-08-01 14:10:53 -0400362"""
George Burgess IV3b98be72023-09-12 14:20:43 -0600363 result = gen_luci_scheduler.genLuciSchedulerConfig(site_config)
Don Garrettbe3608b2018-06-05 17:10:09 -0700364
Alex Klein1699fab2022-09-08 08:46:06 -0600365 self.assertEqual(result, expected)