• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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.
4import logging
5
6import common
7from autotest_lib.server import test
8from autotest_lib.site_utils import acts_lib
9from autotest_lib.server.cros import dnsname_mangler
10from autotest_lib.server.hosts import host_info
11
12
13class android_EasySetup(test.test):
14    """A test that does nothing except setup a phone.
15
16    This test will only setup a phone how a user wants and will perform no
17    tests.
18    """
19    version = 1
20
21    def run_once(self,
22                testbed=None,
23                install_sl4a=True,
24                additional_apks=[]):
25        """When run the testbed will be setup.
26
27        @param testbed: The testbed to setup.
28        @param install_sl4a: When true sl4a will be installed.
29        @param additional_apks: An array of apk info dictionaries.
30                                apk = Name of the apk (eg. sl4a.apk)
31                                package = Name of the package (eg. test.tools)
32                                artifact = Name of the artifact, if not given
33                                           package is used.
34        """
35        hostname = testbed.hostname
36        if dnsname_mangler.is_ip_address(hostname):
37            testbed_name = hostname
38        else:
39            testbed_name = hostname.split('.')[0]
40
41        valid_hosts = []
42        for v in testbed.get_adb_devices().values():
43            try:
44                info = v.host_info_store.get()
45            except host_info.StoreError:
46                pass
47            else:
48                if v.job_repo_url_attribute in info.attributes:
49                    valid_hosts.append(v)
50
51        if not valid_hosts:
52            logging.error('No valid devices.')
53            return
54
55        testbed_env = acts_lib.AndroidTestingEnvironment(
56                devices=valid_hosts,
57                testbed_name=testbed_name)
58
59        if install_sl4a:
60            testbed_env.install_sl4a_apk()
61
62        for apk in additional_apks:
63            testbed_env.install_apk(apk)
64