Huawei driver code review
Code and log format. Change external lock to internal to improve performance. Use deepcopy instead of copy. Change-Id: Icb816fa9b47dbdfa5dfbb34e55ded8e167ba7ec8 Closes-Bug: #1550106
This commit is contained in:
parent
83d7bc60f4
commit
1cbf87a382
@ -69,7 +69,8 @@ class HuaweiNasDriver(driver.ShareDriver):
|
||||
self.plugin = importutils.import_object(backend_driver,
|
||||
self.configuration)
|
||||
else:
|
||||
raise exception.InvalidShare(_("Huawei configuration missing."))
|
||||
raise exception.InvalidShare(
|
||||
reason=_("Huawei configuration missing."))
|
||||
|
||||
def check_for_setup_error(self):
|
||||
"""Returns an error if prerequisites aren't met."""
|
||||
@ -128,11 +129,11 @@ class HuaweiNasDriver(driver.ShareDriver):
|
||||
def delete_share(self, context, share, share_server=None):
|
||||
"""Delete a share."""
|
||||
LOG.debug("Delete a share.")
|
||||
|
||||
self.plugin.delete_share(share, share_server)
|
||||
|
||||
def create_snapshot(self, context, snapshot, share_server=None):
|
||||
"""Create a snapshot."""
|
||||
LOG.debug("Create a snapshot.")
|
||||
self.plugin.create_snapshot(snapshot, share_server)
|
||||
|
||||
def delete_snapshot(self, context, snapshot, share_server=None):
|
||||
@ -149,13 +150,11 @@ class HuaweiNasDriver(driver.ShareDriver):
|
||||
def allow_access(self, context, share, access, share_server=None):
|
||||
"""Allow access to the share."""
|
||||
LOG.debug("Allow access.")
|
||||
|
||||
self.plugin.allow_access(share, access, share_server)
|
||||
|
||||
def deny_access(self, context, share, access, share_server=None):
|
||||
"""Deny access to the share."""
|
||||
LOG.debug("Deny access.")
|
||||
|
||||
self.plugin.deny_access(share, access, share_server)
|
||||
|
||||
def update_access(self, context, share, access_rules, add_rules=None,
|
||||
|
@ -13,6 +13,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
|
||||
from oslo_log import log
|
||||
|
||||
from manila.i18n import _LE
|
||||
@ -36,7 +38,7 @@ def get_share_extra_specs_params(type_id):
|
||||
|
||||
|
||||
def _get_opts_from_specs(specs):
|
||||
opts = constants.OPTS_CAPABILITIES.copy()
|
||||
opts = copy.deepcopy(constants.OPTS_CAPABILITIES)
|
||||
opts.update(constants.OPTS_VALUE)
|
||||
|
||||
for key, value in specs.items():
|
||||
|
@ -73,7 +73,7 @@ class V3StorageConnection(driver.HuaweiBase):
|
||||
result = self.helper._find_all_pool_info()
|
||||
poolinfo = self.helper._find_pool_info(pool_name, result)
|
||||
if not poolinfo:
|
||||
msg = (_("Can not find pool info by pool name: %s") % pool_name)
|
||||
msg = (_("Can not find pool info by pool name: %s.") % pool_name)
|
||||
raise exception.InvalidHost(reason=msg)
|
||||
|
||||
fs_id = None
|
||||
@ -95,8 +95,9 @@ class V3StorageConnection(driver.HuaweiBase):
|
||||
if not self.check_fs_status(fs['HEALTHSTATUS'],
|
||||
fs['RUNNINGSTATUS']):
|
||||
raise exception.InvalidShare(
|
||||
reason=(_('Invalid status of filesystem: %(health)s '
|
||||
'%(running)s.')
|
||||
reason=(_('Invalid status of filesystem: '
|
||||
'HEALTHSTATUS=%(health)s '
|
||||
'RUNNINGSTATUS=%(running)s.')
|
||||
% {'health': fs['HEALTHSTATUS'],
|
||||
'running': fs['RUNNINGSTATUS']}))
|
||||
except Exception as err:
|
||||
@ -156,8 +157,8 @@ class V3StorageConnection(driver.HuaweiBase):
|
||||
fs_info = self.helper._get_fs_info_by_id(fsid)
|
||||
|
||||
current_size = int(fs_info['CAPACITY']) / units.Mi / 2
|
||||
if current_size > new_size:
|
||||
err_msg = (_("New size for extend must be equal or bigger than "
|
||||
if current_size >= new_size:
|
||||
err_msg = (_("New size for extend must be bigger than "
|
||||
"current size on array. (current: %(size)s, "
|
||||
"new: %(new_size)s).")
|
||||
% {'size': current_size, 'new_size': new_size})
|
||||
@ -191,7 +192,7 @@ class V3StorageConnection(driver.HuaweiBase):
|
||||
raise exception.InvalidShare(reason=err_msg)
|
||||
|
||||
current_size = int(fs_info['CAPACITY']) / units.Mi / 2
|
||||
if current_size < new_size:
|
||||
if current_size <= new_size:
|
||||
err_msg = (_("New size for shrink must be less than current "
|
||||
"size on array. (current: %(size)s, "
|
||||
"new: %(new_size)s).")
|
||||
@ -224,7 +225,7 @@ class V3StorageConnection(driver.HuaweiBase):
|
||||
'RUNNINGSTATUS=%(running)s.')
|
||||
% {'health': fs['HEALTHSTATUS'],
|
||||
'running': fs['RUNNINGSTATUS']})
|
||||
raise exception.StorageResourceException(reason=err_msg)
|
||||
raise exception.StorageResourceException(err_msg)
|
||||
|
||||
def create_snapshot(self, snapshot, share_server=None):
|
||||
"""Create a snapshot."""
|
||||
@ -427,9 +428,9 @@ class V3StorageConnection(driver.HuaweiBase):
|
||||
except exception.ManilaException as err:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(_LE('Failed to add access to share %(name)s. '
|
||||
'Reason: %(err)s.')
|
||||
% {'name': old_share['name'],
|
||||
'err': six.text_type(err)})
|
||||
'Reason: %(err)s.'),
|
||||
{'name': old_share['name'],
|
||||
'err': six.text_type(err)})
|
||||
|
||||
new_access = self.get_access(new_share)
|
||||
try:
|
||||
@ -438,9 +439,9 @@ class V3StorageConnection(driver.HuaweiBase):
|
||||
except exception.ShareMountException as err:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(_LE('Failed to mount old share %(name)s. '
|
||||
'Reason: %(err)s.')
|
||||
% {'name': old_share['name'],
|
||||
'err': six.text_type(err)})
|
||||
'Reason: %(err)s.'),
|
||||
{'name': old_share['name'],
|
||||
'err': six.text_type(err)})
|
||||
|
||||
try:
|
||||
self.allow_access(new_share, new_access)
|
||||
@ -449,9 +450,9 @@ class V3StorageConnection(driver.HuaweiBase):
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.umount_share_from_host(old_share)
|
||||
LOG.error(_LE('Failed to mount new share %(name)s. '
|
||||
'Reason: %(err)s.')
|
||||
% {'name': new_share['name'],
|
||||
'err': six.text_type(err)})
|
||||
'Reason: %(err)s.'),
|
||||
{'name': new_share['name'],
|
||||
'err': six.text_type(err)})
|
||||
|
||||
copied = self.copy_snapshot_data(old_share, new_share)
|
||||
|
||||
@ -459,11 +460,10 @@ class V3StorageConnection(driver.HuaweiBase):
|
||||
try:
|
||||
self.umount_share_from_host(item)
|
||||
except exception.ShareUmountException as err:
|
||||
err_msg = (_('Failed to unmount share %(name)s. '
|
||||
'Reason: %(err)s.')
|
||||
% {'name': item['name'],
|
||||
'err': six.text_type(err)})
|
||||
LOG.warning(err_msg)
|
||||
LOG.warning(_LW('Failed to unmount share %(name)s. '
|
||||
'Reason: %(err)s.'),
|
||||
{'name': item['name'],
|
||||
'err': six.text_type(err)})
|
||||
|
||||
self.deny_access(new_share, new_access)
|
||||
|
||||
@ -830,8 +830,9 @@ class V3StorageConnection(driver.HuaweiBase):
|
||||
if not self.check_fs_status(fs['HEALTHSTATUS'],
|
||||
fs['RUNNINGSTATUS']):
|
||||
raise exception.InvalidShare(
|
||||
reason=(_('Invalid status of filesystem: %(health)s '
|
||||
'%(running)s.')
|
||||
reason=(_('Invalid status of filesystem: '
|
||||
'HEALTHSTATUS=%(health)s '
|
||||
'RUNNINGSTATUS=%(running)s.')
|
||||
% {'health': fs['HEALTHSTATUS'],
|
||||
'running': fs['RUNNINGSTATUS']}))
|
||||
|
||||
|
@ -112,8 +112,7 @@ class RestHelper(object):
|
||||
if((result['error']['code'] != 0)
|
||||
or ("data" not in result)
|
||||
or (result['data']['deviceid'] is None)):
|
||||
err_msg = (_("Login to %s failed, try another") % item_url)
|
||||
LOG.error(err_msg)
|
||||
LOG.error(_LE("Login to %s failed, try another."), item_url)
|
||||
continue
|
||||
|
||||
LOG.debug('Login success: %(url)s\n',
|
||||
@ -124,17 +123,17 @@ class RestHelper(object):
|
||||
break
|
||||
|
||||
if deviceid is None:
|
||||
err_msg = (_("All url Login fail"))
|
||||
err_msg = _("All url login fail.")
|
||||
LOG.error(err_msg)
|
||||
raise exception.InvalidShare(reason=err_msg)
|
||||
|
||||
return deviceid
|
||||
|
||||
@utils.synchronized('huawei_manila', external=True)
|
||||
@utils.synchronized('huawei_manila')
|
||||
def call(self, url, data=None, method=None):
|
||||
"""Send requests to server.
|
||||
|
||||
if fail, try another RestURL
|
||||
If fail, try another RestURL.
|
||||
"""
|
||||
deviceid = None
|
||||
old_url = self.url
|
||||
@ -142,8 +141,7 @@ class RestHelper(object):
|
||||
error_code = result['error']['code']
|
||||
if(error_code == constants.ERROR_CONNECT_TO_SERVER
|
||||
or error_code == constants.ERROR_UNAUTHORIZED_TO_SERVER):
|
||||
err_msg = (_("Can't open the recent url, re-login."))
|
||||
LOG.error(err_msg)
|
||||
LOG.error(_LE("Can't open the recent url, re-login."))
|
||||
deviceid = self.login()
|
||||
|
||||
if deviceid is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user