Merge "Add methods that convert any volume BDM to driver format"
This commit is contained in:
commit
cb287b45a9
|
@ -4622,7 +4622,7 @@ class ComputeManager(manager.Manager):
|
|||
if not bdm:
|
||||
bdm = objects.BlockDeviceMapping.get_by_volume_id(
|
||||
context, volume_id)
|
||||
driver_bdm = driver_block_device.DriverVolumeBlockDevice(bdm)
|
||||
driver_bdm = driver_block_device.convert_volume(bdm)
|
||||
|
||||
@utils.synchronized(instance.uuid)
|
||||
def do_attach_volume(context, instance, driver_bdm):
|
||||
|
|
|
@ -622,6 +622,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)
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# under the License.
|
||||
|
||||
import functools
|
||||
import itertools
|
||||
import operator
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
@ -387,6 +388,22 @@ convert_blanks = functools.partial(_convert_block_devices,
|
|||
DriverBlankBlockDevice)
|
||||
|
||||
|
||||
def convert_all_volumes(*volume_bdms):
|
||||
source_volume = convert_volumes(volume_bdms)
|
||||
source_snapshot = convert_snapshots(volume_bdms)
|
||||
source_image = convert_images(volume_bdms)
|
||||
|
||||
return [vol for vol in
|
||||
itertools.chain(source_volume, source_snapshot, source_image)]
|
||||
|
||||
|
||||
def convert_volume(volume_bdm):
|
||||
try:
|
||||
return convert_all_volumes(volume_bdm)[0]
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
|
||||
def attach_block_devices(block_device_mapping, *attach_args, **attach_kwargs):
|
||||
def _log_and_attach(bdm):
|
||||
context = attach_args[0]
|
||||
|
|
|
@ -1696,14 +1696,10 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
bdm = objects.BlockDeviceMapping.get_by_volume_id(context,
|
||||
volume_id)
|
||||
|
||||
if bdm['source_type'] == 'image':
|
||||
driver_bdm = driver_block_device.DriverImageBlockDevice(bdm)
|
||||
else:
|
||||
# source_type = 'volume'
|
||||
driver_bdm = driver_block_device.DriverVolumeBlockDevice(bdm)
|
||||
|
||||
driver_bdm.refresh_connection_info(context, instance,
|
||||
self._volume_api, self)
|
||||
driver_bdm = driver_block_device.convert_volume(bdm)
|
||||
if driver_bdm:
|
||||
driver_bdm.refresh_connection_info(context, instance,
|
||||
self._volume_api, self)
|
||||
|
||||
def volume_snapshot_create(self, context, instance, volume_id,
|
||||
create_info):
|
||||
|
|
Loading…
Reference in New Issue