from ganeti import cmdlib
from ganeti.constants import HKR_SUCCESS, HKR_FAIL, HKR_SKIP
-from mocks import FakeConfig, FakeSStore, FakeProc
+from mocks import FakeConfig, FakeProc, FakeContext
class FakeLU(cmdlib.LogicalUnit):
HPATH = "test"
return dict([(node_name, [("unittest", constants.HKR_SUCCESS, "ok")])
for node_name in node_list])
+ def setUp(self):
+ self.op = opcodes.OpCode()
+ self.context = FakeContext()
+ # WARNING: here we pass None as RpcRunner instance since we know
+ # our usage via HooksMaster will not use lu.rpc
+ self.lu = FakeLU(None, self.op, self.context, None)
+
def testTotalFalse(self):
"""Test complete rpc failure"""
- cfg = FakeConfig()
- sstore = FakeSStore()
- op = opcodes.OpCode()
- lu = FakeLU(None, op, cfg, sstore)
- hm = mcpu.HooksMaster(self._call_false, FakeProc(), lu)
+ hm = mcpu.HooksMaster(self._call_false, FakeProc(), self.lu)
self.failUnlessRaises(errors.HooksFailure,
hm.RunPhase, constants.HOOKS_PHASE_PRE)
hm.RunPhase(constants.HOOKS_PHASE_POST)
def testIndividualFalse(self):
"""Test individual node failure"""
- cfg = FakeConfig()
- sstore = FakeSStore()
- op = opcodes.OpCode()
- lu = FakeLU(None, op, cfg, sstore)
- hm = mcpu.HooksMaster(self._call_nodes_false, FakeProc(), lu)
+ hm = mcpu.HooksMaster(self._call_nodes_false, FakeProc(), self.lu)
hm.RunPhase(constants.HOOKS_PHASE_PRE)
#self.failUnlessRaises(errors.HooksFailure,
# hm.RunPhase, constants.HOOKS_PHASE_PRE)
def testScriptFalse(self):
"""Test individual rpc failure"""
- cfg = FakeConfig()
- op = opcodes.OpCode()
- sstore = FakeSStore()
- lu = FakeLU(None, op, cfg, sstore)
- hm = mcpu.HooksMaster(self._call_script_fail, FakeProc(), lu)
+ hm = mcpu.HooksMaster(self._call_script_fail, FakeProc(), self.lu)
self.failUnlessRaises(errors.HooksAbort,
hm.RunPhase, constants.HOOKS_PHASE_PRE)
hm.RunPhase(constants.HOOKS_PHASE_POST)
def testScriptSucceed(self):
"""Test individual rpc failure"""
- cfg = FakeConfig()
- op = opcodes.OpCode()
- sstore = FakeSStore()
- lu = FakeLU(None, op, cfg, sstore)
- hm = mcpu.HooksMaster(self._call_script_succeed, FakeProc(), lu)
+ hm = mcpu.HooksMaster(self._call_script_succeed, FakeProc(), self.lu)
for phase in (constants.HOOKS_PHASE_PRE, constants.HOOKS_PHASE_POST):
hm.RunPhase(phase)