commit 5905439c5153e938a87f6c0f219d25b05ec7c69d
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Mar 29 14:03:21 2013 +0100
NetTestSlave: add kill_cmds method and cleanup
This commit adds a new slave method kill_cmds that will perform a
cleanup on the command context. This should be used by the controller
during slave cleanup phase, so that there are no leftover commands
running.
I also added a few calls of command context cleanup to the slave server
so that if a connection from controller is lost we also cleanup all
running commands.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
lnst/Slave/NetTestSlave.py | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index c35e6af..be85da4 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -80,6 +80,11 @@ class SlaveMethods:
self._remove_capture_files()
return "bye"
+ def kill_cmds(self):
+ logging.info("Killing all forked processes.")
+ self._command_context.cleanup()
+ return "Commands killed"
+
def get_devices_by_hwaddr(self, hwaddr):
name_scan = scan_netdevs()
netdevs = []
@@ -346,6 +351,7 @@ class NetTestSlave:
self._server_handler.accept_connection()
except socket.error:
continue
+ self._cmd_context.cleanup()
self._log_ctl.set_connection(
self._server_handler.get_ctl_sock())
@@ -355,6 +361,7 @@ class NetTestSlave:
self._process_msg(msg[1])
if self._server_handler.get_ctl_sock() == None:
+ self._cmd_context.cleanup()
self._log_ctl.cancel_connection()
self._cmd_context.cleanup()
@@ -380,14 +387,17 @@ class NetTestSlave:
if result != None:
response = {"type": "result", "result": result}
if not self._server_handler.send_data_to_ctl(response):
+ self._cmd_context.cleanup()
self._log_ctl.cancel_connection()
else:
err = "Method not found: %s" % msg["method_name"]
response = {"type": "error", "err": err}
if not self._server_handler.send_data_to_ctl(response):
+ self._cmd_context.cleanup()
self._log_ctl.cancel_connection()
elif msg["type"] == "log":
if not self._server_handler.send_data_to_ctl(msg):
+ self._cmd_context.cleanup()
self._log_ctl.cancel_connection()
elif msg["type"] == "exception":
if msg["cmd_id"] != None:
@@ -400,11 +410,13 @@ class NetTestSlave:
cmd.join()
self._cmd_context.del_cmd(cmd)
if not self._server_handler.send_data_to_ctl(msg):
+ self._cmd_context.cleanup()
self._log_ctl.cancel_connection()
elif msg["type"] == "result":
if msg["cmd_id"] == None:
del msg["cmd_id"]
if not self._server_handler.send_data_to_ctl(msg):
+ self._cmd_context.cleanup()
self._log_ctl.cancel_connection()
cmd = self._cmd_context.get_cmd(None)
cmd.join()
@@ -416,6 +428,7 @@ class NetTestSlave:
if cmd.finished():
if not self._server_handler.send_data_to_ctl(msg):
+ self._cmd_context.cleanup()
self._log_ctl.cancel_connection()
self._cmd_context.del_cmd(cmd)
else: