commit 26764c8d02df1552c57b5a7cbaf8696aea6821b2
Author: Jan Tluka <jtluka(a)redhat.com>
Date: Wed Sep 3 16:30:41 2014 +0200
Controller: fix the handling of background process timeouts
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>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Controller/Machine.py | 28 ++++++++++++++++++++--------
1 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index 530aef8..c070d26 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -244,13 +244,25 @@ 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 remaining time 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 +271,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
Show replies by date