Bluetooth: rename BluetoothClient to BluetoothDevice

The BluetoothClient class, and BluetoothClientXmlRpcServer, were named
to match the WiFiClient class that they were based on. However for
Bluetooth tests, the DUT can actually behave as either a Client or a
Server depending on the requirements of the test - with the Tester
likewise behaving as a Server or Client appropriately.

This becomes confusing, so instead rename BluetoothClient to
BluetoothDevice so it's clear it refers to the DUT rather than its role.

BUG=chromium:256771
TEST=test_that suite:bluetooth_sanity

Change-Id: I75864de27325f3a74394a092ce7e538d8161f8a8
Reviewed-on: https://chromium-review.googlesource.com/176468
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Scott James Remnant <keybuk@chromium.org>
Tested-by: Scott James Remnant <keybuk@chromium.org>
diff --git a/client/common_lib/cros/bluetooth/bluetooth_client_xmlrpc_server.py b/client/common_lib/cros/bluetooth/bluetooth_device_xmlrpc_server.py
similarity index 96%
rename from client/common_lib/cros/bluetooth/bluetooth_client_xmlrpc_server.py
rename to client/common_lib/cros/bluetooth/bluetooth_device_xmlrpc_server.py
index c2350be..05556fc 100755
--- a/client/common_lib/cros/bluetooth/bluetooth_client_xmlrpc_server.py
+++ b/client/common_lib/cros/bluetooth/bluetooth_device_xmlrpc_server.py
@@ -18,7 +18,7 @@
 from autotest_lib.client.cros import constants
 
 
-class BluetoothClientXmlRpcDelegate(xmlrpc_server.XmlRpcDelegate):
+class BluetoothDeviceXmlRpcDelegate(xmlrpc_server.XmlRpcDelegate):
     """Exposes DUT methods called remotely during Bluetooth autotests.
 
     All instance methods of this object without a preceding '_' are exposed via
@@ -52,7 +52,7 @@
     ADAPTER_TIMEOUT = 30
 
     def __init__(self):
-        super(BluetoothClientXmlRpcDelegate, self).__init__()
+        super(BluetoothDeviceXmlRpcDelegate, self).__init__()
 
         # Open the Bluetooth Control socket to the kernel which provides us
         # raw management access to the Bluetooth Host Subsystem. Read the list
@@ -345,12 +345,12 @@
     logging.basicConfig(level=logging.DEBUG)
     handler = logging.handlers.SysLogHandler(address='/dev/log')
     formatter = logging.Formatter(
-            'bluetooth_client_xmlrpc_server: [%(levelname)s] %(message)s')
+            'bluetooth_device_xmlrpc_server: [%(levelname)s] %(message)s')
     handler.setFormatter(formatter)
     logging.getLogger().addHandler(handler)
-    logging.debug('bluetooth_client_xmlrpc_server main...')
+    logging.debug('bluetooth_device_xmlrpc_server main...')
     server = xmlrpc_server.XmlRpcServer(
             'localhost',
-            constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_PORT)
-    server.register_delegate(BluetoothClientXmlRpcDelegate())
+            constants.BLUETOOTH_DEVICE_XMLRPC_SERVER_PORT)
+    server.register_delegate(BluetoothDeviceXmlRpcDelegate())
     server.run()
diff --git a/client/cros/constants.py b/client/cros/constants.py
index 0c38368..69e974a 100644
--- a/client/cros/constants.py
+++ b/client/cros/constants.py
@@ -142,13 +142,13 @@
 SHILL_XMLRPC_SERVER_CLEANUP_PATTERN = 'shill_xmlrpc_server'
 SHILL_XMLRPC_SERVER_READY_METHOD = 'ready'
 
-BLUETOOTH_CLIENT_XMLRPC_SERVER_PORT = 9990
-BLUETOOTH_CLIENT_XMLRPC_SERVER_COMMAND = (
+BLUETOOTH_DEVICE_XMLRPC_SERVER_PORT = 9990
+BLUETOOTH_DEVICE_XMLRPC_SERVER_COMMAND = (
         'cd /usr/local/autotest/common_lib/cros/bluetooth; '
-        './bluetooth_client_xmlrpc_server.py')
-BLUETOOTH_CLIENT_XMLRPC_SERVER_CLEANUP_PATTERN = (
-        'bluetooth_client_xmlrpc_server')
-BLUETOOTH_CLIENT_XMLRPC_SERVER_READY_METHOD = 'ready'
+        './bluetooth_device_xmlrpc_server.py')
+BLUETOOTH_DEVICE_XMLRPC_SERVER_CLEANUP_PATTERN = (
+        'bluetooth_device_xmlrpc_server')
+BLUETOOTH_DEVICE_XMLRPC_SERVER_READY_METHOD = 'ready'
 
 BLUETOOTH_TESTER_XMLRPC_SERVER_PORT = 9990
 BLUETOOTH_TESTER_XMLRPC_SERVER_COMMAND = (
diff --git a/server/cros/bluetooth/bluetooth_client.py b/server/cros/bluetooth/bluetooth_device.py
similarity index 88%
rename from server/cros/bluetooth/bluetooth_client.py
rename to server/cros/bluetooth/bluetooth_device.py
index 4e68048..47f744f 100644
--- a/server/cros/bluetooth/bluetooth_client.py
+++ b/server/cros/bluetooth/bluetooth_device.py
@@ -8,8 +8,8 @@
 from autotest_lib.server import autotest
 
 
-class BluetoothClient(object):
-    """BluetoothClient is a thin layer of logic over a remote DUT.
+class BluetoothDevice(object):
+    """BluetoothDevice is a thin layer of logic over a remote DUT.
 
     The Autotest host object representing the remote DUT, passed to this
     class on initialization, can be accessed from its host property.
@@ -18,25 +18,25 @@
 
     XMLRPC_BRINGUP_TIMEOUT_SECONDS = 60
 
-    def __init__(self, client_host):
-        """Construct a BluetoothClient.
+    def __init__(self, device_host):
+        """Construct a BluetoothDevice.
 
-        @param client_host: host object representing a remote host.
+        @param device_host: host object representing a remote host.
 
         """
