Revision a18ab868
b/lib/backend.py | ||
---|---|---|
646 | 646 |
def _GetLvmPvSpaceInfo(name, params): |
647 | 647 |
"""Wrapper around C{_GetVgSpindlesInfo} with sanity checks. |
648 | 648 |
|
649 |
@see C{_GetLvmVgSpaceInfo} |
|
649 |
@see: C{_GetLvmVgSpaceInfo}
|
|
650 | 650 |
|
651 | 651 |
""" |
652 | 652 |
excl_stor = _CheckLvmStorageParams(params) |
653 | 653 |
return _GetVgSpindlesInfo(name, excl_stor) |
654 | 654 |
|
655 | 655 |
|
656 |
def _GetVgSpindlesInfo(name, excl_stor): |
|
656 |
def _GetVgSpindlesInfo( |
|
657 |
name, excl_stor, info_fn=bdev.LogicalVolume.GetVgSpindlesInfo): |
|
657 | 658 |
"""Retrieves information about spindles in an LVM volume group. |
658 | 659 |
|
659 | 660 |
@type name: string |
... | ... | |
666 | 667 |
|
667 | 668 |
""" |
668 | 669 |
if excl_stor: |
669 |
(vg_free, vg_size) = bdev.LogicalVolume.GetVgSpindlesInfo(name)
|
|
670 |
(vg_free, vg_size) = info_fn(name)
|
|
670 | 671 |
else: |
671 | 672 |
vg_free = 0 |
672 | 673 |
vg_size = 0 |
b/test/py/ganeti.backend_unittest.py | ||
---|---|---|
676 | 676 |
def testValid(self): |
677 | 677 |
path = "somepath" |
678 | 678 |
excl_stor = True |
679 |
orig_fn = backend._GetVgSpindlesInfo |
|
679 | 680 |
backend._GetVgSpindlesInfo = mock.Mock() |
680 | 681 |
backend._GetLvmPvSpaceInfo(path, [excl_stor]) |
681 | 682 |
backend._GetVgSpindlesInfo.assert_called_with(path, excl_stor) |
683 |
backend._GetVgSpindlesInfo = orig_fn |
|
682 | 684 |
|
683 | 685 |
|
684 | 686 |
class TestCheckStorageParams(unittest.TestCase): |
... | ... | |
702 | 704 |
["b", False], 3) |
703 | 705 |
|
704 | 706 |
|
707 |
class TestGetVgSpindlesInfo(unittest.TestCase): |
|
708 |
|
|
709 |
def setUp(self): |
|
710 |
self.vg_free = 13 |
|
711 |
self.vg_size = 31 |
|
712 |
self.mock_fn = mock.Mock(return_value=(self.vg_free, self.vg_size)) |
|
713 |
|
|
714 |
def testValidInput(self): |
|
715 |
name = "myvg" |
|
716 |
excl_stor = True |
|
717 |
result = backend._GetVgSpindlesInfo(name, excl_stor, info_fn=self.mock_fn) |
|
718 |
self.mock_fn.assert_called_with(name) |
|
719 |
self.assertEqual(name, result["name"]) |
|
720 |
self.assertEqual(constants.ST_LVM_PV, result["type"]) |
|
721 |
self.assertEqual(self.vg_free, result["storage_free"]) |
|
722 |
self.assertEqual(self.vg_size, result["storage_size"]) |
|
723 |
|
|
724 |
def testNoExclStor(self): |
|
725 |
name = "myvg" |
|
726 |
excl_stor = False |
|
727 |
result = backend._GetVgSpindlesInfo(name, excl_stor, info_fn=self.mock_fn) |
|
728 |
self.mock_fn.assert_not_called() |
|
729 |
self.assertEqual(name, result["name"]) |
|
730 |
self.assertEqual(constants.ST_LVM_PV, result["type"]) |
|
731 |
self.assertEqual(0, result["storage_free"]) |
|
732 |
self.assertEqual(0, result["storage_size"]) |
|
733 |
|
|
734 |
|
|
705 | 735 |
class TestGetNodeInfo(unittest.TestCase): |
706 | 736 |
|
707 | 737 |
_SOME_RESULT = None |
Also available in: Unified diff