Chris Masone | f0a902e | 2012-10-03 08:32:48 -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 | |
| 5 | import ast, os, random |
| 6 | |
| 7 | from autotest_lib.client.common_lib.cros import dev_server |
| 8 | from autotest_lib.server import frontend |
| 9 | from autotest_lib.server.cros.dynamic_suite import constants, tools |
| 10 | |
| 11 | """A wrapper around a dynamic suite control file to enable local testing. |
| 12 | |
| 13 | usage: server/autoserv test_suites/dev_harness.py |
| 14 | |
| 15 | dev_harness.py pulls in a suite control file from disk and injects all the |
| 16 | variables that are normally injected by the create_suite_job() RPC, without |
| 17 | which the suite cannot be successfully executed. |
| 18 | |
| 19 | This file can be passed directly to autoserv and executed locally, |
| 20 | allowing for the testing of test suite control file changes without |
| 21 | staging them in the context of a build. It also means that one can |
| 22 | test code changes in the dynamic_suite infrastructure without being |
| 23 | forced to reimage the DUTs every time (by setting SKIP_IMAGE to |
| 24 | False). |
| 25 | """ |
| 26 | |
| 27 | # __file__ is not defined when this is run by autoserv, so hard-code :-/ |
| 28 | CONF_FILE = '/usr/local/autotest/test_suites/dev_harness_conf' |
| 29 | SUITE_CONTROL_FILE = 'test_suites/control.dummy' |
| 30 | config_dict = {} |
| 31 | new_globals = globals() |
| 32 | if os.path.exists(CONF_FILE): |
| 33 | with open(CONF_FILE, 'r') as config: |
| 34 | config_dict.update(ast.literal_eval(config.read())) |
| 35 | else: |
| 36 | # Default values. Put a raw dict into CONF_FILE to override. |
| 37 | config_dict = {'build': 'x86-mario-release/R23-2814.0.0', |
| 38 | 'board': 'x86-mario', |
| 39 | 'check_hosts': True, |
| 40 | 'pool': None, |
| 41 | 'num': 2, |
| 42 | 'file_bugs': False, |
| 43 | 'SKIP_IMAGE': False} |
| 44 | new_globals.update(config_dict) |
| 45 | |
| 46 | ds = dev_server.ImageServer.resolve(new_globals['build']) |
| 47 | if new_globals['SKIP_IMAGE']: |
| 48 | AFE = frontend.AFE(debug=True) |
| 49 | |
| 50 | repo_url = tools.package_url_pattern() % (ds.url(), new_globals['build']) |
| 51 | m = random.choice(AFE.get_hostnames(label='board:'+new_globals['board'])) |
| 52 | |
| 53 | label = AFE.get_labels( |
| 54 | name=constants.VERSION_PREFIX+new_globals['build'])[0] |
| 55 | label.add_hosts([m]) |
| 56 | AFE.set_host_attribute(constants.JOB_REPO_URL, repo_url, hostname=m) |
| 57 | else: |
| 58 | ds.trigger_download(new_globals['build']) |
Dan Shi | 7458bf6 | 2013-06-10 12:50:16 -0700 | [diff] [blame] | 59 | new_globals['devserver_url'] = ds.url() |
Chris Masone | f0a902e | 2012-10-03 08:32:48 -0700 | [diff] [blame] | 60 | |
| 61 | execfile(os.path.join(job.autodir, SUITE_CONTROL_FILE), new_globals, locals()) |