23 |
23 |
|
24 |
24 |
|
25 |
25 |
import inspect
|
|
26 |
import mock
|
26 |
27 |
import re
|
27 |
28 |
import traceback
|
28 |
29 |
|
... | ... | |
36 |
37 |
RpcResultsBuilder
|
37 |
38 |
from cmdlib.testsupport.ssh_mock import patchSsh
|
38 |
39 |
|
|
40 |
from ganeti.cmdlib.base import LogicalUnit
|
39 |
41 |
from ganeti import errors
|
40 |
42 |
from ganeti import objects
|
41 |
43 |
from ganeti import opcodes
|
... | ... | |
45 |
47 |
|
46 |
48 |
|
47 |
49 |
class GanetiContextMock(object):
|
48 |
|
def __init__(self, cfg, glm, rpc):
|
49 |
|
self.cfg = cfg
|
50 |
|
self.glm = glm
|
51 |
|
self.rpc = rpc
|
|
50 |
# pylint: disable=W0212
|
|
51 |
cfg = property(fget=lambda self: self._test_case.cfg)
|
|
52 |
# pylint: disable=W0212
|
|
53 |
glm = property(fget=lambda self: self._test_case.glm)
|
|
54 |
# pylint: disable=W0212
|
|
55 |
rpc = property(fget=lambda self: self._test_case.rpc)
|
|
56 |
|
|
57 |
def __init__(self, test_case):
|
|
58 |
self._test_case = test_case
|
|
59 |
|
|
60 |
|
|
61 |
class MockLU(LogicalUnit):
|
|
62 |
def BuildHooksNodes(self):
|
|
63 |
pass
|
|
64 |
|
|
65 |
def BuildHooksEnv(self):
|
|
66 |
pass
|
52 |
67 |
|
53 |
68 |
|
54 |
69 |
# pylint: disable=R0904
|
... | ... | |
137 |
152 |
self.cfg = ConfigMock()
|
138 |
153 |
self.glm = LockManagerMock()
|
139 |
154 |
self.rpc = CreateRpcRunnerMock()
|
140 |
|
ctx = GanetiContextMock(self.cfg, self.glm, self.rpc)
|
141 |
|
self.mcpu = ProcessorMock(ctx)
|
|
155 |
self.ctx = GanetiContextMock(self)
|
|
156 |
self.mcpu = ProcessorMock(self.ctx)
|
142 |
157 |
|
143 |
158 |
self._StopPatchers()
|
144 |
159 |
try:
|
... | ... | |
163 |
178 |
# this test module does not use ssh, no patching performed
|
164 |
179 |
self._ssh_patcher = None
|
165 |
180 |
|
|
181 |
def GetMockLU(self):
|
|
182 |
"""Creates a mock L{LogialUnit} with access to the mocked config etc.
|
|
183 |
|
|
184 |
@rtype: L{LogialUnit}
|
|
185 |
@return: A mock LU
|
|
186 |
|
|
187 |
"""
|
|
188 |
return MockLU(self.mcpu, mock.MagicMock(), self.ctx, self.rpc)
|
|
189 |
|
166 |
190 |
def RpcResultsBuilder(self, use_node_names=False):
|
167 |
191 |
"""Creates a pre-configured L{RpcResultBuilder}
|
168 |
192 |
|