Huawei: Ensure that share is exported

Ensure share is used when the share manager service starts.
Ensure share checks the share status on the array
and changes the logical IP from the configuration
file.

Implements: blueprint huawei-driver-ensure-share
Change-Id: I29d8a5306b88edcbf7bd405da05db1e6da39f41f
This commit is contained in:
huyang 2015-12-20 08:38:27 +08:00 committed by liuke2
parent 83c4e1521c
commit 32cebee564
4 changed files with 106 additions and 1 deletions

View File

@ -51,6 +51,10 @@ class HuaweiBase(object):
def deny_access(self, share, access, share_server):
"""Deny access to the share."""
@abc.abstractmethod
def ensure_share(self, share, share_server=None):
"""Ensure that share is exported."""
@abc.abstractmethod
def extend_share(self, share, new_size, share_server):
"""Extends size of existing share."""

View File

@ -53,6 +53,7 @@ class HuaweiNasDriver(driver.ShareDriver):
Add smartx capabilities.
Support multi pools in one backend.
1.2 - Add share server support.
Add ensure share.
"""
def __init__(self, *args, **kwargs):
@ -131,8 +132,10 @@ class HuaweiNasDriver(driver.ShareDriver):
self.plugin.delete_snapshot(snapshot, share_server)
def ensure_share(self, context, share, share_server=None):
"""Ensure that storages are mounted and exported."""
"""Ensure that share is exported."""
LOG.debug("Ensure share.")
location = self.plugin.ensure_share(share, share_server)
return location
def allow_access(self, context, share, access, share_server=None):
"""Allow access to the share."""

View File

@ -203,6 +203,17 @@ class V3StorageConnection(driver.HuaweiBase):
else:
return False
def assert_filesystem(self, fsid):
fs = self.helper._get_fs_info_by_id(fsid)
if not self.check_fs_status(fs['HEALTHSTATUS'],
fs['RUNNINGSTATUS']):
err_msg = (_('Invalid status of filesystem: '
'HEALTHSTATUS=%(health)s '
'RUNNINGSTATUS=%(running)s.')
% {'health': fs['HEALTHSTATUS'],
'running': fs['RUNNINGSTATUS']})
raise exception.StorageResourceException(reason=err_msg)
def create_snapshot(self, snapshot, share_server=None):
"""Create a snapshot."""
snap_name = snapshot['id']
@ -1214,3 +1225,22 @@ class V3StorageConnection(driver.HuaweiBase):
if (LDAP_config['LDAPSERVER'] == server
and LDAP_config['BASEDN'] == domain):
self.helper.delete_LDAP_config()
def ensure_share(self, share, share_server=None):
"""Ensure that share is exported."""
share_proto = share['share_proto']
share_name = share['name']
share_id = share['id']
share_url_type = self.helper._get_share_url_type(share_proto)
share_storage = self.helper._get_share_by_name(share_name,
share_url_type)
if not share_storage:
raise exception.ShareResourceNotFound(share_id=share_id)
fs_id = share_storage['FSID']
self.assert_filesystem(fs_id)
ip = self._get_share_ip(share_server)
location = self._get_location_path(share_name, share_proto, ip)
return [location]

View File

@ -700,6 +700,7 @@ class HuaweiShareDriverTestCase(test.TestCase):
'share_proto': 'NFS',
'share_network_id': 'fake_net_id',
'share_server_id': 'fake-share-srv-id',
'host': 'fake_host@fake_backend#OpenStack_Pool',
'export_locations': [
{'path': '100.115.10.68:/share_fake_uuid'},
],
@ -1071,6 +1072,15 @@ class HuaweiShareDriverTestCase(test.TestCase):
}
}
def _get_share_by_proto(self, share_proto):
if share_proto == "NFS":
share = self.share_nfs
elif share_proto == "CIFS":
share = self.share_cifs
else:
share = None
return share
def test_conf_product_fail(self):
self.recreate_fake_conf_file(product_flag=False)
self.driver.plugin.configuration.manila_huawei_conf_file = (
@ -2697,6 +2707,64 @@ class HuaweiShareDriverTestCase(test.TestCase):
self.driver._teardown_server(server_details, None)
mock_debug.assert_called_with('Server details are empty.')
@ddt.data({"share_proto": "NFS",
"path": ["100.115.10.68:/share_fake_uuid"]},
{"share_proto": "CIFS",
"path": ["\\\\100.115.10.68\\share_fake_uuid"]})
@ddt.unpack
def test_ensure_share_sucess(self, share_proto, path):
share = self._get_share_by_proto(share_proto)
self.driver.plugin.helper.login()
location = self.driver.ensure_share(self._context,
share,
self.share_server)
self.assertEqual(path, location)
@ddt.data({"share_proto": "NFS",
"path": ["111.111.111.109:/share_fake_uuid"]},
{"share_proto": "CIFS",
"path": ["\\\\111.111.111.109\\share_fake_uuid"]})
@ddt.unpack
@dec_driver_handles_share_servers
def test_ensure_share_with_share_server_sucess(self, share_proto, path):
share = self._get_share_by_proto(share_proto)
backend_details = self.driver.setup_server(self.fake_network_info)
fake_share_server = {'backend_details': backend_details}
self.driver.plugin.helper.login()
location = self.driver.ensure_share(self._context,
share,
fake_share_server)
self.assertEqual(path, location)
@ddt.data({"share_proto": "NFS"},
{"share_proto": "CIFS"})
@ddt.unpack
def test_ensure_share_get_share_fail(self, share_proto):
share = self._get_share_by_proto(share_proto)
self.mock_object(self.driver.plugin.helper,
'_get_share_by_name',
mock.Mock(return_value={}))
self.driver.plugin.helper.login()
self.assertRaises(exception.ShareResourceNotFound,
self.driver.ensure_share,
self._context,
share,
self.share_server)
def test_ensure_share_get_filesystem_status_fail(self):
self.driver.plugin.helper.fs_status_flag = False
share = self.share_nfs_thickfs
self.driver.plugin.helper.login()
self.assertRaises(exception.StorageResourceException,
self.driver.ensure_share,
self._context,
share,
self.share_server)
def create_fake_conf_file(self, fake_conf_file,
product_flag=True, username_flag=True,
pool_node_flag=True, timeout_flag=True,