Merge "ZFSSA can avoid fetching img when creating vol from cache"

This commit is contained in:
Jenkins 2017-06-02 15:08:56 +00:00 committed by Gerrit Code Review
commit 83525df9b8
2 changed files with 14 additions and 28 deletions

View File

@ -559,15 +559,11 @@ class TestZFSSAISCSIDriver(test.TestCase):
val = None
return val
@mock.patch.object(image_utils, 'qemu_img_info')
@mock.patch.object(image_utils.TemporaryImages, 'fetch')
@mock.patch.object(iscsi.ZFSSAISCSIDriver, '_verify_cache_volume')
def test_clone_image_negative(self, _verify_cache_volume, _fetch, _info):
def test_clone_image_negative(self, _verify_cache_volume):
# Disabling local cache feature:
self.configuration.zfssa_enable_local_cache = False
_fetch.return_value = mock.MagicMock(spec=utils.get_file_spec())
_info.return_value = ImgInfo(small_img['virtual_size'])
self.assertEqual((None, False),
self.drv.clone_image(fakecontext, self.test_vol,
img_location,
@ -576,7 +572,6 @@ class TestZFSSAISCSIDriver(test.TestCase):
self.configuration.zfssa_enable_local_cache = True
# Creating a volume smaller than image:
_info.return_value = ImgInfo(large_img['virtual_size'])
self.assertEqual((None, False),
self.drv.clone_image(fakecontext, self.test_vol,
img_location,
@ -586,7 +581,6 @@ class TestZFSSAISCSIDriver(test.TestCase):
# Creating a volume equal as image:
eq_img = large_img.copy()
eq_img['virtual_size'] = self.test_vol['size'] * units.Gi
_info.return_value = ImgInfo(eq_img['virtual_size'])
self.assertEqual((None, False),
self.drv.clone_image(fakecontext, self.test_vol,
img_location,
@ -594,7 +588,6 @@ class TestZFSSAISCSIDriver(test.TestCase):
img_service))
# Exception raised in _verify_cache_image
_info.return_value = ImgInfo(small_img['virtual_size'])
self.drv._verify_cache_volume.side_effect = (
exception.VolumeBackendAPIException('fakeerror'))
self.assertEqual((None, False),
@ -603,20 +596,15 @@ class TestZFSSAISCSIDriver(test.TestCase):
small_img,
img_service))
@mock.patch.object(image_utils, 'qemu_img_info')
@mock.patch.object(image_utils.TemporaryImages, 'fetch')
@mock.patch.object(iscsi.ZFSSAISCSIDriver, '_get_voltype_specs')
@mock.patch.object(iscsi.ZFSSAISCSIDriver, '_verify_cache_volume')
@mock.patch.object(iscsi.ZFSSAISCSIDriver, 'extend_volume')
def test_clone_image(self, _extend_vol, _verify_cache, _get_specs,
_fetch, _info):
def test_clone_image(self, _extend_vol, _verify_cache, _get_specs):
lcfg = self.configuration
cache_vol = 'volume-os-cache-vol-%s' % small_img['id']
cache_snap = 'image-%s' % small_img['id']
self.drv._get_voltype_specs.return_value = fakespecs.copy()
self.drv._verify_cache_volume.return_value = cache_vol, cache_snap
_fetch.return_value = mock.MagicMock(spec=utils.get_file_spec())
_info.return_value = ImgInfo(small_img['virtual_size'])
model, cloned = self.drv.clone_image(fakecontext, self.test_vol2,
img_location,

View File

@ -1,4 +1,4 @@
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@ -26,7 +26,6 @@ import six
from cinder import exception
from cinder.i18n import _
from cinder.image import image_utils
from cinder import interface
from cinder import utils
from cinder.volume import driver
@ -556,31 +555,30 @@ class ZFSSAISCSIDriver(driver.ISCSIDriver):
LOG.debug('Cloning image %(image)s to volume %(volume)s',
{'image': image_meta['id'], 'volume': volume['name']})
lcfg = self.configuration
cachevol_size = 0
if not lcfg.zfssa_enable_local_cache:
return None, False
with image_utils.TemporaryImages.fetch(image_service,
context,
image_meta['id']) as tmp_image:
info = image_utils.qemu_img_info(tmp_image)
cachevol_size = int(math.ceil(float(info.virtual_size) / units.Gi))
cachevol_size = image_meta['size']
if 'virtual_size' in image_meta and image_meta['virtual_size']:
cachevol_size = image_meta['virtual_size']
cachevol_size_gb = int(math.ceil(float(cachevol_size) / units.Gi))
# Make sure the volume is big enough since cloning adds extra metadata.
# Having it as X Gi can cause creation failures.
if info.virtual_size % units.Gi == 0:
cachevol_size += 1
if cachevol_size % units.Gi == 0:
cachevol_size_gb += 1
if cachevol_size > volume['size']:
if cachevol_size_gb > volume['size']:
exception_msg = ('Image size %(img_size)dGB is larger '
'than volume size %(vol_size)dGB.',
{'img_size': cachevol_size,
{'img_size': cachevol_size_gb,
'vol_size': volume['size']})
LOG.error(exception_msg)
return None, False
specs = self._get_voltype_specs(volume)
cachevol_props = {'size': cachevol_size}
cachevol_props = {'size': cachevol_size_gb}
try:
cache_vol, cache_snap = self._verify_cache_volume(context,
@ -596,7 +594,7 @@ class ZFSSAISCSIDriver(driver.ISCSIDriver):
cache_snap,
lcfg.zfssa_project,
volume['name'])
if cachevol_size < volume['size']:
if cachevol_size_gb < volume['size']:
self.extend_volume(volume, volume['size'])
except exception.VolumeBackendAPIException as exc:
exception_msg = ('Cannot clone image %(image)s to '