Commit 85a87e21 authored by Guido Trotter's avatar Guido Trotter

Add repetition count to the TestDelay opcode

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: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 706c353c
[
{"OP_ID": "OP_TEST_DELAY", "debug_level": 0, "dry_run": false, "duration": 0.0, "on_master": true, "on_nodes": [], "repeat": 5}
]
......@@ -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.
......
......@@ -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):
......
......@@ -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': (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment