Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 1 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Module for tasks triggered by suite scheduler.""" |
| 6 | # pylint: disable=g-bad-import-order |
Xixuan Wu | 244e0ec | 2018-05-23 14:49:55 -0700 | [diff] [blame] | 7 | # pylint: disable=dangerous-default-value |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 8 | |
| 9 | from distutils import version |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 10 | import logging |
| 11 | |
| 12 | import build_lib |
Xixuan Wu | ed878ea | 2019-03-18 15:32:16 -0700 | [diff] [blame] | 13 | import skylab |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 14 | import task_executor |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 15 | import tot_manager |
| 16 | |
| 17 | # The max lifetime of a suite scheduled by suite scheduler |
| 18 | _JOB_MAX_RUNTIME_MINS_DEFAULT = 72 * 60 |
| 19 | |
| 20 | # One kind of formats for RO firmware spec. |
| 21 | _RELEASE_RO_FIRMWARE_SPEC = 'released_ro_' |
| 22 | |
| 23 | |
| 24 | class SchedulingError(Exception): |
| 25 | """Raised to indicate a failure in scheduling a task.""" |
| 26 | |
| 27 | |
| 28 | class Task(object): |
| 29 | """Represents an entry from the suite_scheduler config file. |
| 30 | |
| 31 | Each entry from the suite_scheduler config file maps one-to-one to a |
| 32 | Task. Each instance has enough information to schedule itself. |
| 33 | """ |
| 34 | |
Po-Hsien Wang | dd83307 | 2018-08-16 18:09:20 -0700 | [diff] [blame] | 35 | def __init__(self, task_info, board_family_config={}, tot=None): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 36 | """Initialize a task instance. |
| 37 | |
| 38 | Args: |
| 39 | task_info: a config_reader.TaskInfo object, which includes: |
| 40 | name, name of this task, e.g. 'NightlyPower' |
| 41 | suite, the name of the suite to run, e.g. 'graphics_per-day' |
| 42 | branch_specs, a pre-vetted iterable of branch specifiers, |
| 43 | e.g. ['>=R18', 'factory'] |
| 44 | pool, the pool of machines to schedule tasks. Default is None. |
| 45 | num, the number of devices to shard the test suite. It could |
| 46 | be an Integer or None. By default it's None. |
Po-Hsien Wang | dd83307 | 2018-08-16 18:09:20 -0700 | [diff] [blame] | 47 | board_families, a common separated list of board family to run this |
| 48 | task on. Boards belong to one of the board family in this list |
| 49 | would be added to task_info.boards. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 50 | boards, a comma separated list of boards to run this task on. Default |
Po-Hsien Wang | dd83307 | 2018-08-16 18:09:20 -0700 | [diff] [blame] | 51 | is None, which allows this task to run on all boards. If same board |
| 52 | is specified in 'boards' and 'exclude_boards', we exclude this |
| 53 | board. |
| 54 | exclude_board_families, a common separated list of board family not to |
| 55 | run task on. Boards belong to one of the board family in this list |
| 56 | would be added to task_info.exclude_boards. |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 57 | exclude_boards, a comma separated list of boards not to run this task |
| 58 | on. Default is None, which allows this task to run on all boards. |
Po-Hsien Wang | dd83307 | 2018-08-16 18:09:20 -0700 | [diff] [blame] | 59 | If same board is specified in 'boards' and 'exclude_boards', we |
| 60 | exclude this board. |
Xixuan Wu | 8989718 | 2019-01-03 15:28:01 -0800 | [diff] [blame] | 61 | models, a comma separated list of models to run this task on. Default |
| 62 | is None, which allows this task to run on all models. If same model |
| 63 | is specified in 'models' and 'exclude_models', we exclude this |
| 64 | model. |
| 65 | exclude_models, a comma separated list of models not to run this task |
| 66 | on. Default is None, which allows this task to run on all models. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 67 | priority, the string name of a priority from constants.Priorities. |
| 68 | timeout, the max lifetime of the suite in hours. |
| 69 | cros_build_spec, spec used to determine the ChromeOS build to test |
| 70 | with a firmware build, e.g., tot, R41 etc. |
| 71 | firmware_rw_build_spec, spec used to determine the firmware RW build |
| 72 | test with a ChromeOS build. |
| 73 | firmware_ro_build_spec, spec used to determine the firmware RO build |
| 74 | test with a ChromeOS build. |
| 75 | test_source, the source of test code when firmware will be updated in |
| 76 | the test. The value can be 'firmware_rw', 'firmware_ro' or 'cros'. |
| 77 | job_retry, set to True to enable job-level retry. Default is False. |
Xixuan Wu | 8053193 | 2017-10-12 17:26:51 -0700 | [diff] [blame] | 78 | no_delay, set to True to raise the priority of this task in task. |
| 79 | force, set to True to schedule this suite no matter whether there's |
| 80 | duplicate jobs before. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 81 | queue, so the suite jobs can start running tests with no waiting. |
| 82 | hour, an integer specifying the hour that a nightly run should be |
| 83 | triggered, default is set to 21. |
| 84 | day, an integer specifying the day of a week that a weekly run should |
| 85 | be triggered, default is set to 5 (Saturday). |
| 86 | os_type, type of OS, e.g., cros, brillo, android. Default is cros. |
| 87 | The argument is required for android/brillo builds. |
| 88 | launch_control_branches, comma separated string of launch control |
| 89 | branches. The argument is required and only applicable for |
| 90 | android/brillo builds. |
| 91 | launch_control_targets, comma separated string of build targets for |
| 92 | launch control builds. The argument is required and only |
| 93 | applicable for android/brillo builds. |
| 94 | testbed_dut_count, number of duts to test when using a testbed. |
Xixuan Wu | 83118dd | 2018-08-27 12:11:35 -0700 | [diff] [blame] | 95 | board_family_config: A board family dictionary mapping board_family name |
| 96 | to its corresponding boards. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 97 | tot: The tot manager for checking ToT. If it's None, a new tot_manager |
| 98 | instance will be initialized. |
| 99 | """ |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 100 | # Indicate whether there're suites get pushed into taskqueue for this task. |
| 101 | self.is_pushed = False |
| 102 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 103 | self.name = task_info.name |
| 104 | self.suite = task_info.suite |
| 105 | self.branch_specs = task_info.branch_specs |
| 106 | self.pool = task_info.pool |
| 107 | self.num = task_info.num |
| 108 | self.priority = task_info.priority |
| 109 | self.timeout = task_info.timeout |
| 110 | self.cros_build_spec = task_info.cros_build_spec |
| 111 | self.firmware_rw_build_spec = task_info.firmware_rw_build_spec |
| 112 | self.firmware_ro_build_spec = task_info.firmware_ro_build_spec |
| 113 | self.test_source = task_info.test_source |
| 114 | self.job_retry = task_info.job_retry |
| 115 | self.no_delay = task_info.no_delay |
Xixuan Wu | 8053193 | 2017-10-12 17:26:51 -0700 | [diff] [blame] | 116 | self.force = task_info.force |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 117 | self.os_type = task_info.os_type |
| 118 | self.testbed_dut_count = task_info.testbed_dut_count |
Xixuan Wu | 008ee83 | 2017-10-12 16:59:34 -0700 | [diff] [blame] | 119 | self.hour = task_info.hour |
| 120 | self.day = task_info.day |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 121 | self.only_hwtest_sanity_required = task_info.only_hwtest_sanity_required |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 122 | |
| 123 | if task_info.lc_branches: |
| 124 | self.launch_control_branches = [ |
| 125 | t.strip() for t in task_info.lc_branches.split(',')] |
| 126 | else: |
| 127 | self.launch_control_branches = [] |
| 128 | |
| 129 | if task_info.lc_targets: |
| 130 | self.launch_control_targets = [ |
| 131 | t.strip() for t in task_info.lc_targets.split(',')] |
| 132 | else: |
| 133 | self.launch_control_targets = [] |
| 134 | |
| 135 | if task_info.boards: |
| 136 | self.boards = [t.strip() for t in task_info.boards.split(',')] |
| 137 | else: |
| 138 | self.boards = [] |
| 139 | |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 140 | if task_info.exclude_boards: |
| 141 | self.exclude_boards = [ |
| 142 | t.strip() for t in task_info.exclude_boards.split(',')] |
| 143 | else: |
| 144 | self.exclude_boards = [] |
| 145 | |
Xixuan Wu | 8989718 | 2019-01-03 15:28:01 -0800 | [diff] [blame] | 146 | if task_info.models: |
| 147 | self.models = [t.strip() for t in task_info.models.split(',')] |
| 148 | else: |
| 149 | self.models = [] |
| 150 | |
| 151 | if task_info.exclude_models: |
| 152 | self.exclude_models = [ |
| 153 | t.strip() for t in task_info.exclude_models.split(',')] |
| 154 | else: |
| 155 | self.exclude_models = [] |
| 156 | |
Po-Hsien Wang | dd83307 | 2018-08-16 18:09:20 -0700 | [diff] [blame] | 157 | if task_info.board_families: |
| 158 | # Finetune the allowed boards list with board_families & boards. |
| 159 | families = [family.strip() |
| 160 | for family in task_info.board_families.split(',')] |
| 161 | for family in families: |
| 162 | self.boards += board_family_config.get(family, []) |
Xixuan Wu | 8989718 | 2019-01-03 15:28:01 -0800 | [diff] [blame] | 163 | |
Po-Hsien Wang | dd83307 | 2018-08-16 18:09:20 -0700 | [diff] [blame] | 164 | if task_info.exclude_board_families: |
| 165 | # Finetune the disallowed boards list with exclude_board_families |
| 166 | # & exclude_boards. |
| 167 | families = [family.strip() |
| 168 | for family in task_info.exclude_board_families.split(',')] |
| 169 | for family in families: |
| 170 | self.exclude_boards += board_family_config.get(family, []) |
| 171 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 172 | if tot is None: |
| 173 | self.tot_manager = tot_manager.TotMilestoneManager() |
| 174 | else: |
| 175 | self.tot_manager = tot |
| 176 | |
| 177 | self._set_spec_compare_info() |
| 178 | |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 179 | def schedule(self, launch_control_builds, cros_builds_tuple, configs, |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 180 | build_client): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 181 | """Schedule the task by its settings. |
| 182 | |
| 183 | Args: |
| 184 | launch_control_builds: the build dict for Android boards, see |
| 185 | return value of |get_launch_control_builds|. |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 186 | cros_builds_tuple: the two-tuple of build dicts for ChromeOS boards, |
| 187 | see return value of |get_cros_builds|. |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 188 | configs: a config_reader.Configs object. |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 189 | build_client: a rest_client.BuildBucketBigqueryClient object, to |
| 190 | connect Buildbucket Bigquery. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 191 | |
| 192 | Raises: |
| 193 | SchedulingError: if tasks that should be scheduled fail to schedule. |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 194 | |
| 195 | Returns: |
Jacob Kopczynski | 79d0010 | 2018-07-13 15:37:03 -0700 | [diff] [blame] | 196 | A boolean indicator; true if there were any suites related to this |
| 197 | task which got pushed into the suites queue. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 198 | """ |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 199 | assert configs.lab_config is not None |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 200 | self.is_pushed = False |
| 201 | |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 202 | branch_builds, relaxed_builds = cros_builds_tuple |
| 203 | builds_dict = branch_builds |
| 204 | if self.only_hwtest_sanity_required: |
| 205 | builds_dict = relaxed_builds |
| 206 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 207 | logging.info('######## Scheduling task %s ########', self.name) |
| 208 | if self.os_type == build_lib.OS_TYPE_CROS: |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 209 | if not builds_dict: |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 210 | logging.info('No CrOS build to run, skip running.') |
| 211 | else: |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 212 | self._schedule_cros_builds(builds_dict, configs, build_client) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 213 | else: |
| 214 | if not launch_control_builds: |
| 215 | logging.info('No Android build to run, skip running.') |
| 216 | else: |
| 217 | self._schedule_launch_control_builds(launch_control_builds) |
| 218 | |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 219 | return self.is_pushed |
| 220 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 221 | def _set_spec_compare_info(self): |
| 222 | """Set branch spec compare info for task for further check.""" |
| 223 | self._bare_branches = [] |
| 224 | self._version_equal_constraint = False |
| 225 | self._version_gte_constraint = False |
| 226 | self._version_lte_constraint = False |
| 227 | |
| 228 | if not self.branch_specs: |
| 229 | # Any milestone is OK. |
| 230 | self._numeric_constraint = version.LooseVersion('0') |
| 231 | else: |
| 232 | self._numeric_constraint = None |
| 233 | for spec in self.branch_specs: |
| 234 | if 'tot' in spec.lower(): |
| 235 | # Convert spec >=tot-1 to >=RXX. |
| 236 | tot_str = spec[spec.index('tot'):] |
| 237 | spec = spec.replace( |
| 238 | tot_str, self.tot_manager.convert_tot_spec(tot_str)) |
| 239 | |
| 240 | if spec.startswith('>='): |
| 241 | self._numeric_constraint = version.LooseVersion( |
| 242 | spec.lstrip('>=R')) |
| 243 | self._version_gte_constraint = True |
| 244 | elif spec.startswith('<='): |
| 245 | self._numeric_constraint = version.LooseVersion( |
| 246 | spec.lstrip('<=R')) |
| 247 | self._version_lte_constraint = True |
| 248 | elif spec.startswith('=='): |
| 249 | self._version_equal_constraint = True |
| 250 | self._numeric_constraint = version.LooseVersion( |
| 251 | spec.lstrip('==R')) |
| 252 | else: |
| 253 | self._bare_branches.append(spec) |
| 254 | |
| 255 | def _fits_spec(self, branch): |
| 256 | """Check if a branch is deemed OK by this task's branch specs. |
| 257 | |
| 258 | Will return whether a branch 'fits' the specifications stored in this task. |
| 259 | |
| 260 | Examples: |
| 261 | Assuming tot=R40 |
| 262 | t = Task('Name', 'suite', ['factory', '>=tot-1']) |
| 263 | t._fits_spec('factory') # True |
| 264 | t._fits_spec('40') # True |
| 265 | t._fits_spec('38') # False |
| 266 | t._fits_spec('firmware') # False |
| 267 | |
| 268 | Args: |
| 269 | branch: the branch to check. |
| 270 | |
| 271 | Returns: |
| 272 | True if branch 'fits' with stored specs, False otherwise. |
| 273 | """ |
| 274 | if branch in build_lib.BARE_BRANCHES: |
| 275 | return branch in self._bare_branches |
| 276 | |
| 277 | if self._numeric_constraint: |
| 278 | if self._version_equal_constraint: |
| 279 | return version.LooseVersion(branch) == self._numeric_constraint |
| 280 | elif self._version_gte_constraint: |
| 281 | return version.LooseVersion(branch) >= self._numeric_constraint |
| 282 | elif self._version_lte_constraint: |
| 283 | return version.LooseVersion(branch) <= self._numeric_constraint |
| 284 | else: |
| 285 | return version.LooseVersion(branch) >= self._numeric_constraint |
| 286 | else: |
| 287 | return False |
| 288 | |
Xixuan Wu | 6ec23e3 | 2019-05-23 11:56:02 -0700 | [diff] [blame^] | 289 | def _get_latest_firmware_build(self, spec, board, build_client): |
| 290 | """Get the latest firmware build. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 291 | |
| 292 | Args: |
| 293 | spec: a string build spec for RO or RW firmware, eg. firmware, |
| 294 | cros. For RO firmware, the value can also be released_ro_X. |
| 295 | board: the board against which this task will run suite job. |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 296 | build_client: a rest_client.BuildBucketBigqueryClient object, to |
| 297 | connect Buildbucket Bigquery. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 298 | |
| 299 | Returns: |
| 300 | the latest firmware build. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 301 | """ |
| 302 | build_type = 'release' if spec == 'cros' else spec |
Xixuan Wu | 6ec23e3 | 2019-05-23 11:56:02 -0700 | [diff] [blame^] | 303 | # TODO(xixuan): not all firmware can be fetched in build system. |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 304 | build = build_client.get_latest_passed_builds('%s-%s' % (board, build_type)) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 305 | |
| 306 | if build is None: |
| 307 | return None |
| 308 | else: |
| 309 | latest_build = str(build_lib.CrOSBuild( |
| 310 | board, build_type, build.milestone, build.platform)) |
| 311 | logging.debug('latest firmware build for %s-%s: %s', board, |
| 312 | build_type, latest_build) |
| 313 | return latest_build |
| 314 | |
| 315 | def _get_latest_firmware_build_from_lab_config(self, spec, board, |
| 316 | lab_config): |
| 317 | """Get latest firmware from lab config file. |
| 318 | |
| 319 | Args: |
| 320 | spec: a string build spec for RO or RW firmware, eg. firmware, |
| 321 | cros. For RO firmware, the value can also be released_ro_X. |
| 322 | board: a string board against which this task will run suite job. |
| 323 | lab_config: a config.LabConfig object, to read lab config file. |
| 324 | |
| 325 | Returns: |
| 326 | A string latest firmware build. |
| 327 | |
| 328 | Raises: |
| 329 | ValueError: if no firmware build list is found in lab config file. |
| 330 | """ |
| 331 | index = int(spec[len(_RELEASE_RO_FIRMWARE_SPEC):]) |
| 332 | released_ro_builds = lab_config.get_firmware_ro_build_list( |
| 333 | 'RELEASED_RO_BUILDS_%s' % board).split(',') |
| 334 | if len(released_ro_builds) < index: |
| 335 | raise ValueError('No %dth ro_builds in the lab_config firmware ' |
| 336 | 'list %r' % (index, released_ro_builds)) |
| 337 | |
| 338 | logging.debug('Get ro_build: %s', released_ro_builds[index - 1]) |
| 339 | return released_ro_builds[index - 1] |
| 340 | |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 341 | def _get_firmware_build(self, spec, board, lab_config, build_client): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 342 | """Get the firmware build name to test with ChromeOS build. |
| 343 | |
| 344 | Args: |
| 345 | spec: a string build spec for RO or RW firmware, eg. firmware, |
| 346 | cros. For RO firmware, the value can also be released_ro_X. |
| 347 | board: a string board against which this task will run suite job. |
| 348 | lab_config: a config.LabConfig object, to read lab config file. |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 349 | build_client: a rest_client.BuildBucketBigqueryClient object, to |
| 350 | connect Buildbucket Bigquery. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 351 | |
| 352 | Returns: |
| 353 | A string firmware build name. |
| 354 | |
| 355 | Raises: |
| 356 | ValueError: if failing to get firmware from lab config file; |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 357 | """ |
| 358 | if not spec or spec == 'stable': |
| 359 | # TODO(crbug.com/577316): Query stable RO firmware. |
| 360 | logging.debug('%s RO firmware build is not supported.', spec) |
| 361 | return None |
| 362 | |
| 363 | try: |
| 364 | if spec.startswith(_RELEASE_RO_FIRMWARE_SPEC): |
| 365 | # For RO firmware whose value is released_ro_X, where X is the index of |
| 366 | # the list defined in lab config file: |
| 367 | # CROS/RELEASED_RO_BUILDS_[board]. |
| 368 | # For example, for spec 'released_ro_2', and lab config file |
| 369 | # CROS/RELEASED_RO_BUILDS_veyron_jerry: build1,build2, |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 370 | # return firmware RO build should be 'build2'. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 371 | return self._get_latest_firmware_build_from_lab_config( |
| 372 | spec, board, lab_config) |
| 373 | else: |
Xixuan Wu | 6ec23e3 | 2019-05-23 11:56:02 -0700 | [diff] [blame^] | 374 | return self._get_latest_firmware_build(spec, board, build_client) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 375 | except ValueError as e: |
| 376 | logging.warning('Failed to get firmware from lab config file' |
| 377 | 'for spec %s, board %s: %s', spec, board, str(e)) |
| 378 | return None |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 379 | |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 380 | def _push_suite( |
| 381 | self, |
| 382 | board=None, |
| 383 | model=None, |
| 384 | cros_build=None, |
| 385 | firmware_rw_build=None, |
| 386 | firmware_ro_build=None, |
| 387 | test_source_build=None, |
| 388 | launch_control_build=None, |
Xixuan Wu | bb74a37 | 2018-08-21 17:37:08 -0700 | [diff] [blame] | 389 | run_prod_code=False, |
Xixuan Wu | 028f673 | 2019-04-11 14:47:42 -0700 | [diff] [blame] | 390 | is_skylab=False, |
| 391 | override_pool='', |
| 392 | override_qs_account=''): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 393 | """Schedule suite job for the task by pushing suites to SuiteQueue. |
| 394 | |
| 395 | Args: |
| 396 | board: the board against which this suite job run. |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 397 | model: the model name for unibuild. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 398 | cros_build: the CrOS build of this suite job. |
| 399 | firmware_rw_build: Firmware RW build to run this suite job with. |
| 400 | firmware_ro_build: Firmware RO build to run this suite job with. |
| 401 | test_source_build: Test source build, used for server-side |
| 402 | packaging of this suite job. |
| 403 | launch_control_build: the launch control build of this suite job. |
| 404 | run_prod_code: If True, the suite will run the test code that lives |
| 405 | in prod aka the test code currently on the lab servers. If |
| 406 | False, the control files and test code for this suite run will |
| 407 | be retrieved from the build artifacts. Default is False. |
Xixuan Wu | bb74a37 | 2018-08-21 17:37:08 -0700 | [diff] [blame] | 408 | is_skylab: If True, schedule this suite to skylab, otherwise schedule |
| 409 | it to AFE. Default is False. |
Xixuan Wu | 028f673 | 2019-04-11 14:47:42 -0700 | [diff] [blame] | 410 | override_pool: A string to indicate pool of quota scheduler. |
| 411 | override_qs_account: A string of quota scheduler account. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 412 | """ |
| 413 | android_build = None |
| 414 | testbed_build = None |
| 415 | |
| 416 | if self.testbed_dut_count: |
| 417 | launch_control_build = '%s#%d' % (launch_control_build, |
| 418 | self.testbed_dut_count) |
| 419 | test_source_build = launch_control_build |
| 420 | board = '%s-%d' % (board, self.testbed_dut_count) |
| 421 | |
| 422 | if launch_control_build: |
| 423 | if not self.testbed_dut_count: |
| 424 | android_build = launch_control_build |
| 425 | else: |
| 426 | testbed_build = launch_control_build |
| 427 | |
| 428 | suite_job_parameters = { |
| 429 | 'suite': self.suite, |
| 430 | 'board': board, |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 431 | 'model': model, |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 432 | build_lib.BuildVersionKey.CROS_VERSION: cros_build, |
| 433 | build_lib.BuildVersionKey.FW_RW_VERSION: firmware_rw_build, |
| 434 | build_lib.BuildVersionKey.FW_RO_VERSION: firmware_ro_build, |
| 435 | build_lib.BuildVersionKey.ANDROID_BUILD_VERSION: android_build, |
| 436 | build_lib.BuildVersionKey.TESTBED_BUILD_VERSION: testbed_build, |
| 437 | 'num': self.num, |
| 438 | 'pool': self.pool, |
| 439 | 'priority': self.priority, |
| 440 | 'timeout': self.timeout, |
| 441 | 'timeout_mins': _JOB_MAX_RUNTIME_MINS_DEFAULT, |
| 442 | 'max_runtime_mins': _JOB_MAX_RUNTIME_MINS_DEFAULT, |
Xixuan Wu | 2ba7265 | 2017-09-15 15:49:42 -0700 | [diff] [blame] | 443 | 'no_wait_for_results': not self.job_retry, |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 444 | 'test_source_build': test_source_build, |
| 445 | 'job_retry': self.job_retry, |
| 446 | 'no_delay': self.no_delay, |
Xixuan Wu | 8053193 | 2017-10-12 17:26:51 -0700 | [diff] [blame] | 447 | 'force': self.force, |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 448 | 'run_prod_code': run_prod_code, |
Xixuan Wu | bb74a37 | 2018-08-21 17:37:08 -0700 | [diff] [blame] | 449 | 'is_skylab': is_skylab, |
Xixuan Wu | 028f673 | 2019-04-11 14:47:42 -0700 | [diff] [blame] | 450 | 'override_pool': override_pool, |
| 451 | 'override_qs_account': override_qs_account, |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | task_executor.push(task_executor.SUITES_QUEUE, **suite_job_parameters) |
| 455 | logging.info('Pushing task %r into taskqueue', suite_job_parameters) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 456 | self.is_pushed = True |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 457 | |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 458 | def _schedule_cros_builds(self, build_dict, configs, build_client): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 459 | """Schedule tasks with branch builds. |
| 460 | |
| 461 | Args: |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 462 | build_dict: the build dict for ChromeOS boards, see return |
Xixuan Wu | 6ec23e3 | 2019-05-23 11:56:02 -0700 | [diff] [blame^] | 463 | value of |build_lib.get_cros_builds_since_date|. |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 464 | configs: A config_reader.Configs object. |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 465 | build_client: a rest_client.BuildBucketBigqueryClient object, to |
| 466 | connect Buildbucket Bigquery. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 467 | """ |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 468 | lab_config = configs.lab_config |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 469 | models_by_board = lab_config.get_cros_model_map() if lab_config else {} |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 470 | for (board, passed_model, build_type, |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 471 | milestone), manifest in build_dict.iteritems(): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 472 | cros_build = str(build_lib.CrOSBuild(board, build_type, milestone, |
| 473 | manifest)) |
| 474 | logging.info('Running %s on %s', self.name, cros_build) |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 475 | if self.exclude_boards and board in self.exclude_boards: |
| 476 | logging.debug('Board %s is in excluded board list: %s', |
| 477 | board, self.exclude_boards) |
| 478 | continue |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 479 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 480 | if self.boards and board not in self.boards: |
| 481 | logging.debug('Board %s is not in supported board list: %s', |
| 482 | board, self.boards) |
| 483 | continue |
| 484 | |
| 485 | # Check the fitness of the build's branch for task |
| 486 | branch_build_spec = _pick_branch(build_type, milestone) |
| 487 | if not self._fits_spec(branch_build_spec): |
| 488 | logging.debug("branch_build spec %s doesn't fit this task's " |
| 489 | "requirement: %s", branch_build_spec, self.branch_specs) |
| 490 | continue |
| 491 | |
| 492 | firmware_rw_build = None |
| 493 | firmware_ro_build = None |
| 494 | if self.firmware_rw_build_spec or self.firmware_ro_build_spec: |
| 495 | firmware_rw_build = self._get_firmware_build( |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 496 | self.firmware_rw_build_spec, board, lab_config, build_client) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 497 | firmware_ro_build = self._get_firmware_build( |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 498 | self.firmware_ro_build_spec, board, lab_config, build_client) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 499 | |
| 500 | if not firmware_ro_build and self.firmware_ro_build_spec: |
| 501 | logging.debug('No firmware ro build to run, skip running') |
| 502 | continue |
| 503 | |
| 504 | if self.test_source == build_lib.BuildType.FIRMWARE_RW: |
| 505 | test_source_build = firmware_rw_build |
| 506 | else: |
Jacob Kopczynski | 79d0010 | 2018-07-13 15:37:03 -0700 | [diff] [blame] | 507 | # Default test source build to CrOS build if it's not specified. |
| 508 | # Past versions chose based on run_prod_code, but we no longer respect |
| 509 | # that option and scheduler settings should always set it to False. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 510 | test_source_build = cros_build |
| 511 | |
Xixuan Wu | b4b2f41 | 2019-05-03 11:22:31 -0700 | [diff] [blame] | 512 | hwtest_board = build_lib.reshape_board(board) |
Xixuan Wu | 1f0be4c | 2019-03-18 16:53:23 -0700 | [diff] [blame] | 513 | is_skylab = skylab.should_run_in_skylab(configs.migration_config, |
Xixuan Wu | b4b2f41 | 2019-05-03 11:22:31 -0700 | [diff] [blame] | 514 | hwtest_board, |
Xixuan Wu | ed878ea | 2019-03-18 15:32:16 -0700 | [diff] [blame] | 515 | passed_model, |
Xixuan Wu | 1e42c75 | 2019-03-21 13:41:49 -0700 | [diff] [blame] | 516 | self.suite, |
| 517 | self.pool) |
Xixuan Wu | 028f673 | 2019-04-11 14:47:42 -0700 | [diff] [blame] | 518 | override_pool, override_qs_account = skylab.get_override_info( |
| 519 | configs.migration_config, |
Xixuan Wu | b4b2f41 | 2019-05-03 11:22:31 -0700 | [diff] [blame] | 520 | hwtest_board, |
Xixuan Wu | 028f673 | 2019-04-11 14:47:42 -0700 | [diff] [blame] | 521 | passed_model, |
| 522 | self.suite, |
| 523 | self.pool) |
Harpreet Grewal | bbbb7de | 2019-02-05 19:35:03 +0000 | [diff] [blame] | 524 | models = models_by_board.get(board, [None]) |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 525 | |
Harpreet Grewal | bbbb7de | 2019-02-05 19:35:03 +0000 | [diff] [blame] | 526 | for model in models: |
| 527 | if ((passed_model is not None and model == passed_model) or |
| 528 | passed_model is None): |
Xixuan Wu | a41efa2 | 2019-05-17 14:28:04 -0700 | [diff] [blame] | 529 | full_model_name = '%s_%s' % (board, model) |
| 530 | # Respect exclude first. |
| 531 | if self.exclude_models and full_model_name in self.exclude_models: |
| 532 | logging.debug("Skip model %s as it's in exclude model list %s", |
| 533 | model, self.exclude_models) |
| 534 | continue |
| 535 | |
| 536 | if self.models and full_model_name not in self.models: |
| 537 | logging.debug("Skip model %s as it's not in support model list %s", |
| 538 | model, self.models) |
| 539 | continue |
| 540 | |
Harpreet Grewal | bbbb7de | 2019-02-05 19:35:03 +0000 | [diff] [blame] | 541 | self._push_suite( |
Xixuan Wu | b4b2f41 | 2019-05-03 11:22:31 -0700 | [diff] [blame] | 542 | board=hwtest_board, |
Harpreet Grewal | bbbb7de | 2019-02-05 19:35:03 +0000 | [diff] [blame] | 543 | model=model, |
| 544 | cros_build=cros_build, |
| 545 | firmware_rw_build=firmware_rw_build, |
| 546 | firmware_ro_build=firmware_ro_build, |
| 547 | test_source_build=test_source_build, |
Xixuan Wu | 028f673 | 2019-04-11 14:47:42 -0700 | [diff] [blame] | 548 | is_skylab=is_skylab, |
| 549 | override_pool=override_pool, |
| 550 | override_qs_account=override_qs_account) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 551 | |
| 552 | def _schedule_launch_control_builds(self, launch_control_builds): |
| 553 | """Schedule tasks with launch control builds. |
| 554 | |
| 555 | Args: |
| 556 | launch_control_builds: the build dict for Android boards. |
| 557 | """ |
| 558 | for board, launch_control_build in launch_control_builds.iteritems(): |
| 559 | logging.debug('Running %s on %s', self.name, board) |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 560 | if self.exclude_boards and board in self.exclude_boards: |
| 561 | logging.debug('Board %s is in excluded board list: %s', |
| 562 | board, self.exclude_boards) |
| 563 | continue |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 564 | if self.boards and board not in self.boards: |
| 565 | logging.debug('Board %s is not in supported board list: %s', |
| 566 | board, self.boards) |
| 567 | continue |
| 568 | |
| 569 | for android_build in launch_control_build: |
| 570 | if not any([branch in android_build |
| 571 | for branch in self.launch_control_branches]): |
| 572 | logging.debug('Branch %s is not required to run for task ' |
| 573 | '%s', android_build, self.name) |
| 574 | continue |
| 575 | |
| 576 | self._push_suite(board=board, |
| 577 | test_source_build=android_build, |
| 578 | launch_control_build=android_build) |
| 579 | |
| 580 | |
| 581 | def _pick_branch(build_type, milestone): |
| 582 | """Select branch based on build type. |
| 583 | |
| 584 | If the build_type is a bare branch, return build_type as the build spec. |
| 585 | If the build_type is a normal CrOS branch, return milestone as the build |
| 586 | spec. |
| 587 | |
| 588 | Args: |
| 589 | build_type: a string builder name, like 'release'. |
| 590 | milestone: a string milestone, like '55'. |
| 591 | |
| 592 | Returns: |
| 593 | A string milestone if build_type represents CrOS build, otherwise |
| 594 | return build_type. |
| 595 | """ |
| 596 | return build_type if build_type in build_lib.BARE_BRANCHES else milestone |