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 ee0e49a8c6d..72466a23d29 100644 --- a/cinder/tests/unit/volume/flows/test_create_volume_flow.py +++ b/cinder/tests/unit/volume/flows/test_create_volume_flow.py @@ -1267,8 +1267,9 @@ class CreateVolumeFlowManagerImageCacheTestCase(test.TestCase): image_meta, self.mock_image_service) - # Make sure check_available_space is always called - self.assertTrue(mock_check_space.called) + # Make sure check_available_space is not called because the driver + # will clone things for us. + self.assertFalse(mock_check_space.called) # Make sure clone_image is always called even if the cache is enabled self.assertTrue(self.mock_driver.clone_image.called) diff --git a/cinder/volume/flows/manager/create_volume.py b/cinder/volume/flows/manager/create_volume.py index d578d6ae660..cc0585e27c9 100644 --- a/cinder/volume/flows/manager/create_volume.py +++ b/cinder/volume/flows/manager/create_volume.py @@ -721,6 +721,27 @@ class CreateVolumeFromSpecTask(flow_utils.CinderTask): def _create_from_image_cache_or_download(self, context, volume, image_location, image_id, image_meta, image_service): + # NOTE(e0ne): check for free space in image_conversion_dir before + # image downloading. + # NOTE(mnaser): This check *only* happens if the backend is not able + # to clone volumes and we have to resort to downloading + # the image from Glance and uploading it. + if (CONF.image_conversion_dir and not + os.path.exists(CONF.image_conversion_dir)): + os.makedirs(CONF.image_conversion_dir) + try: + image_utils.check_available_space( + CONF.image_conversion_dir, + image_meta['size'], image_id) + except exception.ImageTooBig as err: + with excutils.save_and_reraise_exception(): + self.message.create( + context, + message_field.Action.COPY_IMAGE_TO_VOLUME, + resource_uuid=volume.id, + detail=message_field.Detail.NOT_ENOUGH_SPACE_FOR_IMAGE, + exception=err) + # Try and use the image cache. should_create_cache_entry = False cloned = False @@ -817,34 +838,6 @@ class CreateVolumeFromSpecTask(flow_utils.CinderTask): {'volume_id': volume.id, 'image_location': image_location, 'image_id': image_id}) - # NOTE(e0ne): check for free space in image_conversion_dir before - # image downloading. - if (CONF.image_conversion_dir and not - os.path.exists(CONF.image_conversion_dir)): - os.makedirs(CONF.image_conversion_dir) - try: - # cinder should not check free space in conversion directory - # if it's creating volume from image snapshot (Bug1683228). - # If image disk format is other than raw, cinder should - # convert it (this means free space check will be needed). - if ('cinder' in CONF.allowed_direct_url_schemes and - image_meta.get('disk_format') == 'raw'): - LOG.debug("Creating volume from image snapshot. " - "Skipping free space check on image " - "convert path.") - else: - image_utils.check_available_space( - CONF.image_conversion_dir, - image_meta['size'], image_id) - except exception.ImageTooBig as err: - with excutils.save_and_reraise_exception(): - self.message.create( - context, - message_field.Action.COPY_IMAGE_TO_VOLUME, - resource_uuid=volume.id, - detail=message_field.Detail.NOT_ENOUGH_SPACE_FOR_IMAGE, - exception=err) - virtual_size = image_meta.get('virtual_size') if virtual_size: virtual_size = image_utils.check_virtual_size(virtual_size,