-        self.host = client_host
+        self.host = device_host
         # Make sure the client library is on the device so that the proxy code
         # is there when we try to call it.
         client_at = autotest.Autotest(self.host)
         client_at.install()
         # Start up the XML-RPC proxy on the client.
         self._proxy = self.host.xmlrpc_connect(
-                constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_COMMAND,
-                constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_PORT,
+                constants.BLUETOOTH_DEVICE_XMLRPC_SERVER_COMMAND,
+                constants.BLUETOOTH_DEVICE_XMLRPC_SERVER_PORT,
                 command_name=
-                  constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_CLEANUP_PATTERN,
+                  constants.BLUETOOTH_DEVICE_XMLRPC_SERVER_CLEANUP_PATTERN,
                 ready_test_name=
-                  constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_READY_METHOD,
+                  constants.BLUETOOTH_DEVICE_XMLRPC_SERVER_READY_METHOD,
                 timeout_seconds=self.XMLRPC_BRINGUP_TIMEOUT_SECONDS)
 
 
diff --git a/server/cros/bluetooth/bluetooth_test.py b/server/cros/bluetooth/bluetooth_test.py
index 5996cd9..2a54780 100644
--- a/server/cros/bluetooth/bluetooth_test.py
+++ b/server/cros/bluetooth/bluetooth_test.py
@@ -4,7 +4,7 @@
 
 from autotest_lib.server import test
 from autotest_lib.server.cros import interactive_client
-from autotest_lib.server.cros.bluetooth import bluetooth_client
+from autotest_lib.server.cros.bluetooth import bluetooth_device
 from autotest_lib.server.cros.bluetooth import bluetooth_tester
 
 
@@ -15,7 +15,7 @@
     collection of Bluetooth tests that sets the following properties, depending
     on the arguments to the test and properties of the test object:
 
