commit 48dfa9512867d77d02952ab84a13317bc47f53ac
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Mar 29 13:55:04 2013 +0100
NetTestSlave: adjust response handling to fit NetTestCommand
This patch reiplements the method run_command to reflect the changes of
NetTestCommand class. The method returns the result of the run() method
of the NetTestCommand class which is None for most cases but in case of
wait/intr/kill commands can be the result of the test command running in
background. And in the case of running a background command in the
traditional sense we still return a notification that yes the command
was forked.
Because of this the server also had to be adjusted a little. Currently
if the server recieves a return value from the run_command method it
will forward it to the controller. However if None is returned, nothing
is send to the controller which causes the controller to wait until a
response arrives. This way I simulate the wait for the end of a
foreground test command while also being able to recieve messages (such
as logs) from other slaves.
Now if the server recieves a result message this could mean 3 things:
* a foreground command finished and the server forwards the result to
the controller
* a background command that wasn't killed/interrupted/waited on has
finished- the server stores the result of this command and will
forward it to the controller when the kill/intr/wait command is
recieved
* a background command that was already killed/interrupted/waited on has
finished- the server forwards the result to the controller.
This way the controller is waiting for a result message for every
command that he sends and at the same time he will be able to continue
when a background command has been launched.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
lnst/Slave/NetTestSlave.py | 39 +++++++++++++++++++++++++++++++++------
1 files changed, 33 insertions(+), 6 deletions(-)
---
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 253a75a..aad7074 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -159,9 +159,14 @@ class SlaveMethods:
def run_command(self, command):
try:
- cmd_cls = NetTestCommand(self._command_context, command,
+ cmd = NetTestCommand(self._command_context, command,
self._resource_table, self._log_ctl)
- return cmd_cls.run()
+ self._command_context.add_cmd(cmd)
+
+ res = cmd.run()
+ if not cmd.forked():
+ self._command_context.del_cmd(cmd)
+ return res
except:
log_exc_traceback()
cmd_type = command["type"]
@@ -351,26 +356,48 @@ class NetTestSlave:
if self._server_handler.get_ctl_sock() == None:
self._log_ctl.cancel_connection()
+ self._cmd_context.cleanup()
+
def _process_msg(self, msg):
if msg["type"] == "command":
method = getattr(self._methods, msg["method_name"], None)
if method != None:
result = method(*msg["args"])
- response = {"type": "result", "result":
result}
- if not self._server_handler.send_data_to_ctl(response):
- self._log_ctl.cancel_connection()
+
+ if result != None:
+ response = {"type": "result", "result":
result}
+ if not self._server_handler.send_data_to_ctl(response):
+ 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._log_ctl.cancel_connection()
-
elif msg["type"] == "log":
if not self._server_handler.send_data_to_ctl(msg):
self._log_ctl.cancel_connection()
elif msg["type"] == "exception":
if not self._server_handler.send_data_to_ctl(msg):
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._log_ctl.cancel_connection()
+ cmd = self._cmd_context.get_cmd(None)
+ cmd.join()
+ self._cmd_context.del_cmd(cmd)
+ else:
+ cmd = self._cmd_context.get_cmd(msg["cmd_id"])
+ cmd.join()
+ del msg["cmd_id"]
+
+ if cmd.finished():
+ if not self._server_handler.send_data_to_ctl(msg):
+ self._log_ctl.cancel_connection()
+ self._cmd_context.del_cmd(cmd)
+ else:
+ cmd.set_result(msg["result"])
else:
raise Exception("Recieved unknown command")