diff --git a/manila/exception.py b/manila/exception.py index af0fc18e31..5bcd4e659d 100644 --- a/manila/exception.py +++ b/manila/exception.py @@ -688,3 +688,8 @@ class InvalidCGSnapshot(Invalid): class DriverNotInitialized(ManilaException): message = _("Share driver '%(driver)s' not initialized.") + + +class ShareResourceNotFound(StorageResourceNotFound): + message = _("Share id %(share_id)s could not be found " + "in storage backend.") diff --git a/manila/share/drivers/quobyte/quobyte.py b/manila/share/drivers/quobyte/quobyte.py index 09aaf4b650..b24367fc7e 100644 --- a/manila/share/drivers/quobyte/quobyte.py +++ b/manila/share/drivers/quobyte/quobyte.py @@ -70,7 +70,7 @@ CONF.register_opts(quobyte_manila_share_opts) class QuobyteShareDriver(driver.ExecuteMixin, driver.ShareDriver,): """Map share commands to Quobyte volumes.""" - DRIVER_VERSION = '1.0' + DRIVER_VERSION = '1.0.1' def __init__(self, *args, **kwargs): super(QuobyteShareDriver, self).__init__(False, *args, **kwargs) @@ -191,7 +191,33 @@ class QuobyteShareDriver(driver.ExecuteMixin, driver.ShareDriver,): remove_export=True)) def ensure_share(self, context, share, share_server=None): - """Invoked to ensure that share is exported.""" + """Invoked to ensure that share is exported. + + :param context: The `context.RequestContext` object for the request + :param share: Share instance that will be checked. + :param share_server: Data structure with share server information. + Not used by this driver. + :returns: IP: of share + :raises: + :ShareResourceNotFound: If the share instance cannot be found in + the backend + """ + + volume_uuid = self._resolve_volume_name( + share['name'], + self._get_project_name(context, share['project_id'])) + + LOG.debug("Ensuring Quobyte share %s" % share['name']) + + if not volume_uuid: + raise (exception.ShareResourceNotFound( + share_id=share['id'])) + + result = self.rpc.call('exportVolume', dict( + volume_uuid=volume_uuid, + protocol='NFS')) + + return '%(nfs_server_ip)s:%(nfs_export_path)s' % result def allow_access(self, context, share, access, share_server=None): """Allow access to a share.""" diff --git a/manila/tests/share/drivers/quobyte/test_quobyte.py b/manila/tests/share/drivers/quobyte/test_quobyte.py index a545cbc6d9..45fa8c5144 100644 --- a/manila/tests/share/drivers/quobyte/test_quobyte.py +++ b/manila/tests/share/drivers/quobyte/test_quobyte.py @@ -35,8 +35,8 @@ def fake_rpc_handler(name, *args): elif name == 'createVolume': return {'volume_uuid': 'voluuid'} elif name == 'exportVolume': - return {'nfs_server_ip': '10.10.1.1', - 'nfs_export_path': '/voluuid'} + return {'nfs_server_ip': 'fake_location', + 'nfs_export_path': '/fake_share'} class QuobyteShareDriverTestCase(test.TestCase): @@ -76,7 +76,7 @@ class QuobyteShareDriverTestCase(test.TestCase): result = self._driver.create_share(self._context, self.share) - self.assertEqual('10.10.1.1:/voluuid', result) + self.assertEqual(self.share['export_location'], result) self._driver.rpc.call.assert_has_calls([ mock.call('createVolume', dict( name=self.share['name'], @@ -281,3 +281,34 @@ class QuobyteShareDriverTestCase(test.TestCase): self.assertEqual((39.223160718, 20.880642548), self._driver._get_capacities()) + + @mock.patch.object(quobyte.QuobyteShareDriver, + "_resolve_volume_name", + return_value="fake_uuid") + def test_ensure_share(self, mock_qb_resolve_volname): + self._driver.rpc.call = mock.Mock(wraps=fake_rpc_handler) + + result = self._driver.ensure_share(self._context, self.share, None) + + self.assertEqual(self.share["export_location"], result) + (mock_qb_resolve_volname. + assert_called_once_with(self.share['name'], + self.share['project_id'])) + self._driver.rpc.call.assert_has_calls([ + mock.call('exportVolume', dict( + volume_uuid="fake_uuid", + protocol='NFS' + ))]) + + @mock.patch.object(quobyte.QuobyteShareDriver, + "_resolve_volume_name", + return_value=None) + def test_ensure_deleted_share(self, mock_qb_resolve_volname): + self._driver.rpc.call = mock.Mock(wraps=fake_rpc_handler) + + self.assertRaises(exception.ShareResourceNotFound, + self._driver.ensure_share, + self._context, self.share, None) + (mock_qb_resolve_volname. + assert_called_once_with(self.share['name'], + self.share['project_id'])) diff --git a/manila/tests/test_exception.py b/manila/tests/test_exception.py index 68081a7afe..bb0514b585 100644 --- a/manila/tests/test_exception.py +++ b/manila/tests/test_exception.py @@ -448,6 +448,13 @@ class ManilaExceptionResponseCode404(test.TestCase): self.assertEqual(404, e.code) self.assertIn(instance_id, e.msg) + def test_share_resource_not_found(self): + # verify response code for exception.ShareNotFound + share_id = "fake_share_id" + e = exception.ShareResourceNotFound(share_id=share_id) + self.assertEqual(500, e.code) + self.assertIn(share_id, e.msg) + class ManilaExceptionResponseCode413(test.TestCase):