-      self.client - BluetoothClient object for the device being tested
+      self.device - BluetoothDevice object for the device being tested
       self.tester - BluetoothTester object for the device's partner tester
       self.interactive - InteractiveClient object for the device
 
@@ -30,11 +30,11 @@
 
     """
 
-    def warmup(self, client_host, tester_host, interactive=False):
+    def warmup(self, device_host, tester_host, interactive=False):
         """Initialize the test member objects based on its arguments."""
         super(BluetoothTest, self).warmup()
 
-        self.client = bluetooth_client.BluetoothClient(client_host)
+        self.device = bluetooth_device.BluetoothDevice(device_host)
 
         if tester_host:
             self.tester = bluetooth_tester.BluetoothTester(tester_host)
@@ -42,7 +42,7 @@
             self.tester = None
 
         if interactive:
-            self.interactive = interactive_client.InteractiveClient(client_host)
+            self.interactive = interactive_client.InteractiveClient(device_host)
         else:
             self.interactive = None
 
@@ -51,7 +51,7 @@
         """Close the test member objects."""
         if self.interactive:
             self.interactive.close()
-        self.client.close()
+        self.device.close()
         if self.tester:
             self.tester.close()
 
diff --git a/server/cros/bluetooth/bluetooth_tester.py b/server/cros/bluetooth/bluetooth_tester.py
index b59efb5..fa351d7 100644
--- a/server/cros/bluetooth/bluetooth_tester.py
+++ b/server/cros/bluetooth/bluetooth_tester.py
@@ -113,20 +113,20 @@
         self.host.close()
 
 
-def create_host_from(client_host):
+def create_host_from(device_host):
     """Creates a host object for the Tester associated with a DUT.
 
     Will raise an exception if there isn't a tester for the DUT.
 
-    @param client_host: Autotest host object for the DUT.
+    @param device_host: Autotest host object for the DUT.
 
     @return Autotest host object for the Tester.
 
     """
 
-    client_hostname = client_host.hostname
+    device_hostname = device_host.hostname
 
-    parts = client_hostname.split('.')
+    parts = device_hostname.split('.')
     parts[0] = parts[0] + '-bluetooth'
     tester_hostname = '.'.join(parts)
 
diff --git a/server/site_tests/bluetooth_Sanity_AdapterPresent/bluetooth_Sanity_AdapterPresent.py b/server/site_tests/bluetooth_Sanity_AdapterPresent/bluetooth_Sanity_AdapterPresent.py
index ca4cf36..847b89b 100644
--- a/server/site_tests/bluetooth_Sanity_AdapterPresent/bluetooth_Sanity_AdapterPresent.py
+++ b/server/site_tests/bluetooth_Sanity_AdapterPresent/bluetooth_Sanity_AdapterPresent.py
@@ -14,10 +14,10 @@
 
     def run_once(self):
         # Reset the adapter (if any) to the powered off state.
-        if not self.client.reset_off():
+        if not self.device.reset_off():
             raise error.TestFail('DUT could not be reset to initial state')
 
         # Verify that there is an adapter. This will only return True if both
         # the kernel and bluetooth daemon see the adapter.
-        if not self.client.has_adapter():
+        if not self.device.has_adapter():
             raise error.TestFail('Adapter not present')
diff --git a/server/site_tests/bluetooth_Sanity_AdapterPresent/control b/server/site_tests/bluetooth_Sanity_AdapterPresent/control
index d6b42fb..02c2ad4 100644
--- a/server/site_tests/bluetooth_Sanity_AdapterPresent/control
+++ b/server/site_tests/bluetooth_Sanity_AdapterPresent/control
@@ -16,9 +16,9 @@
 """
 
 def run(machine):
-    client_host = hosts.create_host(machine)
+    device_host = hosts.create_host(machine)
     job.run_test('bluetooth_Sanity_AdapterPresent',
-                 client_host=client_host,
+                 device_host=device_host,
                  tester_host=None,
                  interactive=False)
 
