This patch fixes an incorrect key 'bg_id' to 'proc_id' for handling wait
command.
Futher it changes how the commands running in background are handled when
wait command is called. When a user calls wait command the controller first
queries the remaining time of the associated bg process. If it has not
timeouted yet the alarm is set to trigger on time calculated from the returned
value of get_remaining_time(). If the bg process already timeouted the alarm is set to two
seconds just to give some time to reach the try/exception block.
Not 100% clean but works reliably than before.
Tested by following recipe:
<lnstrecipe>
<network>
<host id="m1">
<interfaces>
<eth id="x" label="netA"/>
</interfaces>
</host>
</network>
<task>
<run host="m1" command="sleep 5"
timeout="2"/>
<run host="m1" command="sleep 5"
timeout="2" bg_id="1"/>
<wait host="m1" bg_id="1"/>
<run host="m1" command="sleep 5"
timeout="6" bg_id="2"/>
<wait host="m1" bg_id="2"/>
<run host="m1" command="sleep 5"
timeout="2" bg_id="3"/>
<run host="m1" command="sleep 5"
timeout="2" bg_id="4"/>
<wait host="m1" bg_id="3"/>
<wait host="m1" bg_id="4"/>
</task>
</lnstrecipe>
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
lnst/Controller/Machine.py | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index 530aef8..5c53379 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -244,13 +244,24 @@ class Machine(object):
prev_handler = signal.signal(signal.SIGALRM, self._timeout_handler)
- if "timeout" in command:
- timeout = command["timeout"]
- logging.debug("Setting timeout to \"%d\"", timeout)
- signal.alarm(timeout)
+ if command["type"] == "wait":
+ logging.debug("Get the uptime of bg process with bg_id == %s" %
command["proc_id"])
+ remaining_time = self._rpc_call("get_remaining_time",
command["proc_id"])
+ logging.debug("Setting timeout to %d", remaining_time)
+ if remaining_time > 0:
+ signal.alarm(remaining_time)
+ else:
+ # 2 seconds is enough time to do wait via RPC and collect
+ # the result
+ signal.alarm(2)
else:
- logging.debug("Setting default timeout (%ds)." % DEFAULT_TIMEOUT)
- signal.alarm(DEFAULT_TIMEOUT)
+ if "timeout" in command:
+ timeout = command["timeout"]
+ logging.debug("Setting timeout to \"%d\"", timeout)
+ signal.alarm(timeout)
+ else:
+ logging.debug("Setting default timeout (%ds)." %
DEFAULT_TIMEOUT)
+ signal.alarm(DEFAULT_TIMEOUT)
try:
if 'netns' in command and command['netns'] != None:
@@ -259,8 +270,8 @@ class Machine(object):
else:
cmd_res = self._rpc_call("run_command", command)
except MachineError as exc:
- if "bg_id" in command:
- cmd_res = self._rpc_call("kill_command",
command["bg_id"])
+ if "proc_id" in command:
+ cmd_res = self._rpc_call("kill_command",
command["proc_id"])
else:
cmd_res = self._rpc_call("kill_command", None)
cmd_res["passed"] = False
--
1.9.3