From 71815e4e1ce55c94c5904979b031ff6723737fc5 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Wed, 18 Oct 2017 11:49:52 +0100 Subject: [PATCH] framework/workload: Implement Workload.requires_network attribute --- wa/framework/workload.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wa/framework/workload.py b/wa/framework/workload.py index 7638b376..bb002e8e 100644 --- a/wa/framework/workload.py +++ b/wa/framework/workload.py @@ -50,6 +50,12 @@ class Workload(TargetedPlugin): prevent this workload from being run accidentally. """ + requires_network = False + """ + Set this to ``True`` to mark the the workload will fail without a network + connection, this enables it to fail early with a clear message. + """ + def init_resources(self, context): """ This method may be used to perform early resource discovery and @@ -77,7 +83,11 @@ class Workload(TargetedPlugin): This is also the place to perform any on-device checks prior to attempting to execute the workload. """ - pass + if self.requires_network and not self.target.is_network_connected(): + raise WorkloadError( + 'Workload "{}" requires internet. Target does not appear ' + 'to be connected to the internet.'.format(self.name)) + def run(self, context): """ @@ -193,6 +203,7 @@ class ApkWorkload(Workload): self.apk.activity) def setup(self, context): + super(ApkWorkload, self).setup(context) self.apk.setup(context) time.sleep(self.loading_time)