cleanup cg field when create image cache volume
when creating volume from image and enabling image cache, cinder forgets to cleanup consistencygroup field in volume object before creating image cache volume entry, so the volume object can not be updated. Change-Id: Ib9bff05d2d5d7e8c7e0919fa9be0776d9cdc0d12 Closes-Bug: #1701998
This commit is contained in:
parent
a688b872be
commit
88290cbfef
@ -1118,13 +1118,17 @@ class CreateVolumeFlowManagerImageCacheTestCase(test.TestCase):
|
||||
self.assertIsNone(model)
|
||||
self.assertFalse(result)
|
||||
|
||||
@mock.patch('cinder.volume.flows.manager.create_volume.'
|
||||
'CreateVolumeFromSpecTask.'
|
||||
'_cleanup_cg_in_volume')
|
||||
@mock.patch('cinder.image.image_utils.check_available_space')
|
||||
@mock.patch('cinder.image.image_utils.qemu_img_info')
|
||||
@mock.patch('cinder.db.volume_update')
|
||||
def test_create_from_image_extend_failure(
|
||||
self, mock_volume_update, mock_qemu_info, mock_check_size,
|
||||
mock_get_internal_context, mock_create_from_img_dl,
|
||||
mock_create_from_src, mock_handle_bootable, mock_fetch_img):
|
||||
mock_create_from_src, mock_handle_bootable, mock_fetch_img,
|
||||
mock_cleanup_cg):
|
||||
self.mock_driver.clone_image.return_value = (None, False)
|
||||
self.mock_cache.get_entry.return_value = None
|
||||
self.mock_driver.extend_volume.side_effect = (
|
||||
@ -1159,6 +1163,7 @@ class CreateVolumeFlowManagerImageCacheTestCase(test.TestCase):
|
||||
image_meta,
|
||||
self.mock_image_service)
|
||||
|
||||
self.assertTrue(mock_cleanup_cg.called)
|
||||
mock_volume_update.assert_any_call(self.ctxt, volume.id, {'size': 1})
|
||||
self.assertEqual(volume_size, volume.size)
|
||||
|
||||
@ -1435,12 +1440,15 @@ class CreateVolumeFlowManagerImageCacheTestCase(test.TestCase):
|
||||
image_meta=image_meta
|
||||
)
|
||||
|
||||
@mock.patch('cinder.volume.flows.manager.create_volume.'
|
||||
'CreateVolumeFromSpecTask.'
|
||||
'_cleanup_cg_in_volume')
|
||||
@mock.patch('cinder.image.image_utils.check_available_space')
|
||||
@mock.patch('cinder.image.image_utils.qemu_img_info')
|
||||
def test_create_from_image_cache_miss_error_size_invalid(
|
||||
self, mock_qemu_info, mock_check_space, mock_get_internal_context,
|
||||
mock_create_from_img_dl, mock_create_from_src,
|
||||
mock_handle_bootable, mock_fetch_img):
|
||||
mock_handle_bootable, mock_fetch_img, mock_cleanup_cg):
|
||||
mock_fetch_img.return_value = mock.MagicMock()
|
||||
image_info = imageutils.QemuImgInfo()
|
||||
image_info.virtual_size = '2147483648'
|
||||
@ -1475,6 +1483,7 @@ class CreateVolumeFlowManagerImageCacheTestCase(test.TestCase):
|
||||
self.mock_image_service
|
||||
)
|
||||
|
||||
self.assertTrue(mock_cleanup_cg.called)
|
||||
# The volume size should NOT be changed when in this case
|
||||
self.assertFalse(self.mock_db.volume_update.called)
|
||||
|
||||
|
@ -750,6 +750,10 @@ class CreateVolumeFromSpecTask(flow_utils.CinderTask):
|
||||
# Don't cache encrypted volume.
|
||||
if not cloned and not volume.encryption_key_id:
|
||||
should_create_cache_entry = True
|
||||
# cleanup consistencygroup field in the volume,
|
||||
# because when creating cache entry, it will need
|
||||
# to update volume object.
|
||||
self._cleanup_cg_in_volume(volume)
|
||||
|
||||
# Fall back to default behavior of creating volume,
|
||||
# download the image data and copy it into the volume.
|
||||
|
Loading…
Reference in New Issue
Block a user