Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [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 | |
| 5 | __author__ = 'cmasone@chromium.org (Chris Masone)' |
| 6 | |
| 7 | import common |
| 8 | import logging |
| 9 | import sys |
| 10 | from autotest_lib.client.common_lib import global_config |
| 11 | from autotest_lib.client.common_lib.cros import dev_server |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 12 | from autotest_lib.server.cros import control_file_getter, dynamic_suite |
| 13 | |
| 14 | |
| 15 | class StageBuildFailure(Exception): |
| 16 | """Raised when the dev server throws 500 while staging a build.""" |
| 17 | pass |
| 18 | |
| 19 | |
| 20 | class ControlFileEmpty(Exception): |
| 21 | """Raised when the control file exists on the server, but can't be read.""" |
| 22 | pass |
| 23 | |
| 24 | |
| 25 | def _rpc_utils(): |
Chris Masone | b1451a0 | 2012-03-12 10:21:14 -0700 | [diff] [blame^] | 26 | """Returns the rpc_utils module. MUST be mocked for unit tests. |
| 27 | |
| 28 | rpc_utils initializes django, which we can't do in unit tests. |
| 29 | This layer of indirection allows us to only load that module if we're |
| 30 | not running unit tests. |
| 31 | |
| 32 | @return: autotest_lib.frontend.afe.rpc_utils |
| 33 | """ |
| 34 | from autotest_lib.frontend.afe import rpc_utils |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 35 | return rpc_utils |
| 36 | |
| 37 | |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 38 | def canonicalize_suite_name(suite_name): |
| 39 | return 'test_suites/control.%s' % suite_name |
| 40 | |
| 41 | |
| 42 | def create_suite_job(suite_name, board, build, pool, check_hosts=True): |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 43 | """ |
| 44 | Create a job to run a test suite on the given device with the given image. |
| 45 | |
| 46 | When the timeout specified in the control file is reached, the |
| 47 | job is guaranteed to have completed and results will be available. |
| 48 | |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 49 | @param suite_name: the test suite to run, e.g. 'bvt'. |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 50 | @param board: the kind of device to run the tests on. |
| 51 | @param build: unique name by which to refer to the image from now on. |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 52 | @param pool: Specify the pool of machines to use for scheduling |
| 53 | purposes. |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 54 | @param check_hosts: require appropriate live hosts to exist in the lab. |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 55 | |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 56 | @raises ControlFileNotFound if a unique suite control file doesn't exist. |
| 57 | @raises NoControlFileList if we can't list the control files at all. |
| 58 | @raises StageBuildFailure if the dev server throws 500 while staging build. |
| 59 | @raises ControlFileEmpty if the control file exists on the server, but |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 60 | can't be read. |
| 61 | |
| 62 | @return: the job ID of the suite; -1 on error. |
| 63 | """ |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 64 | # All suite names are assumed under test_suites/control.XX. |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 65 | suite_name = canonicalize_suite_name(suite_name) |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 66 | # Ensure |build| is staged is on the dev server. |
| 67 | ds = dev_server.DevServer.create() |
| 68 | if not ds.trigger_download(build): |
| 69 | raise StageBuildFailure("Server error while staging " + build) |
| 70 | |
| 71 | getter = control_file_getter.DevServerGetter.create(build, ds) |
| 72 | # Get the control file for the suite. |
| 73 | control_file_in = getter.get_control_file_contents_by_name(suite_name) |
| 74 | if not control_file_in: |
| 75 | raise ControlFileEmpty("Fetching %s returned no data." % suite_name) |
| 76 | |
| 77 | # prepend build and board to the control file |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 78 | inject_dict = {'board': board, |
| 79 | 'build': build, |
Chris Masone | 6257912 | 2012-03-08 15:18:43 -0800 | [diff] [blame] | 80 | 'check_hosts': check_hosts, |
Scott Zawalski | 6565017 | 2012-02-16 11:48:26 -0500 | [diff] [blame] | 81 | 'pool': pool} |
| 82 | control_file = dynamic_suite.inject_vars(inject_dict, control_file_in) |
Chris Masone | 859fdec | 2012-01-30 08:38:09 -0800 | [diff] [blame] | 83 | |
| 84 | return _rpc_utils().create_job_common('%s-%s' % (build, suite_name), |
| 85 | priority='Medium', |
| 86 | control_type='Server', |
| 87 | control_file=control_file, |
| 88 | hostless=True) |