]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
GlusterFS: extend volume to the right path
authorEinst Crazy <yu.changcai@99cloud.net>
Thu, 24 Sep 2015 16:24:18 +0000 (00:24 +0800)
committerEinst Crazy <yu.changcai@99cloud.net>
Mon, 28 Sep 2015 15:25:07 +0000 (23:25 +0800)
Extend volume uses the wrong volume file path. It should
extend the active volume file path.

And set _active_volume_path as a common function, that
also change delete_volume() and backup_volume().

Closes-Bug: 1499452

Change-Id: I2f19a721f4d3e9b05601e820e10a6eb1328a68a9

cinder/tests/unit/test_glusterfs.py
cinder/volume/drivers/glusterfs.py

index 510a7cbbdb469f971cb785091e940a2b85b029dc..3c59148c2596cc1ad6cea46386b5d179b2cf9e81 100644 (file)
@@ -922,16 +922,52 @@ class GlusterFsDriverTestCase(test.TestCase):
 
         with mock.patch.object(drv, 'get_active_image_from_info') as \
                 mock_get_active_image_from_info,\
+                mock.patch.object(self._driver, '_local_volume_dir') as \
+                mock_local_volume_dir,\
                 mock.patch.object(image_utils, 'qemu_img_info') as \
                 mock_qemu_img_info,\
                 mock.patch.object(image_utils, 'resize_image') as \
                 mock_resize_image:
             mock_get_active_image_from_info.return_value = volume['name']
+            mock_local_volume_dir.return_value = self.TEST_MNT_POINT
             mock_qemu_img_info.return_value = img_info
 
             drv.extend_volume(volume, 3)
             self.assertTrue(mock_resize_image.called)
 
+    def test_extend_volume_with_snapshot(self):
+        drv = self._driver
+
+        volume = self._simple_volume()
+
+        snap_file = 'volume-%s.%s' % (self.VOLUME_UUID,
+                                      self.SNAP_UUID)
+
+        qemu_img_info_output = """image: %s
+        file format: qcow2
+        virtual size: 1.0G (1073741824 bytes)
+        disk size: 473K
+        """ % snap_file
+
+        img_info = imageutils.QemuImgInfo(qemu_img_info_output)
+
+        with mock.patch.object(drv, 'get_active_image_from_info') as \
+                mock_get_active_image_from_info,\
+                mock.patch.object(self._driver, '_local_volume_dir') as \
+                mock_local_volume_dir,\
+                mock.patch.object(image_utils, 'qemu_img_info') as \
+                mock_qemu_img_info,\
+                mock.patch.object(image_utils, 'resize_image') as \
+                mock_resize_image:
+            mock_get_active_image_from_info.return_value = snap_file
+            mock_local_volume_dir.return_value = self.TEST_MNT_POINT
+            mock_qemu_img_info.return_value = img_info
+
+            snap_path = '%s/%s' % (self.TEST_MNT_POINT,
+                                   snap_file)
+            drv.extend_volume(volume, 3)
+            mock_resize_image.assert_called_once_with(snap_path, 3)
+
     def test_create_snapshot_online(self):
         drv = self._driver
 
index 761ec48e67734e7652c587cf7e6a4c60bfc37403..dca3be61580a504be2454c658385ba04cf24f5af 100644 (file)
@@ -152,6 +152,12 @@ class GlusterfsDriver(remotefs_drv.RemoteFSSnapDriver, driver.CloneableVD,
                           hashed)
         return path
 
+    def _active_volume_path(self, volume):
+        volume_dir = self._local_volume_dir(volume)
+        path = os.path.join(volume_dir,
+                            self.get_active_image_from_info(volume))
+        return path
+
     def _update_volume_stats(self):
         """Retrieve stats info from volume group."""
         super(GlusterfsDriver, self)._update_volume_stats()
@@ -240,9 +246,7 @@ class GlusterfsDriver(remotefs_drv.RemoteFSSnapDriver, driver.CloneableVD,
 
         self._ensure_share_mounted(volume['provider_location'])
 
-        volume_dir = self._local_volume_dir(volume)
-        mounted_path = os.path.join(volume_dir,
-                                    self.get_active_image_from_info(volume))
+        mounted_path = self._active_volume_path(volume)
 
         self._execute('rm', '-f', mounted_path, run_as_root=True)
 
@@ -309,7 +313,7 @@ class GlusterfsDriver(remotefs_drv.RemoteFSSnapDriver, driver.CloneableVD,
 
     @remotefs_drv.locked_volume_id_operation
     def extend_volume(self, volume, size_gb):
-        volume_path = self.local_path(volume)
+        volume_path = self._active_volume_path(volume)
 
         info = self._qemu_img_info(volume_path, volume['name'])
         backing_fmt = info.file_format
@@ -446,10 +450,7 @@ class GlusterfsDriver(remotefs_drv.RemoteFSSnapDriver, driver.CloneableVD,
 
         volume = self.db.volume_get(context, backup['volume_id'])
 
-        volume_dir = self._local_volume_dir(volume)
-        active_file_path = os.path.join(
-            volume_dir,
-            self.get_active_image_from_info(volume))
+        active_file_path = self._active_volume_path(volume)
 
         info = self._qemu_img_info(active_file_path, volume['name'])