blob: 622a268aa97c7c3aa77266ebfd264d3f3c8022bf [file] [log] [blame]
Chris Masonef0a902e2012-10-03 08:32:48 -07001# 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
5import ast, os, random
6
7from autotest_lib.client.common_lib.cros import dev_server
8from autotest_lib.server import frontend
9from autotest_lib.server.cros.dynamic_suite import constants, tools
10
11"""A wrapper around a dynamic suite control file to enable local testing.
12
13usage: server/autoserv test_suites/dev_harness.py
14
15dev_harness.py pulls in a suite control file from disk and injects all the
16variables that are normally injected by the create_suite_job() RPC, without
17which the suite cannot be successfully executed.
18
19This file can be passed directly to autoserv and executed locally,
20allowing for the testing of test suite control file changes without
21staging them in the context of a build. It also means that one can
22test code changes in the dynamic_suite infrastructure without being
23forced to reimage the DUTs every time (by setting SKIP_IMAGE to
24False).
25"""
26
27# __file__ is not defined when this is run by autoserv, so hard-code :-/
28CONF_FILE = '/usr/local/autotest/test_suites/dev_harness_conf'
29SUITE_CONTROL_FILE = 'test_suites/control.dummy'
30config_dict = {}
31new_globals = globals()
32if os.path.exists(CONF_FILE):
33 with open(CONF_FILE, 'r') as config:
34 config_dict.update(ast.literal_eval(config.read()))
35else:
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}
44new_globals.update(config_dict)
45
46ds = dev_server.ImageServer.resolve(new_globals['build'])
47if 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)
57else:
58 ds.trigger_download(new_globals['build'])
Dan Shi7458bf62013-06-10 12:50:16 -070059new_globals['devserver_url'] = ds.url()
Chris Masonef0a902e2012-10-03 08:32:48 -070060
61execfile(os.path.join(job.autodir, SUITE_CONTROL_FILE), new_globals, locals())