Implements ensure_share() in Quobyte driver

Added ensure_share implementation that checks share
availability and re-exports the given share.
Unit tests are added as well as a new ShareResourceNotFound
Exception (with its own unit test).

Change-Id: Ifbb144fa16df5d0ff3560d1a7476b75e5ccf184a
Closes-Bug: #1510552
This commit is contained in:
Silvan Kaiser 2015-10-27 15:52:35 +01:00
parent fabadd9404
commit 616ffabece
4 changed files with 74 additions and 5 deletions

View File

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

View File

@ -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:<nfs_export_path> 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."""

View File

@ -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']))

View File

@ -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):