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 <[email protected]> --- doc/examples/gnt-debug/delayR.json | 3 +++ lib/cmdlib.py | 20 +++++++++++++++++++- lib/opcodes.py | 2 +- scripts/gnt-debug | 5 ++++- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 doc/examples/gnt-debug/delayR.json diff --git a/doc/examples/gnt-debug/delayR.json b/doc/examples/gnt-debug/delayR.json new file mode 100644 index 0000000..edbbca3 --- /dev/null +++ b/doc/examples/gnt-debug/delayR.json @@ -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} +] diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 6e16aa3..b1889ab 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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. diff --git a/lib/opcodes.py b/lib/opcodes.py index e05d2d8..a0f7f83 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -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): diff --git a/scripts/gnt-debug b/scripts/gnt-debug index 0d59d5b..bf9d98d 100755 --- a/scripts/gnt-debug +++ b/scripts/gnt-debug @@ -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': ( -- 1.7.1
