NFS driver: Fix fail to resize NFS volume with snapshots
The NFS driver may fail to update the virtual size of the Image-volume to the new size when it has snapshots created, due to image_utils incorrectly rejecting qcow2 backing files as they were not allowed. This patch explicitly tells `image_utils.qemu_img_info` to allow the use of qcow2 backing files when performing a extend operation. Closes-Bug: #2103742 Change-Id: I0582daac259dbda78481b56378562350def59598
This commit is contained in:
@@ -1151,26 +1151,30 @@ class NfsDriverTestCase(test.TestCase):
|
||||
self._set_driver()
|
||||
drv = self._driver
|
||||
path = 'fake/path'
|
||||
volume_name = 'volume1'
|
||||
size = 2
|
||||
data = mock.MagicMock()
|
||||
data.virtual_size = size * units.Gi
|
||||
|
||||
with mock.patch.object(image_utils, 'qemu_img_info',
|
||||
return_value=data):
|
||||
self.assertTrue(drv._is_file_size_equal(path, size))
|
||||
with mock.patch.object(drv, '_qemu_img_info',
|
||||
return_value=data) as mock_qemu_img_info:
|
||||
self.assertTrue(drv._is_file_size_equal(path, volume_name, size))
|
||||
mock_qemu_img_info.assert_called_once_with(path, volume_name)
|
||||
|
||||
def test_is_file_size_equal_false(self):
|
||||
"""File sizes are not equal."""
|
||||
self._set_driver()
|
||||
drv = self._driver
|
||||
path = 'fake/path'
|
||||
volume_name = 'volume1'
|
||||
size = 2
|
||||
data = mock.MagicMock()
|
||||
data.virtual_size = (size + 1) * units.Gi
|
||||
|
||||
with mock.patch.object(image_utils, 'qemu_img_info',
|
||||
return_value=data):
|
||||
self.assertFalse(drv._is_file_size_equal(path, size))
|
||||
with mock.patch.object(drv, '_qemu_img_info',
|
||||
return_value=data) as mock_qemu_img_info:
|
||||
self.assertFalse(drv._is_file_size_equal(path, volume_name, size))
|
||||
mock_qemu_img_info.assert_called_once_with(path, volume_name)
|
||||
|
||||
@mock.patch.object(nfs, 'LOG')
|
||||
def test_set_nas_security_options_when_true(self, LOG):
|
||||
|
||||
@@ -408,14 +408,13 @@ class NfsDriver(remotefs.RemoteFSSnapDriverDistributed):
|
||||
run_as_root=self._execute_as_root,
|
||||
file_format=file_format)
|
||||
if file_format == 'qcow2' and not self._is_file_size_equal(
|
||||
active_file_path, new_size):
|
||||
active_file_path, volume.name, new_size):
|
||||
raise exception.ExtendVolumeError(
|
||||
reason='Resizing image file failed.')
|
||||
|
||||
def _is_file_size_equal(self, path, size):
|
||||
def _is_file_size_equal(self, path, volume_name, size):
|
||||
"""Checks if file size at path is equal to size."""
|
||||
data = image_utils.qemu_img_info(path,
|
||||
run_as_root=self._execute_as_root)
|
||||
data = self._qemu_img_info(path, volume_name)
|
||||
virt_size = int(data.virtual_size / units.Gi)
|
||||
return virt_size == size
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
NFS driver `bug #2103742
|
||||
<https://bugs.launchpad.net/cinder/+bug/2103742>`_: Fixed issue
|
||||
preventing the volume resize operation from properly updating the NFS
|
||||
image virtual size with the new size when volume has snapshots.
|
||||
Reference in New Issue
Block a user