From: Ondrej Lichtner <olichtne(a)redhat.com>
Sometimes it is necessary for the controller to wait and do nothing
while the slaves do stuff in the background. Until now we were using the
exec type command. However recently we made a change that forbid the
controller to run commands.
This patch adds a new command type "ctl_wait" that accepts an integer
value indicating for how many seconds will the controller sleep. To
ensure the usage of this command only for the controller the only
accepted attributes are: type, value and desc. The attribute machine_id
is not supported since the command can only be used by the controller.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/NetTestController.py | 6 ++++++
lnst/Controller/NetTestParse.py | 27 +++++++++++++++++++++++++--
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index 340cdea..b31e842 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -17,6 +17,7 @@ import os
import re
import pickle
import tempfile
+from time import sleep
from xmlrpclib import Binary
from pprint import pprint, pformat
from lnst.Common.Logs import Logs, log_exc_traceback
@@ -379,6 +380,11 @@ class NetTestController:
except KeyError:
pass
+ if command["type"] == "ctl_wait":
+ sleep(command["value"])
+ cmd_res = {"passed" : True}
+ return cmd_res
+
if "timeout" in command:
timeout = command["timeout"]
logging.debug("Setting socket timeout to \"%d\"",
timeout)
diff --git a/lnst/Controller/NetTestParse.py b/lnst/Controller/NetTestParse.py
index 40223f5..79df154 100644
--- a/lnst/Controller/NetTestParse.py
+++ b/lnst/Controller/NetTestParse.py
@@ -554,13 +554,21 @@ class CommandParse(RecipeParser):
recipe["sequences"][self._seq_num]["commands"].append(command)
self._cmd_num =
len(recipe["sequences"][self._seq_num]["commands"]) - 1
- machine_id = self._get_attribute(node, "machine_id")
- if machine_id and not machine_id in recipe["machines"]:
+ if self._has_attribute(node, "machine_id"):
+ machine_id = self._get_attribute(node, "machine_id")
+ else:
+ machine_id = None
+
+ if machine_id and machine_id not in recipe["machines"]:
raise XmlProcessingError("Invalid machine_id", node)
command["machine_id"] = machine_id
command["type"] = self._get_attribute(node, "type")
+ if (command["type"] != "ctl_wait" and not machine_id) or\
+ (machine_id and machine_id not in recipe["machines"]):
+ raise XmlProcessingError("Invalid machine_id", node)
+
command["value"] = None
if self._has_attribute(node, "value"):
command["value"] = self._get_attribute(node, "value")
@@ -586,6 +594,21 @@ class CommandParse(RecipeParser):
elif command["type"] == "exec":
if self._has_attribute(node, "from"):
command["from"] = self._get_attribute(node, "from")
+ elif command["type"] == "ctl_wait":
+ if command["machine_id"] != None:
+ msg = "Invalid attribute machine_id for command ctl_wait"
+ raise XmlProcessingError(msg, node)
+
+ try:
+ command["value"] = int(command["value"])
+ except ValueError:
+ msg = "Invalid value for command ctl_wait"
+ raise XmlProcessingError(msg, node)
+ for key in command.keys():
+ if key != "type" and key != "value" and\
+ key != "desc" and key != "machine_id":
+ msg = "Invalid attribute %s for command ctl_wait" % key
+ raise XmlProcessingError(msg, node)
scheme = {"options": self._options}
self._process_child_nodes(node, scheme)
--
1.7.11.7
Show replies by date