From 1a8c0ce1a2a7d57a212e08818e25837bc447a2a8 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Mon, 29 Oct 2007 20:09:25 +0000 Subject: [PATCH] Change the signature of some methods of mcpu.Processor This patch moves the passing of the feedback_fn argument from the (Exec|Chain)OpCode to the initialization of the Processor instance. Reviewed-by: imsnah --- lib/cli.py | 6 +++--- lib/cmdlib.py | 6 +++--- lib/mcpu.py | 19 +++++++++---------- tools/burnin | 18 +++++++++--------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index d1b6925ec..780e002e4 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -346,11 +346,11 @@ def SubmitOpCode(op, proc=None, feedback_fn=None): interaction functions. """ - if proc is None: - proc = mcpu.Processor() if feedback_fn is None: feedback_fn = logger.ToStdout - return proc.ExecOpCode(op, feedback_fn) + if proc is None: + proc = mcpu.Processor(feedback=feedback_fn) + return proc.ExecOpCode(op) def FormatError(err): diff --git a/lib/cmdlib.py b/lib/cmdlib.py index e273ee239..2c9a20693 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -4027,7 +4027,7 @@ class LUExportInstance(LogicalUnit): # shutdown the instance, unless requested not to do so if self.op.shutdown: op = opcodes.OpShutdownInstance(instance_name=instance.name) - self.processor.ChainOpCode(op, feedback_fn) + self.processor.ChainOpCode(op) vgname = self.cfg.GetVGName() @@ -4053,7 +4053,7 @@ class LUExportInstance(LogicalUnit): if self.op.shutdown: op = opcodes.OpStartupInstance(instance_name=instance.name, force=False) - self.processor.ChainOpCode(op, feedback_fn) + self.processor.ChainOpCode(op) # TODO: check for size @@ -4079,7 +4079,7 @@ class LUExportInstance(LogicalUnit): # substitutes an empty list with the full cluster node list. if nodelist: op = opcodes.OpQueryExports(nodes=nodelist) - exportlist = self.processor.ChainOpCode(op, feedback_fn) + exportlist = self.processor.ChainOpCode(op) for node in exportlist: if instance.name in exportlist[node]: if not rpc.call_export_remove(node, instance.name): diff --git a/lib/mcpu.py b/lib/mcpu.py index 2f89842fb..139a3bd68 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -84,22 +84,23 @@ class Processor(object): opcodes.OpDelTags: cmdlib.LUDelTags, } - - def __init__(self): + def __init__(self, feedback=None): """Constructor for Processor + Args: + - feedback_fn: the feedback function (taking one string) to be run when + interesting events are happening """ self.cfg = None self.sstore = None + self._feedback_fn = feedback - def ExecOpCode(self, op, feedback_fn): + def ExecOpCode(self, op): """Execute an opcode. Args: - cfg: the configuration in which we execute this opcode - opcode: the opcode to be executed - - feedback_fn: the feedback function (taking one string) to be run when - interesting events are happening """ if not isinstance(op, opcodes.OpCode): @@ -121,7 +122,7 @@ class Processor(object): lu.CheckPrereq() hm = HooksMaster(rpc.call_hooks_runner, lu) hm.RunPhase(constants.HOOKS_PHASE_PRE) - result = lu.Exec(feedback_fn) + result = lu.Exec(self._feedback_fn) hm.RunPhase(constants.HOOKS_PHASE_POST) if lu.cfg is not None: # we use lu.cfg and not self.cfg as for init cluster, self.cfg @@ -132,15 +133,13 @@ class Processor(object): return result - def ChainOpCode(self, op, feedback_fn): + def ChainOpCode(self, op): """Chain and execute an opcode. This is used by LUs when they need to execute a child LU. Args: - opcode: the opcode to be executed - - feedback_fn: the feedback function (taking one string) to be run when - interesting events are happening """ if not isinstance(op, opcodes.OpCode): @@ -160,7 +159,7 @@ class Processor(object): #if do_hooks: # hm = HooksMaster(rpc.call_hooks_runner, lu) # hm.RunPhase(constants.HOOKS_PHASE_PRE) - result = lu.Exec(feedback_fn) + result = lu.Exec(self._feedback_fn) #if do_hooks: # hm.RunPhase(constants.HOOKS_PHASE_POST) return result diff --git a/tools/burnin b/tools/burnin index 440c2fbc7..85916cc8f 100755 --- a/tools/burnin +++ b/tools/burnin @@ -81,14 +81,14 @@ def BurninCluster(opts, args): """ logger.SetupLogging(debug=True, program="ganeti/burnin") - proc = mcpu.Processor() + proc = mcpu.Processor(feedback=Feedback) result = proc.ExecOpCode(opcodes.OpQueryNodes(output_fields=["name"], - names=[]), Feedback) + names=[])) nodelist = [data[0] for data in result] Feedback("- Testing global parameters") - result = proc.ExecOpCode(opcodes.OpDiagnoseOS(), Feedback) + result = proc.ExecOpCode(opcodes.OpDiagnoseOS()) if not result: Feedback("Can't get the OS list") @@ -135,7 +135,7 @@ def BurninCluster(opts, args): ip_check=True, wait_for_sync=True) Feedback("- Add instance %s on node %s" % (instance_name, pnode)) - result = proc.ExecOpCode(op, Feedback) + result = proc.ExecOpCode(op) to_remove.append(instance_name) idx = next_idx @@ -148,7 +148,7 @@ def BurninCluster(opts, args): remote_node=None) Feedback("- Replace disks for instance %s" % (instance_name)) - result = proc.ExecOpCode(op, Feedback) + result = proc.ExecOpCode(op) else: Feedback("- Can't run replace1, not enough nodes") @@ -160,7 +160,7 @@ def BurninCluster(opts, args): ignore_consistency=True) Feedback("- Failover instance %s" % (instance_name)) - result = proc.ExecOpCode(op, Feedback) + result = proc.ExecOpCode(op) else: Feedback("- Can't run failovers, not enough nodes") @@ -168,17 +168,17 @@ def BurninCluster(opts, args): for instance_name in args: op = opcodes.OpShutdownInstance(instance_name=instance_name) Feedback("- Shutdown instance %s" % instance_name) - result = proc.ExecOpCode(op, Feedback) + result = proc.ExecOpCode(op) op = opcodes.OpStartupInstance(instance_name=instance_name, force=False) Feedback("- Start instance %s" % instance_name) - result = proc.ExecOpCode(op, Feedback) + result = proc.ExecOpCode(op) finally: # remove for instance_name in to_remove: op = opcodes.OpRemoveInstance(instance_name=instance_name) Feedback("- Remove instance %s" % instance_name) - result = proc.ExecOpCode(op, Feedback) + result = proc.ExecOpCode(op) return 0 -- GitLab