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:
zhaohua 2016-02-26 11:33:06 +08:00
parent 83d7bc60f4
commit 1cbf87a382
4 changed files with 35 additions and 35 deletions

View File

@ -69,7 +69,8 @@ class HuaweiNasDriver(driver.ShareDriver):
self.plugin = importutils.import_object(backend_driver, self.plugin = importutils.import_object(backend_driver,
self.configuration) self.configuration)
else: else:
raise exception.InvalidShare(_("Huawei configuration missing.")) raise exception.InvalidShare(
reason=_("Huawei configuration missing."))
def check_for_setup_error(self): def check_for_setup_error(self):
"""Returns an error if prerequisites aren't met.""" """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): def delete_share(self, context, share, share_server=None):
"""Delete a share.""" """Delete a share."""
LOG.debug("Delete a share.") LOG.debug("Delete a share.")
self.plugin.delete_share(share, share_server) self.plugin.delete_share(share, share_server)
def create_snapshot(self, context, snapshot, share_server=None): def create_snapshot(self, context, snapshot, share_server=None):
"""Create a snapshot.""" """Create a snapshot."""
LOG.debug("Create a snapshot.")
self.plugin.create_snapshot(snapshot, share_server) self.plugin.create_snapshot(snapshot, share_server)
def delete_snapshot(self, context, snapshot, share_server=None): 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): def allow_access(self, context, share, access, share_server=None):
"""Allow access to the share.""" """Allow access to the share."""
LOG.debug("Allow access.") LOG.debug("Allow access.")
self.plugin.allow_access(share, access, share_server) self.plugin.allow_access(share, access, share_server)
def deny_access(self, context, share, access, share_server=None): def deny_access(self, context, share, access, share_server=None):
"""Deny access to the share.""" """Deny access to the share."""
LOG.debug("Deny access.") LOG.debug("Deny access.")
self.plugin.deny_access(share, access, share_server) self.plugin.deny_access(share, access, share_server)
def update_access(self, context, share, access_rules, add_rules=None, def update_access(self, context, share, access_rules, add_rules=None,

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import copy
from oslo_log import log from oslo_log import log
from manila.i18n import _LE from manila.i18n import _LE
@ -36,7 +38,7 @@ def get_share_extra_specs_params(type_id):
def _get_opts_from_specs(specs): def _get_opts_from_specs(specs):
opts = constants.OPTS_CAPABILITIES.copy() opts = copy.deepcopy(constants.OPTS_CAPABILITIES)
opts.update(constants.OPTS_VALUE) opts.update(constants.OPTS_VALUE)
for key, value in specs.items(): for key, value in specs.items():

View File

@ -73,7 +73,7 @@ class V3StorageConnection(driver.HuaweiBase):
result = self.helper._find_all_pool_info() result = self.helper._find_all_pool_info()
poolinfo = self.helper._find_pool_info(pool_name, result) poolinfo = self.helper._find_pool_info(pool_name, result)
if not poolinfo: 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) raise exception.InvalidHost(reason=msg)
fs_id = None fs_id = None
@ -95,8 +95,9 @@ class V3StorageConnection(driver.HuaweiBase):
if not self.check_fs_status(fs['HEALTHSTATUS'], if not self.check_fs_status(fs['HEALTHSTATUS'],
fs['RUNNINGSTATUS']): fs['RUNNINGSTATUS']):
raise exception.InvalidShare( raise exception.InvalidShare(
reason=(_('Invalid status of filesystem: %(health)s ' reason=(_('Invalid status of filesystem: '
'%(running)s.') 'HEALTHSTATUS=%(health)s '
'RUNNINGSTATUS=%(running)s.')
% {'health': fs['HEALTHSTATUS'], % {'health': fs['HEALTHSTATUS'],
'running': fs['RUNNINGSTATUS']})) 'running': fs['RUNNINGSTATUS']}))
except Exception as err: except Exception as err:
@ -156,8 +157,8 @@ class V3StorageConnection(driver.HuaweiBase):
fs_info = self.helper._get_fs_info_by_id(fsid) fs_info = self.helper._get_fs_info_by_id(fsid)
current_size = int(fs_info['CAPACITY']) / units.Mi / 2 current_size = int(fs_info['CAPACITY']) / units.Mi / 2
if current_size > new_size: if current_size >= new_size:
err_msg = (_("New size for extend must be equal or bigger than " err_msg = (_("New size for extend must be bigger than "
"current size on array. (current: %(size)s, " "current size on array. (current: %(size)s, "
"new: %(new_size)s).") "new: %(new_size)s).")
% {'size': current_size, 'new_size': new_size}) % {'size': current_size, 'new_size': new_size})
@ -191,7 +192,7 @@ class V3StorageConnection(driver.HuaweiBase):
raise exception.InvalidShare(reason=err_msg) raise exception.InvalidShare(reason=err_msg)
current_size = int(fs_info['CAPACITY']) / units.Mi / 2 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 " err_msg = (_("New size for shrink must be less than current "
"size on array. (current: %(size)s, " "size on array. (current: %(size)s, "
"new: %(new_size)s).") "new: %(new_size)s).")
@ -224,7 +225,7 @@ class V3StorageConnection(driver.HuaweiBase):
'RUNNINGSTATUS=%(running)s.') 'RUNNINGSTATUS=%(running)s.')
% {'health': fs['HEALTHSTATUS'], % {'health': fs['HEALTHSTATUS'],
'running': fs['RUNNINGSTATUS']}) 'running': fs['RUNNINGSTATUS']})
raise exception.StorageResourceException(reason=err_msg) raise exception.StorageResourceException(err_msg)
def create_snapshot(self, snapshot, share_server=None): def create_snapshot(self, snapshot, share_server=None):
"""Create a snapshot.""" """Create a snapshot."""
@ -427,9 +428,9 @@ class V3StorageConnection(driver.HuaweiBase):
except exception.ManilaException as err: except exception.ManilaException as err:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error(_LE('Failed to add access to share %(name)s. ' LOG.error(_LE('Failed to add access to share %(name)s. '
'Reason: %(err)s.') 'Reason: %(err)s.'),
% {'name': old_share['name'], {'name': old_share['name'],
'err': six.text_type(err)}) 'err': six.text_type(err)})
new_access = self.get_access(new_share) new_access = self.get_access(new_share)
try: try:
@ -438,9 +439,9 @@ class V3StorageConnection(driver.HuaweiBase):
except exception.ShareMountException as err: except exception.ShareMountException as err:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error(_LE('Failed to mount old share %(name)s. ' LOG.error(_LE('Failed to mount old share %(name)s. '
'Reason: %(err)s.') 'Reason: %(err)s.'),
% {'name': old_share['name'], {'name': old_share['name'],
'err': six.text_type(err)}) 'err': six.text_type(err)})
try: try:
self.allow_access(new_share, new_access) self.allow_access(new_share, new_access)
@ -449,9 +450,9 @@ class V3StorageConnection(driver.HuaweiBase):
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
self.umount_share_from_host(old_share) self.umount_share_from_host(old_share)
LOG.error(_LE('Failed to mount new share %(name)s. ' LOG.error(_LE('Failed to mount new share %(name)s. '
'Reason: %(err)s.') 'Reason: %(err)s.'),
% {'name': new_share['name'], {'name': new_share['name'],
'err': six.text_type(err)}) 'err': six.text_type(err)})
copied = self.copy_snapshot_data(old_share, new_share) copied = self.copy_snapshot_data(old_share, new_share)
@ -459,11 +460,10 @@ class V3StorageConnection(driver.HuaweiBase):
try: try:
self.umount_share_from_host(item) self.umount_share_from_host(item)
except exception.ShareUmountException as err: except exception.ShareUmountException as err:
err_msg = (_('Failed to unmount share %(name)s. ' LOG.warning(_LW('Failed to unmount share %(name)s. '
'Reason: %(err)s.') 'Reason: %(err)s.'),
% {'name': item['name'], {'name': item['name'],
'err': six.text_type(err)}) 'err': six.text_type(err)})
LOG.warning(err_msg)
self.deny_access(new_share, new_access) self.deny_access(new_share, new_access)
@ -830,8 +830,9 @@ class V3StorageConnection(driver.HuaweiBase):
if not self.check_fs_status(fs['HEALTHSTATUS'], if not self.check_fs_status(fs['HEALTHSTATUS'],
fs['RUNNINGSTATUS']): fs['RUNNINGSTATUS']):
raise exception.InvalidShare( raise exception.InvalidShare(
reason=(_('Invalid status of filesystem: %(health)s ' reason=(_('Invalid status of filesystem: '
'%(running)s.') 'HEALTHSTATUS=%(health)s '
'RUNNINGSTATUS=%(running)s.')
% {'health': fs['HEALTHSTATUS'], % {'health': fs['HEALTHSTATUS'],
'running': fs['RUNNINGSTATUS']})) 'running': fs['RUNNINGSTATUS']}))

View File

@ -112,8 +112,7 @@ class RestHelper(object):
if((result['error']['code'] != 0) if((result['error']['code'] != 0)
or ("data" not in result) or ("data" not in result)
or (result['data']['deviceid'] is None)): or (result['data']['deviceid'] is None)):
err_msg = (_("Login to %s failed, try another") % item_url) LOG.error(_LE("Login to %s failed, try another."), item_url)
LOG.error(err_msg)
continue continue
LOG.debug('Login success: %(url)s\n', LOG.debug('Login success: %(url)s\n',
@ -124,17 +123,17 @@ class RestHelper(object):
break break
if deviceid is None: if deviceid is None:
err_msg = (_("All url Login fail")) err_msg = _("All url login fail.")
LOG.error(err_msg) LOG.error(err_msg)
raise exception.InvalidShare(reason=err_msg) raise exception.InvalidShare(reason=err_msg)
return deviceid return deviceid
@utils.synchronized('huawei_manila', external=True) @utils.synchronized('huawei_manila')
def call(self, url, data=None, method=None): def call(self, url, data=None, method=None):
"""Send requests to server. """Send requests to server.
if fail, try another RestURL If fail, try another RestURL.
""" """
deviceid = None deviceid = None
old_url = self.url old_url = self.url
@ -142,8 +141,7 @@ class RestHelper(object):
error_code = result['error']['code'] error_code = result['error']['code']
if(error_code == constants.ERROR_CONNECT_TO_SERVER if(error_code == constants.ERROR_CONNECT_TO_SERVER
or error_code == constants.ERROR_UNAUTHORIZED_TO_SERVER): or error_code == constants.ERROR_UNAUTHORIZED_TO_SERVER):
err_msg = (_("Can't open the recent url, re-login.")) LOG.error(_LE("Can't open the recent url, re-login."))
LOG.error(err_msg)
deviceid = self.login() deviceid = self.login()
if deviceid is not None: if deviceid is not None: