Commit 73d6b4a7 authored by Helga Velroyen's avatar Helga Velroyen
Browse files

Auto-upgrade of disks' config wrt LD-renaming

This patch adds auto-upgrade functionality to the disk
objects with respected to the switch from LD constants
to DT constants. Unit tests are provided.
Signed-off-by: default avatarHelga Velroyen <>
Reviewed-by: default avatarGuido Trotter <>
parent 880ab678
......@@ -830,6 +830,12 @@ class Disk(ConfigObject):
self.params = {}
# add here config upgrade for this disk
# map of legacy device types (mapping differing LD constants to new
# DT constants)
LEG_DEV_TYPE_MAP = {"lvm": constants.DT_PLAIN, "drbd8": constants.DT_DRBD8}
if self.dev_type in LEG_DEV_TYPE_MAP:
self.dev_type = LEG_DEV_TYPE_MAP[self.dev_type]
def ComputeLDParams(disk_template, disk_params):
"""Computes Logical Disk parameters from Disk Template parameters.
......@@ -685,5 +685,36 @@ class TestInstancePolicy(unittest.TestCase):
self.assertTrue(INVALID_KEY in policy)
class TestDisk(unittest.TestCase):
def addChild(self, disk):
"""Adds a child of the same device type as the parent."""
disk.children = []
child = objects.Disk()
child.dev_type = disk.dev_type
def testUpgradeConfigDevTypeLegacy(self):
for old, new in [("drbd8", constants.DT_DRBD8),
("lvm", constants.DT_PLAIN)]:
disk = objects.Disk()
disk.dev_type = old
self.assertEqual(new, disk.dev_type)
self.assertEqual(new, disk.children[0].dev_type)
def testUpgradeConfigDevTypeLegacyUnchanged(self):
dev_types = [constants.DT_FILE, constants.DT_SHARED_FILE,
constants.DT_BLOCK, constants.DT_EXT,
for dev_type in dev_types:
disk = objects.Disk()
disk.dev_type = dev_type
self.assertEqual(dev_type, disk.dev_type)
self.assertEqual(dev_type, disk.children[0].dev_type)
if __name__ == "__main__":
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