From 6735817ee258a8e620b0c9889e89c32a13b2004c Mon Sep 17 00:00:00 2001 From: muendelezaji Date: Wed, 31 Aug 2016 14:43:42 +0100 Subject: [PATCH] Add method to check AND raise if device is not connected to internet This ensures consistency across workloads by allowing them to replace: ``` if not self.device.is_network_connected(): # handle error here e.g. raise DeviceError ``` with a simple call to: `self.device.check_network_connected()` The former approach can still be used by workloads that choose to do so --- wlauto/common/linux/device.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/wlauto/common/linux/device.py b/wlauto/common/linux/device.py index b65f148b..a855d0e9 100644 --- a/wlauto/common/linux/device.py +++ b/wlauto/common/linux/device.py @@ -320,11 +320,11 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method def is_network_connected(self, ip_address='8.8.8.8'): """ - Checks for internet connectivity on the device - by pinging IP address provided. + 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) + :param ip_address: IP address to ping. Default: Google's public DNS server (8.8.8.8) + + :returns: ``True`` if internet is available, ``False`` otherwise. """ self.logger.debug('Checking for internet connectivity.') @@ -338,6 +338,16 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method self.logger.debug('Cannot find IP address {}'.format(ip_address)) return False + def check_network_connected(self): + """ + Checks if the internet is available, as determined by ``is_network_connected``. + + :raises DeviceError: If internet is not connected. + + """ + if not self.is_network_connected(): + raise DeviceError('Device {} is not connected to the internet.'.format(self.name)) + def get_binary_path(self, name, search_system_binaries=True): """ Searches the devices ``binary_directory`` for the given binary,