Fix extend operation of shrinked share in generic driver

If a share is shrank from 10G to 5G, the volume is still 10G.
This share`s size display is 5G, but the share extend newsize
must be > 10G in the old code. So, I think only need to perform
resize_filesystem when the share extend newsize <= volume size.
The volume extension is performed only when new size larger than
volume size.

Change-Id: I7e49b446445b8005e2eb23e1d439354eb24915e0
Close-Bug: #1639188
This commit is contained in:
Xiaoyang Zhang 2016-11-14 17:08:33 +08:00
parent bcb064becb
commit 77a0349adc
3 changed files with 36 additions and 16 deletions

View File

@ -667,16 +667,18 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
helper = self._get_helper(share)
helper.disable_access_for_maintenance(server_details, share['name'])
self._unmount_device(share, server_details)
self._detach_volume(self.admin_context, share, server_details)
volume = self._get_volume(self.admin_context, share['id'])
volume = self._extend_volume(self.admin_context, volume, new_size)
volume = self._attach_volume(
self.admin_context,
share,
server_details['instance_id'],
volume)
if int(new_size) > volume['size']:
self._detach_volume(self.admin_context, share, server_details)
volume = self._extend_volume(self.admin_context, volume, new_size)
volume = self._attach_volume(
self.admin_context,
share,
server_details['instance_id'],
volume)
self._resize_filesystem(server_details, volume)
self._mount_device(share, server_details, volume)
helper.restore_access_after_maintenance(server_details,

View File

@ -1630,8 +1630,12 @@ class GenericShareDriverTestCase(test.TestCase):
"fake", "fake"
)
def test_extend_share(self):
fake_volume = "fake"
@ddt.data(100, 130, 123)
def test_extend_share(self, volume_size):
fake_volume = {
"name": "fake",
"size": volume_size,
}
fake_share = {
'id': 'fake',
'share_proto': 'NFS',
@ -1662,14 +1666,21 @@ class GenericShareDriverTestCase(test.TestCase):
self._driver.service_instance_manager.get_common_server.called)
self._driver._unmount_device.assert_called_once_with(
fake_share, srv_details)
self._driver._detach_volume.assert_called_once_with(
mock.ANY, fake_share, srv_details)
self._driver._get_volume.assert_called_once_with(
mock.ANY, fake_share['id'])
self._driver._extend_volume.assert_called_once_with(
mock.ANY, fake_volume, new_size)
self._driver._attach_volume.assert_called_once_with(
mock.ANY, fake_share, srv_details['instance_id'], mock.ANY)
if new_size > volume_size:
self._driver._detach_volume.assert_called_once_with(
mock.ANY, fake_share, srv_details)
self._driver._extend_volume.assert_called_once_with(
mock.ANY, fake_volume, new_size)
self._driver._attach_volume.assert_called_once_with(
mock.ANY, fake_share, srv_details['instance_id'], mock.ANY)
else:
self.assertFalse(self._driver._detach_volume.called)
self.assertFalse(self._driver._extend_volume.called)
self.assertFalse(self._driver._attach_volume.called)
self._helper_nfs.disable_access_for_maintenance.\
assert_called_once_with(srv_details, 'test_share')
self._helper_nfs.restore_access_after_maintenance.\

View File

@ -0,0 +1,7 @@
---
fixes:
- In the Generic driver, the backing volume size is
greater than the share size when the share has been
shrunk. So share extend logic in this driver was
changed to only extend the backing volume if its
size is less than the size of the new, extended share.