from cinder.volume.drivers.netapp.dataontap import ssc_cmode
from cinder.volume.drivers.netapp import utils
-
from oslo_config import cfg
-CONF = cfg.CONF
+CONF = cfg.CONF
+
CONNECTION_INFO = {
'hostname': 'fake_host',
'transport_type': 'https',
mox = self.mox
drv._mounted_shares = ['testshare']
mox.StubOutWithMock(drv, '_get_mount_point_for_share')
- mox.StubOutWithMock(os.path, 'exists')
+ mox.StubOutWithMock(os.path, 'isfile')
drv._get_mount_point_for_share('testshare').AndReturn('/mnt')
- os.path.exists('/mnt/img-cache-id').AndReturn(True)
+ os.path.isfile('/mnt/img-cache-id').AndReturn(True)
mox.ReplayAll()
result = drv._find_image_in_cache('id')
(share, file_name) = result[0]
image_service = object()
image_id = 'image_id'
drv.zapi_client.get_ontapi_version = mock.Mock(return_value=(1, 20))
- drv._try_copyoffload = mock.Mock()
+ drv._copy_from_img_service = mock.Mock()
drv._get_provider_location = mock.Mock(return_value='share')
drv._get_vol_for_share = mock.Mock(return_value='vol')
drv._update_stale_vols = mock.Mock()
drv.copy_image_to_volume(context, volume, image_service, image_id)
- drv._try_copyoffload.assert_called_once_with(context, volume,
- image_service,
- image_id)
+ drv._copy_from_img_service.assert_called_once_with(context, volume,
+ image_service,
+ image_id)
drv._update_stale_vols.assert_called_once_with('vol')
def test_copy_img_to_vol_copyoffload_failure(self):
image_service = object()
image_id = 'image_id'
drv.zapi_client.get_ontapi_version = mock.Mock(return_value=(1, 20))
- drv._try_copyoffload = mock.Mock(side_effect=Exception())
+ drv._copy_from_img_service = mock.Mock(side_effect=Exception())
nfs_base.NetAppNfsDriver.copy_image_to_volume = mock.Mock()
drv._get_provider_location = mock.Mock(return_value='share')
drv._get_vol_for_share = mock.Mock(return_value='vol')
drv._update_stale_vols = mock.Mock()
drv.copy_image_to_volume(context, volume, image_service, image_id)
- drv._try_copyoffload.assert_called_once_with(context, volume,
- image_service,
- image_id)
- nfs_base.NetAppNfsDriver.copy_image_to_volume.\
+ drv._copy_from_img_service.assert_called_once_with(context, volume,
+ image_service,
+ image_id)
+ nfs_base.NetAppNfsDriver.copy_image_to_volume. \
assert_called_once_with(context, volume, image_service, image_id)
drv._update_stale_vols.assert_called_once_with('vol')
drv._clone_file_dst_exists = mock.Mock(side_effect=OSError())
# Verify the original error is propagated
- self.assertRaises(OSError, drv._try_copyoffload,
+ self.assertRaises(OSError, drv._copy_from_img_service,
context, volume, image_service, image_id)
def test_copyoffload_frm_cache_success(self):
volume = {'id': 'vol_id', 'name': 'name'}
image_service = object()
image_id = 'image_id'
+ drv.zapi_client.get_ontapi_version = mock.Mock(return_value=(1, 20))
+ nfs_base.NetAppNfsDriver.copy_image_to_volume = mock.Mock()
+ drv._get_provider_location = mock.Mock(return_value='share')
+ drv._get_vol_for_share = mock.Mock(return_value='vol')
+ drv._update_stale_vols = mock.Mock()
drv._find_image_in_cache = mock.Mock(return_value=[('share', 'img')])
drv._copy_from_cache = mock.Mock(return_value=True)
- drv._try_copyoffload(context, volume, image_service, image_id)
+ drv.copy_image_to_volume(context, volume, image_service, image_id)
drv._copy_from_cache.assert_called_once_with(volume,
image_id,
[('share', 'img')])
image_service = object()
image_id = 'image_id'
drv._client = mock.Mock()
- drv._client.get_api_version = mock.Mock(return_value=(1, 20))
- drv._find_image_in_cache = mock.Mock(return_value=[])
+ drv.zapi_client.get_ontapi_version = mock.Mock(return_value=(1, 20))
+ nfs_base.NetAppNfsDriver.copy_image_to_volume = mock.Mock()
+ drv._get_provider_location = mock.Mock(return_value='share')
+ drv._get_vol_for_share = mock.Mock(return_value='vol')
+ drv._update_stale_vols = mock.Mock()
+ drv._find_image_in_cache = mock.Mock(return_value=False)
drv._copy_from_img_service = mock.Mock()
- drv._try_copyoffload(context, volume, image_service, image_id)
+ drv.copy_image_to_volume(context, volume, image_service, image_id)
drv._copy_from_img_service.assert_called_once_with(context,
volume,
image_service,
try:
major, minor = self.zapi_client.get_ontapi_version()
col_path = self.configuration.netapp_copyoffload_tool_path
- if major == 1 and minor >= 20 and col_path:
- self._try_copyoffload(context, volume, image_service, image_id)
- copy_success = True
- LOG.info(_LI('Copied image %(img)s to volume %(vol)s using '
- 'copy offload workflow.'),
+ # Search the local image cache before attempting copy offload
+ cache_result = self._find_image_in_cache(image_id)
+ if cache_result:
+ copy_success = self._copy_from_cache(volume, image_id,
+ cache_result)
+ if copy_success:
+ LOG.info(_LI('Copied image %(img)s to volume %(vol)s '
+ 'using local image cache.'),
+ {'img': image_id, 'vol': volume['id']})
+ # Image cache was not present, attempt copy offload workflow
+ if not copy_success and col_path and major == 1 and minor >= 20:
+ LOG.debug('No result found in image cache')
+ self._copy_from_img_service(context, volume, image_service,
+ image_id)
+ LOG.info(_LI('Copied image %(img)s to volume %(vol)s using'
+ ' copy offload workflow.'),
{'img': image_id, 'vol': volume['id']})
- else:
- LOG.debug("Copy offload either not configured or"
- " unsupported.")
+ copy_success = True
except Exception as e:
LOG.exception(_LE('Copy offload workflow unsuccessful. %s'), e)
finally:
sh = self._get_provider_location(volume['id'])
self._update_stale_vols(self._get_vol_for_share(sh))
- def _try_copyoffload(self, context, volume, image_service, image_id):
- """Tries server side file copy offload."""
- copied = False
- cache_result = self._find_image_in_cache(image_id)
- if cache_result:
- copied = self._copy_from_cache(volume, image_id, cache_result)
- if not cache_result or not copied:
- self._copy_from_img_service(context, volume, image_service,
- image_id)
-
def _get_ip_verify_on_cluster(self, host):
"""Verifies if host on same cluster and returns ip."""
ip = na_utils.resolve_hostname(host)