Merge "Fix extend operation of shrinked share in generic driver"

This commit is contained in:
Jenkins 2016-11-22 13:57:02 +00:00 committed by Gerrit Code Review
commit 799fc8d55f
3 changed files with 36 additions and 16 deletions

@ -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,

@ -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.\

@ -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.