From 15be2869a01fdb3c9d6ff4f58d0a72d94a997fc0 Mon Sep 17 00:00:00 2001 From: Silvan Kaiser Date: Fri, 8 Jan 2016 10:27:31 +0100 Subject: [PATCH] Adds extend_share for Quobyte shares Adds extend_share (and shrink_share) to the Quobyte driver. Both are mapped to a common resize operation in the backend. Implements: blueprint extend-quobyte-share Change-Id: I3395310e4658d68f098da6980ecc5a6832458f5a --- ...hare_back_ends_feature_support_mapping.rst | 2 +- manila/share/drivers/quobyte/quobyte.py | 38 ++++++++++++++++++- .../share/drivers/quobyte/test_quobyte.py | 27 +++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/doc/source/devref/share_back_ends_feature_support_mapping.rst b/doc/source/devref/share_back_ends_feature_support_mapping.rst index dccfa7ca9a..a2179db514 100644 --- a/doc/source/devref/share_back_ends_feature_support_mapping.rst +++ b/doc/source/devref/share_back_ends_feature_support_mapping.rst @@ -55,7 +55,7 @@ Mapping of share drivers and share features support +----------------------------------------+-----------------------------+-----------------------+--------------+--------------+------------------------+----------------------------+ | IBM GPFS | DHSS = False(K) | \- | L | \- | K | K | +----------------------------------------+-----------------------------+-----------------------+--------------+--------------+------------------------+----------------------------+ -| Quobyte | DHSS = False (K) | \- | \- | \- | \- | \- | +| Quobyte | DHSS = False (K) | \- | M | M | \- | \- | +----------------------------------------+-----------------------------+-----------------------+--------------+--------------+------------------------+----------------------------+ | Windows SMB | DHSS = True (L) & False (L) | L | L | L | L | L | +----------------------------------------+-----------------------------+-----------------------+--------------+--------------+------------------------+----------------------------+ diff --git a/manila/share/drivers/quobyte/quobyte.py b/manila/share/drivers/quobyte/quobyte.py index b24367fc7e..0b23e418d9 100644 --- a/manila/share/drivers/quobyte/quobyte.py +++ b/manila/share/drivers/quobyte/quobyte.py @@ -68,9 +68,15 @@ CONF.register_opts(quobyte_manila_share_opts) class QuobyteShareDriver(driver.ExecuteMixin, driver.ShareDriver,): - """Map share commands to Quobyte volumes.""" + """Map share commands to Quobyte volumes. - DRIVER_VERSION = '1.0.1' + Version history: + 1.0 - Initial driver. + 1.0.1 - Adds ensure_share() implementation. + 1.1 - Adds extend_share() and shrink_share() implementation. + """ + + DRIVER_VERSION = '1.1' def __init__(self, *args, **kwargs): super(QuobyteShareDriver, self).__init__(False, *args, **kwargs) @@ -136,6 +142,12 @@ class QuobyteShareDriver(driver.ExecuteMixin, driver.ShareDriver,): """ return project_id + def _resize_share(self, share, new_size): + # TODO(kaisers): check and update existing quota if already present + self.rpc.call('setQuota', {"consumer": {"type": 3, + "identifier": share["name"]}, + "limits": {"type": 5, "value": new_size}}) + def _resolve_volume_name(self, volume_name, tenant_domain): """Resolve a volume name to the global volume uuid.""" result = self.rpc.call('resolveVolumeName', dict( @@ -249,3 +261,25 @@ class QuobyteShareDriver(driver.ExecuteMixin, driver.ShareDriver,): self.rpc.call('exportVolume', dict( volume_uuid=volume_uuid, remove_allow_ip=access['access_to'])) + + def extend_share(self, ext_share, ext_size, share_server=None): + """Uses resize_share to extend a share. + + :param ext_share: Share model. + :param ext_size: New size of share (new_size > share['size']). + :param share_server: Currently not used. + """ + 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. + + 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 + from the share but new writes receive out of disk space replies. + + :param shrink_share: Share model. + :param shrink_size: New size of share (new_size < share['size']). + :param share_server: Currently not used. + """ + self._resize_share(share=shrink_share, new_size=shrink_size) diff --git a/manila/tests/share/drivers/quobyte/test_quobyte.py b/manila/tests/share/drivers/quobyte/test_quobyte.py index 45fa8c5144..1c383e3726 100644 --- a/manila/tests/share/drivers/quobyte/test_quobyte.py +++ b/manila/tests/share/drivers/quobyte/test_quobyte.py @@ -312,3 +312,30 @@ class QuobyteShareDriverTestCase(test.TestCase): (mock_qb_resolve_volname. assert_called_once_with(self.share['name'], self.share['project_id'])) + + @mock.patch.object(quobyte.QuobyteShareDriver, "_resize_share") + def test_extend_share(self, mock_qsd_resize_share): + self._driver.extend_share(ext_share=self.share, + ext_size=2, + share_server=None) + mock_qsd_resize_share.assert_called_once_with(share=self.share, + new_size=2) + + def test_resize_share(self): + self._driver.rpc.call = mock.Mock(wraps=fake_rpc_handler) + + self._driver._resize_share(share=self.share, new_size=7) + + self._driver.rpc.call.assert_has_calls([ + mock.call('setQuota', + {"consumer": {"type": 3, + "identifier": self.share["name"]}, + "limits": {"type": 5, "value": 7}})]) + + @mock.patch.object(quobyte.QuobyteShareDriver, "_resize_share") + def test_shrink_share(self, mock_qsd_resize_share): + self._driver.shrink_share(shrink_share=self.share, + shrink_size=3, + share_server=None) + mock_qsd_resize_share.assert_called_once_with(share=self.share, + new_size=3)