From: Ondrej Lichtner <olichtne(a)redhat.com>
The job type property could be useful as a public facing api and it also
makes working with it a bit cleaner.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/Job.py | 24 ++++++++++++++----------
lnst/Controller/Machine.py | 2 +-
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/lnst/Controller/Job.py b/lnst/Controller/Job.py
index 92ea483..908986c 100644
--- a/lnst/Controller/Job.py
+++ b/lnst/Controller/Job.py
@@ -40,11 +40,7 @@ def __init__(self, namespace, what,
self._res = None
- if isinstance(what, BaseTestModule):
- self._type = "module"
- elif type(what) == str:
- self._type = "shell"
- else:
+ if self.type == "unknown":
raise JobError("Unable to run '%s'" % str(what))
self._id = None
@@ -69,6 +65,14 @@ def id(self, val):
def what(self):
return self._what
+ @property
+ def type(self):
+ if isinstance(self.what, BaseTestModule):
+ return "module"
+ elif isinstance(self.what, str):
+ return "shell"
+ return "unknown"
+
@property
def host(self):
"""the initial namespace of the host the job is running
on"""
@@ -201,18 +205,18 @@ def kill(self, signal=signal.SIGKILL):
def _to_dict(self):
d = {"job_id": self._id,
- "type": self._type,
+ "type": self.type,
"json": self._json}
- if self._type == "shell":
+ if self.type == "shell":
d["command"] = self._what
- elif self._type == "module":
+ elif self.type == "module":
d["module"] = self._what
else:
- raise JobError("Unknown Job type %s" % self._type)
+ raise JobError("Unknown Job type %s" % self.type)
return d
def __str__(self):
- attrs = ["type(%s)" % self._type]
+ attrs = ["type(%s)" % self.type]
if self._type == "module":
attrs.append("module(%s)" % self._what.__class__.__name__)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index 59f402b..a74b5a9 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -348,7 +348,7 @@ def run_job(self, job):
self._job_id_seq += 1
self._jobs[job.id] = job
- if job._type == "module":
+ if job.type == "module":
self.send_class(job._what.__class__)
logging.info("Host %s executing job %d: %s" %
--
2.21.0