Revision f79be8ec
b/lib/constants.py | ||
---|---|---|
394 | 394 |
ST_RADOS, |
395 | 395 |
]) |
396 | 396 |
|
397 |
# the set of storage types for which storage reporting is available |
|
398 |
# FIXME: Remove this, once storage reporting is available for all types. |
|
399 |
STS_REPORT = compat.UniqueFrozenset([ST_FILE, ST_LVM_PV, ST_LVM_VG]) |
|
400 |
|
|
397 | 401 |
# Storage fields |
398 | 402 |
# first two are valid in LU context only, not passed to backend |
399 | 403 |
SF_NODE = "node" |
b/lib/utils/storage.py | ||
---|---|---|
117 | 117 |
return (constants.ST_LVM_PV, cfg.GetVGName()) |
118 | 118 |
|
119 | 119 |
|
120 |
# List of storage type for which space reporting is implemented. |
|
121 |
# FIXME: Remove this, once the backend is capable to do this for all |
|
122 |
# storage types. |
|
123 |
_DISK_TEMPLATES_SPACE_QUERYABLE = GetLvmDiskTemplates() \ |
|
124 |
+ GetDiskTemplatesOfStorageType(constants.ST_FILE) |
|
125 |
|
|
126 |
|
|
127 | 120 |
def GetStorageUnitsOfCluster(cfg, include_spindles=False): |
128 | 121 |
"""Examines the cluster's configuration and returns a list of storage |
129 | 122 |
units and their storage keys, ordered by the order in which they |
... | ... | |
145 | 138 |
cluster_config = cfg.GetClusterInfo() |
146 | 139 |
storage_units = [] |
147 | 140 |
for disk_template in cluster_config.enabled_disk_templates: |
148 |
if disk_template in _DISK_TEMPLATES_SPACE_QUERYABLE: |
|
141 |
if constants.DISK_TEMPLATES_STORAGE_TYPE[disk_template]\ |
|
142 |
in constants.STS_REPORT: |
|
149 | 143 |
storage_units.append( |
150 | 144 |
_GetDefaultStorageUnitForDiskTemplate(cfg, disk_template)) |
151 | 145 |
if include_spindles: |
b/test/py/ganeti.backend_unittest.py | ||
---|---|---|
625 | 625 |
|
626 | 626 |
def testApplyValidStorageType(self): |
627 | 627 |
storage_type = constants.ST_LVM_VG |
628 |
info_fn_orig = backend._STORAGE_TYPE_INFO_FN |
|
628 | 629 |
backend._STORAGE_TYPE_INFO_FN = { |
629 | 630 |
storage_type: self.mock_storage_fn |
630 | 631 |
} |
... | ... | |
633 | 634 |
storage_type, self._STORAGE_KEY, self._SOME_ARGS) |
634 | 635 |
|
635 | 636 |
self.mock_storage_fn.assert_called_with(self._STORAGE_KEY, self._SOME_ARGS) |
637 |
backend._STORAGE_TYPE_INFO_FN = info_fn_orig |
|
636 | 638 |
|
637 | 639 |
def testApplyInValidStorageType(self): |
638 | 640 |
storage_type = "invalid_storage_type" |
641 |
info_fn_orig = backend._STORAGE_TYPE_INFO_FN |
|
639 | 642 |
backend._STORAGE_TYPE_INFO_FN = {} |
640 | 643 |
|
641 | 644 |
self.assertRaises(KeyError, backend._ApplyStorageInfoFunction, |
642 | 645 |
storage_type, self._STORAGE_KEY, self._SOME_ARGS) |
646 |
backend._STORAGE_TYPE_INFO_FN = info_fn_orig |
|
643 | 647 |
|
644 | 648 |
def testApplyNotImplementedStorageType(self): |
645 | 649 |
storage_type = "not_implemented_storage_type" |
650 |
info_fn_orig = backend._STORAGE_TYPE_INFO_FN |
|
646 | 651 |
backend._STORAGE_TYPE_INFO_FN = {storage_type: None} |
647 | 652 |
|
648 | 653 |
self.assertRaises(NotImplementedError, |
649 | 654 |
backend._ApplyStorageInfoFunction, |
650 | 655 |
storage_type, self._STORAGE_KEY, self._SOME_ARGS) |
656 |
backend._STORAGE_TYPE_INFO_FN = info_fn_orig |
|
651 | 657 |
|
652 | 658 |
|
653 | 659 |
class TestGetLvmVgSpaceInfo(unittest.TestCase): |
... | ... | |
784 | 790 |
backend._ApplyStorageInfoFunction = orig_fn |
785 | 791 |
|
786 | 792 |
|
793 |
class TestSpaceReportingConstants(unittest.TestCase): |
|
794 |
"""Ensures consistency between STS_REPORT and backend. |
|
795 |
|
|
796 |
These tests ensure, that the constant 'STS_REPORT' is consitent |
|
797 |
with the implementation of invoking space reporting functions |
|
798 |
in backend.py. Once space reporting is available for all types, |
|
799 |
the constant can be removed and these tests as well. |
|
800 |
|
|
801 |
""" |
|
802 |
def testAllReportingTypesHaveAReportingFunction(self): |
|
803 |
for storage_type in constants.STS_REPORT: |
|
804 |
self.assertTrue(backend._STORAGE_TYPE_INFO_FN[storage_type] is not None) |
|
805 |
|
|
806 |
def testAllNotReportingTypesDoneHaveFunction(self): |
|
807 |
non_reporting_types = set(constants.VALID_STORAGE_TYPES)\ |
|
808 |
- set(constants.STS_REPORT) |
|
809 |
for storage_type in non_reporting_types: |
|
810 |
self.assertEqual(None, backend._STORAGE_TYPE_INFO_FN[storage_type]) |
|
811 |
|
|
812 |
|
|
787 | 813 |
if __name__ == "__main__": |
788 | 814 |
testutils.GanetiTestProgram() |
Also available in: Unified diff