Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 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 | |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 5 | |
Prashanth Balasubramanian | 1b85962 | 2014-10-28 16:02:15 -0700 | [diff] [blame] | 6 | import logging |
| 7 | import re |
| 8 | import subprocess |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 9 | |
| 10 | import base_event |
Aviv Keshet | d83ef44 | 2013-01-16 16:19:35 -0800 | [diff] [blame] | 11 | import deduping_scheduler |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 12 | import driver |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 13 | import manifest_versions |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 14 | from distutils import version |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 15 | from constants import Labels |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 16 | from constants import Builds |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 17 | |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 18 | import common |
Dan Shi | 648ce92 | 2016-03-26 00:22:47 -0700 | [diff] [blame] | 19 | from autotest_lib.client.common_lib import global_config |
Fang Deng | f08814a | 2015-08-03 18:12:18 +0000 | [diff] [blame] | 20 | from autotest_lib.server import utils as server_utils |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 21 | from autotest_lib.server.cros.dynamic_suite import constants |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 22 | |
Dan Shi | 648ce92 | 2016-03-26 00:22:47 -0700 | [diff] [blame] | 23 | |
| 24 | CONFIG = global_config.global_config |
| 25 | |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 26 | OS_TYPE_CROS = 'cros' |
| 27 | OS_TYPE_BRILLO = 'brillo' |
| 28 | OS_TYPE_ANDROID = 'android' |
| 29 | OS_TYPES = {OS_TYPE_CROS, OS_TYPE_BRILLO, OS_TYPE_ANDROID} |
| 30 | OS_TYPES_LAUNCH_CONTROL = {OS_TYPE_BRILLO, OS_TYPE_ANDROID} |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 31 | |
Dan Shi | 481b8b6 | 2016-03-08 13:03:08 -0800 | [diff] [blame] | 32 | _WEEKDAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', |
| 33 | 'Sunday'] |
| 34 | |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 35 | # regex to parse the dut count from board label. Note that the regex makes sure |
| 36 | # there is only one board specified in `boards` |
| 37 | TESTBED_DUT_COUNT_REGEX = '[^,]*-(\d+)' |
| 38 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 39 | class MalformedConfigEntry(Exception): |
| 40 | """Raised to indicate a failure to parse a Task out of a config.""" |
| 41 | pass |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 42 | |
| 43 | |
Alex Miller | 0d00357 | 2013-03-18 11:51:30 -0700 | [diff] [blame] | 44 | BARE_BRANCHES = ['factory', 'firmware'] |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 45 | |
| 46 | |
| 47 | def PickBranchName(type, milestone): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 48 | """Pick branch name. If type is among BARE_BRANCHES, return type, |
| 49 | otherwise, return milestone. |
| 50 | |
| 51 | @param type: type of the branch, e.g., 'release', 'factory', or 'firmware' |
| 52 | @param milestone: CrOS milestone number |
| 53 | """ |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 54 | if type in BARE_BRANCHES: |
| 55 | return type |
| 56 | return milestone |
| 57 | |
| 58 | |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 59 | class TotMilestoneManager(object): |
| 60 | """A class capable of converting tot string to milestone numbers. |
| 61 | |
| 62 | This class is used as a cache for the tot milestone, so we don't |
| 63 | repeatedly hit google storage for all O(100) tasks in suite |
| 64 | scheduler's ini file. |
| 65 | """ |
| 66 | |
Fang Deng | f08814a | 2015-08-03 18:12:18 +0000 | [diff] [blame] | 67 | __metaclass__ = server_utils.Singleton |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 68 | |
Dan Shi | 2324514 | 2015-01-22 13:22:28 -0800 | [diff] [blame] | 69 | # True if suite_scheduler is running for sanity check. When it's set to |
| 70 | # True, the code won't make gsutil call to get the actual tot milestone to |
| 71 | # avoid dependency on the installation of gsutil to run sanity check. |
| 72 | is_sanity = False |
| 73 | |
| 74 | |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 75 | @staticmethod |
| 76 | def _tot_milestone(): |
| 77 | """Get the tot milestone, eg: R40 |
| 78 | |
| 79 | @returns: A string representing the Tot milestone as declared by |
| 80 | the LATEST_BUILD_URL, or an empty string if LATEST_BUILD_URL |
| 81 | doesn't exist. |
| 82 | """ |
Dan Shi | 2324514 | 2015-01-22 13:22:28 -0800 | [diff] [blame] | 83 | if TotMilestoneManager.is_sanity: |
| 84 | logging.info('suite_scheduler is running for sanity purpose, no ' |
| 85 | 'need to get the actual tot milestone string.') |
| 86 | return 'R40' |
| 87 | |
Prashanth Balasubramanian | 1b85962 | 2014-10-28 16:02:15 -0700 | [diff] [blame] | 88 | cmd = ['gsutil', 'cat', constants.LATEST_BUILD_URL] |
| 89 | proc = subprocess.Popen( |
| 90 | cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 91 | stdout, stderr = proc.communicate() |
| 92 | if proc.poll(): |
| 93 | logging.warning('Failed to get latest build: %s', stderr) |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 94 | return '' |
Prashanth Balasubramanian | 1b85962 | 2014-10-28 16:02:15 -0700 | [diff] [blame] | 95 | return stdout.split('-')[0] |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 96 | |
| 97 | |
| 98 | def refresh(self): |
| 99 | """Refresh the tot milestone string managed by this class.""" |
| 100 | self.tot = self._tot_milestone() |
| 101 | |
| 102 | |
| 103 | def __init__(self): |
| 104 | """Initialize a TotMilestoneManager.""" |
| 105 | self.refresh() |
| 106 | |
| 107 | |
| 108 | def ConvertTotSpec(self, tot_spec): |
| 109 | """Converts a tot spec to the appropriate milestone. |
| 110 | |
| 111 | Assume tot is R40: |
| 112 | tot -> R40 |
| 113 | tot-1 -> R39 |
| 114 | tot-2 -> R38 |
| 115 | tot-(any other numbers) -> R40 |
| 116 | |
| 117 | With the last option one assumes that a malformed configuration that has |
| 118 | 'tot' in it, wants at least tot. |
| 119 | |
| 120 | @param tot_spec: A string representing the tot spec. |
| 121 | @raises MalformedConfigEntry: If the tot_spec doesn't match the |
| 122 | expected format. |
| 123 | """ |
| 124 | tot_spec = tot_spec.lower() |
| 125 | match = re.match('(tot)[-]?(1$|2$)?', tot_spec) |
| 126 | if not match: |
| 127 | raise MalformedConfigEntry( |
| 128 | "%s isn't a valid branch spec." % tot_spec) |
| 129 | tot_mstone = self.tot |
| 130 | num_back = match.groups()[1] |
| 131 | if num_back: |
| 132 | tot_mstone_num = tot_mstone.lstrip('R') |
| 133 | tot_mstone = tot_mstone.replace( |
| 134 | tot_mstone_num, str(int(tot_mstone_num)-int(num_back))) |
| 135 | return tot_mstone |
| 136 | |
| 137 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 138 | class Task(object): |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 139 | """Represents an entry from the scheduler config. Can schedule itself. |
| 140 | |
| 141 | Each entry from the scheduler config file maps one-to-one to a |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 142 | Task. Each instance has enough info to schedule itself |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 143 | on-demand with the AFE. |
| 144 | |
Aviv Keshet | 52c7a21 | 2015-12-07 15:27:22 -0800 | [diff] [blame] | 145 | This class also overrides __hash__() and all comparator methods to enable |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 146 | correct use in dicts, sets, etc. |
| 147 | """ |
| 148 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 149 | |
| 150 | @staticmethod |
| 151 | def CreateFromConfigSection(config, section): |
| 152 | """Create a Task from a section of a config file. |
| 153 | |
| 154 | The section to parse should look like this: |
| 155 | [TaskName] |
| 156 | suite: suite_to_run # Required |
| 157 | run_on: event_on which to run # Required |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 158 | hour: integer of the hour to run, only applies to nightly. # Optional |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 159 | branch_specs: factory,firmware,>=R12 or ==R12 # Optional |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 160 | pool: pool_of_devices # Optional |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 161 | num: sharding_factor # int, Optional |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 162 | boards: board1, board2 # comma seperated string, Optional |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 163 | # Settings for Launch Control builds only: |
| 164 | os_type: brillo # Type of OS, e.g., cros, brillo, android. Default is |
| 165 | cros. Required for android/brillo builds. |
| 166 | branches: git_mnc_release # comma separated string of Launch Control |
| 167 | branches. Required and only applicable for android/brillo |
| 168 | builds. |
| 169 | targets: dragonboard-eng # comma separated string of build targets. |
| 170 | Required and only applicable for android/brillo builds. |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 171 | testbed_dut_count: Number of duts to test when using a testbed. |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 172 | |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 173 | By default, Tasks run on all release branches, not factory or firmware. |
| 174 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 175 | @param config: a ForgivingConfigParser. |
| 176 | @param section: the section to parse into a Task. |
| 177 | @return keyword, Task object pair. One or both will be None on error. |
| 178 | @raise MalformedConfigEntry if there's a problem parsing |section|. |
| 179 | """ |
Alex Miller | 0669502 | 2012-07-18 09:31:36 -0700 | [diff] [blame] | 180 | if not config.has_section(section): |
| 181 | raise MalformedConfigEntry('unknown section %s' % section) |
| 182 | |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 183 | allowed = set(['suite', 'run_on', 'branch_specs', 'pool', 'num', |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 184 | 'boards', 'file_bugs', 'cros_build_spec', |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 185 | 'firmware_rw_build_spec', 'firmware_ro_build_spec', |
| 186 | 'test_source', 'job_retry', 'hour', 'day', 'branches', |
Dan Shi | 1d0e639 | 2016-10-26 13:02:37 -0700 | [diff] [blame^] | 187 | 'targets', 'os_type', 'no_delay']) |
Alex Miller | bb535e2 | 2012-07-11 20:11:33 -0700 | [diff] [blame] | 188 | # The parameter of union() is the keys under the section in the config |
| 189 | # The union merges this with the allowed set, so if any optional keys |
| 190 | # are omitted, then they're filled in. If any extra keys are present, |
| 191 | # then they will expand unioned set, causing it to fail the following |
| 192 | # comparison against the allowed set. |
| 193 | section_headers = allowed.union(dict(config.items(section)).keys()) |
| 194 | if allowed != section_headers: |
| 195 | raise MalformedConfigEntry('unknown entries: %s' % |
| 196 | ", ".join(map(str, section_headers.difference(allowed)))) |
| 197 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 198 | keyword = config.getstring(section, 'run_on') |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 199 | hour = config.getstring(section, 'hour') |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 200 | suite = config.getstring(section, 'suite') |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 201 | branch_specs = config.getstring(section, 'branch_specs') |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 202 | pool = config.getstring(section, 'pool') |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 203 | boards = config.getstring(section, 'boards') |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 204 | file_bugs = config.getboolean(section, 'file_bugs') |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 205 | cros_build_spec = config.getstring(section, 'cros_build_spec') |
| 206 | firmware_rw_build_spec = config.getstring( |
| 207 | section, 'firmware_rw_build_spec') |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 208 | firmware_ro_build_spec = config.getstring( |
| 209 | section, 'firmware_ro_build_spec') |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 210 | test_source = config.getstring(section, 'test_source') |
Dan Shi | 29a1699 | 2015-09-22 11:29:58 -0700 | [diff] [blame] | 211 | job_retry = config.getboolean(section, 'job_retry') |
Dan Shi | 1d0e639 | 2016-10-26 13:02:37 -0700 | [diff] [blame^] | 212 | no_delay = config.getboolean(section, 'no_delay') |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 213 | for klass in driver.Driver.EVENT_CLASSES: |
| 214 | if klass.KEYWORD == keyword: |
| 215 | priority = klass.PRIORITY |
| 216 | timeout = klass.TIMEOUT |
| 217 | break |
| 218 | else: |
| 219 | priority = None |
| 220 | timeout = None |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 221 | try: |
| 222 | num = config.getint(section, 'num') |
| 223 | except ValueError as e: |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 224 | raise MalformedConfigEntry("Ill-specified 'num': %r" % e) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 225 | if not keyword: |
| 226 | raise MalformedConfigEntry('No event to |run_on|.') |
| 227 | if not suite: |
| 228 | raise MalformedConfigEntry('No |suite|') |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 229 | try: |
| 230 | hour = config.getint(section, 'hour') |
| 231 | except ValueError as e: |
| 232 | raise MalformedConfigEntry("Ill-specified 'hour': %r" % e) |
| 233 | if hour is not None and (hour < 0 or hour > 23): |
| 234 | raise MalformedConfigEntry( |
| 235 | '`hour` must be an integer between 0 and 23.') |
| 236 | if hour is not None and keyword != 'nightly': |
| 237 | raise MalformedConfigEntry( |
| 238 | '`hour` is the trigger time that can only apply to nightly ' |
| 239 | 'event.') |
Dan Shi | ce1f20a | 2016-01-25 17:27:40 -0800 | [diff] [blame] | 240 | |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 241 | testbed_dut_count = None |
Dan Shi | eb014bc | 2016-10-10 10:20:57 -0700 | [diff] [blame] | 242 | if boards: |
| 243 | match = re.match(TESTBED_DUT_COUNT_REGEX, boards) |
| 244 | if match: |
| 245 | testbed_dut_count = int(match.group(1)) |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 246 | |
Dan Shi | ce1f20a | 2016-01-25 17:27:40 -0800 | [diff] [blame] | 247 | try: |
| 248 | day = config.getint(section, 'day') |
| 249 | except ValueError as e: |
| 250 | raise MalformedConfigEntry("Ill-specified 'day': %r" % e) |
| 251 | if day is not None and (day < 0 or day > 6): |
| 252 | raise MalformedConfigEntry( |
| 253 | '`day` must be an integer between 0 and 6, where 0 is for ' |
| 254 | 'Monday and 6 is for Sunday.') |
| 255 | if day is not None and keyword != 'weekly': |
| 256 | raise MalformedConfigEntry( |
| 257 | '`day` is the trigger of the day of a week, that can only ' |
| 258 | 'apply to weekly events.') |
| 259 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 260 | specs = [] |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 261 | if branch_specs: |
| 262 | specs = re.split('\s*,\s*', branch_specs) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 263 | Task.CheckBranchSpecs(specs) |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 264 | |
| 265 | os_type = config.getstring(section, 'os_type') or OS_TYPE_CROS |
| 266 | if os_type not in OS_TYPES: |
| 267 | raise MalformedConfigEntry('`os_type` must be one of %s' % OS_TYPES) |
| 268 | |
| 269 | lc_branches = config.getstring(section, 'branches') |
| 270 | lc_targets = config.getstring(section, 'targets') |
| 271 | if os_type == OS_TYPE_CROS and (lc_branches or lc_targets): |
| 272 | raise MalformedConfigEntry( |
| 273 | '`branches` and `targets` are only supported for Launch ' |
| 274 | 'Control builds, not ChromeOS builds.') |
| 275 | if (os_type in OS_TYPES_LAUNCH_CONTROL and |
| 276 | (not lc_branches or not lc_targets)): |
| 277 | raise MalformedConfigEntry( |
| 278 | '`branches` and `targets` must be specified for Launch ' |
| 279 | 'Control builds.') |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 280 | if (os_type in OS_TYPES_LAUNCH_CONTROL and boards and |
| 281 | not testbed_dut_count): |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 282 | raise MalformedConfigEntry( |
| 283 | '`boards` for Launch Control builds are retrieved from ' |
| 284 | '`targets` setting, it should not be set for Launch ' |
| 285 | 'Control builds.') |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 286 | if os_type == OS_TYPE_CROS and testbed_dut_count: |
| 287 | raise MalformedConfigEntry( |
| 288 | 'testbed_dut_count is only supported for Launch Control ' |
| 289 | 'builds testing with testbed.') |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 290 | |
| 291 | # Extract boards from targets list. |
| 292 | if os_type in OS_TYPES_LAUNCH_CONTROL: |
| 293 | boards = '' |
| 294 | for target in lc_targets.split(','): |
| 295 | board_name, _ = server_utils.parse_launch_control_target( |
| 296 | target.strip()) |
Dan Shi | 8db7e61 | 2016-07-21 12:55:16 -0700 | [diff] [blame] | 297 | boards += '%s,' % board_name |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 298 | boards = boards.strip(',') |
| 299 | |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 300 | return keyword, Task(section, suite, specs, pool, num, boards, |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 301 | priority, timeout, |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 302 | file_bugs=file_bugs if file_bugs else False, |
| 303 | cros_build_spec=cros_build_spec, |
| 304 | firmware_rw_build_spec=firmware_rw_build_spec, |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 305 | firmware_ro_build_spec=firmware_ro_build_spec, |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 306 | test_source=test_source, job_retry=job_retry, |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 307 | hour=hour, day=day, os_type=os_type, |
| 308 | launch_control_branches=lc_branches, |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 309 | launch_control_targets=lc_targets, |
Dan Shi | 1d0e639 | 2016-10-26 13:02:37 -0700 | [diff] [blame^] | 310 | testbed_dut_count=testbed_dut_count, |
| 311 | no_delay=no_delay) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 312 | |
| 313 | |
| 314 | @staticmethod |
| 315 | def CheckBranchSpecs(branch_specs): |
| 316 | """Make sure entries in the list branch_specs are correctly formed. |
| 317 | |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 318 | We accept any of BARE_BRANCHES in |branch_specs|, as |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 319 | well as _one_ string of the form '>=RXX' or '==RXX', where 'RXX' is a |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 320 | CrOS milestone number. |
| 321 | |
| 322 | @param branch_specs: an iterable of branch specifiers. |
| 323 | @raise MalformedConfigEntry if there's a problem parsing |branch_specs|. |
| 324 | """ |
| 325 | have_seen_numeric_constraint = False |
| 326 | for branch in branch_specs: |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 327 | if branch in BARE_BRANCHES: |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 328 | continue |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 329 | if not have_seen_numeric_constraint: |
| 330 | #TODO(beeps): Why was <= dropped on the floor? |
| 331 | if branch.startswith('>=R') or branch.startswith('==R'): |
| 332 | have_seen_numeric_constraint = True |
| 333 | elif 'tot' in branch: |
| 334 | TotMilestoneManager().ConvertTotSpec( |
| 335 | branch[branch.index('tot'):]) |
| 336 | have_seen_numeric_constraint = True |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 337 | continue |
Chris Masone | 97cf0a7 | 2012-05-16 09:55:52 -0700 | [diff] [blame] | 338 | raise MalformedConfigEntry("%s isn't a valid branch spec." % branch) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 339 | |
| 340 | |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 341 | def __init__(self, name, suite, branch_specs, pool=None, num=None, |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 342 | boards=None, priority=None, timeout=None, file_bugs=False, |
| 343 | cros_build_spec=None, firmware_rw_build_spec=None, |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 344 | firmware_ro_build_spec=None, test_source=None, job_retry=False, |
| 345 | hour=None, day=None, os_type=OS_TYPE_CROS, |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 346 | launch_control_branches=None, launch_control_targets=None, |
Dan Shi | 1d0e639 | 2016-10-26 13:02:37 -0700 | [diff] [blame^] | 347 | testbed_dut_count=None, no_delay=False): |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 348 | """Constructor |
| 349 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 350 | Given an iterable in |branch_specs|, pre-vetted using CheckBranchSpecs, |
| 351 | we'll store them such that _FitsSpec() can be used to check whether a |
| 352 | given branch 'fits' with the specifications passed in here. |
| 353 | For example, given branch_specs = ['factory', '>=R18'], we'd set things |
| 354 | up so that _FitsSpec() would return True for 'factory', or 'RXX' |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 355 | where XX is a number >= 18. Same check is done for branch_specs = [ |
| 356 | 'factory', '==R18'], which limit the test to only one specific branch. |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 357 | |
| 358 | Given branch_specs = ['factory', 'firmware'], _FitsSpec() |
| 359 | would pass only those two specific strings. |
| 360 | |
| 361 | Example usage: |
Chris Masone | cc4631d | 2012-04-20 12:06:39 -0700 | [diff] [blame] | 362 | t = Task('Name', 'suite', ['factory', '>=R18']) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 363 | t._FitsSpec('factory') # True |
| 364 | t._FitsSpec('R19') # True |
| 365 | t._FitsSpec('R17') # False |
| 366 | t._FitsSpec('firmware') # False |
| 367 | t._FitsSpec('goober') # False |
| 368 | |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 369 | t = Task('Name', 'suite', ['factory', '==R18']) |
| 370 | t._FitsSpec('R19') # False, branch does not equal to 18 |
| 371 | t._FitsSpec('R18') # True |
| 372 | t._FitsSpec('R17') # False |
| 373 | |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 374 | cros_build_spec and firmware_rw_build_spec are set for tests require |
| 375 | firmware update on the dut. Only one of them can be set. |
| 376 | For example: |
| 377 | branch_specs: ==tot |
| 378 | firmware_rw_build_spec: firmware |
| 379 | test_source: cros |
| 380 | This will run test using latest build on firmware branch, and the latest |
| 381 | ChromeOS build on ToT. The test source build is ChromeOS build. |
| 382 | |
| 383 | branch_specs: firmware |
| 384 | cros_build_spec: ==tot-1 |
| 385 | test_source: firmware_rw |
| 386 | This will run test using latest build on firmware branch, and the latest |
| 387 | ChromeOS build on dev channel (ToT-1). The test source build is the |
| 388 | firmware RW build. |
| 389 | |
Dan Shi | 59562a8 | 2016-01-06 16:05:31 -0800 | [diff] [blame] | 390 | branch_specs: ==tot |
| 391 | firmware_rw_build_spec: cros |
| 392 | test_source: cros |
| 393 | This will run test using latest ChromeOS and firmware RW build on ToT. |
| 394 | ChromeOS build on ToT. The test source build is ChromeOS build. |
| 395 | |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 396 | @param name: name of this task, e.g. 'NightlyPower' |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 397 | @param suite: the name of the suite to run, e.g. 'bvt' |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 398 | @param branch_specs: a pre-vetted iterable of branch specifiers, |
| 399 | e.g. ['>=R18', 'factory'] |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 400 | @param pool: the pool of machines to use for scheduling purposes. |
| 401 | Default: None |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 402 | @param num: the number of devices across which to shard the test suite. |
Aviv Keshet | d83ef44 | 2013-01-16 16:19:35 -0800 | [diff] [blame] | 403 | Type: integer or None |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 404 | Default: None |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 405 | @param boards: A comma separated list of boards to run this task on. |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 406 | Default: Run on all boards. |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 407 | @param priority: The string name of a priority from |
| 408 | client.common_lib.priorities.Priority. |
| 409 | @param timeout: The max lifetime of the suite in hours. |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 410 | @param file_bugs: True if bug filing is desired for the suite created |
| 411 | for this task. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 412 | @param cros_build_spec: Spec used to determine the ChromeOS build to |
| 413 | test with a firmware build, e.g., tot, R41 etc. |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 414 | @param firmware_rw_build_spec: Spec used to determine the firmware RW |
| 415 | build test with a ChromeOS build. |
| 416 | @param firmware_ro_build_spec: Spec used to determine the firmware RO |
| 417 | build test with a ChromeOS build. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 418 | @param test_source: The source of test code when firmware will be |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 419 | updated in the test. The value can be `firmware_rw`, |
| 420 | `firmware_ro` or `cros`. |
Dan Shi | 29a1699 | 2015-09-22 11:29:58 -0700 | [diff] [blame] | 421 | @param job_retry: Set to True to enable job-level retry. Default is |
| 422 | False. |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 423 | @param hour: An integer specifying the hour that a nightly run should |
| 424 | be triggered, default is set to 21. |
Dan Shi | ce1f20a | 2016-01-25 17:27:40 -0800 | [diff] [blame] | 425 | @param day: An integer specifying the day of a week that a weekly run |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 426 | should be triggered, default is set to 5, which is Saturday. |
| 427 | @param os_type: Type of OS, e.g., cros, brillo, android. Default is |
| 428 | cros. The argument is required for android/brillo builds. |
| 429 | @param launch_control_branches: Comma separated string of Launch Control |
| 430 | branches. The argument is required and only applicable for |
| 431 | android/brillo builds. |
| 432 | @param launch_control_targets: Comma separated string of build targets |
| 433 | for Launch Control builds. The argument is required and only |
| 434 | applicable for android/brillo builds. |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 435 | @param testbed_dut_count: Number of duts to test when using a testbed. |
Dan Shi | 1d0e639 | 2016-10-26 13:02:37 -0700 | [diff] [blame^] | 436 | @param no_delay: Set to True to allow suite to be created without |
| 437 | configuring delay_minutes. Default is False. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 438 | """ |
Chris Masone | cc4631d | 2012-04-20 12:06:39 -0700 | [diff] [blame] | 439 | self._name = name |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 440 | self._suite = suite |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 441 | self._branch_specs = branch_specs |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 442 | self._pool = pool |
Aviv Keshet | d83ef44 | 2013-01-16 16:19:35 -0800 | [diff] [blame] | 443 | self._num = num |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 444 | self._priority = priority |
| 445 | self._timeout = timeout |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 446 | self._file_bugs = file_bugs |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 447 | self._cros_build_spec = cros_build_spec |
| 448 | self._firmware_rw_build_spec = firmware_rw_build_spec |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 449 | self._firmware_ro_build_spec = firmware_ro_build_spec |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 450 | self._test_source = test_source |
Dan Shi | 29a1699 | 2015-09-22 11:29:58 -0700 | [diff] [blame] | 451 | self._job_retry = job_retry |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 452 | self._hour = hour |
| 453 | self._day = day |
| 454 | self._os_type = os_type |
| 455 | self._launch_control_branches = ( |
| 456 | [b.strip() for b in launch_control_branches.split(',')] |
| 457 | if launch_control_branches else []) |
| 458 | self._launch_control_targets = ( |
| 459 | [t.strip() for t in launch_control_targets.split(',')] |
| 460 | if launch_control_targets else []) |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 461 | self._testbed_dut_count = testbed_dut_count |
Dan Shi | 1d0e639 | 2016-10-26 13:02:37 -0700 | [diff] [blame^] | 462 | self._no_delay = no_delay |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 463 | |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 464 | if ((self._firmware_rw_build_spec or self._firmware_ro_build_spec or |
| 465 | cros_build_spec) and |
| 466 | not self.test_source in [Builds.FIRMWARE_RW, Builds.FIRMWARE_RO, |
| 467 | Builds.CROS]): |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 468 | raise MalformedConfigEntry( |
| 469 | 'You must specify the build for test source. It can only ' |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 470 | 'be `firmware_rw`, `firmware_ro` or `cros`.') |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 471 | if self._firmware_rw_build_spec and cros_build_spec: |
| 472 | raise MalformedConfigEntry( |
| 473 | 'You cannot specify both firmware_rw_build_spec and ' |
| 474 | 'cros_build_spec. firmware_rw_build_spec is used to specify' |
| 475 | ' a firmware build when the suite requires firmware to be ' |
Dan Shi | 59562a8 | 2016-01-06 16:05:31 -0800 | [diff] [blame] | 476 | 'updated in the dut, its value can only be `firmware` or ' |
| 477 | '`cros`. cros_build_spec is used to specify a ChromeOS ' |
| 478 | 'build when build_specs is set to firmware.') |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 479 | if (self._firmware_rw_build_spec and |
Dan Shi | 59562a8 | 2016-01-06 16:05:31 -0800 | [diff] [blame] | 480 | self._firmware_rw_build_spec not in ['firmware', 'cros']): |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 481 | raise MalformedConfigEntry( |
Dan Shi | 59562a8 | 2016-01-06 16:05:31 -0800 | [diff] [blame] | 482 | 'firmware_rw_build_spec can only be empty, firmware or ' |
| 483 | 'cros. It does not support other build type yet.') |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 484 | |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 485 | if os_type not in OS_TYPES_LAUNCH_CONTROL and self._testbed_dut_count: |
| 486 | raise MalformedConfigEntry( |
| 487 | 'testbed_dut_count is only applicable to testbed to run ' |
| 488 | 'test with builds from Launch Control.') |
| 489 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 490 | self._bare_branches = [] |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 491 | self._version_equal_constraint = False |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 492 | self._version_gte_constraint = False |
| 493 | self._version_lte_constraint = False |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 494 | if not branch_specs: |
| 495 | # Any milestone is OK. |
| 496 | self._numeric_constraint = version.LooseVersion('0') |
| 497 | else: |
| 498 | self._numeric_constraint = None |
| 499 | for spec in branch_specs: |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 500 | if 'tot' in spec.lower(): |
| 501 | tot_str = spec[spec.index('tot'):] |
| 502 | spec = spec.replace( |
| 503 | tot_str, TotMilestoneManager().ConvertTotSpec( |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 504 | tot_str)) |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 505 | if spec.startswith('>='): |
| 506 | self._numeric_constraint = version.LooseVersion( |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 507 | spec.lstrip('>=R')) |
| 508 | self._version_gte_constraint = True |
| 509 | elif spec.startswith('<='): |
| 510 | self._numeric_constraint = version.LooseVersion( |
| 511 | spec.lstrip('<=R')) |
| 512 | self._version_lte_constraint = True |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 513 | elif spec.startswith('=='): |
| 514 | self._version_equal_constraint = True |
| 515 | self._numeric_constraint = version.LooseVersion( |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 516 | spec.lstrip('==R')) |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 517 | else: |
| 518 | self._bare_branches.append(spec) |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 519 | |
Aviv Keshet | 52c7a21 | 2015-12-07 15:27:22 -0800 | [diff] [blame] | 520 | # Since we expect __hash__() and other comparator methods to be used |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 521 | # frequently by set operations, and they use str() a lot, pre-compute |
| 522 | # the string representation of this object. |
Aviv Keshet | 8ce3c98 | 2013-01-24 09:23:13 -0800 | [diff] [blame] | 523 | if num is None: |
| 524 | numStr = '[Default num]' |
| 525 | else: |
| 526 | numStr = '%d' % num |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 527 | |
| 528 | if boards is None: |
| 529 | self._boards = set() |
| 530 | boardsStr = '[All boards]' |
| 531 | else: |
| 532 | self._boards = set([x.strip() for x in boards.split(',')]) |
| 533 | boardsStr = boards |
| 534 | |
Dan Shi | 481b8b6 | 2016-03-08 13:03:08 -0800 | [diff] [blame] | 535 | time_str = '' |
| 536 | if self._hour: |
| 537 | time_str = ' Run at %d:00.' % self._hour |
| 538 | elif self._day: |
| 539 | time_str = ' Run on %s.' % _WEEKDAYS[self._day] |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 540 | if os_type == OS_TYPE_CROS: |
| 541 | self._str = ('%s: %s on %s with pool %s, boards [%s], file_bugs = ' |
Dan Shi | 481b8b6 | 2016-03-08 13:03:08 -0800 | [diff] [blame] | 542 | '%s across %s machines.%s' % |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 543 | (self.__class__.__name__, suite, branch_specs, pool, |
Dan Shi | 481b8b6 | 2016-03-08 13:03:08 -0800 | [diff] [blame] | 544 | boardsStr, self._file_bugs, numStr, time_str)) |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 545 | else: |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 546 | testbed_dut_count_str = '.' |
| 547 | if self._testbed_dut_count: |
| 548 | testbed_dut_count_str = (', each with %d duts.' % |
| 549 | self._testbed_dut_count) |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 550 | self._str = ('%s: %s on branches %s and targets %s with pool %s, ' |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 551 | 'boards [%s], file_bugs = %s across %s machines%s%s' % |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 552 | (self.__class__.__name__, suite, |
| 553 | launch_control_branches, launch_control_targets, |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 554 | pool, boardsStr, self._file_bugs, numStr, |
| 555 | testbed_dut_count_str, time_str)) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 556 | |
| 557 | |
| 558 | def _FitsSpec(self, branch): |
| 559 | """Checks if a branch is deemed OK by this instance's branch specs. |
| 560 | |
| 561 | When called on a branch name, will return whether that branch |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 562 | 'fits' the specifications stored in self._bare_branches, |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 563 | self._numeric_constraint, self._version_equal_constraint, |
| 564 | self._version_gte_constraint and self._version_lte_constraint. |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 565 | |
| 566 | @param branch: the branch to check. |
| 567 | @return True if b 'fits' with stored specs, False otherwise. |
| 568 | """ |
Chris Masone | 657e155 | 2012-05-30 17:06:20 -0700 | [diff] [blame] | 569 | if branch in BARE_BRANCHES: |
| 570 | return branch in self._bare_branches |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 571 | if self._numeric_constraint: |
| 572 | if self._version_equal_constraint: |
| 573 | return version.LooseVersion(branch) == self._numeric_constraint |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 574 | elif self._version_gte_constraint: |
| 575 | return version.LooseVersion(branch) >= self._numeric_constraint |
| 576 | elif self._version_lte_constraint: |
| 577 | return version.LooseVersion(branch) <= self._numeric_constraint |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 578 | else: |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 579 | # Default to great or equal constraint. |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 580 | return version.LooseVersion(branch) >= self._numeric_constraint |
| 581 | else: |
| 582 | return False |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 583 | |
| 584 | |
| 585 | @property |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 586 | def name(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 587 | """Name of this task, e.g. 'NightlyPower'.""" |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 588 | return self._name |
| 589 | |
| 590 | |
| 591 | @property |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 592 | def suite(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 593 | """Name of the suite to run, e.g. 'bvt'.""" |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 594 | return self._suite |
| 595 | |
| 596 | |
| 597 | @property |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 598 | def branch_specs(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 599 | """a pre-vetted iterable of branch specifiers, |
| 600 | e.g. ['>=R18', 'factory'].""" |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 601 | return self._branch_specs |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 602 | |
| 603 | |
| 604 | @property |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 605 | def pool(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 606 | """The pool of machines to use for scheduling purposes.""" |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 607 | return self._pool |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 608 | |
| 609 | |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 610 | @property |
| 611 | def num(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 612 | """The number of devices across which to shard the test suite. |
| 613 | Type: integer or None""" |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 614 | return self._num |
| 615 | |
| 616 | |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 617 | @property |
| 618 | def boards(self): |
| 619 | """The boards on which to run this suite. |
| 620 | Type: Iterable of strings""" |
| 621 | return self._boards |
| 622 | |
| 623 | |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 624 | @property |
| 625 | def priority(self): |
| 626 | """The priority of the suite""" |
| 627 | return self._priority |
| 628 | |
| 629 | |
| 630 | @property |
| 631 | def timeout(self): |
| 632 | """The maximum lifetime of the suite in hours.""" |
| 633 | return self._timeout |
| 634 | |
| 635 | |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 636 | @property |
| 637 | def cros_build_spec(self): |
| 638 | """The build spec of ChromeOS to test with a firmware build.""" |
| 639 | return self._cros_build_spec |
| 640 | |
| 641 | |
| 642 | @property |
| 643 | def firmware_rw_build_spec(self): |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 644 | """The build spec of RW firmware to test with a ChromeOS build. |
| 645 | |
| 646 | The value can be firmware or cros. |
| 647 | """ |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 648 | return self._firmware_rw_build_spec |
| 649 | |
| 650 | |
| 651 | @property |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 652 | def firmware_ro_build_spec(self): |
| 653 | """The build spec of RO firmware to test with a ChromeOS build. |
| 654 | |
| 655 | The value can be stable, firmware or cros, where stable is the stable |
| 656 | firmware build retrieved from stable_version table. |
| 657 | """ |
| 658 | return self._firmware_ro_build_spec |
| 659 | |
| 660 | |
| 661 | @property |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 662 | def test_source(self): |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 663 | """Source of the test code, value can be `firmware_rw`, `firmware_ro` or |
| 664 | `cros`.""" |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 665 | return self._test_source |
| 666 | |
| 667 | |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 668 | @property |
| 669 | def hour(self): |
| 670 | """An integer specifying the hour that a nightly run should be triggered |
| 671 | """ |
| 672 | return self._hour |
| 673 | |
| 674 | |
| 675 | @property |
| 676 | def day(self): |
| 677 | """An integer specifying the day of a week that a weekly run should be |
| 678 | triggered""" |
| 679 | return self._day |
| 680 | |
| 681 | |
| 682 | @property |
| 683 | def os_type(self): |
| 684 | """Type of OS, e.g., cros, brillo, android.""" |
| 685 | return self._os_type |
| 686 | |
| 687 | |
| 688 | @property |
| 689 | def launch_control_branches(self): |
| 690 | """A list of Launch Control builds.""" |
| 691 | return self._launch_control_branches |
| 692 | |
| 693 | |
| 694 | @property |
| 695 | def launch_control_targets(self): |
| 696 | """A list of Launch Control targets.""" |
| 697 | return self._launch_control_targets |
| 698 | |
| 699 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 700 | def __str__(self): |
| 701 | return self._str |
| 702 | |
| 703 | |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 704 | def __repr__(self): |
| 705 | return self._str |
| 706 | |
| 707 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 708 | def __lt__(self, other): |
| 709 | return str(self) < str(other) |
| 710 | |
| 711 | |
| 712 | def __le__(self, other): |
| 713 | return str(self) <= str(other) |
| 714 | |
| 715 | |
| 716 | def __eq__(self, other): |
| 717 | return str(self) == str(other) |
| 718 | |
| 719 | |
| 720 | def __ne__(self, other): |
| 721 | return str(self) != str(other) |
| 722 | |
| 723 | |
| 724 | def __gt__(self, other): |
| 725 | return str(self) > str(other) |
| 726 | |
| 727 | |
| 728 | def __ge__(self, other): |
| 729 | return str(self) >= str(other) |
| 730 | |
| 731 | |
| 732 | def __hash__(self): |
| 733 | """Allows instances to be correctly deduped when used in a set.""" |
| 734 | return hash(str(self)) |
| 735 | |
| 736 | |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 737 | def _GetCrOSBuild(self, mv, board): |
| 738 | """Get the ChromeOS build name to test with firmware build. |
| 739 | |
| 740 | The ChromeOS build to be used is determined by `self.cros_build_spec`. |
| 741 | Its value can be: |
| 742 | tot: use the latest ToT build. |
| 743 | tot-x: use the latest build in x milestone before ToT. |
| 744 | Rxx: use the latest build on xx milestone. |
| 745 | |
| 746 | @param board: the board against which to run self._suite. |
| 747 | @param mv: an instance of manifest_versions.ManifestVersions. |
| 748 | |
| 749 | @return: The ChromeOS build name to test with firmware build. |
| 750 | |
| 751 | """ |
| 752 | if not self.cros_build_spec: |
| 753 | return None |
| 754 | if self.cros_build_spec.startswith('tot'): |
| 755 | milestone = TotMilestoneManager().ConvertTotSpec( |
| 756 | self.cros_build_spec)[1:] |
| 757 | elif self.cros_build_spec.startswith('R'): |
| 758 | milestone = self.cros_build_spec[1:] |
| 759 | milestone, latest_manifest = mv.GetLatestManifest( |
| 760 | board, 'release', milestone=milestone) |
| 761 | latest_build = base_event.BuildName(board, 'release', milestone, |
| 762 | latest_manifest) |
| 763 | logging.debug('Found latest build of %s for spec %s: %s', |
| 764 | board, self.cros_build_spec, latest_build) |
| 765 | return latest_build |
| 766 | |
| 767 | |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 768 | def _GetFirmwareBuild(self, spec, mv, board): |
| 769 | """Get the firmware build name to test with ChromeOS build. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 770 | |
Dan Shi | 648ce92 | 2016-03-26 00:22:47 -0700 | [diff] [blame] | 771 | @param spec: build spec for RO or RW firmware, e.g., firmware, cros. |
| 772 | For RO firmware, the value can also be in the format of |
| 773 | released_ro_X, where X is the index of the list or RO builds |
| 774 | defined in global config RELEASED_RO_BUILDS_[board]. |
| 775 | For example, for spec `released_ro_2`, and global config |
| 776 | CROS/RELEASED_RO_BUILDS_veyron_jerry: build1,build2 |
| 777 | the return firmare RO build should be build2. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 778 | @param mv: an instance of manifest_versions.ManifestVersions. |
| 779 | @param board: the board against which to run self._suite. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 780 | |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 781 | @return: The firmware build name to test with ChromeOS build. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 782 | """ |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 783 | if spec == 'stable': |
| 784 | # TODO(crbug.com/577316): Query stable RO firmware. |
| 785 | raise NotImplementedError('`stable` RO firmware build is not ' |
| 786 | 'supported yet.') |
| 787 | if not spec: |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 788 | return None |
Dan Shi | 648ce92 | 2016-03-26 00:22:47 -0700 | [diff] [blame] | 789 | |
| 790 | if spec.startswith('released_ro_'): |
| 791 | index = int(spec[12:]) |
| 792 | released_ro_builds = CONFIG.get_config_value( |
| 793 | 'CROS', 'RELEASED_RO_BUILDS_%s' % board, type=str, |
| 794 | default='').split(',') |
| 795 | if not released_ro_builds or len(released_ro_builds) < index: |
| 796 | return None |
| 797 | else: |
| 798 | return released_ro_builds[index-1] |
| 799 | |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 800 | # build_type is the build type of the firmware build, e.g., factory, |
| 801 | # firmware or release. If spec is set to cros, build type should be |
| 802 | # mapped to release. |
| 803 | build_type = 'release' if spec == 'cros' else spec |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 804 | latest_milestone, latest_manifest = mv.GetLatestManifest( |
| 805 | board, build_type) |
| 806 | latest_build = base_event.BuildName(board, build_type, latest_milestone, |
| 807 | latest_manifest) |
| 808 | logging.debug('Found latest firmware build of %s for spec %s: %s', |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 809 | board, spec, latest_build) |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 810 | return latest_build |
| 811 | |
| 812 | |
Alex Miller | 7ce1b36 | 2012-07-10 09:24:10 -0700 | [diff] [blame] | 813 | def AvailableHosts(self, scheduler, board): |
| 814 | """Query what hosts are able to run a test on a board and pool |
| 815 | combination. |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 816 | |
| 817 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 818 | deduping_scheduler.py |
| 819 | @param board: the board against which one wants to run the test. |
Alex Miller | 7ce1b36 | 2012-07-10 09:24:10 -0700 | [diff] [blame] | 820 | @return The list of hosts meeting the board and pool requirements, |
| 821 | or None if no hosts were found.""" |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 822 | if self._boards and board not in self._boards: |
| 823 | return [] |
| 824 | |
Dan Shi | 8a1fbac | 2016-10-13 12:36:18 -0700 | [diff] [blame] | 825 | board_label = Labels.BOARD_PREFIX + board |
| 826 | if self._testbed_dut_count: |
| 827 | board_label += '-%d' % self._testbed_dut_count |
| 828 | labels = [board_label] |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 829 | if self._pool: |
Chris Masone | cd214e0 | 2012-07-10 16:22:10 -0700 | [diff] [blame] | 830 | labels.append(Labels.POOL_PREFIX + self._pool) |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 831 | |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 832 | return scheduler.CheckHostsExist(multiple_labels=labels) |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 833 | |
| 834 | |
Alex Miller | d621cf2 | 2012-07-11 13:57:10 -0700 | [diff] [blame] | 835 | def ShouldHaveAvailableHosts(self): |
| 836 | """As a sanity check, return true if we know for certain that |
| 837 | we should be able to schedule this test. If we claim this test |
| 838 | should be able to run, and it ends up not being scheduled, then |
| 839 | a warning will be reported. |
| 840 | |
| 841 | @return True if this test should be able to run, False otherwise. |
| 842 | """ |
| 843 | return self._pool == 'bvt' |
| 844 | |
| 845 | |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 846 | def _ScheduleSuite(self, scheduler, cros_build, firmware_rw_build, |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 847 | firmware_ro_build, test_source_build, |
| 848 | launch_control_build, board, force, run_prod_code=False): |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 849 | """Try to schedule a suite with given build and board information. |
| 850 | |
| 851 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 852 | deduping_scheduler.py |
| 853 | @oaran build: Build to run suite for, e.g., 'daisy-release/R18-1655.0.0' |
| 854 | and 'git_mnc_release/shamu-eng/123'. |
| 855 | @param firmware_rw_build: Firmware RW build to run test with. |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 856 | @param firmware_ro_build: Firmware RO build to run test with. |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 857 | @param test_source_build: Test source build, used for server-side |
| 858 | packaging. |
| 859 | @param launch_control_build: Name of a Launch Control build, e.g., |
| 860 | 'git_mnc_release/shamu-eng/123' |
| 861 | @param board: the board against which to run self._suite. |
| 862 | @param force: Always schedule the suite. |
| 863 | @param run_prod_code: If True, the suite will run the test code that |
| 864 | lives in prod aka the test code currently on the |
| 865 | lab servers. If False, the control files and test |
| 866 | code for this suite run will be retrieved from the |
| 867 | build artifacts. Default is False. |
| 868 | """ |
| 869 | test_source_build_msg = ( |
| 870 | ' Test source build is %s.' % test_source_build |
Dan Shi | 8446fac | 2016-03-02 22:07:39 -0800 | [diff] [blame] | 871 | if test_source_build else '') |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 872 | firmware_rw_build_msg = ( |
| 873 | ' Firmware RW build is %s.' % firmware_rw_build |
Dan Shi | 8446fac | 2016-03-02 22:07:39 -0800 | [diff] [blame] | 874 | if firmware_rw_build else '') |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 875 | firmware_ro_build_msg = ( |
| 876 | ' Firmware RO build is %s.' % firmware_ro_build |
Dan Shi | 8446fac | 2016-03-02 22:07:39 -0800 | [diff] [blame] | 877 | if firmware_ro_build else '') |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 878 | # If testbed_dut_count is set, the suite is for testbed. Update build |
| 879 | # and board with the dut count. |
| 880 | if self._testbed_dut_count: |
| 881 | launch_control_build = '%s#%d' % (launch_control_build, |
| 882 | self._testbed_dut_count) |
| 883 | test_source_build = launch_control_build |
| 884 | board = '%s-%d' % (board, self._testbed_dut_count) |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 885 | build_string = cros_build or launch_control_build |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 886 | logging.debug('Schedule %s for build %s.%s%s%s', |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 887 | self._suite, build_string, test_source_build_msg, |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 888 | firmware_rw_build_msg, firmware_ro_build_msg) |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 889 | |
| 890 | if not scheduler.ScheduleSuite( |
| 891 | self._suite, board, cros_build, self._pool, self._num, |
| 892 | self._priority, self._timeout, force, |
| 893 | file_bugs=self._file_bugs, |
| 894 | firmware_rw_build=firmware_rw_build, |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 895 | firmware_ro_build=firmware_ro_build, |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 896 | test_source_build=test_source_build, |
| 897 | job_retry=self._job_retry, |
| 898 | launch_control_build=launch_control_build, |
Dan Shi | 8458536 | 2016-10-03 14:11:43 -0700 | [diff] [blame] | 899 | run_prod_code=run_prod_code, |
Dan Shi | 1d0e639 | 2016-10-26 13:02:37 -0700 | [diff] [blame^] | 900 | testbed_dut_count=self._testbed_dut_count, |
| 901 | no_delay=self._no_delay): |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 902 | logging.info('Skipping scheduling %s on %s for %s', |
| 903 | self._suite, build_string, board) |
| 904 | |
| 905 | |
| 906 | def _Run_CrOS_Builds(self, scheduler, branch_builds, board, force=False, |
| 907 | mv=None): |
| 908 | """Run this task for CrOS builds. Returns False if it should be |
| 909 | destroyed. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 910 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 911 | Execute this task. Attempt to schedule the associated suite. |
| 912 | Return True if this task should be kept around, False if it |
| 913 | should be destroyed. This allows for one-shot Tasks. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 914 | |
| 915 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 916 | deduping_scheduler.py |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 917 | @param branch_builds: a dict mapping branch name to the build(s) to |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 918 | install for that branch, e.g. |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 919 | {'R18': ['x86-alex-release/R18-1655.0.0'], |
| 920 | 'R19': ['x86-alex-release/R19-2077.0.0']} |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 921 | @param board: the board against which to run self._suite. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 922 | @param force: Always schedule the suite. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 923 | @param mv: an instance of manifest_versions.ManifestVersions. |
| 924 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 925 | @return True if the task should be kept, False if not |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 926 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 927 | """ |
Chris Masone | a3a3817 | 2012-05-14 15:19:56 -0700 | [diff] [blame] | 928 | logging.info('Running %s on %s', self._name, board) |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 929 | is_firmware_build = 'firmware' in self.branch_specs |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 930 | |
| 931 | # firmware_xx_build is only needed if firmware_xx_build_spec is given. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 932 | firmware_rw_build = None |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 933 | firmware_ro_build = None |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 934 | try: |
| 935 | if is_firmware_build: |
| 936 | # When build specified in branch_specs is a firmware build, |
| 937 | # we need a ChromeOS build to test with the firmware build. |
| 938 | cros_build = self._GetCrOSBuild(mv, board) |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 939 | elif self.firmware_rw_build_spec or self.firmware_ro_build_spec: |
| 940 | # When firmware_xx_build_spec is specified, the test involves |
| 941 | # updating the RW firmware by firmware build specified in |
| 942 | # firmware_xx_build_spec. |
| 943 | firmware_rw_build = self._GetFirmwareBuild( |
| 944 | self.firmware_rw_build_spec, mv, board) |
| 945 | firmware_ro_build = self._GetFirmwareBuild( |
| 946 | self.firmware_ro_build_spec, mv, board) |
Dan Shi | 648ce92 | 2016-03-26 00:22:47 -0700 | [diff] [blame] | 947 | # If RO firmware is specified, force to create suite, because |
| 948 | # dedupe based on test source build does not reflect the change |
| 949 | # of RO firmware. |
| 950 | if firmware_ro_build: |
| 951 | force = True |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 952 | except manifest_versions.QueryException as e: |
| 953 | logging.error(e) |
| 954 | logging.error('Running %s on %s is failed. Failed to find build ' |
| 955 | 'required to run the suite.', self._name, board) |
| 956 | return False |
| 957 | |
Dan Shi | 648ce92 | 2016-03-26 00:22:47 -0700 | [diff] [blame] | 958 | # Return if there is no firmware RO build found for given spec. |
| 959 | if not firmware_ro_build and self.firmware_ro_build_spec: |
| 960 | return True |
| 961 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 962 | builds = [] |
Chris Masone | fe5a509 | 2012-04-11 18:29:07 -0700 | [diff] [blame] | 963 | for branch, build in branch_builds.iteritems(): |
Chris Masone | a3a3817 | 2012-05-14 15:19:56 -0700 | [diff] [blame] | 964 | logging.info('Checking if %s fits spec %r', |
| 965 | branch, self.branch_specs) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 966 | if self._FitsSpec(branch): |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 967 | logging.debug('Build %s fits the spec.', build) |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 968 | builds.extend(build) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 969 | for build in builds: |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 970 | try: |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 971 | if is_firmware_build: |
| 972 | firmware_rw_build = build |
| 973 | else: |
| 974 | cros_build = build |
| 975 | if self.test_source == Builds.FIRMWARE_RW: |
| 976 | test_source_build = firmware_rw_build |
| 977 | elif self.test_source == Builds.CROS: |
| 978 | test_source_build = cros_build |
| 979 | else: |
| 980 | test_source_build = None |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 981 | self._ScheduleSuite(scheduler, cros_build, firmware_rw_build, |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 982 | firmware_ro_build, test_source_build, |
| 983 | None, board, force) |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 984 | except deduping_scheduler.DedupingSchedulerException as e: |
| 985 | logging.error(e) |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 986 | return True |
| 987 | |
| 988 | |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 989 | def _Run_LaunchControl_Builds(self, scheduler, launch_control_builds, board, |
| 990 | force=False): |
| 991 | """Run this task. Returns False if it should be destroyed. |
| 992 | |
| 993 | Execute this task. Attempt to schedule the associated suite. |
| 994 | Return True if this task should be kept around, False if it |
| 995 | should be destroyed. This allows for one-shot Tasks. |
| 996 | |
| 997 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 998 | deduping_scheduler.py |
| 999 | @param launch_control_builds: A list of Launch Control builds. |
| 1000 | @param board: the board against which to run self._suite. |
| 1001 | @param force: Always schedule the suite. |
| 1002 | |
| 1003 | @return True if the task should be kept, False if not |
| 1004 | |
| 1005 | """ |
| 1006 | logging.info('Running %s on %s', self._name, board) |
| 1007 | for build in launch_control_builds: |
| 1008 | try: |
Dan Shi | 8446fac | 2016-03-02 22:07:39 -0800 | [diff] [blame] | 1009 | self._ScheduleSuite(scheduler, None, None, None, |
| 1010 | test_source_build=build, |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 1011 | launch_control_build=build, board=board, |
| 1012 | force=force, run_prod_code=True) |
| 1013 | except deduping_scheduler.DedupingSchedulerException as e: |
| 1014 | logging.error(e) |
| 1015 | return True |
| 1016 | |
| 1017 | |
| 1018 | def Run(self, scheduler, branch_builds, board, force=False, mv=None, |
| 1019 | launch_control_builds=None): |
| 1020 | """Run this task. Returns False if it should be destroyed. |
| 1021 | |
| 1022 | Execute this task. Attempt to schedule the associated suite. |
| 1023 | Return True if this task should be kept around, False if it |
| 1024 | should be destroyed. This allows for one-shot Tasks. |
| 1025 | |
| 1026 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 1027 | deduping_scheduler.py |
| 1028 | @param branch_builds: a dict mapping branch name to the build(s) to |
| 1029 | install for that branch, e.g. |
| 1030 | {'R18': ['x86-alex-release/R18-1655.0.0'], |
| 1031 | 'R19': ['x86-alex-release/R19-2077.0.0']} |
| 1032 | @param board: the board against which to run self._suite. |
| 1033 | @param force: Always schedule the suite. |
| 1034 | @param mv: an instance of manifest_versions.ManifestVersions. |
| 1035 | @param launch_control_builds: A list of Launch Control builds. |
| 1036 | |
| 1037 | @return True if the task should be kept, False if not |
| 1038 | |
| 1039 | """ |
| 1040 | if ((self._os_type == OS_TYPE_CROS and not branch_builds) or |
| 1041 | (self._os_type != OS_TYPE_CROS and not launch_control_builds)): |
| 1042 | logging.debug('No build to run, skip running %s on %s.', self._name, |
| 1043 | board) |
| 1044 | # Return True so the task will be kept, as the given build and board |
| 1045 | # do not match. |
| 1046 | return True |
| 1047 | |
| 1048 | if self._os_type == OS_TYPE_CROS: |
| 1049 | return self._Run_CrOS_Builds( |
| 1050 | scheduler, branch_builds, board, force, mv) |
| 1051 | else: |
| 1052 | return self._Run_LaunchControl_Builds( |
| 1053 | scheduler, launch_control_builds, board, force) |
| 1054 | |
| 1055 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 1056 | class OneShotTask(Task): |
| 1057 | """A Task that can be run only once. Can schedule itself.""" |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 1058 | |
| 1059 | |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 1060 | def Run(self, scheduler, branch_builds, board, force=False, mv=None, |
| 1061 | launch_control_builds=None): |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 1062 | """Run this task. Returns False, indicating it should be destroyed. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 1063 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 1064 | Run this task. Attempt to schedule the associated suite. |
| 1065 | Return False, indicating to the caller that it should discard this task. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 1066 | |
| 1067 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 1068 | deduping_scheduler.py |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 1069 | @param branch_builds: a dict mapping branch name to the build(s) to |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 1070 | install for that branch, e.g. |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 1071 | {'R18': ['x86-alex-release/R18-1655.0.0'], |
| 1072 | 'R19': ['x86-alex-release/R19-2077.0.0']} |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 1073 | @param board: the board against which to run self._suite. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 1074 | @param force: Always schedule the suite. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 1075 | @param mv: an instance of manifest_versions.ManifestVersions. |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 1076 | @param launch_control_builds: A list of Launch Control builds. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 1077 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 1078 | @return False |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 1079 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 1080 | """ |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 1081 | super(OneShotTask, self).Run(scheduler, branch_builds, board, force, |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 1082 | mv, launch_control_builds) |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 1083 | return False |