From b3352993d6f28b73805d90442897255c87558db3 Mon Sep 17 00:00:00 2001 From: Einst Crazy Date: Fri, 25 Sep 2015 00:24:18 +0800 Subject: [PATCH] GlusterFS: extend volume to the right path 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 | 36 +++++++++++++++++++++++++++++ cinder/volume/drivers/glusterfs.py | 17 +++++++------- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/cinder/tests/unit/test_glusterfs.py b/cinder/tests/unit/test_glusterfs.py index 510a7cbbd..3c59148c2 100644 --- a/cinder/tests/unit/test_glusterfs.py +++ b/cinder/tests/unit/test_glusterfs.py @@ -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 diff --git a/cinder/volume/drivers/glusterfs.py b/cinder/volume/drivers/glusterfs.py index 761ec48e6..dca3be615 100644 --- a/cinder/volume/drivers/glusterfs.py +++ b/cinder/volume/drivers/glusterfs.py @@ -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']) -- 2.45.2