1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2024-10-06 19:01:15 +01:00

Merge pull request #237 from jimboatarm/workload-check-internet

Add network check methods to Device and Workload classes
This commit is contained in:
Sebastian Goscik 2016-09-02 10:35:01 +01:00 committed by GitHub
commit 175e7f3cc0
4 changed files with 35 additions and 13 deletions

View File

@ -86,6 +86,7 @@ class UiAutomatorWorkload(Workload):
self.uiauto_package = os.path.splitext(os.path.basename(self.uiauto_file))[0]
def setup(self, context):
super(UiAutomatorWorkload, self).setup(context)
method_string = '{}.{}#{}'.format(self.uiauto_package, self.uiauto_class, self.uiauto_method)
params_dict = self.uiauto_params
params_dict['workdir'] = self.device.working_directory
@ -179,6 +180,7 @@ class ApkWorkload(Workload):
self.logcat_log = None
def setup(self, context):
super(ApkWorkload, self).setup(context)
# Get APK for the correct version and device ABI
self.apk_file = context.resolver.get(ApkFile(self, self.device.abi),
version=getattr(self, 'version', None),
@ -363,6 +365,7 @@ class ReventWorkload(Workload):
self.run_timeout = self.run_timeout or default_run_timeout
def setup(self, context):
super(ReventWorkload, self).setup(context)
self.device.killall('revent')
command = '{} replay {}'.format(self.on_device_revent_binary, self.on_device_setup_revent)
self.device.execute(command, timeout=self.setup_timeout)

View File

@ -39,6 +39,8 @@ FstabEntry = namedtuple('FstabEntry', ['device', 'mount_point', 'fs_type', 'opti
PsEntry = namedtuple('PsEntry', 'user pid ppid vsize rss wchan pc state name')
LsmodEntry = namedtuple('LsmodEntry', ['name', 'size', 'use_count', 'used_by'])
GOOGLE_DNS_SERVER_ADDRESS = '8.8.8.8'
class BaseLinuxDevice(Device): # pylint: disable=abstract-method
@ -318,25 +320,28 @@ 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'):
def is_network_connected(self):
"""
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 is Google's public DNS server (8.8.8.8)
:returns: ``True`` if internet is available, ``False`` otherwise.
"""
self.logger.debug('Checking for internet connectivity.')
output = self.execute('ping -q -w 1 -c 1 {}'.format(ip_address),
self.logger.debug('Checking for internet connectivity...')
return self._ping_server(GOOGLE_DNS_SERVER_ADDRESS)
def _ping_server(self, ip_address, timeout=1, packet_count=1):
output = self.execute('ping -q -c {} -w {} {}'.format(packet_count, timeout, 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:
if 'network is unreachable' in output.lower():
self.logger.debug('Cannot find IP address {}'.format(ip_address))
return False
else:
self.logger.debug('Found IP address {}'.format(ip_address))
return True
def get_binary_path(self, name, search_system_binaries=True):
"""

View File

@ -426,6 +426,13 @@ class Device(Extension):
"""
pass
def is_network_connected(self):
"""
Checks if the device is connected to the internet
"""
raise NotImplementedError()
def __str__(self):
return 'Device<{}>'.format(self.name)

View File

@ -37,6 +37,7 @@ class Workload(Extension):
supported_devices = []
supported_platforms = []
summary_metrics = []
requires_network = False
def __init__(self, device, **kwargs):
"""
@ -69,7 +70,7 @@ class Workload(Extension):
"""
pass
def setup(self, context):
def setup(self, context): # pylint: disable=unused-argument
"""
Perform the setup necessary to run the workload, such as copying the necessary files
to the device, configuring the environments, etc.
@ -78,7 +79,8 @@ class Workload(Extension):
the workload.
"""
pass
if self.requires_network:
self.check_network_connected()
def run(self, context):
"""Execute the workload. This is the method that performs the actual "work" of the"""
@ -99,5 +101,10 @@ class Workload(Extension):
def finalize(self, context):
pass
def check_network_connected(self):
if not self.device.is_network_connected():
message = 'Workload "{}" requires internet. Device "{}" does not appear to be connected to the internet.'
raise WorkloadError(message.format(self.name, self.device.name))
def __str__(self):
return '<Workload {}>'.format(self.name)