From 2872080d1a83cfdcbab65e8f9edab9cdd5ba5047 Mon Sep 17 00:00:00 2001 From: John Richardson Date: Fri, 22 Jul 2016 11:46:12 +0100 Subject: [PATCH] Add network connectivity check for devices Add a general check that pings a IP address rather than checking the status of dumpsys wifi due to the fact that not all devices are connected via wifi. Intended for workloads that require an internet connection to operate. --- wlauto/common/linux/device.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/wlauto/common/linux/device.py b/wlauto/common/linux/device.py index b3eb4822..b65f148b 100644 --- a/wlauto/common/linux/device.py +++ b/wlauto/common/linux/device.py @@ -318,6 +318,26 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method please see: https://pythonhosted.org/wlauto/writing_extensions.html""") + def is_network_connected(self, ip_address='8.8.8.8'): + """ + Checks for internet connectivity on the device + by pinging IP address provided. + + :param ip_address: the IP address to ping + (default - google-public-dns-a.google.com) + + """ + self.logger.debug('Checking for internet connectivity.') + output = self.execute('ping -q -w 1 -c 1 {}'.format(ip_address), + check_exit_code=False) + + if 'network is unreachable' not in output.lower(): + self.logger.debug('Found IP address {}'.format(ip_address)) + return True + else: + self.logger.debug('Cannot find IP address {}'.format(ip_address)) + return False + def get_binary_path(self, name, search_system_binaries=True): """ Searches the devices ``binary_directory`` for the given binary,