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

utils/ storage info lookup by disk template

This patch improves the handling of storage information
before and after a call to the RPC 'node_info'. It
adds a function to not only call for all storage
information on the cluster (as it is used right now),
but to ask only for storage information for a particular
disk template. This way, in many cases, for example
by the iallocator, less information is requested and thus
performance is increased. Unit tests are provided.
Signed-off-by: default avatarHelga Velroyen <>
Reviewed-by: default avatarKlaus Aehlig <>
parent 7f6d0b05
......@@ -148,6 +148,54 @@ def GetStorageUnitsOfCluster(cfg, include_spindles=False):
return storage_units
def GetStorageUnits(cfg, disk_templates):
"""Get the cluster's storage units for the given disk templates.
If any lvm-based disk template is requested, spindle information
is added to the request.
@type cfg: L{config.ConfigWriter}
@param cfg: Cluster configuration
@type disk_templates: list of string
@param disk_templates: list of disk templates for which the storage
units will be computed
@rtype: list of tuples (string, string)
@return: list of storage units, each storage unit being a tuple of
(storage_type, storage_key); storage_type is in
C{constants.STORAGE_TYPES} and the storage_key a string to
identify an entity of that storage type, for example a volume group
name for LVM storage or a file for file storage.
storage_units = []
for disk_template in disk_templates:
if constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[disk_template]\
in constants.STS_REPORT:
_GetDefaultStorageUnitForDiskTemplate(cfg, disk_template))
if len(set(disk_templates) & constants.DTS_LVM) > 0:
return storage_units
def LookupSpaceInfoByDiskTemplate(storage_space_info, disk_template):
"""Looks up the storage space info for a given disk template.
@type storage_space_info: list of dicts
@param storage_space_info: result of C{GetNodeInfo}
@type disk_template: string
@param disk_template: disk template to get storage space info
@rtype: tuple
@return: returns the element of storage_space_info that matches the given
disk template
storage_type = constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[disk_template]
return LookupSpaceInfoByStorageType(storage_space_info, storage_type)
def LookupSpaceInfoByStorageType(storage_space_info, storage_type):
"""Looks up the storage space info for a given storage type.
......@@ -106,6 +106,24 @@ class TestGetStorageUnitsOfCluster(unittest.TestCase):
self.assertTrue(constants.ST_LVM_PV in [st for (st, sk) in storage_units])
class TestGetStorageUnits(unittest.TestCase):
def setUp(self):
storage._GetDefaultStorageUnitForDiskTemplate = \
mock.Mock(return_value=("foo", "bar"))
self._cfg = mock.Mock()
def testGetStorageUnits(self):
disk_templates = [constants.DT_FILE, constants.DT_SHARED_FILE]
storage_units = storage.GetStorageUnits(self._cfg, disk_templates)
self.assertEqual(len(storage_units), len(disk_templates))
def testGetStorageUnitsLvm(self):
disk_templates = [constants.DT_PLAIN, constants.DT_DRBD8]
storage_units = storage.GetStorageUnits(self._cfg, disk_templates)
self.assertEqual(len(storage_units), len(disk_templates) + 1)
class TestLookupSpaceInfoByStorageType(unittest.TestCase):
def setUp(self):
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