From: Ondrej Lichtner <olichtne(a)redhat.com>
The prepare_job method will create and return a lnst.Controller.Job
object the same as the Namespace.run method but won't send the command
to start it to the Slave. Instead the tester can call the Job.start
method himself to send the start command later.
This could be used to achieve better grouping of time related job
starts, currently it would only be useful if you intend to do resource
intensive work between Namespace.run calls, but I can imagine extending
this functionality to actually provide a more intelligent synchronized
start of multiple jobs.
Consider this just an idea, might be removed later.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/Job.py | 9 +++++++++
lnst/Controller/Namespace.py | 5 +++++
2 files changed, 14 insertions(+)
diff --git a/lnst/Controller/Job.py b/lnst/Controller/Job.py
index 89b8451..0e17934 100644
--- a/lnst/Controller/Job.py
+++ b/lnst/Controller/Job.py
@@ -146,6 +146,15 @@ class Job(object):
else:
return False
+ def start(self, bg=False, timeout=DEFAULT_TIMEOUT):
+ self._netns._machine.run_job(self)
+
+ if not bg:
+ if not self.wait(timeout):
+ logging.debug("Killing timed-out job")
+ self.kill()
+ return self
+
def wait(self, timeout=DEFAULT_TIMEOUT):
"""waits for the Job to finish for the specified amount of time
diff --git a/lnst/Controller/Namespace.py b/lnst/Controller/Namespace.py
index af5bda1..b8bb2f7 100644
--- a/lnst/Controller/Namespace.py
+++ b/lnst/Controller/Namespace.py
@@ -80,6 +80,11 @@ class Namespace(object):
returns a string name for any other namespace"""
return self._name
+ def prepare_job(self, what, fail=False, json=False, desc=None,
+ job_level=ResultLevel.DEBUG):
+ return Job(self, what, expect=not fail, json=json, desc=desc,
+ level=job_level)
+
def run(self, what, bg=False, fail=False, timeout=DEFAULT_TIMEOUT,
json=False, desc=None, job_level=ResultLevel.DEBUG):
"""
--
2.19.1