From 88290cbfef93824855e8e2baa861878d8d3052af Mon Sep 17 00:00:00 2001 From: Jia Min Date: Sun, 2 Jul 2017 21:35:08 -0700 Subject: [PATCH] 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 --- .../unit/volume/flows/test_create_volume_flow.py | 13 +++++++++++-- cinder/volume/flows/manager/create_volume.py | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cinder/tests/unit/volume/flows/test_create_volume_flow.py b/cinder/tests/unit/volume/flows/test_create_volume_flow.py index 0def4f72d4a..9646e23c48d 100644 --- a/cinder/tests/unit/volume/flows/test_create_volume_flow.py +++ b/cinder/tests/unit/volume/flows/test_create_volume_flow.py @@ -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) diff --git a/cinder/volume/flows/manager/create_volume.py b/cinder/volume/flows/manager/create_volume.py index 02773c0805a..5b2b3792f79 100644 --- a/cinder/volume/flows/manager/create_volume.py +++ b/cinder/volume/flows/manager/create_volume.py @@ -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.