From 207774131724caaf0849450a19fbb207cf5655f4 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Fri, 19 Jun 2009 14:09:19 +0200 Subject: [PATCH] LU execution: implement dry-run framework This patch adds a new (global) opcode flag 'dry_run' which, when True, causes early exit from the LU workflow, returning a special value from the LU object (initialized in the parent LogicalUnit class, and which if not overriden from child LUs will be None). Signed-off-by: Iustin Pop Reviewed-by: Guido Trotter --- lib/cmdlib.py | 5 +++++ lib/mcpu.py | 9 +++++++++ lib/opcodes.py | 6 ++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index bda05fa..de16fcc 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -56,6 +56,9 @@ class LogicalUnit(object): Note that all commands require root permissions. + @ivar dry_run_result: the value (if any) that will be returned to the caller + in dry-run mode (signalled by opcode dry_run parameter) + """ HPATH = None HTYPE = None @@ -86,6 +89,8 @@ class LogicalUnit(object): # logging self.LogWarning = processor.LogWarning self.LogInfo = processor.LogInfo + # support for dry-run + self.dry_run_result = None for attr_name in self._OP_REQP: attr_val = getattr(op, attr_name, None) diff --git a/lib/mcpu.py b/lib/mcpu.py index 11fa743..0844b74 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -113,6 +113,15 @@ class Processor(object): h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE) lu.HooksCallBack(constants.HOOKS_PHASE_PRE, h_results, self._feedback_fn, None) + + if getattr(lu.op, "dry_run", False): + # in this mode, no post-hooks are run, and the config is not + # written (as it might have been modified by another LU, and we + # shouldn't do writeout on behalf of other threads + self.LogInfo("dry-run mode requested, not actually executing" + " the operation") + return lu.dry_run_result + try: result = lu.Exec(self._feedback_fn) h_results = hm.RunPhase(constants.HOOKS_PHASE_POST) diff --git a/lib/opcodes.py b/lib/opcodes.py index 541bbc0..4de40ba 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -103,11 +103,13 @@ class OpCode(BaseOpCode): from this class should override OP_ID. @cvar OP_ID: The ID of this opcode. This should be unique amongst all - childre of this class. + children of this class. + @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just + the check steps """ OP_ID = "OP_ABSTRACT" - __slots__ = BaseOpCode.__slots__ + [] + __slots__ = BaseOpCode.__slots__ + ["dry_run"] def __getstate__(self): """Specialized getstate for opcodes. -- 1.7.10.4