Chris Masone | 8ac6671 | 2012-02-15 14:21:02 -0800 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | import common |
Chris Masone | 9937858 | 2012-04-30 13:10:58 -0700 | [diff] [blame] | 6 | import compiler, datetime, logging, os, random, re, time, traceback |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 7 | from autotest_lib.client.common_lib import base_job, control_data, global_config |
| 8 | from autotest_lib.client.common_lib import error, utils |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 9 | from autotest_lib.client.common_lib.cros import dev_server |
Chris Masone | 8ac6671 | 2012-02-15 14:21:02 -0800 | [diff] [blame] | 10 | from autotest_lib.server.cros import control_file_getter, frontend_wrappers |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 11 | from autotest_lib.server import frontend |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 12 | from autotest_lib.frontend.afe.json_rpc import proxy |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 13 | |
Chris Masone | 6cfb712 | 2012-05-02 11:36:28 -0700 | [diff] [blame] | 14 | """CrOS dynamic test suite generation and execution module. |
| 15 | |
| 16 | This module implements runtime-generated test suites for CrOS. |
| 17 | Design doc: http://goto.google.com/suitesv2 |
| 18 | |
| 19 | Individual tests can declare themselves as a part of one or more |
| 20 | suites, and the code here enables control files to be written |
| 21 | that can refer to these "dynamic suites" by name. We also provide |
| 22 | support for reimaging devices with a given build and running a |
| 23 | dynamic suite across all reimaged devices. |
| 24 | |
| 25 | The public API for defining a suite includes one method: reimage_and_run(). |
| 26 | A suite control file can be written by importing this module and making |
| 27 | an appropriate call to this single method. In normal usage, this control |
| 28 | file will be run in a 'hostless' server-side autotest job, scheduling |
| 29 | sub-jobs to do the needed reimaging and test running. |
| 30 | |
| 31 | Example control file: |
| 32 | |
| 33 | import common |
| 34 | from autotest_lib.server.cros import dynamic_suite |
| 35 | |
| 36 | dynamic_suite.reimage_and_run( |
| 37 | build=build, board=board, name='bvt', job=job, pool=pool, |
| 38 | check_hosts=check_hosts, add_experimental=True, num=4, |
| 39 | skip_reimage=dynamic_suite.skip_reimage(globals())) |
| 40 | |
| 41 | This will -- at runtime -- find all control files that contain "bvt" |
| 42 | in their "SUITE=" clause, schedule jobs to reimage 4 devices in the |
| 43 | specified pool of the specified board with the specified build and, |
| 44 | upon completion of those jobs, schedule and wait for jobs that run all |
| 45 | the tests it discovered across those 4 machines. |
| 46 | |
| 47 | Suites can be run by using the atest command-line tool: |
| 48 | atest suite create -b <board> -i <build/name> <suite> |
| 49 | e.g. |
| 50 | atest suite create -b x86-mario -i x86-mario/R20-2203.0.0 bvt |
| 51 | |
| 52 | ------------------------------------------------------------------------- |
| 53 | Implementation details |
| 54 | |
| 55 | In addition to the create_suite_job() RPC defined in the autotest frontend, |
| 56 | there are two main classes defined here: Suite and Reimager. |
| 57 | |
| 58 | A Suite instance represents a single test suite, defined by some predicate |
| 59 | run over all known control files. The simplest example is creating a Suite |
| 60 | by 'name'. |
| 61 | |
| 62 | The Reimager class provides support for reimaging a heterogenous set |
| 63 | of devices with an appropriate build, in preparation for a test run. |
| 64 | One could use a single Reimager, followed by the instantiation and use |
| 65 | of multiple Suite objects. |
| 66 | |
| 67 | create_suite_job() takes the parameters needed to define a suite run (board, |
| 68 | build to test, machine pool, and which suite to run), ensures important |
| 69 | preconditions are met, finds the appropraite suite control file, and then |
| 70 | schedules the hostless job that will do the rest of the work. |
| 71 | |
| 72 | reimage_and_run() works by creating a Reimager, using it to perform the |
| 73 | requested installs, and then instantiating a Suite and running it on the |
| 74 | machines that were just reimaged. We'll go through this process in stages. |
| 75 | |
| 76 | - create_suite_job() |
| 77 | The primary role of create_suite_job() is to ensure that the required |
| 78 | artifacts for the build to be tested are staged on the dev server. This |
| 79 | includes payloads required to autoupdate machines to the desired build, as |
| 80 | well as the autotest control files appropriate for that build. Then, the |
| 81 | RPC pulls the control file for the suite to be run from the dev server and |
| 82 | uses it to create the suite job with the autotest frontend. |
| 83 | |
| 84 | +----------------+ |
| 85 | | Google Storage | Client |
| 86 | +----------------+ | |
| 87 | | ^ | create_suite_job() |
| 88 | payloads/ | | | |
| 89 | control files | | request | |
| 90 | V | V |
| 91 | +-------------+ download request +--------------------------+ |
| 92 | | |<----------------------| | |
| 93 | | Dev Server | | Autotest Frontend (AFE) | |
| 94 | | |---------------------->| | |
| 95 | +-------------+ suite control file +--------------------------+ |
| 96 | | |
| 97 | V |
| 98 | Suite Job (hostless) |
| 99 | |
| 100 | - The Reimaging process |
| 101 | In short, the Reimager schedules and waits for a number of autoupdate 'test' |
| 102 | jobs that perform image installation and make sure the device comes back up. |
| 103 | It labels the machines that it reimages with the newly-installed CrOS version, |
| 104 | so that later steps in the can refer to the machines by version and board, |
| 105 | instead of having to keep track of hostnames or some such. |
| 106 | |
| 107 | The number of machines to use is called the 'sharding_factor', and the default |
| 108 | is defined in the [CROS] section of global_config.ini. This can be overridden |
| 109 | by passing a 'num=N' parameter to reimage_and_run() as shown in the example |
| 110 | above. |
| 111 | |
| 112 | Step by step: |
| 113 | 1) Schedule autoupdate 'tests' across N devices of the appropriate board. |
| 114 | - Technically, one job that has N tests across N hosts. |
| 115 | - This 'test' is in server/site_tests/autoupdate/ |
| 116 | - The control file is modified at runtime to inject the name of the build |
| 117 | to install, and the URL to get said build from. |
| 118 | - This is the _TOT_ version of the autoupdate test; it must be able to run |
| 119 | successfully on all currently supported branches at all times. |
| 120 | 2) Wait for this job to get kicked off and run to completion. |
| 121 | 3) Label successfully reimaged devices with a 'cros-version' label |
| 122 | - This is actually done by the autoupdate 'test' control file. |
| 123 | 4) Add a host attribute ('job_repo_url') to each reimaged host indicating |
| 124 | the URL where packages should be downloaded for subsequent tests |
| 125 | - This is actually done by the autoupdate 'test' control file |
| 126 | - This information is consumed in server/site_autotest.py |
| 127 | - job_repo_url points to some location on the dev server, where build |
| 128 | artifacts are staged -- including autotest packages. |
| 129 | 5) Return success or failure. |
| 130 | |
| 131 | +------------+ +--------------------------+ |
| 132 | | | | | |
| 133 | | Dev Server | | Autotest Frontend (AFE) | |
| 134 | | | | [Suite Job] | |
| 135 | +------------+ +--------------------------+ |
| 136 | | payloads | | | | |
| 137 | V V autoupdate test | | | |
| 138 | +--------+ +--------+ <-----+----------------+ | | |
| 139 | | Host 1 |<------| Host 2 |-------+ | | |
| 140 | +--------+ +--------+ label | | |
| 141 | VersLabel VersLabel <-----------------------+ | |
| 142 | job_repo_url job_repo_url <-----------------------------+ |
| 143 | host-attribute |
| 144 | |
| 145 | To sum up, after re-imaging, we have the following assumptions: |
| 146 | - |num| devices of type |board| have |build| installed. |
| 147 | - These devices are labeled appropriately |
| 148 | - They have a host attribute called 'job_repo_url' dictating where autotest |
| 149 | packages can be downloaded for test runs. |
| 150 | |
| 151 | |
| 152 | - Running Suites |
| 153 | A Suite instance uses the labels created by the Reimager to schedule test jobs |
| 154 | across all the hosts that were just reimaged. It then waits for all these jobs. |
| 155 | |
| 156 | Step by step: |
| 157 | 1) At instantiation time, find all appropriate control files for this suite |
| 158 | that were included in the build to be tested. To do this, we consult the |
| 159 | Dev Server, where all these control files are staged. |
| 160 | |
| 161 | +------------+ control files? +--------------------------+ |
| 162 | | |<----------------------| | |
| 163 | | Dev Server | | Autotest Frontend (AFE) | |
| 164 | | |---------------------->| [Suite Job] | |
| 165 | +------------+ control files! +--------------------------+ |
| 166 | |
| 167 | 2) Now that the Suite instance exists, it schedules jobs for every control |
| 168 | file it deemed appropriate, to be run on the hosts that were labeled |
| 169 | by the Reimager. We stuff keyvals into these jobs, indicating what |
| 170 | build they were testing and which suite they were for. |
| 171 | |
| 172 | +--------------------------+ Job for VersLabel +--------+ |
| 173 | | |------------------------>| Host 1 | VersLabel |
| 174 | | Autotest Frontend (AFE) | +--------+ +--------+ |
| 175 | | [Suite Job] |----------->| Host 2 | |
| 176 | +--------------------------+ Job for +--------+ |
| 177 | | ^ VersLabel VersLabel |
| 178 | | | |
| 179 | +----------------+ |
| 180 | One job per test |
| 181 | {'build': build/name, |
| 182 | 'suite': suite_name} |
| 183 | |
| 184 | 3) Now that all jobs are scheduled, they'll be doled out as labeled hosts |
| 185 | finish their assigned work and become available again. |
| 186 | 4) As we clean up each job, we check to see if any crashes occurred. If they |
| 187 | did, we look at the 'build' keyval in the job to see which build's debug |
| 188 | symbols we'll need to symbolicate the crash dump we just found. |
| 189 | 5) Using this info, we tell the Dev Server to stage the required debug symbols. |
| 190 | Once that's done, we ask the dev server to use those symbols to symbolicate |
| 191 | the crash dump in question. |
| 192 | |
| 193 | +----------------+ |
| 194 | | Google Storage | |
| 195 | +----------------+ |
| 196 | | ^ |
| 197 | symbols! | | symbols? |
| 198 | V | |
| 199 | +------------+ stage symbols for build +--------------------------+ |
| 200 | | |<--------------------------| | |
| 201 | | | | | |
| 202 | | Dev Server | dump to symbolicate | Autotest Frontend (AFE) | |
| 203 | | |<--------------------------| [Suite Job] | |
| 204 | | |-------------------------->| | |
| 205 | +------------+ symbolicated dump +--------------------------+ |
| 206 | |
| 207 | 6) As jobs finish, we record their success or failure in the status of the suite |
| 208 | job. We also record a 'job keyval' in the suite job for each test, noting |
| 209 | the job ID and job owner. This can be used to refer to test logs later. |
| 210 | 7) Once all jobs are complete, status is recorded for the suite job, and the |
| 211 | job_repo_url host attribute is removed from all hosts used by the suite. |
| 212 | |
| 213 | """ |
| 214 | |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 215 | |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 216 | VERSION_PREFIX = 'cros-version:' |
Chris Masone | 2ef1d4e | 2011-12-20 11:06:53 -0800 | [diff] [blame] | 217 | CONFIG = global_config.global_config |
| 218 | |
| 219 | |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 220 | # Relevant CrosDynamicSuiteExceptions are defined in client/common_lib/error.py. |
Chris Masone | 502b71e | 2012-04-10 10:41:35 -0700 | [diff] [blame] | 221 | |
| 222 | |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 223 | def reimage_and_run(**dargs): |
| 224 | """ |
| 225 | Backward-compatible API for dynamic_suite. |
| 226 | |
| 227 | Will re-image a number of devices (of the specified board) with the |
| 228 | provided build, and then run the indicated test suite on them. |
| 229 | Guaranteed to be compatible with any build from stable to dev. |
| 230 | |
| 231 | Currently required args: |
| 232 | @param build: the build to install e.g. |
| 233 | x86-alex-release/R18-1655.0.0-a1-b1584. |
| 234 | @param board: which kind of devices to reimage. |
| 235 | @param name: a value of the SUITE control file variable to search for. |
| 236 | @param job: an instance of client.common_lib.base_job representing the |
| 237 | currently running suite job. |
| 238 | |
| 239 | Currently supported optional args: |
| 240 | @param pool: specify the pool of machines to use for scheduling purposes. |
| 241 | Default: None |
| 242 | @param num: how many devices to reimage. |
| 243 | Default in global_config |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 244 | @param check_hosts: require appropriate hosts to be available now. |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 245 | @param skip_reimage: skip reimaging, used for testing purposes. |
| 246 | Default: False |
| 247 | @param add_experimental: schedule experimental tests as well, or not. |
| 248 | Default: True |
Chris Sosa | 6b288c8 | 2012-03-29 15:31:06 -0700 | [diff] [blame] | 249 | @raises AsynchronousBuildFailure: if there was an issue finishing staging |
| 250 | from the devserver. |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 251 | """ |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 252 | (build, board, name, job, pool, num, check_hosts, skip_reimage, |
| 253 | add_experimental) = _vet_reimage_and_run_args(**dargs) |
Chris Masone | 5374c67 | 2012-03-05 15:11:39 -0800 | [diff] [blame] | 254 | board = 'board:%s' % board |
| 255 | if pool: |
| 256 | pool = 'pool:%s' % pool |
Chris Masone | 9f13ff2 | 2012-03-05 13:45:25 -0800 | [diff] [blame] | 257 | reimager = Reimager(job.autodir, pool=pool, results_dir=job.resultdir) |
Chris Masone | d368cc4 | 2012-03-07 15:16:59 -0800 | [diff] [blame] | 258 | |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 259 | if skip_reimage or reimager.attempt(build, board, job.record, check_hosts, |
| 260 | num=num): |
Chris Sosa | 6b288c8 | 2012-03-29 15:31:06 -0700 | [diff] [blame] | 261 | |
| 262 | # Ensure that the image's artifacts have completed downloading. |
| 263 | ds = dev_server.DevServer.create() |
| 264 | if not ds.finish_download(build): |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 265 | raise error.AsynchronousBuildFailure( |
Chris Sosa | 6b288c8 | 2012-03-29 15:31:06 -0700 | [diff] [blame] | 266 | "Server error completing staging for " + build) |
Chris Masone | a8066a9 | 2012-05-01 16:52:31 -0700 | [diff] [blame] | 267 | timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') |
| 268 | utils.write_keyval(job.resultdir, |
| 269 | {'artifact_finished_time': timestamp}) |
Chris Sosa | 6b288c8 | 2012-03-29 15:31:06 -0700 | [diff] [blame] | 270 | |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 271 | suite = Suite.create_from_name(name, build, pool=pool, |
| 272 | results_dir=job.resultdir) |
Chris Masone | 9937858 | 2012-04-30 13:10:58 -0700 | [diff] [blame] | 273 | suite.run_and_wait(job.record_entry, add_experimental=add_experimental) |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 274 | |
Chris Masone | d368cc4 | 2012-03-07 15:16:59 -0800 | [diff] [blame] | 275 | reimager.clear_reimaged_host_state(build) |
| 276 | |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 277 | |
| 278 | def _vet_reimage_and_run_args(build=None, board=None, name=None, job=None, |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 279 | pool=None, num=None, check_hosts=True, |
| 280 | skip_reimage=False, add_experimental=True, |
| 281 | **dargs): |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 282 | """ |
| 283 | Vets arguments for reimage_and_run(). |
| 284 | |
| 285 | Currently required args: |
| 286 | @param build: the build to install e.g. |
| 287 | x86-alex-release/R18-1655.0.0-a1-b1584. |
| 288 | @param board: which kind of devices to reimage. |
| 289 | @param name: a value of the SUITE control file variable to search for. |
| 290 | @param job: an instance of client.common_lib.base_job representing the |
| 291 | currently running suite job. |
| 292 | |
| 293 | Currently supported optional args: |
| 294 | @param pool: specify the pool of machines to use for scheduling purposes. |
| 295 | Default: None |
| 296 | @param num: how many devices to reimage. |
| 297 | Default in global_config |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 298 | @param check_hosts: require appropriate hosts to be available now. |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 299 | @param skip_reimage: skip reimaging, used for testing purposes. |
| 300 | Default: False |
| 301 | @param add_experimental: schedule experimental tests as well, or not. |
| 302 | Default: True |
| 303 | @return a tuple of args set to provided (or default) values. |
| 304 | """ |
| 305 | required_keywords = {'build': str, |
| 306 | 'board': str, |
| 307 | 'name': str, |
| 308 | 'job': base_job.base_job} |
| 309 | for key, expected in required_keywords.iteritems(): |
| 310 | value = locals().get(key) |
| 311 | if not value or not isinstance(value, expected): |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 312 | raise error.SuiteArgumentException( |
| 313 | "reimage_and_run() needs %s=<%r>" % (key, expected)) |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 314 | return (build, board, name, job, pool, num, check_hosts, skip_reimage, |
| 315 | add_experimental) |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 316 | |
| 317 | |
Chris Masone | 8b76425 | 2012-01-17 11:12:51 -0800 | [diff] [blame] | 318 | def inject_vars(vars, control_file_in): |
| 319 | """ |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 320 | Inject the contents of |vars| into |control_file_in|. |
Chris Masone | 8b76425 | 2012-01-17 11:12:51 -0800 | [diff] [blame] | 321 | |
| 322 | @param vars: a dict to shoehorn into the provided control file string. |
| 323 | @param control_file_in: the contents of a control file to munge. |
| 324 | @return the modified control file string. |
| 325 | """ |
| 326 | control_file = '' |
| 327 | for key, value in vars.iteritems(): |
Chris Masone | 6cb0d0d | 2012-03-05 15:37:49 -0800 | [diff] [blame] | 328 | # None gets injected as 'None' without this check; same for digits. |
| 329 | if isinstance(value, str): |
| 330 | control_file += "%s='%s'\n" % (key, value) |
| 331 | else: |
| 332 | control_file += "%s=%r\n" % (key, value) |
Chris Masone | 8b76425 | 2012-01-17 11:12:51 -0800 | [diff] [blame] | 333 | return control_file + control_file_in |
| 334 | |
| 335 | |
Chris Masone | 2ef1d4e | 2011-12-20 11:06:53 -0800 | [diff] [blame] | 336 | def _image_url_pattern(): |
| 337 | return CONFIG.get_config_value('CROS', 'image_url_pattern', type=str) |
| 338 | |
| 339 | |
| 340 | def _package_url_pattern(): |
| 341 | return CONFIG.get_config_value('CROS', 'package_url_pattern', type=str) |
| 342 | |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 343 | |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 344 | def skip_reimage(g): |
| 345 | return g.get('SKIP_IMAGE') |
| 346 | |
| 347 | |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 348 | class Reimager(object): |
| 349 | """ |
| 350 | A class that can run jobs to reimage devices. |
| 351 | |
| 352 | @var _afe: a frontend.AFE instance used to talk to autotest. |
| 353 | @var _tko: a frontend.TKO instance used to query the autotest results db. |
| 354 | @var _cf_getter: a ControlFileGetter used to get the AU control file. |
| 355 | """ |
| 356 | |
| 357 | |
Chris Masone | 9f13ff2 | 2012-03-05 13:45:25 -0800 | [diff] [blame] | 358 | def __init__(self, autotest_dir, afe=None, tko=None, pool=None, |
| 359 | results_dir=None): |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 360 | """ |
| 361 | Constructor |
| 362 | |
| 363 | @param autotest_dir: the place to find autotests. |
| 364 | @param afe: an instance of AFE as defined in server/frontend.py. |
| 365 | @param tko: an instance of TKO as defined in server/frontend.py. |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 366 | @param pool: Specify the pool of machines to use for scheduling |
| 367 | purposes. |
Chris Masone | 9f13ff2 | 2012-03-05 13:45:25 -0800 | [diff] [blame] | 368 | @param results_dir: The directory where the job can write results to. |
| 369 | This must be set if you want job_id of sub-jobs |
| 370 | list in the job keyvals. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 371 | """ |
Chris Masone | 8ac6671 | 2012-02-15 14:21:02 -0800 | [diff] [blame] | 372 | self._afe = afe or frontend_wrappers.RetryingAFE(timeout_min=30, |
| 373 | delay_sec=10, |
| 374 | debug=False) |
| 375 | self._tko = tko or frontend_wrappers.RetryingTKO(timeout_min=30, |
| 376 | delay_sec=10, |
| 377 | debug=False) |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 378 | self._pool = pool |
Chris Masone | 9f13ff2 | 2012-03-05 13:45:25 -0800 | [diff] [blame] | 379 | self._results_dir = results_dir |
Chris Masone | d368cc4 | 2012-03-07 15:16:59 -0800 | [diff] [blame] | 380 | self._reimaged_hosts = {} |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 381 | self._cf_getter = control_file_getter.FileSystemGetter( |
| 382 | [os.path.join(autotest_dir, 'server/site_tests')]) |
| 383 | |
| 384 | |
Chris Masone | 2ef1d4e | 2011-12-20 11:06:53 -0800 | [diff] [blame] | 385 | def skip(self, g): |
Chris Masone | ab3e733 | 2012-02-29 18:54:58 -0800 | [diff] [blame] | 386 | """Deprecated in favor of dynamic_suite.skip_reimage().""" |
Chris Masone | 2ef1d4e | 2011-12-20 11:06:53 -0800 | [diff] [blame] | 387 | return 'SKIP_IMAGE' in g and g['SKIP_IMAGE'] |
| 388 | |
| 389 | |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 390 | def attempt(self, build, board, record, check_hosts, num=None): |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 391 | """ |
| 392 | Synchronously attempt to reimage some machines. |
| 393 | |
| 394 | Fire off attempts to reimage |num| machines of type |board|, using an |
Chris Masone | 8abb6fc | 2012-01-31 09:27:36 -0800 | [diff] [blame] | 395 | image at |url| called |build|. Wait for completion, polling every |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 396 | 10s, and log results with |record| upon completion. |
| 397 | |
Chris Masone | 8abb6fc | 2012-01-31 09:27:36 -0800 | [diff] [blame] | 398 | @param build: the build to install e.g. |
| 399 | x86-alex-release/R18-1655.0.0-a1-b1584. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 400 | @param board: which kind of devices to reimage. |
| 401 | @param record: callable that records job status. |
Chris Masone | 796fcf1 | 2012-02-22 16:53:31 -0800 | [diff] [blame] | 402 | prototype: |
| 403 | record(status, subdir, name, reason) |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 404 | @param check_hosts: require appropriate hosts to be available now. |
Chris Masone | 5552dd7 | 2012-02-15 15:01:04 -0800 | [diff] [blame] | 405 | @param num: how many devices to reimage. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 406 | @return True if all reimaging jobs succeed, false otherwise. |
| 407 | """ |
Chris Masone | 5552dd7 | 2012-02-15 15:01:04 -0800 | [diff] [blame] | 408 | if not num: |
| 409 | num = CONFIG.get_config_value('CROS', 'sharding_factor', type=int) |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 410 | logging.debug("scheduling reimaging across %d machines", num) |
Chris Masone | 9f13ff2 | 2012-03-05 13:45:25 -0800 | [diff] [blame] | 411 | wrapper_job_name = 'try_new_image' |
Chris Masone | 73f6502 | 2012-01-31 14:00:43 -0800 | [diff] [blame] | 412 | record('START', None, wrapper_job_name) |
Chris Masone | 796fcf1 | 2012-02-22 16:53:31 -0800 | [diff] [blame] | 413 | try: |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 414 | self._ensure_version_label(VERSION_PREFIX + build) |
| 415 | |
| 416 | if check_hosts: |
| 417 | self._ensure_enough_hosts(board, self._pool, num) |
Chris Masone | 5374c67 | 2012-03-05 15:11:39 -0800 | [diff] [blame] | 418 | |
Chris Masone | d368cc4 | 2012-03-07 15:16:59 -0800 | [diff] [blame] | 419 | # Schedule job and record job metadata. |
Chris Masone | d368cc4 | 2012-03-07 15:16:59 -0800 | [diff] [blame] | 420 | canary_job = self._schedule_reimage_job(build, num, board) |
| 421 | self._record_job_if_possible(wrapper_job_name, canary_job) |
| 422 | logging.debug('Created re-imaging job: %d', canary_job.id) |
| 423 | |
| 424 | # Poll until reimaging is complete. |
| 425 | self._wait_for_job_to_start(canary_job.id) |
| 426 | self._wait_for_job_to_finish(canary_job.id) |
| 427 | |
| 428 | # Gather job results. |
| 429 | canary_job.result = self._afe.poll_job_results(self._tko, |
| 430 | canary_job, |
| 431 | 0) |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 432 | except error.InadequateHostsException as e: |
Chris Masone | 5374c67 | 2012-03-05 15:11:39 -0800 | [diff] [blame] | 433 | logging.warning(e) |
| 434 | record('END WARN', None, wrapper_job_name, str(e)) |
| 435 | return False |
Chris Masone | 796fcf1 | 2012-02-22 16:53:31 -0800 | [diff] [blame] | 436 | except Exception as e: |
| 437 | # catch Exception so we record the job as terminated no matter what. |
| 438 | logging.error(e) |
| 439 | record('END ERROR', None, wrapper_job_name, str(e)) |
| 440 | return False |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 441 | |
Chris Masone | d368cc4 | 2012-03-07 15:16:59 -0800 | [diff] [blame] | 442 | self._remember_reimaged_hosts(build, canary_job) |
| 443 | |
| 444 | if canary_job.result is True: |
| 445 | self._report_results(canary_job, record) |
Chris Masone | 73f6502 | 2012-01-31 14:00:43 -0800 | [diff] [blame] | 446 | record('END GOOD', None, wrapper_job_name) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 447 | return True |
| 448 | |
Chris Masone | d368cc4 | 2012-03-07 15:16:59 -0800 | [diff] [blame] | 449 | if canary_job.result is None: |
| 450 | record('FAIL', None, canary_job.name, 'reimaging tasks did not run') |
| 451 | else: # canary_job.result is False |
| 452 | self._report_results(canary_job, record) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 453 | |
Chris Masone | 73f6502 | 2012-01-31 14:00:43 -0800 | [diff] [blame] | 454 | record('END FAIL', None, wrapper_job_name) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 455 | return False |
| 456 | |
| 457 | |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 458 | def _ensure_enough_hosts(self, board, pool, num): |
| 459 | """ |
| 460 | Determine if there are enough working hosts to run on. |
| 461 | |
| 462 | Raises exception if there are not enough hosts. |
| 463 | |
| 464 | @param board: which kind of devices to reimage. |
| 465 | @param pool: the pool of machines to use for scheduling purposes. |
| 466 | @param num: how many devices to reimage. |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 467 | @raises NoHostsException: if no working hosts. |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 468 | @raises InadequateHostsException: if too few working hosts. |
| 469 | """ |
| 470 | labels = [l for l in [board, pool] if l is not None] |
Chris Masone | 502b71e | 2012-04-10 10:41:35 -0700 | [diff] [blame] | 471 | available = self._count_usable_hosts(labels) |
| 472 | if available == 0: |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 473 | raise error.NoHostsException('All hosts with %r are dead!' % labels) |
Chris Masone | 502b71e | 2012-04-10 10:41:35 -0700 | [diff] [blame] | 474 | elif num > available: |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 475 | raise error.InadequateHostsException( |
| 476 | 'Too few hosts with %r' % labels) |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 477 | |
| 478 | |
Chris Masone | d368cc4 | 2012-03-07 15:16:59 -0800 | [diff] [blame] | 479 | def _wait_for_job_to_start(self, job_id): |
| 480 | """ |
| 481 | Wait for the job specified by |job_id| to start. |
| 482 | |
| 483 | @param job_id: the job ID to poll on. |
| 484 | """ |
| 485 | while len(self._afe.get_jobs(id=job_id, not_yet_run=True)) > 0: |
| 486 | time.sleep(10) |
| 487 | logging.debug('Re-imaging job running.') |
| 488 | |
| 489 | |
| 490 | def _wait_for_job_to_finish(self, job_id): |
| 491 | """ |
| 492 | Wait for the job specified by |job_id| to finish. |
| 493 | |
| 494 | @param job_id: the job ID to poll on. |
| 495 | """ |
| 496 | while len(self._afe.get_jobs(id=job_id, finished=True)) == 0: |
| 497 | time.sleep(10) |
| 498 | logging.debug('Re-imaging job finished.') |
| 499 | |
| 500 | |
| 501 | def _remember_reimaged_hosts(self, build, canary_job): |
| 502 | """ |
| 503 | Remember hosts that were reimaged with |build| as a part |canary_job|. |
| 504 | |
| 505 | @param build: the build that was installed e.g. |
| 506 | x86-alex-release/R18-1655.0.0-a1-b1584. |
| 507 | @param canary_job: a completed frontend.Job object, possibly populated |
| 508 | by frontend.AFE.poll_job_results. |
| 509 | """ |
| 510 | if not hasattr(canary_job, 'results_platform_map'): |
| 511 | return |
| 512 | if not self._reimaged_hosts.get('build'): |
| 513 | self._reimaged_hosts[build] = [] |
| 514 | for platform in canary_job.results_platform_map: |
| 515 | for host in canary_job.results_platform_map[platform]['Total']: |
| 516 | self._reimaged_hosts[build].append(host) |
| 517 | |
| 518 | |
| 519 | def clear_reimaged_host_state(self, build): |
| 520 | """ |
| 521 | Clear per-host state created in the autotest DB for this job. |
| 522 | |
| 523 | After reimaging a host, we label it and set some host attributes on it |
| 524 | that are then used by the suite scheduling code. This call cleans |
| 525 | that up. |
| 526 | |
| 527 | @param build: the build whose hosts we want to clean up e.g. |
| 528 | x86-alex-release/R18-1655.0.0-a1-b1584. |
| 529 | """ |
Chris Masone | d368cc4 | 2012-03-07 15:16:59 -0800 | [diff] [blame] | 530 | for host in self._reimaged_hosts.get('build', []): |
| 531 | self._clear_build_state(host) |
| 532 | |
| 533 | |
| 534 | def _clear_build_state(self, machine): |
| 535 | """ |
| 536 | Clear all build-specific labels, attributes from the target. |
| 537 | |
| 538 | @param machine: the host to clear labels, attributes from. |
| 539 | """ |
| 540 | self._afe.set_host_attribute('job_repo_url', None, hostname=machine) |
| 541 | |
| 542 | |
Chris Masone | 9f13ff2 | 2012-03-05 13:45:25 -0800 | [diff] [blame] | 543 | def _record_job_if_possible(self, test_name, job): |
| 544 | """ |
| 545 | Record job id as keyval, if possible, so it can be referenced later. |
| 546 | |
| 547 | If |self._results_dir| is None, then this is a NOOP. |
Chris Masone | 5374c67 | 2012-03-05 15:11:39 -0800 | [diff] [blame] | 548 | |
| 549 | @param test_name: the test to record id/owner for. |
| 550 | @param job: the job object to pull info from. |
Chris Masone | 9f13ff2 | 2012-03-05 13:45:25 -0800 | [diff] [blame] | 551 | """ |
| 552 | if self._results_dir: |
| 553 | job_id_owner = '%s-%s' % (job.id, job.owner) |
| 554 | utils.write_keyval(self._results_dir, {test_name: job_id_owner}) |
| 555 | |
| 556 | |
Chris Masone | 5374c67 | 2012-03-05 15:11:39 -0800 | [diff] [blame] | 557 | def _count_usable_hosts(self, host_spec): |
| 558 | """ |
| 559 | Given a set of host labels, count the live hosts that have them all. |
| 560 | |
| 561 | @param host_spec: list of labels specifying a set of hosts. |
| 562 | @return the number of live hosts that satisfy |host_spec|. |
| 563 | """ |
| 564 | count = 0 |
| 565 | for h in self._afe.get_hosts(multiple_labels=host_spec): |
| 566 | if h.status not in ['Repair Failed', 'Repairing']: |
| 567 | count += 1 |
| 568 | return count |
| 569 | |
| 570 | |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 571 | def _ensure_version_label(self, name): |
| 572 | """ |
| 573 | Ensure that a label called |name| exists in the autotest DB. |
| 574 | |
| 575 | @param name: the label to check for/create. |
| 576 | """ |
Chris Masone | 47c9e64 | 2012-04-25 14:22:18 -0700 | [diff] [blame] | 577 | try: |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 578 | self._afe.create_label(name=name) |
Chris Masone | 47c9e64 | 2012-04-25 14:22:18 -0700 | [diff] [blame] | 579 | except proxy.ValidationError as ve: |
| 580 | if ('name' in ve.problem_keys and |
| 581 | 'This value must be unique' in ve.problem_keys['name']): |
| 582 | logging.debug('Version label %s already exists', name) |
| 583 | else: |
| 584 | raise ve |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 585 | |
| 586 | |
Chris Masone | 8abb6fc | 2012-01-31 09:27:36 -0800 | [diff] [blame] | 587 | def _schedule_reimage_job(self, build, num_machines, board): |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 588 | """ |
| 589 | Schedules the reimaging of |num_machines| |board| devices with |image|. |
| 590 | |
| 591 | Sends an RPC to the autotest frontend to enqueue reimaging jobs on |
| 592 | |num_machines| devices of type |board| |
| 593 | |
Chris Masone | 8abb6fc | 2012-01-31 09:27:36 -0800 | [diff] [blame] | 594 | @param build: the build to install (must be unique). |
Chris Masone | 2ef1d4e | 2011-12-20 11:06:53 -0800 | [diff] [blame] | 595 | @param num_machines: how many devices to reimage. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 596 | @param board: which kind of devices to reimage. |
| 597 | @return a frontend.Job object for the reimaging job we scheduled. |
| 598 | """ |
Chris Masone | 8b76425 | 2012-01-17 11:12:51 -0800 | [diff] [blame] | 599 | control_file = inject_vars( |
Chris Masone | 8abb6fc | 2012-01-31 09:27:36 -0800 | [diff] [blame] | 600 | {'image_url': _image_url_pattern() % build, 'image_name': build}, |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 601 | self._cf_getter.get_control_file_contents_by_name('autoupdate')) |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 602 | job_deps = [] |
| 603 | if self._pool: |
Chris Masone | 5374c67 | 2012-03-05 15:11:39 -0800 | [diff] [blame] | 604 | meta_host = self._pool |
| 605 | board_label = board |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 606 | job_deps.append(board_label) |
| 607 | else: |
| 608 | # No pool specified use board. |
Chris Masone | 5374c67 | 2012-03-05 15:11:39 -0800 | [diff] [blame] | 609 | meta_host = board |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 610 | |
Chris Masone | 2ef1d4e | 2011-12-20 11:06:53 -0800 | [diff] [blame] | 611 | return self._afe.create_job(control_file=control_file, |
Chris Masone | 8abb6fc | 2012-01-31 09:27:36 -0800 | [diff] [blame] | 612 | name=build + '-try', |
Chris Masone | 2ef1d4e | 2011-12-20 11:06:53 -0800 | [diff] [blame] | 613 | control_type='Server', |
Chris Masone | 9732536 | 2012-04-26 16:19:13 -0700 | [diff] [blame] | 614 | priority='Low', |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 615 | meta_hosts=[meta_host] * num_machines, |
| 616 | dependencies=job_deps) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 617 | |
| 618 | |
| 619 | def _report_results(self, job, record): |
| 620 | """ |
| 621 | Record results from a completed frontend.Job object. |
| 622 | |
| 623 | @param job: a completed frontend.Job object populated by |
| 624 | frontend.AFE.poll_job_results. |
| 625 | @param record: callable that records job status. |
| 626 | prototype: |
| 627 | record(status, subdir, name, reason) |
| 628 | """ |
| 629 | if job.result == True: |
| 630 | record('GOOD', None, job.name) |
| 631 | return |
| 632 | |
| 633 | for platform in job.results_platform_map: |
| 634 | for status in job.results_platform_map[platform]: |
| 635 | if status == 'Total': |
| 636 | continue |
| 637 | for host in job.results_platform_map[platform][status]: |
| 638 | if host not in job.test_status: |
| 639 | record('ERROR', None, host, 'Job failed to run.') |
| 640 | elif status == 'Failed': |
| 641 | for test_status in job.test_status[host].fail: |
| 642 | record('FAIL', None, host, test_status.reason) |
| 643 | elif status == 'Aborted': |
| 644 | for test_status in job.test_status[host].fail: |
| 645 | record('ABORT', None, host, test_status.reason) |
| 646 | elif status == 'Completed': |
| 647 | record('GOOD', None, host) |
| 648 | |
| 649 | |
Chris Masone | 9937858 | 2012-04-30 13:10:58 -0700 | [diff] [blame] | 650 | class Status(object): |
| 651 | """ |
| 652 | A class representing a test result. |
| 653 | |
| 654 | Stores all pertinent info about a test result and, given a callable |
| 655 | to use, can record start, result, and end info appropriately. |
| 656 | |
| 657 | @var _status: status code, e.g. 'INFO', 'FAIL', etc. |
| 658 | @var _test_name: the name of the test whose result this is. |
| 659 | @var _reason: message explaining failure, if any. |
| 660 | @var _begin_timestamp: when test started (in seconds since the epoch). |
| 661 | @var _end_timestamp: when test finished (in seconds since the epoch). |
| 662 | |
| 663 | @var _TIME_FMT: format string for parsing human-friendly timestamps. |
| 664 | """ |
| 665 | _status = None |
| 666 | _test_name = None |
| 667 | _reason = None |
| 668 | _begin_timestamp = None |
| 669 | _end_timestamp = None |
| 670 | _TIME_FMT = '%Y-%m-%d %H:%M:%S' |
| 671 | |
| 672 | |
| 673 | def __init__(self, status, test_name, reason='', begin_time_str=None, |
| 674 | end_time_str=None): |
| 675 | """ |
| 676 | Constructor |
| 677 | |
| 678 | @param status: status code, e.g. 'INFO', 'FAIL', etc. |
| 679 | @param test_name: the name of the test whose result this is. |
| 680 | @param reason: message explaining failure, if any; Optional. |
| 681 | @param begin_time_str: when test started (in _TIME_FMT); now() if None. |
| 682 | @param end_time_str: when test finished (in _TIME_FMT); now() if None. |
| 683 | """ |
| 684 | |
| 685 | self._status = status |
| 686 | self._test_name = test_name |
| 687 | self._reason = reason |
| 688 | if begin_time_str: |
| 689 | self._begin_timestamp = int(time.mktime( |
| 690 | datetime.datetime.strptime( |
| 691 | begin_time_str, self._TIME_FMT).timetuple())) |
| 692 | else: |
| 693 | self._begin_timestamp = time.time() |
| 694 | |
| 695 | if end_time_str: |
| 696 | self._end_timestamp = int(time.mktime( |
| 697 | datetime.datetime.strptime( |
| 698 | end_time_str, self._TIME_FMT).timetuple())) |
| 699 | else: |
| 700 | self._end_timestamp = time.time() |
| 701 | |
| 702 | |
| 703 | def record_start(self, record_entry): |
| 704 | """ |
| 705 | Use record_entry to log message about start of test. |
| 706 | |
| 707 | @param record_entry: a callable to use for logging. |
| 708 | prototype: |
| 709 | record_entry(base_job.status_log_entry) |
| 710 | """ |
| 711 | record_entry( |
| 712 | base_job.status_log_entry( |
| 713 | 'START', None, self._test_name, '', |
| 714 | None, self._begin_timestamp)) |
| 715 | |
| 716 | |
| 717 | def record_result(self, record_entry): |
| 718 | """ |
| 719 | Use record_entry to log message about result of test. |
| 720 | |
| 721 | @param record_entry: a callable to use for logging. |
| 722 | prototype: |
| 723 | record_entry(base_job.status_log_entry) |
| 724 | """ |
| 725 | record_entry( |
| 726 | base_job.status_log_entry( |
| 727 | self._status, None, self._test_name, self._reason, |
| 728 | None, self._end_timestamp)) |
| 729 | |
| 730 | |
| 731 | def record_end(self, record_entry): |
| 732 | """ |
| 733 | Use record_entry to log message about end of test. |
| 734 | |
| 735 | @param record_entry: a callable to use for logging. |
| 736 | prototype: |
| 737 | record_entry(base_job.status_log_entry) |
| 738 | """ |
| 739 | record_entry( |
| 740 | base_job.status_log_entry( |
| 741 | 'END %s' % self._status, None, self._test_name, '', |
| 742 | None, self._end_timestamp)) |
| 743 | |
| 744 | |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 745 | class Suite(object): |
| 746 | """ |
| 747 | A suite of tests, defined by some predicate over control file variables. |
| 748 | |
| 749 | Given a place to search for control files a predicate to match the desired |
| 750 | tests, can gather tests and fire off jobs to run them, and then wait for |
| 751 | results. |
| 752 | |
| 753 | @var _predicate: a function that should return True when run over a |
| 754 | ControlData representation of a control file that should be in |
| 755 | this Suite. |
| 756 | @var _tag: a string with which to tag jobs run in this suite. |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 757 | @var _build: the build on which we're running this suite. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 758 | @var _afe: an instance of AFE as defined in server/frontend.py. |
| 759 | @var _tko: an instance of TKO as defined in server/frontend.py. |
| 760 | @var _jobs: currently scheduled jobs, if any. |
| 761 | @var _cf_getter: a control_file_getter.ControlFileGetter |
| 762 | """ |
| 763 | |
| 764 | |
Chris Masone | fef2138 | 2012-01-17 11:16:32 -0800 | [diff] [blame] | 765 | @staticmethod |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 766 | def create_ds_getter(build): |
Chris Masone | fef2138 | 2012-01-17 11:16:32 -0800 | [diff] [blame] | 767 | """ |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 768 | @param build: the build on which we're running this suite. |
Chris Masone | fef2138 | 2012-01-17 11:16:32 -0800 | [diff] [blame] | 769 | @return a FileSystemGetter instance that looks under |autotest_dir|. |
| 770 | """ |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 771 | return control_file_getter.DevServerGetter( |
| 772 | build, dev_server.DevServer.create()) |
Chris Masone | fef2138 | 2012-01-17 11:16:32 -0800 | [diff] [blame] | 773 | |
| 774 | |
| 775 | @staticmethod |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 776 | def create_fs_getter(autotest_dir): |
| 777 | """ |
| 778 | @param autotest_dir: the place to find autotests. |
| 779 | @return a FileSystemGetter instance that looks under |autotest_dir|. |
| 780 | """ |
| 781 | # currently hard-coded places to look for tests. |
| 782 | subpaths = ['server/site_tests', 'client/site_tests', |
| 783 | 'server/tests', 'client/tests'] |
| 784 | directories = [os.path.join(autotest_dir, p) for p in subpaths] |
| 785 | return control_file_getter.FileSystemGetter(directories) |
| 786 | |
| 787 | |
| 788 | @staticmethod |
Zdenek Behan | 849db05 | 2012-02-29 19:16:28 +0100 | [diff] [blame] | 789 | def parse_tag(tag): |
| 790 | """Splits a string on ',' optionally surrounded by whitespace.""" |
| 791 | return map(lambda x: x.strip(), tag.split(',')) |
| 792 | |
| 793 | |
| 794 | @staticmethod |
Chris Masone | 8456479 | 2012-02-23 10:52:42 -0800 | [diff] [blame] | 795 | def name_in_tag_predicate(name): |
| 796 | """Returns predicate that takes a control file and looks for |name|. |
| 797 | |
| 798 | Builds a predicate that takes in a parsed control file (a ControlData) |
| 799 | and returns True if the SUITE tag is present and contains |name|. |
| 800 | |
| 801 | @param name: the suite name to base the predicate on. |
| 802 | @return a callable that takes a ControlData and looks for |name| in that |
| 803 | ControlData object's suite member. |
| 804 | """ |
Zdenek Behan | 849db05 | 2012-02-29 19:16:28 +0100 | [diff] [blame] | 805 | return lambda t: hasattr(t, 'suite') and \ |
| 806 | name in Suite.parse_tag(t.suite) |
Chris Masone | 8456479 | 2012-02-23 10:52:42 -0800 | [diff] [blame] | 807 | |
Zdenek Behan | 849db05 | 2012-02-29 19:16:28 +0100 | [diff] [blame] | 808 | |
| 809 | @staticmethod |
| 810 | def list_all_suites(build, cf_getter=None): |
| 811 | """ |
| 812 | Parses all ControlData objects with a SUITE tag and extracts all |
| 813 | defined suite names. |
| 814 | |
| 815 | @param cf_getter: control_file_getter.ControlFileGetter. Defaults to |
| 816 | using DevServerGetter. |
| 817 | |
| 818 | @return list of suites |
| 819 | """ |
| 820 | if cf_getter is None: |
| 821 | cf_getter = Suite.create_ds_getter(build) |
| 822 | |
| 823 | suites = set() |
| 824 | predicate = lambda t: hasattr(t, 'suite') |
| 825 | for test in Suite.find_and_parse_tests(cf_getter, predicate): |
| 826 | suites.update(Suite.parse_tag(test.suite)) |
| 827 | return list(suites) |
Chris Masone | 8456479 | 2012-02-23 10:52:42 -0800 | [diff] [blame] | 828 | |
| 829 | |
| 830 | @staticmethod |
Scott Zawalski | 9ece653 | 2012-02-28 14:10:47 -0500 | [diff] [blame] | 831 | def create_from_name(name, build, cf_getter=None, afe=None, tko=None, |
| 832 | pool=None, results_dir=None): |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 833 | """ |
| 834 | Create a Suite using a predicate based on the SUITE control file var. |
| 835 | |
| 836 | Makes a predicate based on |name| and uses it to instantiate a Suite |
| 837 | that looks for tests in |autotest_dir| and will schedule them using |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 838 | |afe|. Pulls control files from the default dev server. |
| 839 | Results will be pulled from |tko| upon completion. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 840 | |
| 841 | @param name: a value of the SUITE control file variable to search for. |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 842 | @param build: the build on which we're running this suite. |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 843 | @param cf_getter: a control_file_getter.ControlFileGetter. |
| 844 | If None, default to using a DevServerGetter. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 845 | @param afe: an instance of AFE as defined in server/frontend.py. |
| 846 | @param tko: an instance of TKO as defined in server/frontend.py. |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 847 | @param pool: Specify the pool of machines to use for scheduling |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 848 | purposes. |
Scott Zawalski | 9ece653 | 2012-02-28 14:10:47 -0500 | [diff] [blame] | 849 | @param results_dir: The directory where the job can write results to. |
| 850 | This must be set if you want job_id of sub-jobs |
| 851 | list in the job keyvals. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 852 | @return a Suite instance. |
| 853 | """ |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 854 | if cf_getter is None: |
| 855 | cf_getter = Suite.create_ds_getter(build) |
Chris Masone | 8456479 | 2012-02-23 10:52:42 -0800 | [diff] [blame] | 856 | return Suite(Suite.name_in_tag_predicate(name), |
Scott Zawalski | 9ece653 | 2012-02-28 14:10:47 -0500 | [diff] [blame] | 857 | name, build, cf_getter, afe, tko, pool, results_dir) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 858 | |
| 859 | |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 860 | def __init__(self, predicate, tag, build, cf_getter, afe=None, tko=None, |
Scott Zawalski | 9ece653 | 2012-02-28 14:10:47 -0500 | [diff] [blame] | 861 | pool=None, results_dir=None): |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 862 | """ |
| 863 | Constructor |
| 864 | |
| 865 | @param predicate: a function that should return True when run over a |
| 866 | ControlData representation of a control file that should be in |
| 867 | this Suite. |
| 868 | @param tag: a string with which to tag jobs run in this suite. |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 869 | @param build: the build on which we're running this suite. |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 870 | @param cf_getter: a control_file_getter.ControlFileGetter |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 871 | @param afe: an instance of AFE as defined in server/frontend.py. |
| 872 | @param tko: an instance of TKO as defined in server/frontend.py. |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 873 | @param pool: Specify the pool of machines to use for scheduling |
| 874 | purposes. |
Scott Zawalski | 9ece653 | 2012-02-28 14:10:47 -0500 | [diff] [blame] | 875 | @param results_dir: The directory where the job can write results to. |
| 876 | This must be set if you want job_id of sub-jobs |
| 877 | list in the job keyvals. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 878 | """ |
| 879 | self._predicate = predicate |
| 880 | self._tag = tag |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 881 | self._build = build |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 882 | self._cf_getter = cf_getter |
Scott Zawalski | 9ece653 | 2012-02-28 14:10:47 -0500 | [diff] [blame] | 883 | self._results_dir = results_dir |
Chris Masone | 8ac6671 | 2012-02-15 14:21:02 -0800 | [diff] [blame] | 884 | self._afe = afe or frontend_wrappers.RetryingAFE(timeout_min=30, |
| 885 | delay_sec=10, |
| 886 | debug=False) |
| 887 | self._tko = tko or frontend_wrappers.RetryingTKO(timeout_min=30, |
| 888 | delay_sec=10, |
| 889 | debug=False) |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 890 | self._pool = pool |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 891 | self._jobs = [] |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 892 | self._tests = Suite.find_and_parse_tests(self._cf_getter, |
| 893 | self._predicate, |
| 894 | add_experimental=True) |
| 895 | |
| 896 | |
| 897 | @property |
| 898 | def tests(self): |
| 899 | """ |
| 900 | A list of ControlData objects in the suite, with added |text| attr. |
| 901 | """ |
| 902 | return self._tests |
| 903 | |
| 904 | |
| 905 | def stable_tests(self): |
| 906 | """ |
| 907 | |self.tests|, filtered for non-experimental tests. |
| 908 | """ |
| 909 | return filter(lambda t: not t.experimental, self.tests) |
| 910 | |
| 911 | |
| 912 | def unstable_tests(self): |
| 913 | """ |
| 914 | |self.tests|, filtered for experimental tests. |
| 915 | """ |
| 916 | return filter(lambda t: t.experimental, self.tests) |
| 917 | |
| 918 | |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 919 | def _create_job(self, test): |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 920 | """ |
| 921 | Thin wrapper around frontend.AFE.create_job(). |
| 922 | |
| 923 | @param test: ControlData object for a test to run. |
Scott Zawalski | e5bb1c5 | 2012-02-29 13:15:50 -0500 | [diff] [blame] | 924 | @return a frontend.Job object with an added test_name member. |
| 925 | test_name is used to preserve the higher level TEST_NAME |
| 926 | name of the job. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 927 | """ |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 928 | job_deps = [] |
| 929 | if self._pool: |
Chris Masone | 5374c67 | 2012-03-05 15:11:39 -0800 | [diff] [blame] | 930 | meta_hosts = self._pool |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 931 | cros_label = VERSION_PREFIX + self._build |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 932 | job_deps.append(cros_label) |
| 933 | else: |
| 934 | # No pool specified use any machines with the following label. |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 935 | meta_hosts = VERSION_PREFIX + self._build |
Scott Zawalski | e5bb1c5 | 2012-02-29 13:15:50 -0500 | [diff] [blame] | 936 | test_obj = self._afe.create_job( |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 937 | control_file=test.text, |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 938 | name='/'.join([self._build, self._tag, test.name]), |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 939 | control_type=test.test_type.capitalize(), |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 940 | meta_hosts=[meta_hosts], |
Chris Masone | 52c7fb7 | 2012-05-07 14:12:05 -0700 | [diff] [blame] | 941 | dependencies=job_deps) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 942 | |
Scott Zawalski | e5bb1c5 | 2012-02-29 13:15:50 -0500 | [diff] [blame] | 943 | setattr(test_obj, 'test_name', test.name) |
| 944 | |
| 945 | return test_obj |
| 946 | |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 947 | |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 948 | def run_and_wait(self, record, add_experimental=True): |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 949 | """ |
| 950 | Synchronously run tests in |self.tests|. |
| 951 | |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 952 | Schedules tests against a device running image |self._build|, and |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 953 | then polls for status, using |record| to print status when each |
| 954 | completes. |
| 955 | |
| 956 | Tests returned by self.stable_tests() will always be run, while tests |
| 957 | in self.unstable_tests() will only be run if |add_experimental| is true. |
| 958 | |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 959 | @param record: callable that records job status. |
| 960 | prototype: |
| 961 | record(status, subdir, name, reason) |
| 962 | @param add_experimental: schedule experimental tests as well, or not. |
| 963 | """ |
Chris Masone | ed35639 | 2012-05-08 14:07:13 -0700 | [diff] [blame] | 964 | logging.debug('Discovered %d stable tests.', len(self.stable_tests())) |
| 965 | logging.debug('Discovered %d unstable tests.', |
| 966 | len(self.unstable_tests())) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 967 | try: |
Chris Masone | 9937858 | 2012-04-30 13:10:58 -0700 | [diff] [blame] | 968 | Status('INFO', 'Start %s' % self._tag).record_result(record) |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 969 | self.schedule(add_experimental) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 970 | try: |
| 971 | for result in self.wait_for_results(): |
Chris Masone | 9937858 | 2012-04-30 13:10:58 -0700 | [diff] [blame] | 972 | result.record_start(record) |
| 973 | result.record_result(record) |
| 974 | result.record_end(record) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 975 | except Exception as e: |
Chris Masone | 9937858 | 2012-04-30 13:10:58 -0700 | [diff] [blame] | 976 | logging.error(traceback.format_exc()) |
| 977 | Status('FAIL', self._tag, |
| 978 | 'Exception waiting for results').record_result(record) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 979 | except Exception as e: |
Chris Masone | 9937858 | 2012-04-30 13:10:58 -0700 | [diff] [blame] | 980 | logging.error(traceback.format_exc()) |
| 981 | Status('FAIL', self._tag, |
| 982 | 'Exception while scheduling suite').record_result(record) |
Chris Masone | ed35639 | 2012-05-08 14:07:13 -0700 | [diff] [blame] | 983 | # Sanity check |
| 984 | tests_at_end = self.find_and_parse_tests(self._cf_getter, |
| 985 | self._predicate, |
| 986 | add_experimental=True) |
| 987 | if len(self.tests) != len(tests_at_end): |
| 988 | msg = 'Dev Server enumerated %d tests at start, %d at end.' % ( |
| 989 | len(self.tests), len(tests_at_end)) |
| 990 | Status('FAIL', self._tag, msg).record_result(record) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 991 | |
| 992 | |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 993 | def schedule(self, add_experimental=True): |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 994 | """ |
| 995 | Schedule jobs using |self._afe|. |
| 996 | |
| 997 | frontend.Job objects representing each scheduled job will be put in |
| 998 | |self._jobs|. |
| 999 | |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 1000 | @param add_experimental: schedule experimental tests as well, or not. |
| 1001 | """ |
| 1002 | for test in self.stable_tests(): |
| 1003 | logging.debug('Scheduling %s', test.name) |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 1004 | self._jobs.append(self._create_job(test)) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 1005 | |
| 1006 | if add_experimental: |
| 1007 | # TODO(cmasone): ensure I can log results from these differently. |
| 1008 | for test in self.unstable_tests(): |
Zdenek Behan | 150fbd6 | 2012-04-06 17:20:01 +0200 | [diff] [blame] | 1009 | logging.debug('Scheduling experimental %s', test.name) |
| 1010 | test.name = 'experimental_' + test.name |
Chris Masone | 8b7cd42 | 2012-02-22 13:16:11 -0800 | [diff] [blame] | 1011 | self._jobs.append(self._create_job(test)) |
Scott Zawalski | 9ece653 | 2012-02-28 14:10:47 -0500 | [diff] [blame] | 1012 | if self._results_dir: |
| 1013 | self._record_scheduled_jobs() |
| 1014 | |
| 1015 | |
| 1016 | def _record_scheduled_jobs(self): |
| 1017 | """ |
| 1018 | Record scheduled job ids as keyvals, so they can be referenced later. |
Scott Zawalski | 9ece653 | 2012-02-28 14:10:47 -0500 | [diff] [blame] | 1019 | """ |
| 1020 | for job in self._jobs: |
| 1021 | job_id_owner = '%s-%s' % (job.id, job.owner) |
Scott Zawalski | e5bb1c5 | 2012-02-29 13:15:50 -0500 | [diff] [blame] | 1022 | utils.write_keyval(self._results_dir, {job.test_name: job_id_owner}) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 1023 | |
| 1024 | |
| 1025 | def _status_is_relevant(self, status): |
| 1026 | """ |
| 1027 | Indicates whether the status of a given test is meaningful or not. |
| 1028 | |
| 1029 | @param status: frontend.TestStatus object to look at. |
| 1030 | @return True if this is a test result worth looking at further. |
| 1031 | """ |
| 1032 | return not (status.test_name.startswith('SERVER_JOB') or |
| 1033 | status.test_name.startswith('CLIENT_JOB')) |
| 1034 | |
| 1035 | |
| 1036 | def _collate_aborted(self, current_value, entry): |
| 1037 | """ |
| 1038 | reduce() over a list of HostQueueEntries for a job; True if any aborted. |
| 1039 | |
| 1040 | Functor that can be reduced()ed over a list of |
| 1041 | HostQueueEntries for a job. If any were aborted |
| 1042 | (|entry.aborted| exists and is True), then the reduce() will |
| 1043 | return True. |
| 1044 | |
| 1045 | Ex: |
| 1046 | entries = self._afe.run('get_host_queue_entries', job=job.id) |
| 1047 | reduce(self._collate_aborted, entries, False) |
| 1048 | |
| 1049 | @param current_value: the current accumulator (a boolean). |
| 1050 | @param entry: the current entry under consideration. |
| 1051 | @return the value of |entry.aborted| if it exists, False if not. |
| 1052 | """ |
| 1053 | return current_value or ('aborted' in entry and entry['aborted']) |
| 1054 | |
| 1055 | |
| 1056 | def wait_for_results(self): |
| 1057 | """ |
| 1058 | Wait for results of all tests in all jobs in |self._jobs|. |
| 1059 | |
| 1060 | Currently polls for results every 5s. When all results are available, |
| 1061 | @return a list of tuples, one per test: (status, subdir, name, reason) |
| 1062 | """ |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 1063 | while self._jobs: |
| 1064 | for job in list(self._jobs): |
| 1065 | if not self._afe.get_jobs(id=job.id, finished=True): |
| 1066 | continue |
| 1067 | |
| 1068 | self._jobs.remove(job) |
| 1069 | |
| 1070 | entries = self._afe.run('get_host_queue_entries', job=job.id) |
| 1071 | if reduce(self._collate_aborted, entries, False): |
Chris Masone | 9937858 | 2012-04-30 13:10:58 -0700 | [diff] [blame] | 1072 | yield Status('ABORT', job.name) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 1073 | else: |
| 1074 | statuses = self._tko.get_status_counts(job=job.id) |
| 1075 | for s in filter(self._status_is_relevant, statuses): |
Chris Masone | 9937858 | 2012-04-30 13:10:58 -0700 | [diff] [blame] | 1076 | yield Status(s.status, s.test_name, s.reason, |
| 1077 | s.test_started_time, |
| 1078 | s.test_finished_time) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 1079 | time.sleep(5) |
| 1080 | |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 1081 | |
Chris Masone | fef2138 | 2012-01-17 11:16:32 -0800 | [diff] [blame] | 1082 | @staticmethod |
| 1083 | def find_and_parse_tests(cf_getter, predicate, add_experimental=False): |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 1084 | """ |
| 1085 | Function to scan through all tests and find eligible tests. |
| 1086 | |
| 1087 | Looks at control files returned by _cf_getter.get_control_file_list() |
| 1088 | for tests that pass self._predicate(). |
| 1089 | |
| 1090 | @param cf_getter: a control_file_getter.ControlFileGetter used to list |
| 1091 | and fetch the content of control files |
| 1092 | @param predicate: a function that should return True when run over a |
| 1093 | ControlData representation of a control file that should be in |
| 1094 | this Suite. |
| 1095 | @param add_experimental: add tests with experimental attribute set. |
| 1096 | |
| 1097 | @return list of ControlData objects that should be run, with control |
| 1098 | file text added in |text| attribute. |
| 1099 | """ |
| 1100 | tests = {} |
| 1101 | files = cf_getter.get_control_file_list() |
Chris Masone | 75a2061 | 2012-05-08 12:37:31 -0700 | [diff] [blame] | 1102 | matcher = re.compile(r'[^/]+/(deps|profilers)/.+') |
| 1103 | for file in filter(lambda f: not matcher.match(f), files): |
Chris Masone | ed35639 | 2012-05-08 14:07:13 -0700 | [diff] [blame] | 1104 | logging.debug('Considering %s', file) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 1105 | text = cf_getter.get_control_file_contents(file) |
| 1106 | try: |
Chris Masone | ed35639 | 2012-05-08 14:07:13 -0700 | [diff] [blame] | 1107 | found_test = control_data.parse_control_string( |
| 1108 | text, raise_warnings=True) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 1109 | if not add_experimental and found_test.experimental: |
| 1110 | continue |
| 1111 | |
| 1112 | found_test.text = text |
Chris Masone | e8a4eff | 2012-02-28 16:33:43 -0800 | [diff] [blame] | 1113 | found_test.path = file |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 1114 | tests[file] = found_test |
| 1115 | except control_data.ControlVariableException, e: |
| 1116 | logging.warn("Skipping %s\n%s", file, e) |
| 1117 | except Exception, e: |
| 1118 | logging.error("Bad %s\n%s", file, e) |
| 1119 | |
| 1120 | return [test for test in tests.itervalues() if predicate(test)] |