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

Use 'DTS_LVM' when possible



This patch replaces all usages of the utility function
'GetLvmDiskTemplate' by the new 'DTS_LVM' constant
to make it consistant with the usage of other DTS_*
constants.

Additionally, it provides a unit tests to ensure
consistancy between DTS_LVM and the mapping of disk
templates and storage types.
Signed-off-by: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent e8936ef7
......@@ -87,7 +87,7 @@ def _CheckNoLvmStorageOptDeprecated(opts):
" to disable lvm-based storage cluster-wide, use the option"
" --enabled-disk-templates to disable all of these lvm-base disk "
" templates: %s" %
utils.CommaJoin(utils.GetLvmDiskTemplates()))
utils.CommaJoin(constants.DTS_LVM))
return 1
......@@ -1048,7 +1048,7 @@ def _GetVgName(opts, enabled_disk_templates):
if vg_name and not utils.IsLvmEnabled(enabled_disk_templates):
ToStdout("You specified a volume group with --vg-name, but you did not"
" enable any of the following lvm-based disk templates: %s" %
utils.CommaJoin(utils.GetLvmDiskTemplates()))
utils.CommaJoin(constants.DTS_LVM))
return vg_name
......
......@@ -1090,7 +1090,7 @@ class LUInstanceCreate(LogicalUnit):
elif self.op.disk_template == constants.DT_EXT:
# FIXME: Function that checks prereqs if needed
pass
elif self.op.disk_template in utils.GetLvmDiskTemplates():
elif self.op.disk_template in constants.DTS_LVM:
# Check lv size requirements, if not adopting
req_sizes = ComputeDiskSizePerVG(self.op.disk_template, self.disks)
CheckNodesFreeDiskPerVG(self, node_uuids, req_sizes)
......
......@@ -34,11 +34,6 @@ def GetDiskTemplatesOfStorageType(storage_type):
if constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[dt] == storage_type]
def GetLvmDiskTemplates():
"""Returns all disk templates that use LVM."""
return GetDiskTemplatesOfStorageType(constants.ST_LVM_VG)
def IsDiskTemplateEnabled(disk_template, enabled_disk_templates):
"""Checks if a particular disk template is enabled.
......@@ -62,8 +57,7 @@ def IsSharedFileStorageEnabled(enabled_disk_templates):
def IsLvmEnabled(enabled_disk_templates):
"""Check whether or not any lvm-based disk templates are enabled."""
return len(set(GetLvmDiskTemplates())
.intersection(set(enabled_disk_templates))) != 0
return len(constants.DTS_LVM & set(enabled_disk_templates)) != 0
def LvmGetsEnabled(enabled_disk_templates, new_enabled_disk_templates):
......@@ -73,8 +67,7 @@ def LvmGetsEnabled(enabled_disk_templates, new_enabled_disk_templates):
"""
if IsLvmEnabled(enabled_disk_templates):
return False
return set(GetLvmDiskTemplates()).intersection(
set(new_enabled_disk_templates))
return len(constants.DTS_LVM & set(new_enabled_disk_templates)) != 0
def _GetDefaultStorageUnitForDiskTemplate(cfg, disk_template):
......@@ -92,7 +85,7 @@ def _GetDefaultStorageUnitForDiskTemplate(cfg, disk_template):
"""
storage_type = constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[disk_template]
cluster = cfg.GetClusterInfo()
if disk_template in GetLvmDiskTemplates():
if disk_template in constants.DTS_LVM:
return (storage_type, cfg.GetVGName())
elif disk_template == constants.DT_FILE:
return (storage_type, cluster.file_storage_dir)
......
......@@ -684,10 +684,9 @@ def _TestClusterModifyDiskTemplatesVgName(enabled_disk_templates):
return
# determine an LVM and a non-LVM disk template for the tests
non_lvm_template = _GetOtherEnabledDiskTemplate(utils.GetLvmDiskTemplates(),
non_lvm_template = _GetOtherEnabledDiskTemplate(constants.DTS_LVM,
enabled_disk_templates)
lvm_template = list(set(enabled_disk_templates)
.intersection(set(utils.GetLvmDiskTemplates())))[0]
lvm_template = list(set(enabled_disk_templates) & constants.DTS_LVM)[0]
vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
......@@ -783,7 +782,7 @@ def _TestClusterModifyUnusedDiskTemplate(instance_template):
all_disk_templates = constants.DISK_TEMPLATES
if not utils.IsLvmEnabled(qa_config.GetEnabledDiskTemplates()):
all_disk_templates = list(set(all_disk_templates) -
set(utils.GetLvmDiskTemplates()))
constants.DTS_LVM)
AssertCommand(
["gnt-cluster", "modify",
......
......@@ -170,6 +170,12 @@ class TestDiskTemplateConstants(unittest.TestCase):
self.assertTrue(
constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[disk_template] is not None)
def testLvmDiskTemplates(self):
lvm_by_storage_type = [
dt for dt in constants.DISK_TEMPLATES
if constants.ST_LVM_VG == constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[dt]]
self.assertEqual(set(lvm_by_storage_type), set(constants.DTS_LVM))
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