Commit a09639d1 authored by Santi Raffa's avatar Santi Raffa Committed by Hrvoje Ribicic

Remove hardcoded references to File, SharedFile templates

DTS_FILEBASED is a constant that exists and this commit makes sure
that it is used whenever sensible, rather than resorting to hardcoding
the pair of templates in very many files.
Signed-off-by: default avatarSanti Raffa <rsanti@google.com>
Reviewed-by: default avatarHrvoje Ribicic <riba@google.com>
parent 704b51ff
......@@ -2939,7 +2939,7 @@ def OSEnvironment(instance, inst_os, debug=0):
instance.hvparams[constants.HV_DISK_TYPE]
if disk.dev_type in constants.DTS_BLOCK:
result["DISK_%d_BACKEND_TYPE" % idx] = "block"
elif disk.dev_type in [constants.DT_FILE, constants.DT_SHARED_FILE]:
elif disk.dev_type in constants.DTS_FILEBASED:
result["DISK_%d_BACKEND_TYPE" % idx] = \
"file:%s" % disk.logical_id[0]
......
......@@ -341,7 +341,7 @@ class LUBackupExport(LogicalUnit):
# instance disk type verification
# TODO: Implement export support for file-based disks
for disk in self.instance.disks:
if disk.dev_type in [constants.DT_FILE, constants.DT_SHARED_FILE]:
if disk.dev_type in constants.DTS_FILEBASED:
raise errors.OpPrereqError("Export not supported for instances with"
" file-based disks", errors.ECODE_INVAL)
......
......@@ -463,8 +463,7 @@ class LUInstanceCreate(LogicalUnit):
# set default file_driver if unset and required
if (not self.op.file_driver and
self.op.disk_template in [constants.DT_FILE,
constants.DT_SHARED_FILE]):
self.op.disk_template in constants.DTS_FILEBASED):
self.op.file_driver = constants.FD_LOOP
### Node/iallocator related checks
......
......@@ -459,7 +459,7 @@ def GenerateDiskTemplate(
vg = disk.get(constants.IDISK_VG, vgname)
return (vg, names[idx])
elif template_name in (constants.DT_FILE, constants.DT_SHARED_FILE):
elif template_name in constants.DTS_FILEBASED:
logical_id_fn = \
lambda _, disk_index, disk: (file_driver,
"%s/disk%d" % (file_storage_dir,
......
......@@ -295,7 +295,7 @@ def _GetConfigFileDiskData(block_devices, blockdev_prefix,
else:
mode = "r"
if cfdev.dev_type in [constants.DT_FILE, constants.DT_SHARED_FILE]:
if cfdev.dev_type in constants.DTS_FILEBASED:
driver = _FILE_DRIVER_MAP[cfdev.logical_id[0]]
else:
driver = "phy"
......
......@@ -422,8 +422,7 @@ def RunExportImportTests(instance, inodes):
# based storage types are untested, though. Also note that import could still
# work, but is deeply embedded into the "export" case.
if (qa_config.TestEnabled("instance-export") and
instance.disk_template not in [constants.DT_FILE,
constants.DT_SHARED_FILE]):
instance.disk_template not in constants.DTS_FILEBASED):
RunTest(qa_instance.TestInstanceExportNoTarget, instance)
pnode = inodes[0]
......@@ -449,8 +448,7 @@ def RunExportImportTests(instance, inodes):
# FIXME: inter-cluster-instance-move crashes on file based instances :/
# See Issue 414.
if (qa_config.TestEnabled([qa_rapi.Enabled, "inter-cluster-instance-move"])
and (instance.disk_template not in
[constants.DT_FILE, constants.DT_SHARED_FILE])):
and (instance.disk_template not in constants.DTS_FILEBASED)):
newinst = qa_config.AcquireInstance()
try:
tnode = qa_config.AcquireNode(exclude=inodes)
......
......@@ -492,7 +492,7 @@ def TestClusterModifyFileBasedStorageDir(
"""
enabled_disk_templates = qa_config.GetEnabledDiskTemplates()
assert file_disk_template in [constants.DT_FILE, constants.DT_SHARED_FILE]
assert file_disk_template in constants.DTS_FILEBASED
if not qa_config.IsTemplateSupported(file_disk_template):
return
......
......@@ -1098,7 +1098,7 @@ class TestGenerateDiskTemplate(CmdlibTestCase):
self.assertRaises(errors.OpPrereqError, self._TestTrivialDisk,
constants.DT_SHARED_FILE, [], 0, NotImplemented)
for disk_template in [constants.DT_FILE, constants.DT_SHARED_FILE]:
for disk_template in constants.DTS_FILEBASED:
disk_info = [{
constants.IDISK_SIZE: 80 * 1024,
constants.IDISK_MODE: constants.DISK_RDONLY,
......
......@@ -399,7 +399,7 @@ class ConfigMock(config.ConfigWriter):
elif dev_type == constants.DT_PLAIN:
if logical_id is None:
logical_id = ("mockvg", "mock_disk_%d" % disk_id)
elif dev_type in (constants.DT_FILE, constants.DT_SHARED_FILE):
elif dev_type in constants.DTS_FILEBASED:
if logical_id is None:
logical_id = (constants.FD_LOOP, "/file/storage/disk%d" % disk_id)
elif dev_type == constants.DT_BLOCK:
......
......@@ -80,7 +80,7 @@ class TestGetStorageUnits(unittest.TestCase):
self._cfg = mock.Mock()
def testGetStorageUnits(self):
disk_templates = [constants.DT_FILE, constants.DT_SHARED_FILE]
disk_templates = constants.DTS_FILEBASED
storage_units = storage.GetStorageUnits(self._cfg, disk_templates)
self.assertEqual(len(storage_units), len(disk_templates))
......
......@@ -600,8 +600,7 @@ class MoveSourceExecutor(object):
logging.info("Retrieving instance information from source cluster")
instinfo = self._GetInstanceInfo(src_client, mrt.PollJob,
mrt.move.src_instance_name)
if (instinfo["disk_template"] in
[constants.DT_FILE, constants.DT_SHARED_FILE]):
if (instinfo["disk_template"] in constants.DTS_FILEBASED):
raise Error("Inter-cluster move of file-based instances is not"
" supported.")
......
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