Revision 688b5752 test/py/ganeti.storage.bdev_unittest.py
b/test/py/ganeti.storage.bdev_unittest.py | ||
---|---|---|
300 | 300 |
self.assertTrue(len(epvs) == num_req or pvi.free != pvi.size) |
301 | 301 |
|
302 | 302 |
|
303 |
class TestLogicalVolume(unittest.TestCase): |
|
304 |
"""Tests for bdev.LogicalVolume.""" |
|
305 |
def testParseLvInfoLine(self): |
|
306 |
"""Tests for LogicalVolume._ParseLvInfoLine.""" |
|
307 |
broken_lines = [ |
|
308 |
" toomuch#-wi-ao#253#3#4096.00#2", |
|
309 |
" -wi-ao#253#3#4096.00", |
|
310 |
" -wi-a#253#3#4096.00#2", |
|
311 |
" -wi-ao#25.3#3#4096.00#2", |
|
312 |
" -wi-ao#twenty#3#4096.00#2", |
|
313 |
" -wi-ao#253#3.1#4096.00#2", |
|
314 |
" -wi-ao#253#three#4096.00#2", |
|
315 |
" -wi-ao#253#3#four#2", |
|
316 |
" -wi-ao#253#3#4096..00#2", |
|
317 |
" -wi-ao#253#3#4096.00#2.0", |
|
318 |
" -wi-ao#253#3#4096.00#two", |
|
319 |
] |
|
320 |
for broken in broken_lines: |
|
321 |
self.assertRaises(errors.BlockDeviceError, |
|
322 |
bdev.LogicalVolume._ParseLvInfoLine, broken, "#") |
|
323 |
|
|
324 |
true_out = [ |
|
325 |
("-wi-ao", 253, 3, 4096.00, 2), |
|
326 |
("-wi-a-", 253, 7, 4096.00, 4), |
|
327 |
("-ri-a-", 253, 4, 4.00, 5), |
|
328 |
("-wc-ao", 15, 18, 4096.00, 32), |
|
329 |
] |
|
330 |
for exp in true_out: |
|
331 |
for sep in "#;|,": |
|
332 |
lvs_line = sep.join((" %s", "%d", "%d", "%.2f", "%d")) % exp |
|
333 |
parsed = bdev.LogicalVolume._ParseLvInfoLine(lvs_line, sep) |
|
334 |
self.assertEqual(parsed, exp) |
|
335 |
|
|
336 |
@staticmethod |
|
337 |
def _FakeRunCmd(success, stdout): |
|
338 |
if success: |
|
339 |
exit_code = 0 |
|
340 |
else: |
|
341 |
exit_code = 1 |
|
342 |
return lambda cmd: utils.RunResult(exit_code, None, stdout, "", cmd, |
|
343 |
utils.process._TIMEOUT_NONE, 5) |
|
344 |
|
|
345 |
def testGetLvInfo(self): |
|
346 |
"""Tests for LogicalVolume._GetLvInfo.""" |
|
347 |
self.assertRaises(errors.BlockDeviceError, bdev.LogicalVolume._GetLvInfo, |
|
348 |
"fake_path", |
|
349 |
_run_cmd=self._FakeRunCmd(False, "Fake error msg")) |
|
350 |
self.assertRaises(errors.BlockDeviceError, bdev.LogicalVolume._GetLvInfo, |
|
351 |
"fake_path", _run_cmd=self._FakeRunCmd(True, "")) |
|
352 |
self.assertRaises(errors.BlockDeviceError, bdev.LogicalVolume._GetLvInfo, |
|
353 |
"fake_path", _run_cmd=self._FakeRunCmd(True, "BadStdOut")) |
|
354 |
good_line = " -wi-ao,253,3,4096.00,2" |
|
355 |
fake_cmd = self._FakeRunCmd(True, good_line) |
|
356 |
good_res = bdev.LogicalVolume._GetLvInfo("fake_path", _run_cmd=fake_cmd) |
|
357 |
# Only the last line should be parsed and taken into account |
|
358 |
for lines in [ |
|
359 |
[good_line] * 2, |
|
360 |
[good_line] * 3, |
|
361 |
["bad line", good_line], |
|
362 |
]: |
|
363 |
fake_cmd = self._FakeRunCmd(True, "\n".join(lines)) |
|
364 |
same_res = bdev.LogicalVolume._GetLvInfo("fake_path", fake_cmd) |
|
365 |
self.assertEqual(same_res, good_res) |
|
366 |
|
|
367 |
|
|
303 | 368 |
if __name__ == "__main__": |
304 | 369 |
testutils.GanetiTestProgram() |
Also available in: Unified diff