From: Ondrej Lichtner olichtne@redhat.com
We used to have a default timeout for commands with the previous rpc implementation, but didn't implement it in the new one. This commit adds a default timeout for commands, the time is set in the DEFAULT_TIMEOUT constant, which for now is 60 seconds.
This also fixes result reporting for killed commands.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- lnst/Common/NetTestCommand.py | 8 ++++---- lnst/Controller/Machine.py | 12 +++++++++--- lnst/Slave/NetTestSlave.py | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py index fa36d29..9e1708d 100644 --- a/lnst/Common/NetTestCommand.py +++ b/lnst/Common/NetTestCommand.py @@ -187,13 +187,13 @@ class NetTestCommand:
def get_result(self): if self._killed: - result = {} + self._cmd_cls.set_pass() + result = self._cmd_cls.get_result() result["passed"] = True result["msg"] = "Command killed." - else: - result = self._result + self._result = result
- return result + return self._result
def set_result(self, result): if self._control_cmd != None: diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py index 4ac7d2f..36c9d52 100644 --- a/lnst/Controller/Machine.py +++ b/lnst/Controller/Machine.py @@ -29,6 +29,8 @@ from lnst.Common.Utils import wait_for, md5sum, dir_md5sum, create_tar_archive from lnst.Common.ConnectionHandler import send_data, recv_data from lnst.Common.ConnectionHandler import ConnectionHandler
+DEFAULT_TIMEOUT = 60 + class MachineError(Exception): pass
@@ -196,15 +198,19 @@ class Machine(object): 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: cmd_res = self._rpc_call("run_command", command) except MachineError as exc: if "bg_id" in command: - self._rpc_call("kill_command", command["bg_id"]) + cmd_res = self._rpc_call("kill_command", command["bg_id"]) else: - self._rpc_call("kill_command", None) - cmd_res = {"passed": False, "err_msg": str(exc)} + cmd_res = self._rpc_call("kill_command", None) + 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 f68b96f..b867db2 100644 --- a/lnst/Slave/NetTestSlave.py +++ b/lnst/Slave/NetTestSlave.py @@ -287,7 +287,7 @@ class SlaveMethods: cmd = self._command_context.get_cmd(id) cmd.kill(None) self._command_context.del_cmd(cmd) - return True + return cmd.get_result()
def machine_cleanup(self): logging.info("Performing machine cleanup.")
lnst-developers@lists.fedorahosted.org