Merge "Disallow extension of attached volumes for NFS & Quobyte drivers"

This commit is contained in:
Zuul 2020-10-07 05:50:40 +00:00 committed by Gerrit Code Review
commit bb72a8c259
6 changed files with 59 additions and 8 deletions

View File

@ -1063,6 +1063,28 @@ class NfsDriverTestCase(test.TestCase):
resize.assert_called_once_with(path, newSize,
run_as_root=True)
def test_extend_volume_attached_fail(self):
"""Extend a volume by 1."""
self._set_driver()
drv = self._driver
volume = fake_volume.fake_volume_obj(
self.context,
id='80ee16b6-75d2-4d54-9539-ffc1b4b0fb10',
size=1,
provider_location='nfs_share')
path = 'path'
newSize = volume['size'] + 1
with mock.patch.object(drv, 'local_path', return_value=path):
with mock.patch.object(drv, '_is_share_eligible',
return_value=True):
with mock.patch.object(drv, '_is_file_size_equal',
return_value=True):
with mock.patch.object(drv, '_is_volume_attached',
return_value=True):
self.assertRaises(exception.ExtendVolumeError,
drv.extend_volume, volume, newSize)
def test_extend_volume_failure(self):
"""Error during extend operation."""
self._set_driver()

View File

@ -927,7 +927,10 @@ class QuobyteDriverTestCase(test.TestCase):
drv._ensure_share_mounted.assert_not_called()
drv._execute.assert_not_called()
def test_extend_volume(self):
@ddt.data(True, False)
@mock.patch.object(remotefs.RemoteFSSnapDriverDistributed,
"_is_volume_attached")
def test_extend_volume(self, is_attached, mock_remote_attached):
drv = self._driver
volume = self._simple_volume()
@ -948,12 +951,19 @@ class QuobyteDriverTestCase(test.TestCase):
image_utils.qemu_img_info = mock.Mock(return_value=img_info)
image_utils.resize_image = mock.Mock()
drv.extend_volume(volume, 3)
mock_remote_attached.return_value = is_attached
image_utils.qemu_img_info.assert_called_once_with(volume_path,
force_share=True,
run_as_root=False)
image_utils.resize_image.assert_called_once_with(volume_path, 3)
if is_attached:
self.assertRaises(exception.ExtendVolumeError, drv.extend_volume,
volume, 3)
else:
drv.extend_volume(volume, 3)
image_utils.qemu_img_info.assert_called_once_with(volume_path,
force_share=True,
run_as_root=False
)
image_utils.resize_image.assert_called_once_with(volume_path, 3)
def test_copy_volume_from_snapshot(self):
drv = self._driver

View File

@ -368,6 +368,12 @@ class NfsDriver(remotefs.RemoteFSSnapDriverDistributed):
def extend_volume(self, volume, new_size):
"""Extend an existing volume to the new size."""
if self._is_volume_attached(volume):
# NOTE(kaisers): no attached extensions until #1870367 is fixed
msg = (_("Cannot extend volume %s while it is attached.")
% volume['id'])
raise exception.ExtendVolumeError(msg)
LOG.info('Extending volume %s.', volume.id)
extend_by = int(new_size) - volume.size
if not self._is_share_eligible(volume.provider_location,

View File

@ -540,6 +540,12 @@ class QuobyteDriver(remotefs_drv.RemoteFSSnapDriverDistributed):
@utils.synchronized('quobyte', external=False)
def extend_volume(self, volume, size_gb):
if self._is_volume_attached(volume):
# NOTE(kaisers): no attached extensions until #1870367 is fixed
msg = (_("Cannot extend volume %s while it is attached.")
% volume['id'])
raise exception.ExtendVolumeError(msg)
volume_path = self.local_path(volume)
info = self._qemu_img_info(volume_path, volume.name)

View File

@ -303,12 +303,12 @@ driver.nec=complete
driver.netapp_ontap=complete
driver.netapp_solidfire=complete
driver.nexenta=complete
driver.nfs=complete
driver.nfs=missing
driver.nimble=complete
driver.prophetstor=complete
driver.pure=complete
driver.qnap=complete
driver.quobyte=complete
driver.quobyte=missing
driver.rbd=complete
driver.sandstone=complete
driver.seagate=complete

View File

@ -0,0 +1,7 @@
---
fixes:
- |
`Bug #1870367 <https://bugs.launchpad.net/cinder/+bug/1870367>`_ :
Partially fixed NFS and Quobyte drivers by no longer allowing extending a
volume while it is attached, to prevent failures due to Qemu internal
locking mechanisms.