Commit 20777413 authored by Iustin Pop's avatar Iustin Pop
Browse files

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: default avatarIustin Pop <>
Reviewed-by: default avatarGuido Trotter <>
parent 4f05fd3b
......@@ -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)
......@@ -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
result = lu.Exec(self._feedback_fn)
h_results = hm.RunPhase(constants.HOOKS_PHASE_POST)
......@@ -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
__slots__ = BaseOpCode.__slots__ + []
__slots__ = BaseOpCode.__slots__ + ["dry_run"]
def __getstate__(self):
"""Specialized getstate for opcodes.
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