blob: 861a6f8bfb784b82f7727ad795a13cac272a8b4f [file] [log] [blame]
Scott James Remnant4dcd73f2013-07-22 15:00:24 -07001# Copyright (c) 2013 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
Scott James Remnant4dcd73f2013-07-22 15:00:24 -07005from autotest_lib.client.cros import constants
Scott James Remnant1ca2e0e2013-07-31 16:49:07 -07006from autotest_lib.server import autotest, hosts
Scott James Remnant4dcd73f2013-07-22 15:00:24 -07007
8
9class BluetoothTester(object):
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070010 """BluetoothTester is a thin layer of logic over a remote tester.
11
12 The Autotest host object representing the remote tester, passed to this
13 class on initialization, can be accessed from its host property.
14
15 """
16
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070017
18 XMLRPC_BRINGUP_TIMEOUT_SECONDS = 60
19
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070020 def __init__(self, tester_host):
21 """Construct a BluetoothTester.
22
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070023 @param tester_host: host object representing a remote host.
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070024
25 """
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070026 self.host = tester_host
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070027 # Make sure the client library is on the device so that the proxy code
28 # is there when we try to call it.
29 client_at = autotest.Autotest(self.host)
30 client_at.install()
31 # Start up the XML-RPC proxy on the tester.
32 self._proxy = self.host.xmlrpc_connect(
33 constants.BLUETOOTH_TESTER_XMLRPC_SERVER_COMMAND,
34 constants.BLUETOOTH_TESTER_XMLRPC_SERVER_PORT,
35 command_name=
36 constants.BLUETOOTH_TESTER_XMLRPC_SERVER_CLEANUP_PATTERN,
37 ready_test_name=
38 constants.BLUETOOTH_TESTER_XMLRPC_SERVER_READY_METHOD,
39 timeout_seconds=self.XMLRPC_BRINGUP_TIMEOUT_SECONDS)
40
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070041
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070042 def close(self):
43 """Tear down state associated with the client."""
44 # This kills the RPC server.
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070045 self.host.close()
Scott James Remnant1ca2e0e2013-07-31 16:49:07 -070046
47
48def create_host_from(client_host):
49 """Creates a host object for the Tester associated with a DUT.
50
51 Will raise an exception if there isn't a tester for the DUT.
52
53 @param client_host: Autotest host object for the DUT.
54
55 @return Autotest host object for the Tester.
56
57 """
58
59 client_hostname = client_host.hostname
60
61 parts = client_hostname.split('.')
62 parts[0] = parts[0] + '-bluetooth'
63 tester_hostname = '.'.join(parts)
64
65 return hosts.create_host(tester_hostname)