Commit f79be8ec authored by Helga Velroyen's avatar Helga Velroyen
Browse files

Move space reporting constant to constants.py



This patch moves the constant which is used to determine
whether a storage type provides storage space reporting
from the utils package to the constants. This way, we
can also use it in haskell and it fits there semantically
better anyway.

Additionally, I added unit tests that make sure that the
constant is in sync with the actual implementation in the
backend. This will make sure that when new storage types
provide space reporting, those functions are actually used
in the backend.
Signed-off-by: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 8660ba15
......@@ -394,6 +394,10 @@ VALID_STORAGE_TYPES = compat.UniqueFrozenset([
ST_RADOS,
])
# the set of storage types for which storage reporting is available
# FIXME: Remove this, once storage reporting is available for all types.
STS_REPORT = compat.UniqueFrozenset([ST_FILE, ST_LVM_PV, ST_LVM_VG])
# Storage fields
# first two are valid in LU context only, not passed to backend
SF_NODE = "node"
......
......@@ -117,13 +117,6 @@ def _GetDefaultStorageUnitForSpindles(cfg):
return (constants.ST_LVM_PV, cfg.GetVGName())
# List of storage type for which space reporting is implemented.
# FIXME: Remove this, once the backend is capable to do this for all
# storage types.
_DISK_TEMPLATES_SPACE_QUERYABLE = GetLvmDiskTemplates() \
+ GetDiskTemplatesOfStorageType(constants.ST_FILE)
def GetStorageUnitsOfCluster(cfg, include_spindles=False):
"""Examines the cluster's configuration and returns a list of storage
units and their storage keys, ordered by the order in which they
......@@ -145,7 +138,8 @@ def GetStorageUnitsOfCluster(cfg, include_spindles=False):
cluster_config = cfg.GetClusterInfo()
storage_units = []
for disk_template in cluster_config.enabled_disk_templates:
if disk_template in _DISK_TEMPLATES_SPACE_QUERYABLE:
if constants.DISK_TEMPLATES_STORAGE_TYPE[disk_template]\
in constants.STS_REPORT:
storage_units.append(
_GetDefaultStorageUnitForDiskTemplate(cfg, disk_template))
if include_spindles:
......
......@@ -625,6 +625,7 @@ class TestApplyStorageInfoFunction(unittest.TestCase):
def testApplyValidStorageType(self):
storage_type = constants.ST_LVM_VG
info_fn_orig = backend._STORAGE_TYPE_INFO_FN
backend._STORAGE_TYPE_INFO_FN = {
storage_type: self.mock_storage_fn
}
......@@ -633,21 +634,26 @@ class TestApplyStorageInfoFunction(unittest.TestCase):
storage_type, self._STORAGE_KEY, self._SOME_ARGS)
self.mock_storage_fn.assert_called_with(self._STORAGE_KEY, self._SOME_ARGS)
backend._STORAGE_TYPE_INFO_FN = info_fn_orig
def testApplyInValidStorageType(self):
storage_type = "invalid_storage_type"
info_fn_orig = backend._STORAGE_TYPE_INFO_FN
backend._STORAGE_TYPE_INFO_FN = {}
self.assertRaises(KeyError, backend._ApplyStorageInfoFunction,
storage_type, self._STORAGE_KEY, self._SOME_ARGS)
backend._STORAGE_TYPE_INFO_FN = info_fn_orig
def testApplyNotImplementedStorageType(self):
storage_type = "not_implemented_storage_type"
info_fn_orig = backend._STORAGE_TYPE_INFO_FN
backend._STORAGE_TYPE_INFO_FN = {storage_type: None}
self.assertRaises(NotImplementedError,
backend._ApplyStorageInfoFunction,
storage_type, self._STORAGE_KEY, self._SOME_ARGS)
backend._STORAGE_TYPE_INFO_FN = info_fn_orig
class TestGetLvmVgSpaceInfo(unittest.TestCase):
......@@ -784,5 +790,25 @@ class TestGetNodeInfo(unittest.TestCase):
backend._ApplyStorageInfoFunction = orig_fn
class TestSpaceReportingConstants(unittest.TestCase):
"""Ensures consistency between STS_REPORT and backend.
These tests ensure, that the constant 'STS_REPORT' is consitent
with the implementation of invoking space reporting functions
in backend.py. Once space reporting is available for all types,
the constant can be removed and these tests as well.
"""
def testAllReportingTypesHaveAReportingFunction(self):
for storage_type in constants.STS_REPORT:
self.assertTrue(backend._STORAGE_TYPE_INFO_FN[storage_type] is not None)
def testAllNotReportingTypesDoneHaveFunction(self):
non_reporting_types = set(constants.VALID_STORAGE_TYPES)\
- set(constants.STS_REPORT)
for storage_type in non_reporting_types:
self.assertEqual(None, backend._STORAGE_TYPE_INFO_FN[storage_type])
if __name__ == "__main__":
testutils.GanetiTestProgram()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment