Skip to content

Commit

Permalink
Merge "fup: Remove unused legacy block_device_info format"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Aug 25, 2021
2 parents 1624b5f + b11e3f1 commit fded762
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 234 deletions.
27 changes: 15 additions & 12 deletions doc/source/reference/block-device-structs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ or volumes, and some associated data.
``block_device_info``
---------------------

.. versionchanged:: 24.0.0 (Xena)

The legacy block_device_info format is no longer supported.

Drivers do not directly use BDM objects. Instead, they are transformed into a
different driver-specific representation. This representation is normally
called ``block_device_info``, and is generated by
Expand All @@ -74,24 +78,23 @@ called ``block_device_info``, and is generated by
``swap``
A swap disk, or None if there is no swap disk

The disks are represented in one of two ways, depending on the specific
driver currently in use. There's the 'new' representation, used by the libvirt
and vmwareAPI drivers, and the 'legacy' representation used by all other
drivers. The legacy representation is a plain dict. It does not contain the
same information as the new representation.
.. note::

The disks were previously represented in one of two ways, depending on the
specific driver in use. A legacy plain dict format or the currently used
DriverBlockDevice format discussed below. Support for the legacy format
was removed in Xena.

The new representation involves subclasses of
``nova.block_device.DriverBlockDevice``. As well as containing different
fields, the new representation significantly also retains a reference to the
underlying BDM object. This means that by manipulating the
``DriverBlockDevice`` object, the driver is able to persist data to the BDM
object in the DB.
Disks are represented by subclasses of ``nova.block_device.DriverBlockDevice``.
These subclasses retain a reference to the underlying BDM object. This means
that by manipulating the ``DriverBlockDevice`` object, the driver is able to
persist data to the BDM object in the DB.

.. note::

Common usage is to pull ``block_device_mapping`` out of this
dict into a variable called ``block_device_mapping``. This is not a
``BlockDeviceMapping`` object, or list of them.
``BlockDeviceMapping`` object, or a list of them.

.. note::

Expand Down
24 changes: 0 additions & 24 deletions nova/block_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,30 +311,6 @@ def snapshot_from_bdm(snapshot_id, template):
return BlockDeviceDict(snapshot_dict)


def legacy_mapping(block_device_mapping):
"""Transform a list of block devices of an instance back to the
legacy data format.
"""

legacy_block_device_mapping = []

for bdm in block_device_mapping:
try:
legacy_block_device = BlockDeviceDict(bdm).legacy()
except exception.InvalidBDMForLegacy:
continue

legacy_block_device_mapping.append(legacy_block_device)

# Re-enumerate the ephemeral devices
for i, dev in enumerate(dev for dev in legacy_block_device_mapping
if dev['virtual_name'] and
is_ephemeral(dev['virtual_name'])):
dev['virtual_name'] = dev['virtual_name'][:-1] + str(i)

return legacy_block_device_mapping


def from_legacy_mapping(legacy_block_device_mapping, image_uuid='',
root_device_name=None, no_root=False):
"""Transform a legacy list of block devices to the new data format."""
Expand Down
22 changes: 0 additions & 22 deletions nova/compute/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,6 @@ def __init__(self, compute_driver=None, *args, **kwargs):
# compute manager via the virtapi, so we want it to be fully
# initialized before that happens.
self.driver = driver.load_compute_driver(self.virtapi, compute_driver)
self.use_legacy_block_device_info = \
self.driver.need_legacy_block_device_info
self.rt = resource_tracker.ResourceTracker(
self.host, self.driver, reportclient=self.reportclient)

Expand Down Expand Up @@ -1945,23 +1943,6 @@ def _default_block_device_names(self, instance, image_meta, block_devices):
swap,
block_device_mapping)

def _block_device_info_to_legacy(self, block_device_info):
"""Convert BDI to the old format for drivers that need it."""

if self.use_legacy_block_device_info:
ephemerals = driver_block_device.legacy_block_devices(
driver.block_device_info_get_ephemerals(block_device_info))
mapping = driver_block_device.legacy_block_devices(
driver.block_device_info_get_mapping(block_device_info))
swap = block_device_info['swap']
if swap:
swap = swap.legacy()

block_device_info.update({
'ephemerals': ephemerals,
'swap': swap,
'block_device_mapping': mapping})

def _add_missing_dev_names(self, bdms, instance):
for bdm in bdms:
if bdm.device_name is not None:
Expand All @@ -1983,7 +1964,6 @@ def _prep_block_device(self, context, instance, bdms):
mapping, context, instance, self.volume_api, self.driver,
wait_func=self._await_block_device_map_created)

