]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
NetApp NFS: Do not reference dst_img_local before assignment
authorAlex Meade <mr.alex.meade@gmail.com>
Thu, 17 Apr 2014 15:42:05 +0000 (11:42 -0400)
committerAlex Meade <mr.alex.meade@gmail.com>
Mon, 5 May 2014 12:54:48 +0000 (08:54 -0400)
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
cinder/volume/drivers/netapp/nfs.py

index db25043e51e7559825aa44217d074fb0c9c44662..74ec874eea4407ca9410ca4c11a56033fab1e904 100644 (file)
@@ -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()
index 2f1a90c294a041a1cae9635178b0f1f3be740a68..4b4ede27d7ac2ce9205851b483b061180009ed64 100644 (file)
@@ -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})