Scott James Remnant | 4dcd73f | 2013-07-22 15:00:24 -0700 | [diff] [blame] | 1 | # 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 Remnant | 4dcd73f | 2013-07-22 15:00:24 -0700 | [diff] [blame] | 5 | from autotest_lib.client.cros import constants |
Scott James Remnant | 1ca2e0e | 2013-07-31 16:49:07 -0700 | [diff] [blame] | 6 | from autotest_lib.server import autotest, hosts |
Scott James Remnant | 4dcd73f | 2013-07-22 15:00:24 -0700 | [diff] [blame] | 7 | |
| 8 | |
| 9 | class BluetoothTester(object): |
Scott James Remnant | 1c72d7a | 2013-07-29 15:00:04 -0700 | [diff] [blame] | 10 | """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 Remnant | 4dcd73f | 2013-07-22 15:00:24 -0700 | [diff] [blame] | 17 | |
| 18 | XMLRPC_BRINGUP_TIMEOUT_SECONDS = 60 |
| 19 | |
Scott James Remnant | 4dcd73f | 2013-07-22 15:00:24 -0700 | [diff] [blame] | 20 | def __init__(self, tester_host): |
| 21 | """Construct a BluetoothTester. |
| 22 | |
Scott James Remnant | 1c72d7a | 2013-07-29 15:00:04 -0700 | [diff] [blame] | 23 | @param tester_host: host object representing a remote host. |
Scott James Remnant | 4dcd73f | 2013-07-22 15:00:24 -0700 | [diff] [blame] | 24 | |
| 25 | """ |
Scott James Remnant | 1c72d7a | 2013-07-29 15:00:04 -0700 | [diff] [blame] | 26 | self.host = tester_host |
Scott James Remnant | 4dcd73f | 2013-07-22 15:00:24 -0700 | [diff] [blame] | 27 | # 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 Remnant | 1c72d7a | 2013-07-29 15:00:04 -0700 | [diff] [blame] | 41 | |
Scott James Remnant | 4dcd73f | 2013-07-22 15:00:24 -0700 | [diff] [blame] | 42 | def close(self): |
| 43 | """Tear down state associated with the client.""" |
| 44 | # This kills the RPC server. |
Scott James Remnant | 1c72d7a | 2013-07-29 15:00:04 -0700 | [diff] [blame] | 45 | self.host.close() |
Scott James Remnant | 1ca2e0e | 2013-07-31 16:49:07 -0700 | [diff] [blame] | 46 | |
| 47 | |
| 48 | def 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) |