self._block_device_info_to_legacy(block_device_info)
return block_device_info

except exception.OverQuota as e:
Expand Down Expand Up @@ -2099,8 +2079,6 @@ def _get_instance_block_device_info(self, context, instance,
driver.block_device_info_get_mapping(block_device_info),
context, instance, self.volume_api, self.driver)

self._block_device_info_to_legacy(block_device_info)

return block_device_info

def _build_failed(self, node):
Expand Down
1 change: 0 additions & 1 deletion nova/tests/unit/compute/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,6 @@ def fake_attach_block_devices(bdm, *args, **kwargs):
}

manager = compute_manager.ComputeManager()
manager.use_legacy_block_device_info = False
mock_bdm_saves = [mock.patch.object(bdm, 'save') for bdm in bdms]
with test.nested(*mock_bdm_saves):
block_device_info = manager._prep_block_device(self.context,
Expand Down
39 changes: 0 additions & 39 deletions nova/tests/unit/test_block_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,45 +656,6 @@ def test_from_api_invalid_specify_volume_type_with_source_volume_mapping(
self.assertIn('Specifying volume type to existing volume is '
'not supported', str(ex))

def test_legacy(self):
for legacy, new in zip(self.legacy_mapping, self.new_mapping):
self.assertThat(
legacy,
matchers.IsSubDictOf(new.legacy()))

def test_legacy_mapping(self):
got_legacy = block_device.legacy_mapping(self.new_mapping)

for legacy, expected in zip(got_legacy, self.legacy_mapping):
self.assertThat(expected, matchers.IsSubDictOf(legacy))

def test_legacy_source_image(self):
for legacy, new in zip(self.legacy_mapping_source_image,
self.new_mapping_source_image):
if new['destination_type'] == 'volume':
self.assertThat(legacy, matchers.IsSubDictOf(new.legacy()))
else:
self.assertRaises(exception.InvalidBDMForLegacy, new.legacy)

def test_legacy_mapping_source_image(self):
got_legacy = block_device.legacy_mapping(self.new_mapping)

for legacy, expected in zip(got_legacy, self.legacy_mapping):
self.assertThat(expected, matchers.IsSubDictOf(legacy))

def test_legacy_mapping_from_object_list(self):
bdm1 = objects.BlockDeviceMapping()
bdm1 = objects.BlockDeviceMapping._from_db_object(
None, bdm1, fake_block_device.FakeDbBlockDeviceDict(
self.new_mapping[0]))
bdm2 = objects.BlockDeviceMapping()
bdm2 = objects.BlockDeviceMapping._from_db_object(
None, bdm2, fake_block_device.FakeDbBlockDeviceDict(
self.new_mapping[1]))
bdmlist = objects.BlockDeviceMappingList()
bdmlist.objects = [bdm1, bdm2]
block_device.legacy_mapping(bdmlist)

def test_image_mapping(self):
removed_fields = ['id', 'instance_uuid', 'connection_info',
'created_at', 'updated_at', 'deleted_at', 'deleted']
Expand Down
4 changes: 0 additions & 4 deletions nova/tests/unit/virt/libvirt/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,10 +943,6 @@ def test_public_api_signatures(self):
inst = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
self.assertPublicAPISignatures(baseinst, inst)

def test_legacy_block_device_info(self):
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
self.assertFalse(drvr.need_legacy_block_device_info)

@mock.patch.object(libvirt_driver.LibvirtDriver, '_get_cpu_traits')
@mock.patch.object(libvirt_driver.LibvirtDriver, '_get_storage_bus_traits')
@mock.patch.object(libvirt_driver.LibvirtDriver, '_get_video_model_traits')
Expand Down
59 changes: 0 additions & 59 deletions nova/tests/unit/virt/test_block_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ class TestDriverBlockDevice(test.NoDBTestCase):
'swap_size': 2,
'disk_bus': 'scsi'}

swap_legacy_driver_bdm = {
'device_name': '/dev/sdb1',
'swap_size': 2}

ephemeral_bdm_dict = block_device.BlockDeviceDict(
{'id': 2, 'instance_uuid': uuids.instance,
'device_name': '/dev/sdc1',
Expand All @@ -87,12 +83,6 @@ class TestDriverBlockDevice(test.NoDBTestCase):
'guest_format': 'ext4',
'disk_bus': 'scsi'}

ephemeral_legacy_driver_bdm = {
'device_name': '/dev/sdc1',
'size': 4,
'virtual_name': 'ephemeral0',
'num': 0}

volume_bdm_dict = block_device.BlockDeviceDict(
{'id': 3, 'instance_uuid': uuids.instance,
'device_name': '/dev/sda1',
Expand All @@ -117,11 +107,6 @@ class TestDriverBlockDevice(test.NoDBTestCase):
'boot_index': 0,
'volume_type': None}

volume_legacy_driver_bdm = {
'mount_device': '/dev/sda1',
'connection_info': {"fake": "connection_info"},
'delete_on_termination': False}

volume_bdm_dict_without_conn_info = block_device.BlockDeviceDict(
{'id': 3, 'instance_uuid': uuids.instance,
'device_name': '/dev/sda1',
Expand Down Expand Up @@ -172,11 +157,6 @@ class TestDriverBlockDevice(test.NoDBTestCase):
'boot_index': -1,
'volume_type': None}

volsnapshot_legacy_driver_bdm = {
'mount_device': '/dev/sda2',
'connection_info': {"fake": "connection_info"},
'delete_on_termination': True}

volimage_bdm_dict = block_device.BlockDeviceDict(
{'id': 5, 'instance_uuid': uuids.instance,
'device_name': '/dev/sda2',
Expand All @@ -202,11 +182,6 @@ class TestDriverBlockDevice(test.NoDBTestCase):
'boot_index': -1,
'volume_type': None}

volimage_legacy_driver_bdm = {
'mount_device': '/dev/sda2',
'connection_info': {"fake": "connection_info"},
'delete_on_termination': True}

volblank_bdm_dict = block_device.BlockDeviceDict(
{'id': 6, 'instance_uuid': uuids.instance,
'device_name': '/dev/sda2',
Expand All @@ -231,11 +206,6 @@ class TestDriverBlockDevice(test.NoDBTestCase):
'boot_index': -1,
'volume_type': None}

volblank_legacy_driver_bdm = {
'mount_device': '/dev/sda2',
'connection_info': {"fake": "connection_info"},
'delete_on_termination': True}

def setUp(self):
super(TestDriverBlockDevice, self).setUp()
self.volume_api = mock.MagicMock(autospec=cinder.API)
Expand Down Expand Up @@ -339,9 +309,6 @@ def _test_driver_device(self, name):
# Reset the value
test_bdm[field] = value

expected = getattr(self, "%s_legacy_driver_bdm" % name)
self.assertThat(expected, matchers.DictMatches(test_bdm.legacy()))

# Test passthru attributes
for passthru in test_bdm._proxy_as_attr:
self.assertEqual(getattr(test_bdm, passthru),
Expand Down Expand Up @@ -1289,37 +1256,11 @@ def test_convert_volume_without_connection_info(self):
driver_block_device.convert_volume(
self.volume_bdm_without_conn_info))

def test_legacy_block_devices(self):
test_snapshot = self.driver_classes['volsnapshot'](
self.volsnapshot_bdm)

block_device_mapping = [test_snapshot, test_snapshot]
legacy_bdm = driver_block_device.legacy_block_devices(
block_device_mapping)
self.assertEqual(legacy_bdm, [self.volsnapshot_legacy_driver_bdm,
self.volsnapshot_legacy_driver_bdm])

# Test that the ephemerals work as expected
test_ephemerals = [self.driver_classes['ephemeral'](
self.ephemeral_bdm) for _ in range(2)]
expected = [self.ephemeral_legacy_driver_bdm.copy()
for _ in range(2)]
expected[0]['virtual_name'] = 'ephemeral0'
expected[0]['num'] = 0
expected[1]['virtual_name'] = 'ephemeral1'
expected[1]['num'] = 1
legacy_ephemerals = driver_block_device.legacy_block_devices(
test_ephemerals)
self.assertEqual(expected, legacy_ephemerals)

def test_get_swap(self):
swap = [self.swap_driver_bdm]
legacy_swap = [self.swap_legacy_driver_bdm]
no_swap = [self.volume_driver_bdm]

self.assertEqual(swap[0], driver_block_device.get_swap(swap))
self.assertEqual(legacy_swap[0],
driver_block_device.get_swap(legacy_swap))
self.assertIsNone(driver_block_device.get_swap(no_swap))
self.assertIsNone(driver_block_device.get_swap([]))

Expand Down
3 changes: 0 additions & 3 deletions nova/tests/unit/virt/vmwareapi/test_driver_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ def tearDown(self):
super(VMwareAPIVMTestCase, self).tearDown()
vmwareapi_fake.cleanup()

def test_legacy_block_device_info(self):
self.assertFalse(self.conn.need_legacy_block_device_info)

def test_get_host_ip_addr(self):
self.assertEqual(HOST, self.conn.get_host_ip_addr())

Expand Down
Loading

0 comments on commit fded762

Please sign in to comment.