Revision b5d48e87 test/py/ganeti.storage.bdev_unittest.py
b/test/py/ganeti.storage.bdev_unittest.py | ||
---|---|---|
305 | 305 |
def testParseLvInfoLine(self): |
306 | 306 |
"""Tests for LogicalVolume._ParseLvInfoLine.""" |
307 | 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", |
|
308 |
" toomuch#-wi-ao#253#3#4096.00#2#/dev/abc(20)",
|
|
309 |
" -wi-ao#253#3#4096.00#/dev/abc(20)",
|
|
310 |
" -wi-a#253#3#4096.00#2#/dev/abc(20)",
|
|
311 |
" -wi-ao#25.3#3#4096.00#2#/dev/abc(20)",
|
|
312 |
" -wi-ao#twenty#3#4096.00#2#/dev/abc(20)",
|
|
313 |
" -wi-ao#253#3.1#4096.00#2#/dev/abc(20)",
|
|
314 |
" -wi-ao#253#three#4096.00#2#/dev/abc(20)",
|
|
315 |
" -wi-ao#253#3#four#2#/dev/abc(20)",
|
|
316 |
" -wi-ao#253#3#4096..00#2#/dev/abc(20)",
|
|
317 |
" -wi-ao#253#3#4096.00#2.0#/dev/abc(20)",
|
|
318 |
" -wi-ao#253#3#4096.00#two#/dev/abc(20)",
|
|
319 | 319 |
] |
320 | 320 |
for broken in broken_lines: |
321 | 321 |
self.assertRaises(errors.BlockDeviceError, |
322 | 322 |
bdev.LogicalVolume._ParseLvInfoLine, broken, "#") |
323 | 323 |
|
324 |
# Examples of good lines from "lvs": |
|
325 |
# -wi-ao|253|3|4096.00|2|/dev/sdb(144),/dev/sdc(0) |
|
326 |
# -wi-a-|253|4|4096.00|1|/dev/sdb(208) |
|
324 | 327 |
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), |
|
328 |
("-wi-ao", 253, 3, 4096.00, 2, ["/dev/abc"]),
|
|
329 |
("-wi-a-", 253, 7, 4096.00, 4, ["/dev/abc"]),
|
|
330 |
("-ri-a-", 253, 4, 4.00, 5, ["/dev/abc", "/dev/def"]),
|
|
331 |
("-wc-ao", 15, 18, 4096.00, 32, ["/dev/abc", "/dev/def", "/dev/ghi0"]),
|
|
329 | 332 |
] |
330 | 333 |
for exp in true_out: |
331 |
for sep in "#;|,": |
|
332 |
lvs_line = sep.join((" %s", "%d", "%d", "%.2f", "%d")) % exp |
|
334 |
for sep in "#;|": |
|
335 |
pvs = ",".join("%s(%s)" % (d, i * 12) for (i, d) in enumerate(exp[-1])) |
|
336 |
lvs_line = (sep.join((" %s", "%d", "%d", "%.2f", "%d", "%s")) % |
|
337 |
(exp[0:-1] + (pvs,))) |
|
333 | 338 |
parsed = bdev.LogicalVolume._ParseLvInfoLine(lvs_line, sep) |
334 | 339 |
self.assertEqual(parsed, exp) |
335 | 340 |
|
... | ... | |
351 | 356 |
"fake_path", _run_cmd=self._FakeRunCmd(True, "")) |
352 | 357 |
self.assertRaises(errors.BlockDeviceError, bdev.LogicalVolume._GetLvInfo, |
353 | 358 |
"fake_path", _run_cmd=self._FakeRunCmd(True, "BadStdOut")) |
354 |
good_line = " -wi-ao,253,3,4096.00,2"
|
|
359 |
good_line = " -wi-ao|253|3|4096.00|2|/dev/abc(20)"
|
|
355 | 360 |
fake_cmd = self._FakeRunCmd(True, good_line) |
356 | 361 |
good_res = bdev.LogicalVolume._GetLvInfo("fake_path", _run_cmd=fake_cmd) |
357 |
# Only the last line should be parsed and taken into account
|
|
362 |
# If the same line is repeated, the result should be the same
|
|
358 | 363 |
for lines in [ |
359 | 364 |
[good_line] * 2, |
360 | 365 |
[good_line] * 3, |
361 |
["bad line", good_line], |
|
362 | 366 |
]: |
363 | 367 |
fake_cmd = self._FakeRunCmd(True, "\n".join(lines)) |
364 | 368 |
same_res = bdev.LogicalVolume._GetLvInfo("fake_path", fake_cmd) |
365 | 369 |
self.assertEqual(same_res, good_res) |
366 | 370 |
|
371 |
# Complex multi-line examples |
|
372 |
one_line = " -wi-ao|253|3|4096.00|2|/dev/sda(20),/dev/sdb(50),/dev/sdc(0)" |
|
373 |
fake_cmd = self._FakeRunCmd(True, one_line) |
|
374 |
one_res = bdev.LogicalVolume._GetLvInfo("fake_path", _run_cmd=fake_cmd) |
|
375 |
# These should give the same results |
|
376 |
for multi_lines in [ |
|
377 |
(" -wi-ao|253|3|4096.00|2|/dev/sda(30),/dev/sdb(50)\n" |
|
378 |
" -wi-ao|253|3|4096.00|2|/dev/sdb(200),/dev/sdc(300)"), |
|
379 |
(" -wi-ao|253|3|4096.00|2|/dev/sda(0)\n" |
|
380 |
" -wi-ao|253|3|4096.00|2|/dev/sdb(20)\n" |
|
381 |
" -wi-ao|253|3|4096.00|2|/dev/sdc(30)"), |
|
382 |
(" -wi-ao|253|3|4096.00|2|/dev/sda(20)\n" |
|
383 |
" -wi-ao|253|3|4096.00|2|/dev/sdb(50),/dev/sdc(0)"), |
|
384 |
]: |
|
385 |
fake_cmd = self._FakeRunCmd(True, multi_lines) |
|
386 |
multi_res = bdev.LogicalVolume._GetLvInfo("fake_path", _run_cmd=fake_cmd) |
|
387 |
self.assertEqual(multi_res, one_res) |
|
388 |
|
|
367 | 389 |
|
368 | 390 |
if __name__ == "__main__": |
369 | 391 |
testutils.GanetiTestProgram() |
Also available in: Unified diff