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 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 6 | import logging, re |
Aviv Keshet | d83ef44 | 2013-01-16 16:19:35 -0800 | [diff] [blame] | 7 | import deduping_scheduler |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 8 | import driver |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 9 | from distutils import version |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 10 | from constants import Labels |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 11 | |
| 12 | |
| 13 | class MalformedConfigEntry(Exception): |
| 14 | """Raised to indicate a failure to parse a Task out of a config.""" |
| 15 | pass |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 16 | |
| 17 | |
Alex Miller | 0d00357 | 2013-03-18 11:51:30 -0700 | [diff] [blame] | 18 | BARE_BRANCHES = ['factory', 'firmware'] |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 19 | |
| 20 | |
| 21 | def PickBranchName(type, milestone): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 22 | """Pick branch name. If type is among BARE_BRANCHES, return type, |
| 23 | otherwise, return milestone. |
| 24 | |
| 25 | @param type: type of the branch, e.g., 'release', 'factory', or 'firmware' |
| 26 | @param milestone: CrOS milestone number |
| 27 | """ |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 28 | if type in BARE_BRANCHES: |
| 29 | return type |
| 30 | return milestone |
| 31 | |
| 32 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 33 | class Task(object): |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 34 | """Represents an entry from the scheduler config. Can schedule itself. |
| 35 | |
| 36 | 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] | 37 | Task. Each instance has enough info to schedule itself |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 38 | on-demand with the AFE. |
| 39 | |
| 40 | This class also overrides __hash__() and all comparitor methods to enable |
| 41 | correct use in dicts, sets, etc. |
| 42 | """ |
| 43 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 44 | |
| 45 | @staticmethod |
| 46 | def CreateFromConfigSection(config, section): |
| 47 | """Create a Task from a section of a config file. |
| 48 | |
| 49 | The section to parse should look like this: |
| 50 | [TaskName] |
| 51 | suite: suite_to_run # Required |
| 52 | run_on: event_on which to run # Required |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 53 | branch_specs: factory,firmware,>=R12 or ==R12 # Optional |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 54 | pool: pool_of_devices # Optional |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 55 | num: sharding_factor # int, Optional |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 56 | boards: board1, board2 # comma seperated string, Optional |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 57 | |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 58 | By default, Tasks run on all release branches, not factory or firmware. |
| 59 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 60 | @param config: a ForgivingConfigParser. |
| 61 | @param section: the section to parse into a Task. |
| 62 | @return keyword, Task object pair. One or both will be None on error. |
| 63 | @raise MalformedConfigEntry if there's a problem parsing |section|. |
| 64 | """ |
Alex Miller | 0669502 | 2012-07-18 09:31:36 -0700 | [diff] [blame] | 65 | if not config.has_section(section): |
| 66 | raise MalformedConfigEntry('unknown section %s' % section) |
| 67 | |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 68 | allowed = set(['suite', 'run_on', 'branch_specs', 'pool', 'num', |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 69 | 'boards', 'file_bugs']) |
Alex Miller | bb535e2 | 2012-07-11 20:11:33 -0700 | [diff] [blame] | 70 | # The parameter of union() is the keys under the section in the config |
| 71 | # The union merges this with the allowed set, so if any optional keys |
| 72 | # are omitted, then they're filled in. If any extra keys are present, |
| 73 | # then they will expand unioned set, causing it to fail the following |
| 74 | # comparison against the allowed set. |
| 75 | section_headers = allowed.union(dict(config.items(section)).keys()) |
| 76 | if allowed != section_headers: |
| 77 | raise MalformedConfigEntry('unknown entries: %s' % |
| 78 | ", ".join(map(str, section_headers.difference(allowed)))) |
| 79 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 80 | keyword = config.getstring(section, 'run_on') |
| 81 | suite = config.getstring(section, 'suite') |
| 82 | branches = config.getstring(section, 'branch_specs') |
| 83 | pool = config.getstring(section, 'pool') |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 84 | boards = config.getstring(section, 'boards') |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 85 | file_bugs = config.getboolean(section, 'file_bugs') |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 86 | for klass in driver.Driver.EVENT_CLASSES: |
| 87 | if klass.KEYWORD == keyword: |
| 88 | priority = klass.PRIORITY |
| 89 | timeout = klass.TIMEOUT |
| 90 | break |
| 91 | else: |
| 92 | priority = None |
| 93 | timeout = None |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 94 | try: |
| 95 | num = config.getint(section, 'num') |
| 96 | except ValueError as e: |
| 97 | raise MalformedConfigEntry("Ill-specified 'num': %r" %e) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 98 | if not keyword: |
| 99 | raise MalformedConfigEntry('No event to |run_on|.') |
| 100 | if not suite: |
| 101 | raise MalformedConfigEntry('No |suite|') |
| 102 | specs = [] |
| 103 | if branches: |
| 104 | specs = re.split('\s*,\s*', branches) |
| 105 | Task.CheckBranchSpecs(specs) |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 106 | return keyword, Task(section, suite, specs, pool, num, boards, |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 107 | priority, timeout, |
| 108 | file_bugs=file_bugs if file_bugs else False) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 109 | |
| 110 | |
| 111 | @staticmethod |
| 112 | def CheckBranchSpecs(branch_specs): |
| 113 | """Make sure entries in the list branch_specs are correctly formed. |
| 114 | |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 115 | We accept any of BARE_BRANCHES in |branch_specs|, as |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 116 | 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] | 117 | CrOS milestone number. |
| 118 | |
| 119 | @param branch_specs: an iterable of branch specifiers. |
| 120 | @raise MalformedConfigEntry if there's a problem parsing |branch_specs|. |
| 121 | """ |
| 122 | have_seen_numeric_constraint = False |
| 123 | for branch in branch_specs: |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 124 | if branch in BARE_BRANCHES: |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 125 | continue |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 126 | if ((branch.startswith('>=R') or branch.startswith('==R')) and |
| 127 | not have_seen_numeric_constraint): |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 128 | have_seen_numeric_constraint = True |
| 129 | continue |
Chris Masone | 97cf0a7 | 2012-05-16 09:55:52 -0700 | [diff] [blame] | 130 | raise MalformedConfigEntry("%s isn't a valid branch spec." % branch) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 131 | |
| 132 | |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 133 | def __init__(self, name, suite, branch_specs, pool=None, num=None, |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 134 | boards=None, priority=None, timeout=None, file_bugs=False): |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 135 | """Constructor |
| 136 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 137 | Given an iterable in |branch_specs|, pre-vetted using CheckBranchSpecs, |
| 138 | we'll store them such that _FitsSpec() can be used to check whether a |
| 139 | given branch 'fits' with the specifications passed in here. |
| 140 | For example, given branch_specs = ['factory', '>=R18'], we'd set things |
| 141 | up so that _FitsSpec() would return True for 'factory', or 'RXX' |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 142 | where XX is a number >= 18. Same check is done for branch_specs = [ |
| 143 | 'factory', '==R18'], which limit the test to only one specific branch. |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 144 | |
| 145 | Given branch_specs = ['factory', 'firmware'], _FitsSpec() |
| 146 | would pass only those two specific strings. |
| 147 | |
| 148 | Example usage: |
Chris Masone | cc4631d | 2012-04-20 12:06:39 -0700 | [diff] [blame] | 149 | t = Task('Name', 'suite', ['factory', '>=R18']) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 150 | t._FitsSpec('factory') # True |
| 151 | t._FitsSpec('R19') # True |
| 152 | t._FitsSpec('R17') # False |
| 153 | t._FitsSpec('firmware') # False |
| 154 | t._FitsSpec('goober') # False |
| 155 | |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 156 | t = Task('Name', 'suite', ['factory', '==R18']) |
| 157 | t._FitsSpec('R19') # False, branch does not equal to 18 |
| 158 | t._FitsSpec('R18') # True |
| 159 | t._FitsSpec('R17') # False |
| 160 | |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 161 | @param name: name of this task, e.g. 'NightlyPower' |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 162 | @param suite: the name of the suite to run, e.g. 'bvt' |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 163 | @param branch_specs: a pre-vetted iterable of branch specifiers, |
| 164 | e.g. ['>=R18', 'factory'] |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 165 | @param pool: the pool of machines to use for scheduling purposes. |
| 166 | Default: None |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 167 | @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] | 168 | Type: integer or None |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 169 | Default: None |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 170 | @param boards: A comma seperated list of boards to run this task on. |
| 171 | Default: Run on all boards. |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 172 | @param priority: The string name of a priority from |
| 173 | client.common_lib.priorities.Priority. |
| 174 | @param timeout: The max lifetime of the suite in hours. |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 175 | @param file_bugs: True if bug filing is desired for the suite created |
| 176 | for this task. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 177 | """ |
Chris Masone | cc4631d | 2012-04-20 12:06:39 -0700 | [diff] [blame] | 178 | self._name = name |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 179 | self._suite = suite |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 180 | self._branch_specs = branch_specs |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 181 | self._pool = pool |
Aviv Keshet | d83ef44 | 2013-01-16 16:19:35 -0800 | [diff] [blame] | 182 | self._num = num |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 183 | self._priority = priority |
| 184 | self._timeout = timeout |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 185 | self._file_bugs = file_bugs |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 186 | |
| 187 | self._bare_branches = [] |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 188 | self._version_equal_constraint = False |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 189 | if not branch_specs: |
| 190 | # Any milestone is OK. |
| 191 | self._numeric_constraint = version.LooseVersion('0') |
| 192 | else: |
| 193 | self._numeric_constraint = None |
| 194 | for spec in branch_specs: |
| 195 | if spec.startswith('>='): |
| 196 | self._numeric_constraint = version.LooseVersion( |
| 197 | spec.lstrip('>=R')) |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 198 | elif spec.startswith('=='): |
| 199 | self._version_equal_constraint = True |
| 200 | self._numeric_constraint = version.LooseVersion( |
| 201 | spec.lstrip('==R')) |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 202 | else: |
| 203 | self._bare_branches.append(spec) |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 204 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 205 | # Since we expect __hash__() and other comparitor methods to be used |
| 206 | # frequently by set operations, and they use str() a lot, pre-compute |
| 207 | # the string representation of this object. |
Aviv Keshet | 8ce3c98 | 2013-01-24 09:23:13 -0800 | [diff] [blame] | 208 | if num is None: |
| 209 | numStr = '[Default num]' |
| 210 | else: |
| 211 | numStr = '%d' % num |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 212 | |
| 213 | if boards is None: |
| 214 | self._boards = set() |
| 215 | boardsStr = '[All boards]' |
| 216 | else: |
| 217 | self._boards = set([x.strip() for x in boards.split(',')]) |
| 218 | boardsStr = boards |
| 219 | |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 220 | self._str = ('%s: %s on %s with pool %s, boards [%s], file_bugs = %s ' |
| 221 | 'across %s machines.' % (self.__class__.__name__, |
| 222 | suite, branch_specs, pool, boardsStr, self._file_bugs, |
| 223 | numStr)) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 224 | |
| 225 | |
| 226 | def _FitsSpec(self, branch): |
| 227 | """Checks if a branch is deemed OK by this instance's branch specs. |
| 228 | |
| 229 | When called on a branch name, will return whether that branch |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 230 | 'fits' the specifications stored in self._bare_branches, |
| 231 | self._numeric_constraint and self._version_equal_constraint. |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 232 | |
| 233 | @param branch: the branch to check. |
| 234 | @return True if b 'fits' with stored specs, False otherwise. |
| 235 | """ |
Chris Masone | 657e155 | 2012-05-30 17:06:20 -0700 | [diff] [blame] | 236 | if branch in BARE_BRANCHES: |
| 237 | return branch in self._bare_branches |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 238 | if self._numeric_constraint: |
| 239 | if self._version_equal_constraint: |
| 240 | return version.LooseVersion(branch) == self._numeric_constraint |
| 241 | else: |
| 242 | return version.LooseVersion(branch) >= self._numeric_constraint |
| 243 | else: |
| 244 | return False |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 245 | |
| 246 | |
| 247 | @property |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 248 | def name(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 249 | """Name of this task, e.g. 'NightlyPower'.""" |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 250 | return self._name |
| 251 | |
| 252 | |
| 253 | @property |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 254 | def suite(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 255 | """Name of the suite to run, e.g. 'bvt'.""" |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 256 | return self._suite |
| 257 | |
| 258 | |
| 259 | @property |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 260 | def branch_specs(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 261 | """a pre-vetted iterable of branch specifiers, |
| 262 | e.g. ['>=R18', 'factory'].""" |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 263 | return self._branch_specs |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 264 | |
| 265 | |
| 266 | @property |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 267 | def pool(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 268 | """The pool of machines to use for scheduling purposes.""" |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 269 | return self._pool |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 270 | |
| 271 | |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 272 | @property |
| 273 | def num(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 274 | """The number of devices across which to shard the test suite. |
| 275 | Type: integer or None""" |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 276 | return self._num |
| 277 | |
| 278 | |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 279 | @property |
| 280 | def boards(self): |
| 281 | """The boards on which to run this suite. |
| 282 | Type: Iterable of strings""" |
| 283 | return self._boards |
| 284 | |
| 285 | |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 286 | @property |
| 287 | def priority(self): |
| 288 | """The priority of the suite""" |
| 289 | return self._priority |
| 290 | |
| 291 | |
| 292 | @property |
| 293 | def timeout(self): |
| 294 | """The maximum lifetime of the suite in hours.""" |
| 295 | return self._timeout |
| 296 | |
| 297 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 298 | def __str__(self): |
| 299 | return self._str |
| 300 | |
| 301 | |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 302 | def __repr__(self): |
| 303 | return self._str |
| 304 | |
| 305 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 306 | def __lt__(self, other): |
| 307 | return str(self) < str(other) |
| 308 | |
| 309 | |
| 310 | def __le__(self, other): |
| 311 | return str(self) <= str(other) |
| 312 | |
| 313 | |
| 314 | def __eq__(self, other): |
| 315 | return str(self) == str(other) |
| 316 | |
| 317 | |
| 318 | def __ne__(self, other): |
| 319 | return str(self) != str(other) |
| 320 | |
| 321 | |
| 322 | def __gt__(self, other): |
| 323 | return str(self) > str(other) |
| 324 | |
| 325 | |
| 326 | def __ge__(self, other): |
| 327 | return str(self) >= str(other) |
| 328 | |
| 329 | |
| 330 | def __hash__(self): |
| 331 | """Allows instances to be correctly deduped when used in a set.""" |
| 332 | return hash(str(self)) |
| 333 | |
| 334 | |
Alex Miller | 7ce1b36 | 2012-07-10 09:24:10 -0700 | [diff] [blame] | 335 | def AvailableHosts(self, scheduler, board): |
| 336 | """Query what hosts are able to run a test on a board and pool |
| 337 | combination. |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 338 | |
| 339 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 340 | deduping_scheduler.py |
| 341 | @param board: the board against which one wants to run the test. |
Alex Miller | 7ce1b36 | 2012-07-10 09:24:10 -0700 | [diff] [blame] | 342 | @return The list of hosts meeting the board and pool requirements, |
| 343 | or None if no hosts were found.""" |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 344 | if self._boards and board not in self._boards: |
| 345 | return [] |
| 346 | |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 347 | labels = [Labels.BOARD_PREFIX + board] |
| 348 | if self._pool: |
Chris Masone | cd214e0 | 2012-07-10 16:22:10 -0700 | [diff] [blame] | 349 | labels.append(Labels.POOL_PREFIX + self._pool) |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 350 | |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 351 | return scheduler.CheckHostsExist(multiple_labels=labels) |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 352 | |
| 353 | |
Alex Miller | d621cf2 | 2012-07-11 13:57:10 -0700 | [diff] [blame] | 354 | def ShouldHaveAvailableHosts(self): |
| 355 | """As a sanity check, return true if we know for certain that |
| 356 | we should be able to schedule this test. If we claim this test |
| 357 | should be able to run, and it ends up not being scheduled, then |
| 358 | a warning will be reported. |
| 359 | |
| 360 | @return True if this test should be able to run, False otherwise. |
| 361 | """ |
| 362 | return self._pool == 'bvt' |
| 363 | |
| 364 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 365 | def Run(self, scheduler, branch_builds, board, force=False): |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 366 | """Run this task. Returns False if it should be destroyed. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 367 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 368 | Execute this task. Attempt to schedule the associated suite. |
| 369 | Return True if this task should be kept around, False if it |
| 370 | should be destroyed. This allows for one-shot Tasks. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 371 | |
| 372 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 373 | deduping_scheduler.py |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 374 | @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] | 375 | install for that branch, e.g. |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 376 | {'R18': ['x86-alex-release/R18-1655.0.0'], |
| 377 | 'R19': ['x86-alex-release/R19-2077.0.0']} |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 378 | @param board: the board against which to run self._suite. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 379 | @param force: Always schedule the suite. |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 380 | @return True if the task should be kept, False if not |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 381 | """ |
Chris Masone | a3a3817 | 2012-05-14 15:19:56 -0700 | [diff] [blame] | 382 | logging.info('Running %s on %s', self._name, board) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 383 | builds = [] |
Chris Masone | fe5a509 | 2012-04-11 18:29:07 -0700 | [diff] [blame] | 384 | for branch, build in branch_builds.iteritems(): |
Chris Masone | a3a3817 | 2012-05-14 15:19:56 -0700 | [diff] [blame] | 385 | logging.info('Checking if %s fits spec %r', |
| 386 | branch, self.branch_specs) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 387 | if self._FitsSpec(branch): |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 388 | builds.extend(build) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 389 | for build in builds: |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 390 | try: |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 391 | if not scheduler.ScheduleSuite(self._suite, board, build, |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 392 | self._pool, self._num, |
| 393 | self._priority, self._timeout, |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 394 | force, |
| 395 | file_bugs=self._file_bugs): |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 396 | logging.info('Skipping scheduling %s on %s for %s', |
| 397 | self._suite, build, board) |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 398 | except deduping_scheduler.DedupingSchedulerException as e: |
| 399 | logging.error(e) |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 400 | return True |
| 401 | |
| 402 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 403 | class OneShotTask(Task): |
| 404 | """A Task that can be run only once. Can schedule itself.""" |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 405 | |
| 406 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 407 | def Run(self, scheduler, branch_builds, board, force=False): |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 408 | """Run this task. Returns False, indicating it should be destroyed. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 409 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 410 | Run this task. Attempt to schedule the associated suite. |
| 411 | Return False, indicating to the caller that it should discard this task. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 412 | |
| 413 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 414 | deduping_scheduler.py |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 415 | @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] | 416 | install for that branch, e.g. |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 417 | {'R18': ['x86-alex-release/R18-1655.0.0'], |
| 418 | 'R19': ['x86-alex-release/R19-2077.0.0']} |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 419 | @param board: the board against which to run self._suite. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 420 | @param force: Always schedule the suite. |
| 421 | @return False |
| 422 | """ |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 423 | super(OneShotTask, self).Run(scheduler, branch_builds, board, force) |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 424 | return False |