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 |
Garry Wang | 111a26f | 2021-07-23 15:25:14 -0700 | [diff] [blame] | 9 | from collections import defaultdict |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 10 | import logging |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 11 | import uuid |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 12 | |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 13 | import analytics |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 14 | import build_lib |
| 15 | import task_executor |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 16 | import tot_manager |
| 17 | |
Garry Wang | 111a26f | 2021-07-23 15:25:14 -0700 | [diff] [blame] | 18 | from multi_duts_lib import BuildTarget, convert_secondary_targets_to_string |
| 19 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 20 | # The max lifetime of a suite scheduled by suite scheduler |
Dhanya Ganesh | a4ce38e | 2021-10-26 15:45:47 +0000 | [diff] [blame] | 21 | _JOB_MAX_RUNTIME_MINS_DEFAULT = (39 * 60 + 30) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 22 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 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 | |
Xinan Lin | 33937d6 | 2020-04-14 14:41:23 -0700 | [diff] [blame] | 35 | def __init__(self, |
| 36 | task_info, |
| 37 | board_family_config={}, |
| 38 | tot=None, |
| 39 | is_sanity=False): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 40 | """Initialize a task instance. |
| 41 | |
| 42 | Args: |
| 43 | task_info: a config_reader.TaskInfo object, which includes: |
| 44 | name, name of this task, e.g. 'NightlyPower' |
| 45 | suite, the name of the suite to run, e.g. 'graphics_per-day' |
| 46 | branch_specs, a pre-vetted iterable of branch specifiers, |
| 47 | e.g. ['>=R18', 'factory'] |
| 48 | pool, the pool of machines to schedule tasks. Default is None. |
| 49 | num, the number of devices to shard the test suite. It could |
| 50 | be an Integer or None. By default it's None. |
Taylor Clark | 54427ce | 2021-02-18 21:59:27 +0000 | [diff] [blame] | 51 | analytics_name, the build rule name. Initially build rule or test rule |
| 52 | name was used in suite scheduler's dashboard for analytics. Later it |
| 53 | was expanded to the entire pipeline and we want to tag all requests |
| 54 | from Suite Scheduler with the rule name. |
Po-Hsien Wang | dd83307 | 2018-08-16 18:09:20 -0700 | [diff] [blame] | 55 | board_families, a common separated list of board family to run this |
| 56 | task on. Boards belong to one of the board family in this list |
| 57 | would be added to task_info.boards. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 58 | 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] | 59 | is None, which allows this task to run on all boards. If same board |
| 60 | is specified in 'boards' and 'exclude_boards', we exclude this |
| 61 | board. |
Xinan Lin | c864711 | 2020-02-04 16:45:56 -0800 | [diff] [blame] | 62 | dimensions, a comma separated lists of labels. Each label is in |
| 63 | the form of 'key:value'. |
Po-Hsien Wang | dd83307 | 2018-08-16 18:09:20 -0700 | [diff] [blame] | 64 | exclude_board_families, a common separated list of board family not to |
| 65 | run task on. Boards belong to one of the board family in this list |
| 66 | would be added to task_info.exclude_boards. |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 67 | exclude_boards, a comma separated list of boards not to run this task |
| 68 | 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] | 69 | If same board is specified in 'boards' and 'exclude_boards', we |
| 70 | exclude this board. |
Xixuan Wu | 8989718 | 2019-01-03 15:28:01 -0800 | [diff] [blame] | 71 | models, a comma separated list of models to run this task on. Default |
| 72 | is None, which allows this task to run on all models. If same model |
| 73 | is specified in 'models' and 'exclude_models', we exclude this |
| 74 | model. |
| 75 | exclude_models, a comma separated list of models not to run this task |
| 76 | 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] | 77 | any_model, set to True to not pass the model parameter and allow |
| 78 | a test suite to run any/all models available for testing. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 79 | priority, the string name of a priority from constants.Priorities. |
| 80 | timeout, the max lifetime of the suite in hours. |
| 81 | cros_build_spec, spec used to determine the ChromeOS build to test |
| 82 | with a firmware build, e.g., tot, R41 etc. |
| 83 | firmware_rw_build_spec, spec used to determine the firmware RW build |
| 84 | test with a ChromeOS build. |
| 85 | firmware_ro_build_spec, spec used to determine the firmware RO build |
| 86 | test with a ChromeOS build. |
Brigit Rossbach | bb08091 | 2020-11-18 13:52:17 -0700 | [diff] [blame] | 87 | firmware_ro_version, pinned firmware RO version. |
| 88 | firmware_rw_version, pinned firmware RW version. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 89 | test_source, the source of test code when firmware will be updated in |
| 90 | the test. The value can be 'firmware_rw', 'firmware_ro' or 'cros'. |
| 91 | 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] | 92 | no_delay, set to True to raise the priority of this task in task. |
| 93 | force, set to True to schedule this suite no matter whether there's |
| 94 | duplicate jobs before. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 95 | queue, so the suite jobs can start running tests with no waiting. |
| 96 | hour, an integer specifying the hour that a nightly run should be |
| 97 | triggered, default is set to 21. |
| 98 | day, an integer specifying the day of a week that a weekly run should |
| 99 | be triggered, default is set to 5 (Saturday). |
| 100 | os_type, type of OS, e.g., cros, brillo, android. Default is cros. |
| 101 | The argument is required for android/brillo builds. |
| 102 | launch_control_branches, comma separated string of launch control |
| 103 | branches. The argument is required and only applicable for |
| 104 | android/brillo builds. |
| 105 | launch_control_targets, comma separated string of build targets for |
| 106 | launch control builds. The argument is required and only |
| 107 | applicable for android/brillo builds. |
| 108 | testbed_dut_count, number of duts to test when using a testbed. |
Xinan Lin | 4757d6f | 2020-03-24 22:20:31 -0700 | [diff] [blame] | 109 | qs_account, quota account for the unmanaged pool which has enabled |
| 110 | Quota Scheduler. |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 111 | multi_dut_boards, a common separated list of strings to specify |
| 112 | board family in a multi-DUTs testing. Each string contains two |
| 113 | or more boards that separated by semicolon, where the first board |
| 114 | will be treated as primary board while the rest are secondaries. |
| 115 | If this args is not None then multi_dut_models args will be |
| 116 | ignored as they cannot be used together. |
| 117 | multi_dut_models, a common separated list of strings to specify |
| 118 | models of DUTs expected in a multi-DUTs testing. Each string |
| 119 | contains two or more models that separated by semicolon, where the |
| 120 | first model will be treated as primary model while the rest are |
| 121 | secondaries. |
| 122 | multi_dut_trigger, a string to specify how should we trigger a |
| 123 | multi-DUTs testing. E.g. 'primary': when the primary board has |
| 124 | a new build, or 'all': when primary and all secondary has a new |
| 125 | build. |
Jacob Kopczynski | c54520f | 2020-08-07 13:20:12 -0700 | [diff] [blame] | 126 | |
Xixuan Wu | 83118dd | 2018-08-27 12:11:35 -0700 | [diff] [blame] | 127 | board_family_config: A board family dictionary mapping board_family name |
| 128 | to its corresponding boards. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 129 | tot: The tot manager for checking ToT. If it's None, a new tot_manager |
| 130 | instance will be initialized. |
Xinan Lin | 33937d6 | 2020-04-14 14:41:23 -0700 | [diff] [blame] | 131 | is_sanity: A boolean; true if we are running in sanity env. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 132 | """ |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 133 | # Indicate whether there're suites get pushed into taskqueue for this task. |
| 134 | self.is_pushed = False |
| 135 | |
Taylor Clark | 8b06a83 | 2021-02-16 21:45:42 +0000 | [diff] [blame] | 136 | self.analytics_name = task_info.analytics_name |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 137 | self.branch_specs = task_info.branch_specs |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 138 | self.cros_build_spec = task_info.cros_build_spec |
Xixuan Wu | 008ee83 | 2017-10-12 16:59:34 -0700 | [diff] [blame] | 139 | self.day = task_info.day |
Jacob Kopczynski | c1d0f5c | 2020-08-09 10:41:32 -0700 | [diff] [blame] | 140 | self.firmware_ro_build_spec = task_info.firmware_ro_build_spec |
| 141 | self.firmware_rw_build_spec = task_info.firmware_rw_build_spec |
Brigit Rossbach | bb08091 | 2020-11-18 13:52:17 -0700 | [diff] [blame] | 142 | self.firmware_ro_version = task_info.firmware_ro_version |
| 143 | self.firmware_rw_version = task_info.firmware_rw_version |
Jacob Kopczynski | c1d0f5c | 2020-08-09 10:41:32 -0700 | [diff] [blame] | 144 | self.force = task_info.force |
| 145 | self.frontdoor = task_info.frontdoor |
| 146 | self.hour = task_info.hour |
| 147 | self.job_retry = task_info.job_retry |
| 148 | self.name = task_info.name |
| 149 | self.no_delay = task_info.no_delay |
| 150 | self.num = task_info.num |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 151 | self.only_hwtest_sanity_required = task_info.only_hwtest_sanity_required |
Jacob Kopczynski | c1d0f5c | 2020-08-09 10:41:32 -0700 | [diff] [blame] | 152 | self.os_type = task_info.os_type |
| 153 | self.pool = task_info.pool |
| 154 | self.priority = task_info.priority |
Xinan Lin | 4757d6f | 2020-03-24 22:20:31 -0700 | [diff] [blame] | 155 | self.qs_account = task_info.qs_account |
Jacob Kopczynski | c1d0f5c | 2020-08-09 10:41:32 -0700 | [diff] [blame] | 156 | self.suite = task_info.suite |
| 157 | self.test_source = task_info.test_source |
| 158 | self.testbed_dut_count = task_info.testbed_dut_count |
| 159 | self.timeout = task_info.timeout |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 160 | self.multi_dut_trigger = task_info.multi_dut_trigger |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 161 | |
| 162 | if task_info.lc_branches: |
| 163 | self.launch_control_branches = [ |
| 164 | t.strip() for t in task_info.lc_branches.split(',')] |
| 165 | else: |
| 166 | self.launch_control_branches = [] |
| 167 | |
| 168 | if task_info.lc_targets: |
| 169 | self.launch_control_targets = [ |
| 170 | t.strip() for t in task_info.lc_targets.split(',')] |
| 171 | else: |
| 172 | self.launch_control_targets = [] |
| 173 | |
| 174 | if task_info.boards: |
| 175 | self.boards = [t.strip() for t in task_info.boards.split(',')] |
| 176 | else: |
| 177 | self.boards = [] |
| 178 | |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 179 | if task_info.exclude_boards: |
| 180 | self.exclude_boards = [ |
| 181 | t.strip() for t in task_info.exclude_boards.split(',')] |
| 182 | else: |
| 183 | self.exclude_boards = [] |
| 184 | |
Xixuan Wu | 8989718 | 2019-01-03 15:28:01 -0800 | [diff] [blame] | 185 | if task_info.models: |
| 186 | self.models = [t.strip() for t in task_info.models.split(',')] |
| 187 | else: |
| 188 | self.models = [] |
| 189 | |
| 190 | if task_info.exclude_models: |
| 191 | self.exclude_models = [ |
| 192 | t.strip() for t in task_info.exclude_models.split(',')] |
| 193 | else: |
| 194 | self.exclude_models = [] |
| 195 | |
C Shapiro | 0910825 | 2019-08-01 14:52:52 -0500 | [diff] [blame] | 196 | self.any_model = task_info.any_model |
| 197 | |
Po-Hsien Wang | dd83307 | 2018-08-16 18:09:20 -0700 | [diff] [blame] | 198 | if task_info.board_families: |
| 199 | # Finetune the allowed boards list with board_families & boards. |
| 200 | families = [family.strip() |
| 201 | for family in task_info.board_families.split(',')] |
| 202 | for family in families: |
| 203 | self.boards += board_family_config.get(family, []) |
Xixuan Wu | 8989718 | 2019-01-03 15:28:01 -0800 | [diff] [blame] | 204 | |
Po-Hsien Wang | dd83307 | 2018-08-16 18:09:20 -0700 | [diff] [blame] | 205 | if task_info.exclude_board_families: |
| 206 | # Finetune the disallowed boards list with exclude_board_families |
| 207 | # & exclude_boards. |
| 208 | families = [family.strip() |
| 209 | for family in task_info.exclude_board_families.split(',')] |
| 210 | for family in families: |
| 211 | self.exclude_boards += board_family_config.get(family, []) |
| 212 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 213 | if tot is None: |
| 214 | self.tot_manager = tot_manager.TotMilestoneManager() |
| 215 | else: |
| 216 | self.tot_manager = tot |
| 217 | |
Xinan Lin | c864711 | 2020-02-04 16:45:56 -0800 | [diff] [blame] | 218 | self.dimensions = task_info.dimensions |
| 219 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 220 | self._set_spec_compare_info() |
Xinan Lin | 33937d6 | 2020-04-14 14:41:23 -0700 | [diff] [blame] | 221 | # Sanity test does not have to upload metrics. |
| 222 | if not is_sanity: |
| 223 | self.job_section = analytics.ScheduleJobSection(task_info) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 224 | |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 225 | self.is_multi_dut_testing = False |
| 226 | if task_info.multi_dut_boards: |
| 227 | self.is_multi_dut_testing = True |
| 228 | self.multi_dut_boards = [ |
| 229 | t.strip().split(';') for t in task_info.multi_dut_boards.split(',')] |
| 230 | else: |
| 231 | self.multi_dut_boards = [] |
| 232 | |
| 233 | if task_info.multi_dut_models: |
| 234 | self.is_multi_dut_testing = True |
| 235 | self.multi_dut_models = [ |
| 236 | t.strip().split(';') for t in task_info.multi_dut_models.split(',')] |
| 237 | else: |
| 238 | self.multi_dut_models = [] |
| 239 | |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 240 | def schedule(self, launch_control_builds, cros_builds_tuple, |
| 241 | firmware_builds, configs): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 242 | """Schedule the task by its settings. |
| 243 | |
| 244 | Args: |
| 245 | launch_control_builds: the build dict for Android boards, see |
| 246 | return value of |get_launch_control_builds|. |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 247 | cros_builds_tuple: the two-tuple of build dicts for ChromeOS boards, |
| 248 | see return value of |get_cros_builds|. |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 249 | firmware_builds: a dict of firmware artifact, see return value of |
| 250 | |base_event.get_firmware_builds|. |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 251 | configs: a config_reader.Configs object. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 252 | |
| 253 | Raises: |
| 254 | SchedulingError: if tasks that should be scheduled fail to schedule. |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 255 | |
| 256 | Returns: |
Jacob Kopczynski | 79d0010 | 2018-07-13 15:37:03 -0700 | [diff] [blame] | 257 | A boolean indicator; true if there were any suites related to this |
| 258 | task which got pushed into the suites queue. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 259 | """ |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 260 | assert configs.lab_config is not None |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 261 | self.is_pushed = False |
| 262 | |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 263 | branch_builds, relaxed_builds = cros_builds_tuple |
| 264 | builds_dict = branch_builds |
| 265 | if self.only_hwtest_sanity_required: |
Xinan Lin | ae7d637 | 2019-09-12 14:42:10 -0700 | [diff] [blame] | 266 | builds_dict = _split_unibuilds(relaxed_builds, configs) |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 267 | |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 268 | # Record all target boards and models into job section. |
| 269 | lab_config = configs.lab_config |
| 270 | models_by_board = lab_config.get_cros_model_map() if lab_config else {} |
| 271 | boards = self.boards if self.boards else lab_config.get_cros_board_list() |
| 272 | for b in boards: |
| 273 | if self.exclude_boards and b in self.exclude_boards: |
| 274 | continue |
| 275 | self.job_section.add_board(b) |
| 276 | models = self.models or models_by_board.get(b, []) |
| 277 | for m in models: |
| 278 | if m and '%s_%s' % (b, m) not in self.exclude_models: |
| 279 | self.job_section.add_model(m) |
| 280 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 281 | logging.info('######## Scheduling task %s ########', self.name) |
| 282 | if self.os_type == build_lib.OS_TYPE_CROS: |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 283 | if not builds_dict: |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 284 | logging.info('No CrOS build to run, skip running.') |
| 285 | else: |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 286 | self._schedule_cros_builds(builds_dict, firmware_builds, configs) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 287 | else: |
| 288 | if not launch_control_builds: |
| 289 | logging.info('No Android build to run, skip running.') |
| 290 | else: |
| 291 | self._schedule_launch_control_builds(launch_control_builds) |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 292 | upload_result = False |
| 293 | try: |
| 294 | upload_result = self.job_section.upload() |
| 295 | # For any exceptions from BQ, only log it and move on. |
| 296 | except Exception as e: #pylint: disable=broad-except |
| 297 | logging.exception(str(e)) |
| 298 | if not upload_result: |
| 299 | logging.warning('Failed to insert row: %r', self.job_section) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 300 | return self.is_pushed |
| 301 | |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 302 | def schedule_multi_duts(self, cros_builds_tuple, |
Garry Wang | 4e29b51 | 2021-08-26 19:32:59 -0700 | [diff] [blame] | 303 | recent_cros_builds_tuple, configs): |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 304 | """Schedule the multi-DUTs task by its settings. |
| 305 | |
| 306 | Args: |
| 307 | cros_builds_tuple: the two-tuple of build dicts for ChromeOS boards, |
| 308 | see return value of |get_cros_builds|. |
Garry Wang | 4e29b51 | 2021-08-26 19:32:59 -0700 | [diff] [blame] | 309 | recent_cros_builds_tuple: Same as cros_builds_tuple, but contains |
| 310 | build info with a wider time range. |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 311 | configs: a config_reader.Configs object. |
| 312 | |
| 313 | Raises: |
| 314 | SchedulingError: if tasks that should be scheduled fail to schedule. |
| 315 | |
| 316 | Returns: |
| 317 | A boolean indicator; true if there were any suites related to this |
| 318 | task which got pushed into the suites queue. |
| 319 | """ |
| 320 | assert configs.lab_config is not None |
| 321 | # For multi-DUTs We allow either request by board or request by model, |
| 322 | # but not both. |
| 323 | if self.multi_dut_boards and self.multi_dut_models: |
| 324 | logging.error('Both board and model presented in request but expecting' |
| 325 | 'only one of them present at a time.') |
| 326 | return False |
| 327 | self.is_pushed = False |
| 328 | |
| 329 | branch_builds, relaxed_builds = cros_builds_tuple |
Garry Wang | 4e29b51 | 2021-08-26 19:32:59 -0700 | [diff] [blame] | 330 | recent_branch_builds, recent_relaxed_builds = recent_cros_builds_tuple |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 331 | builds_dict = branch_builds |
Garry Wang | 4e29b51 | 2021-08-26 19:32:59 -0700 | [diff] [blame] | 332 | recent_builds_dict = recent_branch_builds |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 333 | if self.only_hwtest_sanity_required: |
| 334 | builds_dict = _split_unibuilds(relaxed_builds, configs) |
| 335 | # We don't need to expand build info to model level as |
| 336 | # secondary DUTs will have their builds determined by |
| 337 | # their board name. |
Garry Wang | 4e29b51 | 2021-08-26 19:32:59 -0700 | [diff] [blame] | 338 | recent_builds_dict = recent_relaxed_builds |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 339 | |
| 340 | # Record multi-DUTs testing only for primary boards as we're |
| 341 | # going to have a replacement for SS and analytics layer soon. |
| 342 | build_targets_dict = self._get_multi_duts_build_targets_dict(configs) |
| 343 | model_set = set() |
| 344 | for board, groups in build_targets_dict.items(): |
| 345 | self.job_section.add_board(board) |
| 346 | for group in groups: |
| 347 | if group[0].model: |
| 348 | model_set.add(group[0].model) |
| 349 | for model in model_set: |
| 350 | if self.exclude_models and model not in self.exclude_models: |
| 351 | self.job_section.add_model(model) |
| 352 | |
| 353 | logging.info('######## Scheduling task %s ########', self.name) |
| 354 | if self.os_type != build_lib.OS_TYPE_CROS: |
Garry Wang | 6ca42dd | 2022-02-28 21:54:19 -0800 | [diff] [blame^] | 355 | logging.info('Multi-DUTs testing only support CrOS builds.') |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 356 | return False |
| 357 | if not builds_dict: |
| 358 | logging.info('No CrOS build to run, skip running.') |
| 359 | return False |
Garry Wang | 4e29b51 | 2021-08-26 19:32:59 -0700 | [diff] [blame] | 360 | if not recent_builds_dict: |
| 361 | logging.info('No recent CrOS build for secondary DUTs to run,' |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 362 | ' skip running.') |
| 363 | return False |
| 364 | self._schedule_multi_duts_cros_builds(builds_dict, |
Garry Wang | 4e29b51 | 2021-08-26 19:32:59 -0700 | [diff] [blame] | 365 | recent_builds_dict, configs) |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 366 | |
| 367 | upload_result = False |
| 368 | try: |
| 369 | upload_result = self.job_section.upload() |
| 370 | # For any exceptions from BQ, only log it and move on. |
| 371 | except Exception as e: #pylint: disable=broad-except |
| 372 | logging.exception(str(e)) |
| 373 | if not upload_result: |
| 374 | logging.warning('Failed to insert row: %r', self.job_section) |
| 375 | return self.is_pushed |
| 376 | |
| 377 | def _model_to_board_dict(self, models_by_board): |
| 378 | """Build a model to board dict based on model by boards dict.""" |
| 379 | d = {} |
| 380 | for board, models in models_by_board.items(): |
| 381 | for model in models: |
| 382 | d[model] = board |
| 383 | return d |
| 384 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 385 | def _set_spec_compare_info(self): |
| 386 | """Set branch spec compare info for task for further check.""" |
| 387 | self._bare_branches = [] |
| 388 | self._version_equal_constraint = False |
| 389 | self._version_gte_constraint = False |
| 390 | self._version_lte_constraint = False |
| 391 | |
| 392 | if not self.branch_specs: |
| 393 | # Any milestone is OK. |
| 394 | self._numeric_constraint = version.LooseVersion('0') |
| 395 | else: |
| 396 | self._numeric_constraint = None |
| 397 | for spec in self.branch_specs: |
| 398 | if 'tot' in spec.lower(): |
| 399 | # Convert spec >=tot-1 to >=RXX. |
| 400 | tot_str = spec[spec.index('tot'):] |
| 401 | spec = spec.replace( |
| 402 | tot_str, self.tot_manager.convert_tot_spec(tot_str)) |
| 403 | |
| 404 | if spec.startswith('>='): |
| 405 | self._numeric_constraint = version.LooseVersion( |
| 406 | spec.lstrip('>=R')) |
| 407 | self._version_gte_constraint = True |
| 408 | elif spec.startswith('<='): |
| 409 | self._numeric_constraint = version.LooseVersion( |
| 410 | spec.lstrip('<=R')) |
| 411 | self._version_lte_constraint = True |
| 412 | elif spec.startswith('=='): |
| 413 | self._version_equal_constraint = True |
| 414 | self._numeric_constraint = version.LooseVersion( |
| 415 | spec.lstrip('==R')) |
| 416 | else: |
| 417 | self._bare_branches.append(spec) |
| 418 | |
| 419 | def _fits_spec(self, branch): |
| 420 | """Check if a branch is deemed OK by this task's branch specs. |
| 421 | |
| 422 | Will return whether a branch 'fits' the specifications stored in this task. |
| 423 | |
| 424 | Examples: |
| 425 | Assuming tot=R40 |
| 426 | t = Task('Name', 'suite', ['factory', '>=tot-1']) |
| 427 | t._fits_spec('factory') # True |
| 428 | t._fits_spec('40') # True |
| 429 | t._fits_spec('38') # False |
| 430 | t._fits_spec('firmware') # False |
| 431 | |
| 432 | Args: |
| 433 | branch: the branch to check. |
| 434 | |
| 435 | Returns: |
| 436 | True if branch 'fits' with stored specs, False otherwise. |
| 437 | """ |
| 438 | if branch in build_lib.BARE_BRANCHES: |
| 439 | return branch in self._bare_branches |
| 440 | |
| 441 | if self._numeric_constraint: |
| 442 | if self._version_equal_constraint: |
| 443 | return version.LooseVersion(branch) == self._numeric_constraint |
| 444 | elif self._version_gte_constraint: |
| 445 | return version.LooseVersion(branch) >= self._numeric_constraint |
| 446 | elif self._version_lte_constraint: |
| 447 | return version.LooseVersion(branch) <= self._numeric_constraint |
| 448 | else: |
| 449 | return version.LooseVersion(branch) >= self._numeric_constraint |
| 450 | else: |
| 451 | return False |
| 452 | |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 453 | def _get_firmware_build(self, spec, board, firmware_build_dict, lab_config): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 454 | """Get the firmware build name to test with ChromeOS build. |
| 455 | |
| 456 | Args: |
| 457 | spec: a string build spec for RO or RW firmware, eg. firmware, |
| 458 | cros. For RO firmware, the value can also be released_ro_X. |
| 459 | board: a string board against which this task will run suite job. |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 460 | firmware_build_dict: a dict of firmware artifacts, see return value of |
| 461 | |base_event.get_firmware_builds|. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 462 | lab_config: a config.LabConfig object, to read lab config file. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 463 | |
| 464 | Returns: |
| 465 | A string firmware build name. |
| 466 | |
| 467 | Raises: |
| 468 | ValueError: if failing to get firmware from lab config file; |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 469 | """ |
| 470 | if not spec or spec == 'stable': |
| 471 | # TODO(crbug.com/577316): Query stable RO firmware. |
| 472 | logging.debug('%s RO firmware build is not supported.', spec) |
| 473 | return None |
| 474 | |
| 475 | try: |
Dhanya Ganesh | f6014b7 | 2020-08-04 22:33:28 +0000 | [diff] [blame] | 476 | if firmware_build_dict: |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 477 | return firmware_build_dict.get((spec, board), None) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 478 | else: |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 479 | return None |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 480 | except ValueError as e: |
| 481 | logging.warning('Failed to get firmware from lab config file' |
| 482 | 'for spec %s, board %s: %s', spec, board, str(e)) |
| 483 | return None |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 484 | |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 485 | def _push_suite( |
| 486 | self, |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 487 | task_id=None, |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 488 | board=None, |
| 489 | model=None, |
| 490 | cros_build=None, |
| 491 | firmware_rw_build=None, |
| 492 | firmware_ro_build=None, |
| 493 | test_source_build=None, |
| 494 | launch_control_build=None, |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 495 | run_prod_code=False, |
| 496 | secondary_targets=None): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 497 | """Schedule suite job for the task by pushing suites to SuiteQueue. |
| 498 | |
| 499 | Args: |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 500 | task_id: the id to track this task in exectuion. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 501 | board: the board against which this suite job run. |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 502 | model: the model name for unibuild. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 503 | cros_build: the CrOS build of this suite job. |
| 504 | firmware_rw_build: Firmware RW build to run this suite job with. |
| 505 | firmware_ro_build: Firmware RO build to run this suite job with. |
| 506 | test_source_build: Test source build, used for server-side |
| 507 | packaging of this suite job. |
| 508 | launch_control_build: the launch control build of this suite job. |
| 509 | run_prod_code: If True, the suite will run the test code that lives |
| 510 | in prod aka the test code currently on the lab servers. If |
| 511 | False, the control files and test code for this suite run will |
| 512 | be retrieved from the build artifacts. Default is False. |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 513 | secondary_targets: A list of BuildTarget namedtuple to represent |
| 514 | required secondary DUTs info in this suite job run. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 515 | """ |
| 516 | android_build = None |
| 517 | testbed_build = None |
| 518 | |
| 519 | if self.testbed_dut_count: |
| 520 | launch_control_build = '%s#%d' % (launch_control_build, |
| 521 | self.testbed_dut_count) |
| 522 | test_source_build = launch_control_build |
| 523 | board = '%s-%d' % (board, self.testbed_dut_count) |
| 524 | |
| 525 | if launch_control_build: |
| 526 | if not self.testbed_dut_count: |
| 527 | android_build = launch_control_build |
| 528 | else: |
| 529 | testbed_build = launch_control_build |
| 530 | |
Garry Wang | 111a26f | 2021-07-23 15:25:14 -0700 | [diff] [blame] | 531 | if secondary_targets: |
| 532 | secondary_targets = convert_secondary_targets_to_string(secondary_targets) |
| 533 | else: |
| 534 | secondary_targets = '' |
| 535 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 536 | suite_job_parameters = { |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 537 | build_lib.BuildVersionKey.ANDROID_BUILD_VERSION: android_build, |
Jacob Kopczynski | c1d0f5c | 2020-08-09 10:41:32 -0700 | [diff] [blame] | 538 | build_lib.BuildVersionKey.CROS_VERSION: cros_build, |
| 539 | build_lib.BuildVersionKey.FW_RO_VERSION: firmware_ro_build, |
| 540 | build_lib.BuildVersionKey.FW_RW_VERSION: firmware_rw_build, |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 541 | build_lib.BuildVersionKey.TESTBED_BUILD_VERSION: testbed_build, |
Taylor Clark | 8b06a83 | 2021-02-16 21:45:42 +0000 | [diff] [blame] | 542 | 'analytics_name': self.analytics_name, |
Jacob Kopczynski | c1d0f5c | 2020-08-09 10:41:32 -0700 | [diff] [blame] | 543 | 'board': board, |
| 544 | 'dimensions': self.dimensions, |
| 545 | 'force': self.force, |
| 546 | 'job_retry': self.job_retry, |
| 547 | 'max_runtime_mins': _JOB_MAX_RUNTIME_MINS_DEFAULT, |
| 548 | 'model': model, |
| 549 | 'name': self.name, |
| 550 | 'no_delay': self.no_delay, |
| 551 | 'no_wait_for_results': not self.job_retry, |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 552 | 'num': self.num, |
| 553 | 'pool': self.pool, |
| 554 | 'priority': self.priority, |
Jacob Kopczynski | c1d0f5c | 2020-08-09 10:41:32 -0700 | [diff] [blame] | 555 | 'qs_account': self.qs_account, |
| 556 | 'run_prod_code': run_prod_code, |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 557 | 'secondary_targets': secondary_targets, |
Jacob Kopczynski | c1d0f5c | 2020-08-09 10:41:32 -0700 | [diff] [blame] | 558 | 'suite': self.suite, |
| 559 | 'task_id': task_id, |
| 560 | 'test_source_build': test_source_build, |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 561 | 'timeout': self.timeout, |
| 562 | 'timeout_mins': _JOB_MAX_RUNTIME_MINS_DEFAULT, |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Xinan Lin | 9e4917d | 2019-11-04 10:58:47 -0800 | [diff] [blame] | 565 | task_executor.push(task_executor.SUITES_QUEUE, |
| 566 | tag=self.suite, |
| 567 | **suite_job_parameters) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 568 | logging.info('Pushing task %r into taskqueue', suite_job_parameters) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 569 | self.is_pushed = True |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 570 | |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 571 | def _schedule_cros_builds(self, build_dict, firmware_build_dict, configs): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 572 | """Schedule tasks with branch builds. |
| 573 | |
| 574 | Args: |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 575 | build_dict: the build dict for ChromeOS boards, see return |
Xinan Lin | ea1efcb | 2019-12-30 23:46:42 -0800 | [diff] [blame] | 576 | value of |build_lib.get_cros_builds|. |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 577 | firmware_build_dict: a dict of firmware artifact, see return value of |
| 578 | |base_event.get_firmware_builds|. |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 579 | configs: A config_reader.Configs object. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 580 | """ |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 581 | lab_config = configs.lab_config |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 582 | 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] | 583 | model_agnostic_cros_builds = set() |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 584 | for (board, passed_model, build_type, |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 585 | milestone), manifest in build_dict.iteritems(): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 586 | cros_build = str(build_lib.CrOSBuild(board, build_type, milestone, |
| 587 | manifest)) |
| 588 | logging.info('Running %s on %s', self.name, cros_build) |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 589 | if self.exclude_boards and board in self.exclude_boards: |
| 590 | logging.debug('Board %s is in excluded board list: %s', |
| 591 | board, self.exclude_boards) |
| 592 | continue |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 593 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 594 | if self.boards and board not in self.boards: |
| 595 | logging.debug('Board %s is not in supported board list: %s', |
| 596 | board, self.boards) |
| 597 | continue |
| 598 | |
| 599 | # Check the fitness of the build's branch for task |
| 600 | branch_build_spec = _pick_branch(build_type, milestone) |
| 601 | if not self._fits_spec(branch_build_spec): |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 602 | msg = ("branch_build spec %s doesn't fit this task's " |
| 603 | "requirement: %s") % (branch_build_spec, |
| 604 | ",".join(self.branch_specs)) |
| 605 | logging.debug(msg) |
| 606 | self.job_section.add_schedule_job(board, passed_model, msg=msg) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 607 | continue |
| 608 | |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 609 | # Record this build as it matches both board and branch specs. |
| 610 | if self.only_hwtest_sanity_required: |
| 611 | self.job_section.add_matched_relax_build( |
| 612 | board, build_type, milestone, manifest) |
| 613 | else: |
| 614 | self.job_section.add_matched_build( |
| 615 | board, build_type, milestone, manifest) |
| 616 | |
Sean McAllister | 7378b69 | 2021-06-03 15:44:22 -0600 | [diff] [blame] | 617 | # check that we only got one spec for ro firmware |
| 618 | if all([self.firmware_ro_version, self.firmware_ro_build_spec]): |
| 619 | logging.error( |
| 620 | "Exactly one of firmware_ro_version or firmware_ro_build_spec " \ |
| 621 | "allowed, got: %s and %s" % ( |
| 622 | self.firmware_ro_version, |
| 623 | self.firmware_ro_build_spec, |
| 624 | ), |
| 625 | ) |
| 626 | continue |
| 627 | |
| 628 | # check that we only got one spec for rw firmware |
| 629 | if all([self.firmware_rw_version, self.firmware_rw_build_spec]): |
| 630 | logging.error( |
| 631 | "Exactly one of firmware_rw_version or firmware_rw_build_spec " \ |
| 632 | "allowed, got: %s and %s" % ( |
| 633 | self.firmware_rw_version, |
| 634 | self.firmware_rw_build_spec, |
| 635 | ), |
| 636 | ) |
| 637 | continue |
| 638 | |
| 639 | # resolve ro firmware version to provision |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 640 | firmware_ro_build = None |
Brigit Rossbach | bb08091 | 2020-11-18 13:52:17 -0700 | [diff] [blame] | 641 | if self.firmware_ro_version: |
| 642 | firmware_ro_build = self.firmware_ro_version |
Sean McAllister | 7378b69 | 2021-06-03 15:44:22 -0600 | [diff] [blame] | 643 | elif self.firmware_ro_build_spec: |
| 644 | firmware_ro_build = self._get_firmware_build( |
| 645 | self.firmware_ro_build_spec, board, firmware_build_dict, lab_config) |
Brigit Rossbach | bb08091 | 2020-11-18 13:52:17 -0700 | [diff] [blame] | 646 | |
Sean McAllister | 7378b69 | 2021-06-03 15:44:22 -0600 | [diff] [blame] | 647 | if not firmware_ro_build: |
| 648 | msg = 'No RO firmware build to run, skip running' |
| 649 | logging.debug(msg) |
| 650 | self.job_section.add_schedule_job(board, passed_model, msg=msg) |
| 651 | continue |
| 652 | |
| 653 | # resolve rw firmware version to provision |
| 654 | firmware_rw_build = None |
Brigit Rossbach | bb08091 | 2020-11-18 13:52:17 -0700 | [diff] [blame] | 655 | if self.firmware_rw_version: |
| 656 | firmware_rw_build = self.firmware_rw_version |
Sean McAllister | 7378b69 | 2021-06-03 15:44:22 -0600 | [diff] [blame] | 657 | elif self.firmware_rw_build_spec: |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 658 | firmware_rw_build = self._get_firmware_build( |
Sean McAllister | 7378b69 | 2021-06-03 15:44:22 -0600 | [diff] [blame] | 659 | self.firmware_rw_build_spec, board, firmware_build_dict, lab_config) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 660 | |
Sean McAllister | 7378b69 | 2021-06-03 15:44:22 -0600 | [diff] [blame] | 661 | if not firmware_rw_build: |
| 662 | msg = 'No RW firmware build to run, skip running' |
| 663 | logging.debug(msg) |
| 664 | self.job_section.add_schedule_job(board, passed_model, msg=msg) |
| 665 | continue |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 666 | |
| 667 | if self.test_source == build_lib.BuildType.FIRMWARE_RW: |
| 668 | test_source_build = firmware_rw_build |
| 669 | else: |
Jacob Kopczynski | 79d0010 | 2018-07-13 15:37:03 -0700 | [diff] [blame] | 670 | # Default test source build to CrOS build if it's not specified. |
| 671 | # Past versions chose based on run_prod_code, but we no longer respect |
| 672 | # that option and scheduler settings should always set it to False. |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 673 | test_source_build = cros_build |
| 674 | |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 675 | # Record the matched firwmare build. |
| 676 | if firmware_rw_build: |
| 677 | self.job_section.add_matched_fw_build( |
| 678 | board, |
| 679 | self.firmware_rw_build_spec, |
| 680 | firmware_rw_build, |
| 681 | read_only=False) |
| 682 | if firmware_ro_build: |
| 683 | self.job_section.add_matched_fw_build( |
| 684 | board, |
| 685 | self.firmware_ro_build_spec, |
| 686 | firmware_ro_build, |
| 687 | read_only=True) |
| 688 | |
Xinan Lin | 6668e0f | 2020-05-29 10:02:57 -0700 | [diff] [blame] | 689 | # Board above is used as build target to control the CrOS image. |
| 690 | # The following part is to assign models for lab boards, where |
| 691 | # the suffix should be removed. |
Prathmesh Prabhu | 074b8d4 | 2020-08-13 17:17:33 +0000 | [diff] [blame] | 692 | hwtest_board = build_lib.reshape_board(board) |
| 693 | |
Xinan Lin | 6668e0f | 2020-05-29 10:02:57 -0700 | [diff] [blame] | 694 | models = models_by_board.get(hwtest_board, [None]) |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 695 | |
Harpreet Grewal | bbbb7de | 2019-02-05 19:35:03 +0000 | [diff] [blame] | 696 | for model in models: |
| 697 | if ((passed_model is not None and model == passed_model) or |
| 698 | passed_model is None): |
Xinan Lin | 6668e0f | 2020-05-29 10:02:57 -0700 | [diff] [blame] | 699 | full_model_name = '%s_%s' % (hwtest_board, model) |
Xixuan Wu | a41efa2 | 2019-05-17 14:28:04 -0700 | [diff] [blame] | 700 | # Respect exclude first. |
| 701 | if self.exclude_models and full_model_name in self.exclude_models: |
| 702 | logging.debug("Skip model %s as it's in exclude model list %s", |
| 703 | model, self.exclude_models) |
| 704 | continue |
| 705 | |
| 706 | if self.models and full_model_name not in self.models: |
| 707 | logging.debug("Skip model %s as it's not in support model list %s", |
| 708 | model, self.models) |
| 709 | continue |
| 710 | |
C Shapiro | 0910825 | 2019-08-01 14:52:52 -0500 | [diff] [blame] | 711 | explicit_model = model |
| 712 | |
| 713 | if self.any_model: |
Xinan Lin | 3ba18a0 | 2019-08-13 15:44:55 -0700 | [diff] [blame] | 714 | explicit_model = None |
C Shapiro | 0910825 | 2019-08-01 14:52:52 -0500 | [diff] [blame] | 715 | unique_build = str(cros_build) |
| 716 | if unique_build in model_agnostic_cros_builds: |
| 717 | # Skip since we've already run with no explicit model set. |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 718 | msg = "Skip model %s as any_model enabled for this job." % model |
| 719 | self.job_section.add_schedule_job(board, model, msg=msg) |
C Shapiro | 0910825 | 2019-08-01 14:52:52 -0500 | [diff] [blame] | 720 | continue |
| 721 | model_agnostic_cros_builds.add(unique_build) |
| 722 | |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 723 | task_id = str(uuid.uuid1()) |
Harpreet Grewal | bbbb7de | 2019-02-05 19:35:03 +0000 | [diff] [blame] | 724 | self._push_suite( |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 725 | task_id=task_id, |
Xixuan Wu | b4b2f41 | 2019-05-03 11:22:31 -0700 | [diff] [blame] | 726 | board=hwtest_board, |
C Shapiro | 0910825 | 2019-08-01 14:52:52 -0500 | [diff] [blame] | 727 | model=explicit_model, |
Harpreet Grewal | bbbb7de | 2019-02-05 19:35:03 +0000 | [diff] [blame] | 728 | cros_build=cros_build, |
| 729 | firmware_rw_build=firmware_rw_build, |
| 730 | firmware_ro_build=firmware_ro_build, |
Xinan Lin | 0550f49 | 2020-01-21 16:25:53 -0800 | [diff] [blame] | 731 | test_source_build=test_source_build) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 732 | |
Xinan Lin | 6668e0f | 2020-05-29 10:02:57 -0700 | [diff] [blame] | 733 | # Analytics table stores the build target instead of the lab board. |
Xinan Lin | 0673a18 | 2020-04-14 15:09:35 -0700 | [diff] [blame] | 734 | self.job_section.add_schedule_job( |
| 735 | board, explicit_model, task_id=task_id) |
Xinan Lin | df0698a | 2020-02-05 22:38:11 -0800 | [diff] [blame] | 736 | |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 737 | def _schedule_multi_duts_cros_builds(self, build_dict, |
Garry Wang | 4e29b51 | 2021-08-26 19:32:59 -0700 | [diff] [blame] | 738 | recent_build_dict, configs): |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 739 | """Schedule multi-DUTs tasks with branch builds. |
| 740 | |
| 741 | Args: |
| 742 | build_dict: the build dict for ChromeOS boards, see return |
| 743 | value of |build_lib.get_cros_builds|. |
Garry Wang | 4e29b51 | 2021-08-26 19:32:59 -0700 | [diff] [blame] | 744 | recent_build_dict: Same as build_dict, but contains build info |
| 745 | with a wider time range. |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 746 | configs: A config_reader.Configs object. |
| 747 | """ |
| 748 | build_targets_dict = self._get_multi_duts_build_targets_dict(configs) |
Garry Wang | 6ca42dd | 2022-02-28 21:54:19 -0800 | [diff] [blame^] | 749 | android_boards_list = configs.lab_config.get_android_model_map().keys() |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 750 | model_agnostic_builds = set() |
| 751 | for (board, passed_model, build_type, |
| 752 | milestone), manifest in build_dict.iteritems(): |
| 753 | cros_build = str(build_lib.CrOSBuild(board, build_type, milestone, |
| 754 | manifest)) |
| 755 | logging.info('Running %s on %s', self.name, cros_build) |
| 756 | if board not in build_targets_dict.keys(): |
| 757 | logging.debug('Board %s is not in primary board list: %s', |
| 758 | board, build_targets_dict.keys()) |
| 759 | continue |
| 760 | |
| 761 | # Check the fitness of the build's branch for task |
| 762 | branch_build_spec = _pick_branch(build_type, milestone) |
| 763 | if not self._fits_spec(branch_build_spec): |
| 764 | msg = ("branch_build spec %s doesn't fit this task's " |
| 765 | "requirement: %s") % (branch_build_spec, |
| 766 | ",".join(self.branch_specs)) |
| 767 | logging.debug(msg) |
| 768 | self.job_section.add_schedule_job(board, passed_model, msg=msg) |
| 769 | continue |
| 770 | |
| 771 | # Record this build as it matches both board and branch specs. |
| 772 | if self.only_hwtest_sanity_required: |
| 773 | self.job_section.add_matched_relax_build( |
| 774 | board, build_type, milestone, manifest) |
| 775 | else: |
| 776 | self.job_section.add_matched_build( |
| 777 | board, build_type, milestone, manifest) |
| 778 | |
| 779 | # Board above is used as build target to control the CrOS image. |
| 780 | # The following part is to assign models for lab boards, where |
| 781 | # the suffix should be removed. |
| 782 | hwtest_board = build_lib.reshape_board(board) |
| 783 | for group in build_targets_dict.get(board): |
| 784 | joined_board_strings = '_'.join(dut.board for dut in group) |
| 785 | build_tag = '%s_%s' % (joined_board_strings, cros_build) |
| 786 | primary_dut = group[0] |
| 787 | if primary_dut.model: |
| 788 | if primary_dut.model != passed_model: |
| 789 | # Explict model specified but not match, so skip to next. |
| 790 | continue |
| 791 | elif build_tag in model_agnostic_builds: |
| 792 | msg = ("Skip model %s as any_model enabled for this job." |
| 793 | % passed_model) |
| 794 | self.job_section.add_schedule_job(board, passed_model, msg=msg) |
| 795 | continue |
| 796 | |
Garry Wang | 4e29b51 | 2021-08-26 19:32:59 -0700 | [diff] [blame] | 797 | # Determine cros builds for secondary DUTs from recent build dict. |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 798 | secondary_targets = [] |
| 799 | for s_dut in group[1:]: |
Garry Wang | 6ca42dd | 2022-02-28 21:54:19 -0800 | [diff] [blame^] | 800 | if s_dut.board in android_boards_list: |
| 801 | # We don't need to provision Android devices for CrOS test. |
| 802 | secondary_targets.append( |
| 803 | BuildTarget(s_dut.board, s_dut.model, None)) |
| 804 | continue |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 805 | s_key = (s_dut.board, None, build_type, milestone) |
Garry Wang | 4e29b51 | 2021-08-26 19:32:59 -0700 | [diff] [blame] | 806 | s_manifest = recent_build_dict.get(s_key, '') |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 807 | if s_manifest: |
| 808 | s_cros_build = str(build_lib.CrOSBuild( |
| 809 | s_dut.board, build_type, milestone, s_manifest)) |
| 810 | s_hwtest_board = build_lib.reshape_board(s_dut.board) |
| 811 | secondary_targets.append( |
| 812 | BuildTarget(s_hwtest_board, s_dut.model, s_cros_build)) |
| 813 | # Check if we get cros build for all secondary DUTs. |
| 814 | if len(secondary_targets) != len(group[1:]): |
| 815 | logging.info('Cannot determine cros version for all secondary' |
| 816 | ' DUTs, skip.') |
| 817 | continue |
| 818 | |
| 819 | # Schedule task. |
| 820 | model_agnostic_builds.add(build_tag) |
| 821 | task_id = str(uuid.uuid1()) |
| 822 | self._push_suite( |
| 823 | task_id = task_id, |
| 824 | board=hwtest_board, |
| 825 | model=primary_dut.model, |
| 826 | cros_build=cros_build, |
| 827 | test_source_build=cros_build, |
| 828 | secondary_targets=secondary_targets |
| 829 | ) |
| 830 | |
| 831 | # Analytics table stores the build target instead of the lab board. |
| 832 | self.job_section.add_schedule_job( |
| 833 | board, primary_dut.model, task_id=task_id) |
| 834 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 835 | def _schedule_launch_control_builds(self, launch_control_builds): |
| 836 | """Schedule tasks with launch control builds. |
| 837 | |
| 838 | Args: |
| 839 | launch_control_builds: the build dict for Android boards. |
| 840 | """ |
| 841 | for board, launch_control_build in launch_control_builds.iteritems(): |
| 842 | logging.debug('Running %s on %s', self.name, board) |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 843 | if self.exclude_boards and board in self.exclude_boards: |
| 844 | logging.debug('Board %s is in excluded board list: %s', |
| 845 | board, self.exclude_boards) |
| 846 | continue |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 847 | if self.boards and board not in self.boards: |
| 848 | logging.debug('Board %s is not in supported board list: %s', |
| 849 | board, self.boards) |
| 850 | continue |
| 851 | |
| 852 | for android_build in launch_control_build: |
| 853 | if not any([branch in android_build |
| 854 | for branch in self.launch_control_branches]): |
| 855 | logging.debug('Branch %s is not required to run for task ' |
| 856 | '%s', android_build, self.name) |
| 857 | continue |
| 858 | |
| 859 | self._push_suite(board=board, |
| 860 | test_source_build=android_build, |
| 861 | launch_control_build=android_build) |
| 862 | |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 863 | def _get_multi_duts_build_targets_dict(self, configs): |
| 864 | """Generate a dict contains all build targets info based on |
| 865 | self.multi_dut_boards or self.multi_dut_models. |
| 866 | |
| 867 | Args: |
| 868 | configs: A config_reader.Configs object. |
| 869 | |
| 870 | Returns: |
| 871 | A dict where key is a cros board, and value is a list that represents |
| 872 | group of DUTs where primary DUT's board equal to key. Each group of |
| 873 | DUTs are represented by a list of BuildTarget. Example: |
| 874 | { |
| 875 | 'coral': [ |
| 876 | [ |
| 877 | BuildTarget(board='coral', model='babytiger', cros_build=None), |
| 878 | BuildTarget(board='eve', model=None, cros_build=None), |
| 879 | BuildTarget(board='nami', model='None', cros_build=None) |
| 880 | ], |
| 881 | [ |
| 882 | BuildTarget(board='coral', model='blacktiplte', cros_build=None), |
| 883 | BuildTarget(board='octopus', model=None, cros_build=None), |
| 884 | BuildTarget(board='nami', model=None, cros_build=None)], |
| 885 | ] |
| 886 | ] |
| 887 | } |
| 888 | """ |
| 889 | lab_config = configs.lab_config |
| 890 | build_targets = defaultdict(lambda: []) |
Garry Wang | 6ca42dd | 2022-02-28 21:54:19 -0800 | [diff] [blame^] | 891 | cros_models_by_board = lab_config.get_cros_model_map() if lab_config else {} |
| 892 | android_models_by_board = lab_config.get_android_model_map() if lab_config else {} |
| 893 | model_to_board_dict = self._model_to_board_dict(cros_models_by_board) |
| 894 | # Multi-DUTs support Android as secondary devices, so we need to update |
| 895 | # the dict to include Android boards/models. |
| 896 | model_to_board_dict.update(self._model_to_board_dict(android_models_by_board)) |
| 897 | |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 898 | # Handle the case when multi-DUTs testing requested by board. |
| 899 | for group in self.multi_dut_boards: |
| 900 | primary_board = group[0] |
| 901 | if self.any_model: |
| 902 | new_group = [BuildTarget(board, None, None) for board in group] |
| 903 | build_targets[primary_board].append(new_group) |
| 904 | else: |
| 905 | # If any_model disbled, we need to have each model from primary_board |
| 906 | # family pair with requested secondary devices. |
| 907 | # Board above is used as build target to control the CrOS image. |
| 908 | # The following part is to assign models for lab boards, where |
| 909 | # the suffix should be removed. |
| 910 | hwtest_board = build_lib.reshape_board(primary_board) |
Garry Wang | 6ca42dd | 2022-02-28 21:54:19 -0800 | [diff] [blame^] | 911 | models = cros_models_by_board.get(hwtest_board, [None]) |
Garry Wang | dce7757 | 2021-07-18 19:33:35 -0700 | [diff] [blame] | 912 | for model in models: |
| 913 | if self.exclude_models and model in self.exclude_models: |
| 914 | logging.info('Model %s is in exclude list, skipping.' % model) |
| 915 | continue |
| 916 | new_group = [] |
| 917 | new_group.append(BuildTarget(primary_board, model, None)) |
| 918 | for board in group[1:]: |
| 919 | new_group.append(BuildTarget(board, None, None)) |
| 920 | build_targets[primary_board].append(new_group) |
| 921 | # Handle the case when multi-DUTs testing requested by model. |
| 922 | for group in self.multi_dut_models: |
| 923 | boards = [model_to_board_dict.get(model, '') for model in group] |
| 924 | if '' in boards: |
| 925 | logging.info('Cannot find board name from one of requested model,' |
| 926 | ' skipping.') |
| 927 | continue |
| 928 | new_group = [BuildTarget(boards[i], group[i], None) for i in range(len(group))] |
| 929 | build_targets[boards[0]].append(new_group) |
| 930 | return build_targets |
| 931 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 932 | |
| 933 | def _pick_branch(build_type, milestone): |
| 934 | """Select branch based on build type. |
| 935 | |
| 936 | If the build_type is a bare branch, return build_type as the build spec. |
| 937 | If the build_type is a normal CrOS branch, return milestone as the build |
| 938 | spec. |
| 939 | |
| 940 | Args: |
| 941 | build_type: a string builder name, like 'release'. |
| 942 | milestone: a string milestone, like '55'. |
| 943 | |
| 944 | Returns: |
| 945 | A string milestone if build_type represents CrOS build, otherwise |
| 946 | return build_type. |
| 947 | """ |
| 948 | 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] | 949 | |
| 950 | |
| 951 | def _split_unibuilds(build_dict, configs): |
| 952 | """Split the uni-builds to all models under a board. |
| 953 | |
| 954 | Args: |
| 955 | build_dict: the build dict for ChromeOS boards, see return |
Xinan Lin | ea1efcb | 2019-12-30 23:46:42 -0800 | [diff] [blame] | 956 | value of |build_lib.get_cros_builds|. |
Xinan Lin | ae7d637 | 2019-09-12 14:42:10 -0700 | [diff] [blame] | 957 | configs: a config_reader.Configs object. |
| 958 | |
| 959 | Returns: |
| 960 | A build dict. |
| 961 | """ |
| 962 | models_by_board = configs.lab_config.get_cros_model_map() |
| 963 | if not models_by_board: |
| 964 | return build_dict |
| 965 | all_branch_build_dict = {} |
| 966 | for (board, model, config, milestone), platform in build_dict.iteritems(): |
| 967 | uni_build_models = models_by_board.get(board) |
| 968 | if uni_build_models is not None and model is None: |
| 969 | for uni_build_model in uni_build_models: |
| 970 | model_key = (board, uni_build_model, config, milestone) |
| 971 | _add_build_dict(all_branch_build_dict, model_key, platform) |
| 972 | continue |
| 973 | build_key = (board, model, config, milestone) |
| 974 | _add_build_dict(all_branch_build_dict, build_key, platform) |
| 975 | |
| 976 | return all_branch_build_dict |
| 977 | |
| 978 | |
| 979 | def _add_build_dict(build_dict, key, value): |
| 980 | """A wrapper to add or update an item in build_dict.""" |
| 981 | cur_manifest = build_dict.get(key) |
| 982 | if cur_manifest is None: |
| 983 | build_dict[key] = value |
| 984 | return |
| 985 | build_dict[key] = max( |
| 986 | [cur_manifest, value], key=version.LooseVersion) |