Allow extension of volumes with snapshots for VZstorage driver

This change lifts an earlier limitation that explicitely did
not extend a volume if snapshots of that volume exist. This
limitation was lifted on the glusterfs driver and this change
mirrors that behaviour.

Partial-bug: #1687048

Change-Id: I9aa727b1880b374105c2cad685dc196c7d39f841
This commit is contained in:
Silvan Kaiser 2017-05-05 12:25:04 +02:00
parent 60bf9d0d9e
commit 7e5916ecdd
2 changed files with 10 additions and 29 deletions

View File

@ -232,7 +232,7 @@ class VZStorageTestCase(test.TestCase):
snap_info = '{"active": "%s"}' % self.vol.id
with mock.patch.object(drv, 'get_volume_format',
return_value="raw"):
with mock.patch.object(drv, 'local_path',
with mock.patch.object(drv, 'get_active_image_from_info',
return_value=self._FAKE_VOLUME_PATH):
with mock.patch.object(drv, '_read_file',
return_value=snap_info):
@ -240,23 +240,15 @@ class VZStorageTestCase(test.TestCase):
mock_resize_image.assert_called_once_with(self._FAKE_VOLUME_PATH, 10)
def _test_check_extend_support(self, has_snapshots=False,
is_eligible=True):
def _test_check_extend_support(self, is_eligible=True):
drv = self._vz_driver
drv.local_path = mock.Mock(return_value=self._FAKE_VOLUME_PATH)
drv._is_share_eligible = mock.Mock(return_value=is_eligible)
if has_snapshots:
active = self._FAKE_SNAPSHOT_PATH
else:
active = self._FAKE_VOLUME_PATH
active = self._FAKE_VOLUME_PATH
drv.get_active_image_from_info = mock.Mock(return_value=active)
if has_snapshots:
self.assertRaises(exception.InvalidVolume,
drv._check_extend_volume_support,
self.vol, 2)
elif not is_eligible:
if not is_eligible:
self.assertRaises(exception.ExtendVolumeError,
drv._check_extend_volume_support,
self.vol, 2)
@ -267,9 +259,6 @@ class VZStorageTestCase(test.TestCase):
def test_check_extend_support(self):
self._test_check_extend_support()
def test_check_extend_volume_with_snapshots(self):
self._test_check_extend_support(has_snapshots=True)
def test_check_extend_volume_uneligible_share(self):
self._test_check_extend_support(is_eligible=False)
@ -368,7 +357,7 @@ class VZStorageTestCase(test.TestCase):
def test_extend_volume_ploop(self):
drv = self._vz_driver
drv.local_path = mock.Mock(
drv.get_active_image_from_info = mock.Mock(
return_value=self._FAKE_VOLUME_PATH)
drv.get_volume_format = mock.Mock(
return_value=vzstorage.DISK_FORMAT_PLOOP)

View File

@ -411,14 +411,16 @@ class VZStorageDriver(remotefs_drv.RemoteFSSnapDriver):
self._extend_volume(volume, size_gb, volume_format)
def _extend_volume(self, volume, size_gb, volume_format):
volume_path = self.local_path(volume)
self._check_extend_volume_support(volume, size_gb)
LOG.info('Resizing file to %sG...', size_gb)
self._do_extend_volume(volume_path, size_gb, volume_format)
active_path = os.path.join(
self._get_mount_point_for_share(volume.provider_location),
self.get_active_image_from_info(volume))
self._do_extend_volume(active_path, size_gb, volume_format)
def _do_extend_volume(self, volume_path, size_gb, volume_format):
if volume_format == DISK_FORMAT_PLOOP:
self._execute('ploop', 'resize', '-s',
'%dG' % size_gb,
@ -431,16 +433,6 @@ class VZStorageDriver(remotefs_drv.RemoteFSSnapDriver):
reason='Resizing image file failed.')
def _check_extend_volume_support(self, volume, size_gb):
volume_path = self.local_path(volume)
active_file = self.get_active_image_from_info(volume)
active_file_path = os.path.join(self._local_volume_dir(volume),
active_file)
if active_file_path != volume_path:
msg = _('Extend volume is only supported for this '
'driver when no snapshots exist.')
raise exception.InvalidVolume(msg)
extend_by = int(size_gb) - volume.size
if not self._is_share_eligible(volume.provider_location,
extend_by):