1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-03-13 22:28:36 +00:00

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
This commit is contained in:
muendelezaji 2016-08-31 14:43:42 +01:00
parent e686e89b39
commit 6735817ee2

View File

@ -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,