From fa5c0fd2ce0818a5265141968a719cb38cc383d7 Mon Sep 17 00:00:00 2001 From: Silvan Kaiser Date: Fri, 18 May 2018 09:53:10 +0200 Subject: [PATCH] Set initial quota in Quobyte and correct resizing Ensure a shares initial quota is set in the backend, and do quota size conversion when resizing. Closes-Bug: #1771958 Closes-Bug: #1771970 Change-Id: I64a1e591c2682bc8bb62554a95399b5651253f59 --- manila/share/drivers/quobyte/quobyte.py | 15 ++++++++++----- .../tests/share/drivers/quobyte/test_quobyte.py | 16 ++++++++++++---- .../bugfix-1771958-1771970-bcec841e7ae6b9f6.yaml | 6 ++++++ 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/bugfix-1771958-1771970-bcec841e7ae6b9f6.yaml diff --git a/manila/share/drivers/quobyte/quobyte.py b/manila/share/drivers/quobyte/quobyte.py index 4dac9a6e78..55d7eeb9aa 100644 --- a/manila/share/drivers/quobyte/quobyte.py +++ b/manila/share/drivers/quobyte/quobyte.py @@ -77,9 +77,10 @@ class QuobyteShareDriver(driver.ExecuteMixin, driver.ShareDriver,): 1.2.2 - Minor optimizations 1.2.3 - Updated RPC layer for improved stability 1.2.4 - Fixed handling updated QB API error codes + 1.2.5 - Fixed two quota handling bugs """ - DRIVER_VERSION = '1.2.4' + DRIVER_VERSION = '1.2.5' def __init__(self, *args, **kwargs): super(QuobyteShareDriver, self).__init__(False, *args, **kwargs) @@ -179,12 +180,14 @@ class QuobyteShareDriver(driver.ExecuteMixin, driver.ShareDriver,): return project_id def _resize_share(self, share, new_size): + newsize_bytes = new_size * units.Gi self.rpc.call('setQuota', {"quotas": [ {"consumer": [{"type": "VOLUME", - "identifier": share["name"]}], + "identifier": share["name"], + "tenant_id": share["project_id"]}], "limits": [{"type": "LOGICAL_DISK_SPACE", - "value": new_size}]} + "value": newsize_bytes}]} ]}) def _resolve_volume_name(self, volume_name, tenant_domain): @@ -242,6 +245,8 @@ class QuobyteShareDriver(driver.ExecuteMixin, driver.ShareDriver,): volume_uuid=volume_uuid, protocol='NFS')) + self._resize_share(share, share['size']) + return '%(nfs_server_ip)s:%(nfs_export_path)s' % result def delete_share(self, context, share, share_server=None): @@ -326,7 +331,7 @@ class QuobyteShareDriver(driver.ExecuteMixin, driver.ShareDriver,): self.rpc.call('exportVolume', call_params) def extend_share(self, ext_share, ext_size, share_server=None): - """Uses resize_share to extend a share. + """Uses _resize_share to extend a share. :param ext_share: Share model. :param ext_size: New size of share (new_size > share['size']). @@ -335,7 +340,7 @@ class QuobyteShareDriver(driver.ExecuteMixin, driver.ShareDriver,): self._resize_share(share=ext_share, new_size=ext_size) def shrink_share(self, shrink_share, shrink_size, share_server=None): - """Uses resize_share to shrink a share. + """Uses _resize_share to shrink a share. Quobyte uses soft quotas. If a shares current size is bigger than the new shrunken size no data is lost. Data can be continuously read diff --git a/manila/tests/share/drivers/quobyte/test_quobyte.py b/manila/tests/share/drivers/quobyte/test_quobyte.py index 4914513a17..a43b3c01bc 100644 --- a/manila/tests/share/drivers/quobyte/test_quobyte.py +++ b/manila/tests/share/drivers/quobyte/test_quobyte.py @@ -15,6 +15,7 @@ import mock from oslo_config import cfg +from oslo_utils import units import six from manila import context @@ -114,7 +115,8 @@ class QuobyteShareDriverTestCase(test.TestCase): self.assertRaises(exception.QBException, self._driver.do_setup, self._context) - def test_create_share_new_volume(self): + @mock.patch.object(quobyte.QuobyteShareDriver, "_resize_share") + def test_create_share_new_volume(self, qb_resize_mock): self._driver.rpc.call = mock.Mock(wraps=fake_rpc_handler) result = self._driver.create_share(self._context, self.share) @@ -130,8 +132,10 @@ class QuobyteShareDriverTestCase(test.TestCase): )), mock.call('exportVolume', dict(protocol='NFS', volume_uuid='voluuid'))]) + qb_resize_mock.assert_called_once_with(self.share, self.share['size']) - def test_create_share_existing_volume(self): + @mock.patch.object(quobyte.QuobyteShareDriver, "_resize_share") + def test_create_share_existing_volume(self, qb_resize_mock): self._driver.rpc.call = mock.Mock(wraps=fake_rpc_handler) self._driver.create_share(self._context, self.share) @@ -153,6 +157,7 @@ class QuobyteShareDriverTestCase(test.TestCase): mock.call('createVolume', create_params), mock.call('exportVolume', dict(protocol='NFS', volume_uuid='voluuid'))]) + qb_resize_mock.assert_called_once_with(self.share, self.share['size']) def test_create_share_wrong_protocol(self): share = {'share_proto': 'WRONG_PROTOCOL'} @@ -413,18 +418,21 @@ class QuobyteShareDriverTestCase(test.TestCase): def test_resize_share(self): self._driver.rpc.call = mock.Mock(wraps=fake_rpc_handler) + manila_size = 7 + newsize_bytes = manila_size * units.Gi - self._driver._resize_share(share=self.share, new_size=7) + self._driver._resize_share(share=self.share, new_size=manila_size) exp_params = { "quotas": [{ "consumer": [{ "type": "VOLUME", "identifier": self.share["name"], + "tenant_id": self.share["project_id"] }], "limits": [{ "type": "LOGICAL_DISK_SPACE", - "value": 7, + "value": newsize_bytes, }], }]} self._driver.rpc.call.assert_has_calls([ diff --git a/releasenotes/notes/bugfix-1771958-1771970-bcec841e7ae6b9f6.yaml b/releasenotes/notes/bugfix-1771958-1771970-bcec841e7ae6b9f6.yaml new file mode 100644 index 0000000000..4b282802a3 --- /dev/null +++ b/releasenotes/notes/bugfix-1771958-1771970-bcec841e7ae6b9f6.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + New shares created on a Quobyte backend are now initialized with the correct quota. + - | + fixes a bug causing incorrect quotas being set in the backend when resizing Quobyte shares.