Add methods that convert any volume BDM to driver format

There are places in the code where we need to get the DriverBlockDevice
instance based on the BDM object for a volume block device, however the
DriverBlockDevice class the object maps to (based on source of
the data) can be any of the following: volume, snapshot or image, all of
which are actually separate classes that extend VolumeDriverBlockDevice.

This patch adds a method to transform a volume BDM object to the correct
class instance, so that we can more easily avoid bugs such as 1411847.

Related-Bug: #1411847

Change-Id: I3496bab7aac448722240483b86c013e5f80d0cb5
This commit is contained in:
Nikola Dipanov
2015-01-26 16:50:45 +01:00
committed by Michael Still
parent 7287314278
commit 42ea00eece
4 changed files with 38 additions and 9 deletions

View File

@@ -627,6 +627,22 @@ class TestDriverBlockDevice(test.NoDBTestCase):
[self.volume_bdm, self.ephemeral_bdm])
self.assertEqual(converted, [self.volume_driver_bdm])
def test_convert_all_volumes(self):
converted = driver_block_device.convert_all_volumes()
self.assertEqual([], converted)
converted = driver_block_device.convert_all_volumes(
self.volume_bdm, self.ephemeral_bdm, self.image_bdm)
self.assertEqual(converted, [self.volume_driver_bdm,
self.image_driver_bdm])
def test_convert_volume(self):
self.assertIsNone(driver_block_device.convert_volume(self.swap_bdm))
self.assertEqual(self.volume_driver_bdm,
driver_block_device.convert_volume(self.volume_bdm))
self.assertEqual(self.snapshot_driver_bdm,
driver_block_device.convert_volume(self.snapshot_bdm))
def test_legacy_block_devices(self):
test_snapshot = self.driver_classes['snapshot'](
self.snapshot_bdm)