From 48a53d32ee243d80b034b38e292e9bfb4b66f881 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 17 Apr 2014 11:42:05 -0400 Subject: [PATCH] NetApp NFS: Do not reference dst_img_local before assignment This patch moves the assignment of the dst_img_local variable to before the try/finally block that references it so that the finally block will have this variable no matter where in the try block an error is raised. Change-Id: Iab48b46559f18a3d6b044abe4bc3e615e7fee075 Closes-Bug: 1309047 --- cinder/tests/test_netapp_nfs.py | 27 +++++++++++++++++++++++++++ cinder/volume/drivers/netapp/nfs.py | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/cinder/tests/test_netapp_nfs.py b/cinder/tests/test_netapp_nfs.py index db25043e5..74ec874ee 100644 --- a/cinder/tests/test_netapp_nfs.py +++ b/cinder/tests/test_netapp_nfs.py @@ -891,6 +891,33 @@ class NetappDirectCmodeNfsDriverOnlyTestCase(test.TestCase): 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_nonexistent_binary_path(self): + drv = self._driver + context = object() + volume = {'id': 'vol_id', 'name': 'name'} + image_service = mock.Mock() + image_service.get_location.return_value = (mock.Mock(), mock.Mock()) + image_service.show.return_value = {'size': 0} + 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._construct_image_nfs_url = mock.Mock(return_value="") + drv._check_get_nfs_path_segs = mock.Mock(return_value=("test:test", + "dr")) + drv._get_ip_verify_on_cluster = mock.Mock(return_value="192.1268.1.1") + drv._get_mount_point_for_share = mock.Mock(return_value='mnt_point') + drv._get_host_ip = mock.Mock() + drv._get_provider_location = mock.Mock() + drv._get_export_path = mock.Mock(return_value="dr") + drv._check_share_can_hold_size = mock.Mock() + # Raise error as if the copyoffload file can not be found + drv._clone_file_dst_exists = mock.Mock(side_effect=OSError()) + + # Verify the orignal error is propagated + self.assertRaises(OSError, drv._try_copyoffload, + context, volume, image_service, image_id) + def test_copyoffload_frm_cache_success(self): drv = self._driver context = object() diff --git a/cinder/volume/drivers/netapp/nfs.py b/cinder/volume/drivers/netapp/nfs.py index 2f1a90c29..4b4ede27d 100644 --- a/cinder/volume/drivers/netapp/nfs.py +++ b/cinder/volume/drivers/netapp/nfs.py @@ -1222,6 +1222,8 @@ class NetAppDirectCmodeNfsDriver (NetAppDirectNfsDriver): dst_share = self._get_provider_location(volume['id']) self._check_share_can_hold_size(dst_share, img_info['size']) + dst_dir = self._get_mount_point_for_share(dst_share) + dst_img_local = os.path.join(dst_dir, tmp_img_file) try: # If src and dst share not equal if (('%s:%s' % (src_ip, dr)) != @@ -1233,8 +1235,6 @@ class NetAppDirectCmodeNfsDriver (NetAppDirectNfsDriver): check_exit_code=0) else: self._clone_file_dst_exists(dst_share, img_file, tmp_img_file) - dst_dir = self._get_mount_point_for_share(dst_share) - dst_img_local = os.path.join(dst_dir, tmp_img_file) self._discover_file_till_timeout(dst_img_local, timeout=120) LOG.debug(_('Copied image %(img)s to tmp file %(tmp)s.') % {'img': image_id, 'tmp': tmp_img_file}) -- 2.45.2