Add repetition count to the TestDelay opcode
authorGuido Trotter <ultrotter@google.com>
Wed, 23 Jun 2010 07:50:26 +0000 (09:50 +0200)
committerGuido Trotter <ultrotter@google.com>
Wed, 23 Jun 2010 09:38:40 +0000 (11:38 +0200)
If the repetition count is not passed or is passed as 0 we sleep exactly
one time, otherwise we sleep "repeat" times and log in between.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

doc/examples/gnt-debug/delayR.json [new file with mode: 0644]
lib/cmdlib.py
lib/opcodes.py
scripts/gnt-debug

diff --git a/doc/examples/gnt-debug/delayR.json b/doc/examples/gnt-debug/delayR.json
new file mode 100644 (file)
index 0000000..edbbca3
--- /dev/null
@@ -0,0 +1,3 @@
+[
+{"OP_ID": "OP_TEST_DELAY", "debug_level": 0, "dry_run": false, "duration": 0.0, "on_master": true, "on_nodes": [], "repeat": 5}
+]
index 6e16aa3..b1889ab 100644 (file)
@@ -9484,6 +9484,12 @@ class LUTestDelay(NoHooksLU):
   _OP_REQP = ["duration", "on_master", "on_nodes"]
   REQ_BGL = False
 
+  def CheckArguments(self):
+    # TODO: convert to the type system
+    self.op.repeat = getattr(self.op, "repeat", 0)
+    if self.op.repeat < 0:
+      raise errors.OpPrereqError("Repetition count cannot be negative")
+
   def ExpandNames(self):
     """Expand names and set required locks.
 
@@ -9503,7 +9509,7 @@ class LUTestDelay(NoHooksLU):
 
     """
 
-  def Exec(self, feedback_fn):
+  def _TestDelay(self):
     """Do the actual sleep.
 
     """
@@ -9515,6 +9521,18 @@ class LUTestDelay(NoHooksLU):
       for node, node_result in result.items():
         node_result.Raise("Failure during rpc call to node %s" % node)
 
+  def Exec(self, feedback_fn):
+    """Execute the test delay opcode, with the wanted repetitions.
+
+    """
+    if self.op.repeat == 0:
+      self._TestDelay()
+    else:
+      top_value = self.op.repeat - 1
+      for i in range(self.op.repeat):
+        self.LogInfo("Test delay iteration %d/%d" % (i, top_value))
+        self._TestDelay()
+
 
 class IAllocator(object):
   """IAllocator framework.
index e05d2d8..a0f7f83 100644 (file)
@@ -766,7 +766,7 @@ class OpTestDelay(OpCode):
   """
   OP_ID = "OP_TEST_DELAY"
   OP_DSC_FIELD = "duration"
-  __slots__ = ["duration", "on_master", "on_nodes"]
+  __slots__ = ["duration", "on_master", "on_nodes", "repeat"]
 
 
 class OpTestAllocator(OpCode):
index 0d59d5b..bf9d98d 100755 (executable)
@@ -50,7 +50,8 @@ def Delay(opts, args):
   delay = float(args[0])
   op = opcodes.OpTestDelay(duration=delay,
                            on_master=opts.on_master,
-                           on_nodes=opts.on_nodes)
+                           on_nodes=opts.on_nodes,
+                           repeat=opts.repeat)
   SubmitOpCode(op, opts=opts)
 
   return 0
@@ -161,6 +162,8 @@ commands = {
                 action="store_false", help="Do not sleep in the master code"),
      cli_option("-n", dest="on_nodes", default=[],
                 action="append", help="Select nodes to sleep on"),
+     cli_option("-r", "--repeat", type="int", default="0", dest="repeat",
+                help="Number of times to repeat the sleep"),
      ],
     "[opts...] <duration>", "Executes a TestDelay OpCode"),
   'submit-job': (