From 77b657a36f635f8d481a9a10ad79325d66079f74 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Tue, 8 Jul 2008 08:49:41 +0000 Subject: [PATCH] Pass context to LUs Rather than passing a ConfigWriter to the LUs we'll pass the whole context, from which a ConfigWriter can be extracted, but we can also access the GanetiLockManager. This also fixes the places where a FakeLU is created. Reviewed-by: iustinp --- lib/cmdlib.py | 5 +++-- lib/mcpu.py | 4 ++-- test/ganeti.hooks_unittest.py | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index afebafce0..9859c8590 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -69,7 +69,7 @@ class LogicalUnit(object): REQ_WSSTORE = False REQ_BGL = True - def __init__(self, processor, op, cfg, sstore): + def __init__(self, processor, op, context, sstore): """Constructor for LogicalUnit. This needs to be overriden in derived classes in order to check op @@ -78,8 +78,9 @@ class LogicalUnit(object): """ self.proc = processor self.op = op - self.cfg = cfg + self.cfg = context.cfg self.sstore = sstore + self.context = context self.__ssh = None for attr_name in self._OP_REQP: diff --git a/lib/mcpu.py b/lib/mcpu.py index be9a3721e..fab8b6279 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -129,7 +129,7 @@ class Processor(object): shared=not lu_class.REQ_BGL) try: self.exclusive_BGL = lu_class.REQ_BGL - lu = lu_class(self, op, self.context.cfg, sstore) + lu = lu_class(self, op, self.context, sstore) lu.CheckPrereq() hm = HooksMaster(rpc.call_hooks_runner, self, lu) h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE) @@ -177,7 +177,7 @@ class Processor(object): sstore = ssconf.SimpleStore() #do_hooks = lu_class.HPATH is not None - lu = lu_class(self, op, self.context.cfg, sstore) + lu = lu_class(self, op, self.context, sstore) lu.CheckPrereq() #if do_hooks: # hm = HooksMaster(rpc.call_hooks_runner, self, lu) diff --git a/test/ganeti.hooks_unittest.py b/test/ganeti.hooks_unittest.py index 441119a3d..001810733 100755 --- a/test/ganeti.hooks_unittest.py +++ b/test/ganeti.hooks_unittest.py @@ -36,7 +36,7 @@ from ganeti import constants from ganeti import cmdlib from ganeti.constants import HKR_SUCCESS, HKR_FAIL, HKR_SKIP -from mocks import FakeConfig, FakeSStore, FakeProc +from mocks import FakeConfig, FakeSStore, FakeProc, FakeContext class FakeLU(cmdlib.LogicalUnit): HPATH = "test" @@ -226,10 +226,10 @@ class TestHooksMaster(unittest.TestCase): for node_name in node_list]) def setUp(self): - self.cfg = FakeConfig() self.sstore = FakeSStore() self.op = opcodes.OpCode() - self.lu = FakeLU(None, self.op, self.cfg, self.sstore) + self.context = FakeContext() + self.lu = FakeLU(None, self.op, self.context, self.sstore) def testTotalFalse(self): """Test complete rpc failure""" -- GitLab