Revision f39a8d14
b/test/py/ganeti.backend_unittest.py | ||
---|---|---|
619 | 619 |
self._test_hv.GetNodeInfo.assert_called_with(hvparams=hvparams) |
620 | 620 |
|
621 | 621 |
|
622 |
class TestApplyStorageInfoFunction(unittest.TestCase): |
|
623 |
|
|
624 |
_STORAGE_KEY = "some_key" |
|
625 |
_SOME_ARGS = "some_args" |
|
626 |
|
|
627 |
def setUp(self): |
|
628 |
self.mock_storage_fn = mock.Mock() |
|
629 |
|
|
630 |
def testApplyValidStorageType(self): |
|
631 |
storage_type = constants.ST_LVM_VG |
|
632 |
backend._STORAGE_TYPE_INFO_FN = { |
|
633 |
storage_type: self.mock_storage_fn |
|
634 |
} |
|
635 |
|
|
636 |
backend._ApplyStorageInfoFunction( |
|
637 |
storage_type, self._STORAGE_KEY, self._SOME_ARGS) |
|
638 |
|
|
639 |
self.mock_storage_fn.assert_called_with(self._STORAGE_KEY, self._SOME_ARGS) |
|
640 |
|
|
641 |
def testApplyInValidStorageType(self): |
|
642 |
storage_type = "invalid_storage_type" |
|
643 |
backend._STORAGE_TYPE_INFO_FN = {} |
|
644 |
|
|
645 |
self.assertRaises(KeyError, backend._ApplyStorageInfoFunction, |
|
646 |
storage_type, self._STORAGE_KEY, self._SOME_ARGS) |
|
647 |
|
|
648 |
def testApplyNotImplementedStorageType(self): |
|
649 |
storage_type = "not_implemented_storage_type" |
|
650 |
backend._STORAGE_TYPE_INFO_FN = {storage_type: None} |
|
651 |
|
|
652 |
self.assertRaises(NotImplementedError, |
|
653 |
backend._ApplyStorageInfoFunction, |
|
654 |
storage_type, self._STORAGE_KEY, self._SOME_ARGS) |
|
655 |
|
|
656 |
|
|
657 |
class TestGetNodeInfo(unittest.TestCase): |
|
658 |
|
|
659 |
_SOME_RESULT = None |
|
660 |
|
|
661 |
def testApplyStorageInfoFunction(self): |
|
662 |
excl_storage_flag = False |
|
663 |
backend._ApplyStorageInfoFunction = mock.Mock( |
|
664 |
return_value=self._SOME_RESULT) |
|
665 |
storage_units = [(st, st + "_key") for st in |
|
666 |
constants.VALID_STORAGE_TYPES] |
|
667 |
|
|
668 |
backend.GetNodeInfo(storage_units, None, excl_storage_flag) |
|
669 |
|
|
670 |
call_args_list = backend._ApplyStorageInfoFunction.call_args_list |
|
671 |
self.assertEqual(len(constants.VALID_STORAGE_TYPES), len(call_args_list)) |
|
672 |
for call in call_args_list: |
|
673 |
storage_type, storage_key, excl_storage = call[0] |
|
674 |
self.assertEqual(storage_type + "_key", storage_key) |
|
675 |
self.assertTrue(storage_type in constants.VALID_STORAGE_TYPES) |
|
676 |
|
|
677 |
|
|
622 | 678 |
if __name__ == "__main__": |
623 | 679 |
testutils.GanetiTestProgram() |
Also available in: Unified diff