diff --git a/server/site_tests/bluetooth_Sanity_DefaultState/bluetooth_Sanity_DefaultState.py b/server/site_tests/bluetooth_Sanity_DefaultState/bluetooth_Sanity_DefaultState.py
index 3d8cb6f..a41301c 100644
--- a/server/site_tests/bluetooth_Sanity_DefaultState/bluetooth_Sanity_DefaultState.py
+++ b/server/site_tests/bluetooth_Sanity_DefaultState/bluetooth_Sanity_DefaultState.py
@@ -42,13 +42,13 @@
 
     def run_once(self):
         # Reset the adapter to the powered off state.
-        if not self.client.reset_off():
+        if not self.device.reset_off():
             raise error.TestFail('DUT could not be reset to initial state')
 
         # Read the initial state of the adapter. Verify that it is powered down.
         ( address, bluetooth_version, manufacturer_id,
                     supported_settings, current_settings, class_of_device,
-                    name, short_name ) = self.client.read_info()
+                    name, short_name ) = self.device.read_info()
         self._log_settings('Initial state', current_settings)
 
         if current_settings & bluetooth_socket.MGMT_SETTING_POWERED:
@@ -65,7 +65,7 @@
 
         # Verify that the Bluetooth Daemon sees that it is also powered down,
         # non-discoverable and not discovering devices.
-        bluez_properties = self.client.get_adapter_properties()
+        bluez_properties = self.device.get_adapter_properties()
 
         if bluez_properties['Powered']:
             raise error.TestFail('Bluetooth daemon Powered property does not '
@@ -80,10 +80,10 @@
         # Power on the adapter, then read the state again. Verify that it is
         # powered up, connectable and pairable (accepting incoming connections)
         # but not discoverable.
-        self.client.set_powered(True)
+        self.device.set_powered(True)
         ( address, bluetooth_version, manufacturer_id,
                     supported_settings, current_settings, class_of_device,
-                    name, short_name ) = self.client.read_info()
+                    name, short_name ) = self.device.read_info()
         self._log_settings("Powered up", current_settings)
 
         if not current_settings & bluetooth_socket.MGMT_SETTING_POWERED:
@@ -98,7 +98,7 @@
 
         # Verify that the Bluetooth Daemon sees the same state as the kernel
         # and that it's not discovering.
-        bluez_properties = self.client.get_adapter_properties()
+        bluez_properties = self.device.get_adapter_properties()
 
         if not bluez_properties['Powered']:
             raise error.TestFail('Bluetooth daemon Powered property does not '
@@ -116,10 +116,10 @@
 
         # Finally power off the adapter again, and verify that the adapter has
         # returned to powered down.
-        self.client.set_powered(False)
+        self.device.set_powered(False)
         ( address, bluetooth_version, manufacturer_id,
                     supported_settings, current_settings, class_of_device,
-                    name, short_name ) = self.client.read_info()
+                    name, short_name ) = self.device.read_info()
         self._log_settings("After power down", current_settings)
 
         if current_settings & bluetooth_socket.MGMT_SETTING_POWERED:
@@ -130,7 +130,7 @@
                                  'during next power on')
 
         # Verify that the Bluetooth Daemon sees the same state as the kernel.
