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