1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-09-02 03:12:34 +01:00

Add network check methods to Device and Workload classes

- Device subclasses should provide their own implementation.
    Default behaviour is to raise a `NotImplementedError`
  - Workload subclasses can set `requires_network` to `True` and
    network connectivity check will be performed during `setup()`
This commit is contained in:
muendelezaji
2016-08-31 16:00:50 +01:00
parent b5c0bdb0eb
commit 392a3f1600
4 changed files with 35 additions and 13 deletions

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)