Browse Source

Merge "block_device: Copy original volume_type when missing for snapshot based volumes" into stable/stein

tags/19.1.0
Zuul 1 month ago
parent
commit
2fceddc451
2 changed files with 38 additions and 0 deletions
  1. +31
    -0
      nova/tests/unit/virt/test_block_device.py
  2. +7
    -0
      nova/virt/block_device.py

+ 31
- 0
nova/tests/unit/virt/test_block_device.py View File

@@ -967,6 +967,37 @@ class TestDriverBlockDevice(test.NoDBTestCase):
self.virt_driver)
self.assertEqual(test_bdm.volume_id, 'fake-volume-id-2')

def test_snapshot_attach_no_volume_and_no_volume_type(self):
bdm = self.driver_classes['volsnapshot'](self.volsnapshot_bdm)
instance = fake_instance.fake_instance_obj(self.context,
**{'uuid': uuids.uuid})
snapshot = {'volume_id': uuids.original_volume_id}
original_volume = {'id': uuids.original_volume_id,
'volume_type_id': 'original_volume_type'}
new_volume = {'id': uuids.new_volume_id}
with test.nested(
mock.patch.object(self.driver_classes['volume'], 'attach'),
mock.patch.object(self.volume_api, 'get_snapshot',
return_value=snapshot),
mock.patch.object(self.volume_api, 'get',
return_value=original_volume),
mock.patch.object(self.volume_api, 'create',
return_value=new_volume),
) as (mock_attach, mock_get_snapshot, mock_get, mock_create):
bdm.volume_id = None
bdm.volume_type = None
bdm.attach(self.context, instance, self.volume_api,
self.virt_driver)

# Assert that the original volume type is fetched, stored within
# the bdm and then used to create the new snapshot based volume.
mock_get.assert_called_once_with(self.context,
uuids.original_volume_id)
self.assertEqual('original_volume_type', bdm.volume_type)
mock_create.assert_called_once_with(self.context, bdm.volume_size,
'', '', snapshot, volume_type='original_volume_type',
availability_zone=None)

def test_image_attach_no_volume(self):
no_volume_image = self.volimage_bdm_dict.copy()
no_volume_image['volume_id'] = None

+ 7
- 0
nova/virt/block_device.py View File

@@ -721,6 +721,13 @@ class DriverVolSnapshotBlockDevice(DriverVolumeBlockDevice):
av_zone = _get_volume_create_az_value(instance)
snapshot = volume_api.get_snapshot(context,
self.snapshot_id)
# NOTE(lyarwood): Try to use the original volume type if one isn't
# set against the bdm but is on the original volume.
if not self.volume_type and snapshot.get('volume_id'):
snap_volume_id = snapshot.get('volume_id')
orig_volume = volume_api.get(context, snap_volume_id)
self.volume_type = orig_volume.get('volume_type_id')

vol = volume_api.create(context, self.volume_size, '', '',
snapshot, volume_type=self.volume_type,
availability_zone=av_zone)

Loading…
Cancel
Save