commit 6c3aa33ee124c182bbbbc8ffc04715545730b59a
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Nov 23 16:52:47 2012 +0100
add command ctl_wait for the controller
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 14c706f..1b3bad0 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
@@ -378,6 +379,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 03fedd1..2f77284 100644
--- a/lnst/Controller/NetTestParse.py
+++ b/lnst/Controller/NetTestParse.py
@@ -551,13 +551,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")
@@ -583,6 +591,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)
Show replies by date