-        bluez_properties = self.client.get_adapter_properties()
+        bluez_properties = self.device.get_adapter_properties()
 
         if bluez_properties['Powered']:
             raise error.TestFail('Bluetooth daemon Powered property does not '
diff --git a/server/site_tests/bluetooth_Sanity_DefaultState/control b/server/site_tests/bluetooth_Sanity_DefaultState/control
index 6b53a8f..c9da507 100644
--- a/server/site_tests/bluetooth_Sanity_DefaultState/control
+++ b/server/site_tests/bluetooth_Sanity_DefaultState/control
@@ -23,9 +23,9 @@
 """
 
 def run(machine):
-    client_host = hosts.create_host(machine)
+    device_host = hosts.create_host(machine)
     job.run_test('bluetooth_Sanity_DefaultState',
-                 client_host=client_host,
+                 device_host=device_host,
                  tester_host=None,
                  interactive=False)
 
diff --git a/server/site_tests/bluetooth_Sanity_Discoverable/bluetooth_Sanity_Discoverable.py b/server/site_tests/bluetooth_Sanity_Discoverable/bluetooth_Sanity_Discoverable.py
index 288513f..2729f86 100644
--- a/server/site_tests/bluetooth_Sanity_Discoverable/bluetooth_Sanity_Discoverable.py
+++ b/server/site_tests/bluetooth_Sanity_Discoverable/bluetooth_Sanity_Discoverable.py
@@ -59,11 +59,11 @@
 
     def run_once(self):
         # Reset the adapter to the powered on, discoverable state.
-        if not (self.client.reset_on() and
-                self.client.set_discoverable(True)):
+        if not (self.device.reset_on() and
+                self.device.set_discoverable(True)):
             raise error.TestFail('DUT could not be reset to initial state')
 
-        self.adapter = self.client.get_adapter_properties()
+        self.adapter = self.device.get_adapter_properties()
 
         if self.interactive:
             self.interactive.login()
diff --git a/server/site_tests/bluetooth_Sanity_Discoverable/control b/server/site_tests/bluetooth_Sanity_Discoverable/control
index 97e7ea6..fc7e3b4 100644
--- a/server/site_tests/bluetooth_Sanity_Discoverable/control
+++ b/server/site_tests/bluetooth_Sanity_Discoverable/control
@@ -21,10 +21,10 @@
 
 
 def run(machine):
-    client_host = hosts.create_host(machine)
-    tester_host = bluetooth_tester.create_host_from(client_host)
+    device_host = hosts.create_host(machine)
+    tester_host = bluetooth_tester.create_host_from(device_host)
     job.run_test('bluetooth_Sanity_Discoverable',
-                 client_host=client_host,
+                 device_host=device_host,
                  tester_host=tester_host,
                  interactive=False)
 
diff --git a/server/site_tests/bluetooth_Sanity_Discoverable/control.manual b/server/site_tests/bluetooth_Sanity_Discoverable/control.manual
index 8c39d41..cf41e69 100644
--- a/server/site_tests/bluetooth_Sanity_Discoverable/control.manual
+++ b/server/site_tests/bluetooth_Sanity_Discoverable/control.manual
@@ -28,9 +28,9 @@
 
 
 def run(machine):
-    client_host = hosts.create_host(machine)
+    device_host = hosts.create_host(machine)
     job.run_test('bluetooth_Sanity_Discoverable',
-                 client_host=client_host,
+                 device_host=device_host,
                  tester_host=None,
                  interactive=True)
 
diff --git a/server/site_tests/bluetooth_Sanity_Discovery/bluetooth_Sanity_Discovery.py b/server/site_tests/bluetooth_Sanity_Discovery/bluetooth_Sanity_Discovery.py
index 8f2d594..8274105 100644
--- a/server/site_tests/bluetooth_Sanity_Discovery/bluetooth_Sanity_Discovery.py
+++ b/server/site_tests/bluetooth_Sanity_Discovery/bluetooth_Sanity_Discovery.py
@@ -26,7 +26,7 @@
 
         """
         # Get the set of devices known to the DUT.
-        devices = self.client.get_devices()
+        devices = self.device.get_devices()
         if devices == False:
             raise error.TestFail('Could not retrieve devices from DUT')
 
@@ -76,7 +76,7 @@
 
     def run_once(self):
         # Reset the adapter to the powered on state.
-        if not self.client.reset_on():
+        if not self.device.reset_on():
             raise error.TestFail('DUT could not be reset to initial state')
 
         if self.tester:
@@ -121,7 +121,7 @@
 
         # Discover devices from the DUT.
         for failed_attempts in range(0, 5):
-            if not self.client.start_discovery():
+            if not self.device.start_discovery():
                 raise error.TestFail('Could not start discovery on DUT')
             try:
                 utils.poll_for_condition(
@@ -137,7 +137,7 @@
                 # loop.
                 pass
             finally:
-                if not self.client.stop_discovery():
+                if not self.device.stop_discovery():
                     logging.warning('Failed to stop discovery on DUT')
         else:
             # We only reach this if we tried five times to find the device and
diff --git a/server/site_tests/bluetooth_Sanity_Discovery/control b/server/site_tests/bluetooth_Sanity_Discovery/control
index 33955f1..6f8c471 100644
--- a/server/site_tests/bluetooth_Sanity_Discovery/control
+++ b/server/site_tests/bluetooth_Sanity_Discovery/control
@@ -21,10 +21,10 @@
 
 
 def run(machine):
-    client_host = hosts.create_host(machine)
-    tester_host = bluetooth_tester.create_host_from(client_host)
+    device_host = hosts.create_host(machine)
+    tester_host = bluetooth_tester.create_host_from(device_host)
     job.run_test('bluetooth_Sanity_Discovery',
-                 client_host=client_host,
+                 device_host=device_host,
                  tester_host=tester_host,
                  interactive=False)
 
diff --git a/server/site_tests/bluetooth_Sanity_Discovery/control.manual b/server/site_tests/bluetooth_Sanity_Discovery/control.manual
index 5738a8b..8d3fe66 100644
--- a/server/site_tests/bluetooth_Sanity_Discovery/control.manual
+++ b/server/site_tests/bluetooth_Sanity_Discovery/control.manual
@@ -28,9 +28,9 @@
 
 
 def run(machine):
-    client_host = hosts.create_host(machine)
+    device_host = hosts.create_host(machine)
     job.run_test('bluetooth_Sanity_Discovery',
-                 client_host=client_host,
+                 device_host=device_host,
                  tester_host=None,
                  interactive=True)
 
diff --git a/server/site_tests/bluetooth_Sanity_ValidAddress/bluetooth_Sanity_ValidAddress.py b/server/site_tests/bluetooth_Sanity_ValidAddress/bluetooth_Sanity_ValidAddress.py
index 701206c..c0e6dd0 100644
--- a/server/site_tests/bluetooth_Sanity_ValidAddress/bluetooth_Sanity_ValidAddress.py
+++ b/server/site_tests/bluetooth_Sanity_ValidAddress/bluetooth_Sanity_ValidAddress.py
@@ -16,13 +16,13 @@
 
     def run_once(self):
         # Reset the adapter to the powered off state.
-        if not self.client.reset_off():
+        if not self.device.reset_off():
             raise error.TestFail('DUT could not be reset to initial state')
 
         # Read the address both via BlueZ and via the kernel mgmt_ops interface.
         # Compare the two, they should not differ.
-        bluez_properties = self.client.get_adapter_properties()
-        controller_info = self.client.read_info()
+        bluez_properties = self.device.get_adapter_properties()
+        controller_info = self.device.read_info()
 
         if bluez_properties['Address'] != controller_info[0]:
             raise error.TestFail(
@@ -48,9 +48,9 @@
             raise error.TestFail('Device portion of address is all ones')
 
         # Verify that the address is still the same after powering on the radio.
-        self.client.set_powered(True)
-        bluez_properties = self.client.get_adapter_properties()
-        controller_info = self.client.read_info()
+        self.device.set_powered(True)
+        bluez_properties = self.device.get_adapter_properties()
+        controller_info = self.device.read_info()
 
         if bluez_properties['Address'] != address:
             raise error.TestFail(
diff --git a/server/site_tests/bluetooth_Sanity_ValidAddress/control b/server/site_tests/bluetooth_Sanity_ValidAddress/control
index 02a5e64..8c6022b 100644
--- a/server/site_tests/bluetooth_Sanity_ValidAddress/control
+++ b/server/site_tests/bluetooth_Sanity_ValidAddress/control
@@ -18,9 +18,9 @@
 """
 
 def run(machine):
-    client_host = hosts.create_host(machine)
+    device_host = hosts.create_host(machine)
     job.run_test('bluetooth_Sanity_ValidAddress',
-                 client_host=client_host,
+                 device_host=device_host,
                  tester_host=None,
                  interactive=False)