From d48c944b70160db86301a10fa37688c39449ea50 Mon Sep 17 00:00:00 2001 From: Helga Velroyen Date: Tue, 8 Oct 2013 17:12:35 +0200 Subject: [PATCH] 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: Helga Velroyen Reviewed-by: Klaus Aehlig --- lib/client/gnt_cluster.py | 4 ++-- lib/cmdlib/instance.py | 2 +- lib/utils/storage.py | 13 +++---------- qa/qa_cluster.py | 7 +++---- test/py/ganeti.constants_unittest.py | 6 ++++++ 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/client/gnt_cluster.py b/lib/client/gnt_cluster.py index af75931..c28936b 100644 --- a/lib/client/gnt_cluster.py +++ b/lib/client/gnt_cluster.py @@ -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 diff --git a/lib/cmdlib/instance.py b/lib/cmdlib/instance.py index 1141d7e..cd73b11 100644 --- a/lib/cmdlib/instance.py +++ b/lib/cmdlib/instance.py @@ -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) diff --git a/lib/utils/storage.py b/lib/utils/storage.py index a3bfe1a..95eba65 100644 --- a/lib/utils/storage.py +++ b/lib/utils/storage.py @@ -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) diff --git a/qa/qa_cluster.py b/qa/qa_cluster.py index 0f3e73a..8d20603 100644 --- a/qa/qa_cluster.py +++ b/qa/qa_cluster.py @@ -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", diff --git a/test/py/ganeti.constants_unittest.py b/test/py/ganeti.constants_unittest.py index 166b963..0db4ee3 100755 --- a/test/py/ganeti.constants_unittest.py +++ b/test/py/ganeti.constants_unittest.py @@ -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() -- 1.7.10.4