From 77a0349adc0a529b52c50347d1df3cca21a6dcfd Mon Sep 17 00:00:00 2001 From: Xiaoyang Zhang Date: Mon, 14 Nov 2016 17:08:33 +0800 Subject: [PATCH] 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 --- manila/share/drivers/generic.py | 18 +++++++------ manila/tests/share/drivers/test_generic.py | 27 +++++++++++++------ ...re-in-generic-driver-5c7f82faefaf26ea.yaml | 7 +++++ 3 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 releasenotes/notes/bug-1639188-fix-extend-operation-of-shrinked-share-in-generic-driver-5c7f82faefaf26ea.yaml diff --git a/manila/share/drivers/generic.py b/manila/share/drivers/generic.py index 117fde516d..49bc5751b5 100644 --- a/manila/share/drivers/generic.py +++ b/manila/share/drivers/generic.py @@ -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, diff --git a/manila/tests/share/drivers/test_generic.py b/manila/tests/share/drivers/test_generic.py index 2e9b233a48..7bbaaaf812 100644 --- a/manila/tests/share/drivers/test_generic.py +++ b/manila/tests/share/drivers/test_generic.py @@ -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.\ diff --git a/releasenotes/notes/bug-1639188-fix-extend-operation-of-shrinked-share-in-generic-driver-5c7f82faefaf26ea.yaml b/releasenotes/notes/bug-1639188-fix-extend-operation-of-shrinked-share-in-generic-driver-5c7f82faefaf26ea.yaml new file mode 100644 index 0000000000..0c8aed12d5 --- /dev/null +++ b/releasenotes/notes/bug-1639188-fix-extend-operation-of-shrinked-share-in-generic-driver-5c7f82faefaf26ea.yaml @@ -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.