From: Ondrej Lichtner <olichtne(a)redhat.com>
This commit makes shure that when the rpc method kill_command is called,
it first checks if the command didn't finish first. If it did, it will
only be removed from the command context. This situation can occur when
the Controller detects a command timeout and sends a kill_command
request, but on the Slave the command is already finished and the result
was sent in the mean time.
This commit should fix this issue and the command will be seen as
finished on time. If the command was killed we now also add a killed
flag to the result message to indicate this action.
Related to #120
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Common/NetTestCommand.py | 1 +
lnst/Controller/Machine.py | 5 +++--
lnst/Slave/NetTestSlave.py | 25 ++++++++++++++++++++-----
3 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py
index 6944051..1489794 100644
--- a/lnst/Common/NetTestCommand.py
+++ b/lnst/Common/NetTestCommand.py
@@ -208,6 +208,7 @@ class NetTestCommand:
result = self._cmd_cls.get_result()
result["passed"] = True
result["msg"] = "Command killed."
+ result["killed"] = True
self._result = result
return self._result
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index 8a40ceb..e60e1ea 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -316,8 +316,9 @@ class Machine(object):
else:
cmd_res = self._rpc_call("kill_command", None)
- cmd_res["passed"] = False
- cmd_res["msg"] = str(exc)
+ if "killed" in cmd_res and cmd_res["killed"]:
+ cmd_res["passed"] = False
+ cmd_res["msg"] = str(exc)
signal.alarm(0)
signal.signal(signal.SIGALRM, prev_handler)
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index a725a62..502abbf 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -366,7 +366,18 @@ class SlaveMethods:
def run_command(self, command):
cmd = NetTestCommand(self._command_context, command,
self._resource_table, self._log_ctl)
- self._command_context.add_cmd(cmd)
+
+ if self._command_context.get_cmd(cmd.get_id()) != None:
+ prev_cmd = self._command_context.get_cmd(cmd.get_id())
+ if not prev_cmd.finished():
+ if cmd.get_id() is None:
+ raise Exception("Previous foreground command still "\
+ "running!")
+ else:
+ raise Exception("Different command with id '%s' "\
+ "still running!" % cmd.get_id())
+ else:
+ self._command_context.add_cmd(cmd)
res = cmd.run()
if not cmd.forked():
@@ -385,9 +396,13 @@ class SlaveMethods:
def kill_command(self, id):
cmd = self._command_context.get_cmd(id)
- cmd.kill(None)
- self._command_context.del_cmd(cmd)
- return cmd.get_result()
+ if cmd is not None:
+ self._command_context.del_cmd(cmd)
+ if not cmd.finished():
+ cmd.kill(None)
+ return cmd.get_result()
+ else:
+ raise Exception("No command with id '%s'." % id)
def machine_cleanup(self):
logging.info("Performing machine cleanup.")
@@ -852,7 +867,7 @@ class NetTestSlave:
self._server_handler.send_data_to_ctl(msg)
cmd = self._cmd_context.get_cmd(None)
cmd.join()
- self._cmd_context.del_cmd(cmd)
+ cmd.set_finished()
else:
cmd = self._cmd_context.get_cmd(msg["cmd_id"])
cmd.join()
--
2.5.0