Revision 87ed6b79 test/py/ganeti.mcpu_unittest.py
b/test/py/ganeti.mcpu_unittest.py | ||
---|---|---|
173 | 173 |
def __init__(self, needed_locks, share_locks): |
174 | 174 |
self.needed_locks = needed_locks |
175 | 175 |
self.share_locks = share_locks |
176 |
self.locks = [] |
|
176 | 177 |
|
177 |
|
|
178 |
class _FakeGlm: |
|
179 |
def __init__(self, owning_nal): |
|
180 |
self._owning_nal = owning_nal |
|
181 |
|
|
182 |
def check_owned(self, level, names): |
|
183 |
assert level == locking.LEVEL_NODE_ALLOC |
|
184 |
assert names == locking.NAL |
|
185 |
return self._owning_nal |
|
186 |
|
|
187 |
def owning_all(self, level): |
|
188 |
return False |
|
178 |
def owned_locks(self, *_): |
|
179 |
return self.locks |
|
189 | 180 |
|
190 | 181 |
|
191 | 182 |
class TestVerifyLocks(unittest.TestCase): |
192 | 183 |
def testNoLocks(self): |
193 | 184 |
lu = _FakeLuWithLocks({}, {}) |
194 |
glm = _FakeGlm(False) |
|
195 |
mcpu._VerifyLocks(lu, glm, |
|
185 |
mcpu._VerifyLocks(lu, |
|
196 | 186 |
_mode_whitelist=NotImplemented, |
197 | 187 |
_nal_whitelist=NotImplemented) |
198 | 188 |
|
... | ... | |
204 | 194 |
level: 0, |
205 | 195 |
locking.LEVEL_NODE_ALLOC: 0, |
206 | 196 |
}) |
207 |
glm = _FakeGlm(False) |
|
208 |
mcpu._VerifyLocks(lu, glm, _mode_whitelist=[], _nal_whitelist=[]) |
|
197 |
mcpu._VerifyLocks(lu, _mode_whitelist=[], _nal_whitelist=[]) |
|
209 | 198 |
|
210 | 199 |
def testDifferentMode(self): |
211 | 200 |
for level in [locking.LEVEL_NODE, locking.LEVEL_NODE_RES]: |
... | ... | |
215 | 204 |
level: 0, |
216 | 205 |
locking.LEVEL_NODE_ALLOC: 1, |
217 | 206 |
}) |
218 |
glm = _FakeGlm(False) |
|
219 | 207 |
try: |
220 |
mcpu._VerifyLocks(lu, glm, _mode_whitelist=[], _nal_whitelist=[])
|
|
208 |
mcpu._VerifyLocks(lu, _mode_whitelist=[], _nal_whitelist=[]) |
|
221 | 209 |
except AssertionError, err: |
222 | 210 |
self.assertTrue("using the same mode as nodes" in str(err)) |
223 | 211 |
else: |
224 | 212 |
self.fail("Exception not raised") |
225 | 213 |
|
226 | 214 |
# Once more with the whitelist |
227 |
mcpu._VerifyLocks(lu, glm, _mode_whitelist=[_FakeLuWithLocks],
|
|
215 |
mcpu._VerifyLocks(lu, _mode_whitelist=[_FakeLuWithLocks], |
|
228 | 216 |
_nal_whitelist=[]) |
229 | 217 |
|
230 | 218 |
def testSameMode(self): |
... | ... | |
236 | 224 |
level: 1, |
237 | 225 |
locking.LEVEL_NODE_ALLOC: 1, |
238 | 226 |
}) |
239 |
glm = _FakeGlm(True) |
|
240 | 227 |
|
241 | 228 |
try: |
242 |
mcpu._VerifyLocks(lu, glm, _mode_whitelist=[_FakeLuWithLocks],
|
|
229 |
mcpu._VerifyLocks(lu, _mode_whitelist=[_FakeLuWithLocks], |
|
243 | 230 |
_nal_whitelist=[]) |
244 | 231 |
except AssertionError, err: |
245 | 232 |
self.assertTrue("whitelisted to use different modes" in str(err)) |
... | ... | |
247 | 234 |
self.fail("Exception not raised") |
248 | 235 |
|
249 | 236 |
# Once more without the whitelist |
250 |
mcpu._VerifyLocks(lu, glm, _mode_whitelist=[], _nal_whitelist=[])
|
|
237 |
mcpu._VerifyLocks(lu, _mode_whitelist=[], _nal_whitelist=[]) |
|
251 | 238 |
|
252 | 239 |
def testAllWithoutAllocLock(self): |
253 | 240 |
for level in [locking.LEVEL_NODE, locking.LEVEL_NODE_RES]: |
... | ... | |
257 | 244 |
level: 0, |
258 | 245 |
locking.LEVEL_NODE_ALLOC: 0, |
259 | 246 |
}) |
260 |
glm = _FakeGlm(False) |
|
247 |
|
|
261 | 248 |
try: |
262 |
mcpu._VerifyLocks(lu, glm, _mode_whitelist=[], _nal_whitelist=[])
|
|
249 |
mcpu._VerifyLocks(lu, _mode_whitelist=[], _nal_whitelist=[]) |
|
263 | 250 |
except AssertionError, err: |
264 | 251 |
self.assertTrue("allocation lock must be used if" in str(err)) |
265 | 252 |
else: |
266 | 253 |
self.fail("Exception not raised") |
267 | 254 |
|
268 | 255 |
# Once more with the whitelist |
269 |
mcpu._VerifyLocks(lu, glm, _mode_whitelist=[],
|
|
256 |
mcpu._VerifyLocks(lu, _mode_whitelist=[], |
|
270 | 257 |
_nal_whitelist=[_FakeLuWithLocks]) |
271 | 258 |
|
272 | 259 |
def testAllWithAllocLock(self): |
... | ... | |
278 | 265 |
level: 0, |
279 | 266 |
locking.LEVEL_NODE_ALLOC: 0, |
280 | 267 |
}) |
281 |
glm = _FakeGlm(True)
|
|
268 |
lu.locks = [locking.NAL]
|
|
282 | 269 |
|
283 | 270 |
try: |
284 |
mcpu._VerifyLocks(lu, glm, _mode_whitelist=[],
|
|
271 |
mcpu._VerifyLocks(lu, _mode_whitelist=[], |
|
285 | 272 |
_nal_whitelist=[_FakeLuWithLocks]) |
286 | 273 |
except AssertionError, err: |
287 | 274 |
self.assertTrue("whitelisted for not acquiring" in str(err)) |
... | ... | |
289 | 276 |
self.fail("Exception not raised") |
290 | 277 |
|
291 | 278 |
# Once more without the whitelist |
292 |
mcpu._VerifyLocks(lu, glm, _mode_whitelist=[], _nal_whitelist=[])
|
|
279 |
mcpu._VerifyLocks(lu, _mode_whitelist=[], _nal_whitelist=[]) |
|
293 | 280 |
|
294 | 281 |
|
295 | 282 |
if __name__ == "__main__": |
Also available in: Unified diff