Move _is_mapping to more central location
The logic to identify volumes is currently a nested function in _default_block_device_names, named _is_mapping. It should be moved to a more general location so others could utilize it and allow it to be properly unit tested. The following patch moves _is_mapping to nova/virt/block_device.py and renames it to is_block_device_mapping. Change-Id: I560abc4b57ca5bd195282af7cd1ab9bbf7600b67 Closes-Bug: #1351810
This commit is contained in:
parent
0d6ce52ed6
commit
062b1f8c0f
|
@ -1693,16 +1693,12 @@ class ComputeManager(manager.Manager):
|
|||
if update_root_bdm:
|
||||
root_bdm.save()
|
||||
|
||||
def _is_mapping(bdm):
|
||||
return (bdm.source_type in ('image', 'volume', 'snapshot', 'blank')
|
||||
and bdm.destination_type == 'volume'
|
||||
and driver_block_device.is_implemented(bdm))
|
||||
|
||||
ephemerals = filter(block_device.new_format_is_ephemeral,
|
||||
block_devices)
|
||||
swap = filter(block_device.new_format_is_swap,
|
||||
block_devices)
|
||||
block_device_mapping = filter(_is_mapping, block_devices)
|
||||
block_device_mapping = filter(
|
||||
driver_block_device.is_block_device_mapping, block_devices)
|
||||
|
||||
self._default_device_names_for_instance(instance,
|
||||
root_device_name,
|
||||
|
|
|
@ -666,3 +666,19 @@ class TestDriverBlockDevice(test.NoDBTestCase):
|
|||
local_image = self.image_bdm.copy()
|
||||
local_image['destination_type'] = 'local'
|
||||
self.assertFalse(driver_block_device.is_implemented(local_image))
|
||||
|
||||
def test_is_block_device_mapping(self):
|
||||
test_swap = self.driver_classes['swap'](self.swap_bdm)
|
||||
test_ephemeral = self.driver_classes['ephemeral'](self.ephemeral_bdm)
|
||||
test_image = self.driver_classes['image'](self.image_bdm)
|
||||
test_snapshot = self.driver_classes['snapshot'](self.snapshot_bdm)
|
||||
test_volume = self.driver_classes['volume'](self.volume_bdm)
|
||||
test_blank = self.driver_classes['blank'](self.blank_bdm)
|
||||
|
||||
for bdm in (test_image, test_snapshot, test_volume, test_blank):
|
||||
self.assertTrue(driver_block_device.is_block_device_mapping(
|
||||
bdm._bdm_obj))
|
||||
|
||||
for bdm in (test_swap, test_ephemeral):
|
||||
self.assertFalse(driver_block_device.is_block_device_mapping(
|
||||
bdm._bdm_obj))
|
||||
|
|
|
@ -466,3 +466,9 @@ def is_implemented(bdm):
|
|||
except _NotTransformable:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def is_block_device_mapping(bdm):
|
||||
return (bdm.source_type in ('image', 'volume', 'snapshot', 'blank')
|
||||
and bdm.destination_type == 'volume'
|
||||
and is_implemented(bdm))
|
||||
|
|
Loading…
Reference in New Issue