Trivial fix LOG.exception issues

Remove redundant 'error' parameter in LOG.exception,
and replace some LOG.error with LOG.exception.

Change-Id: I46c14014c9dc38da9ea3b8ae98c9bd2aafe478d7
This commit is contained in:
zhongjun2 2016-12-20 08:56:11 +08:00
parent 533d19df4a
commit f775c81c89
18 changed files with 88 additions and 104 deletions

View File

@ -181,8 +181,8 @@ class ExtensionManager(object):
LOG.debug('Ext description: %s',
' '.join(extension.__doc__.strip().split()))
LOG.debug('Ext updated: %s', extension.updated)
except AttributeError as ex:
LOG.exception(_LE("Exception loading extension: %s"), ex)
except AttributeError:
LOG.exception(_LE("Exception loading extension."))
return False
return True

View File

@ -45,10 +45,9 @@ class OVSBridge(object):
full_args = ["ovs-vsctl", "--timeout=2"] + args
try:
return utils.execute(*full_args, run_as_root=True)
except Exception as e:
LOG.error(_LE("Unable to execute %(cmd)s. Exception: "
"%(exception)s"),
{'cmd': full_args, 'exception': e})
except Exception:
LOG.exception(_LE("Unable to execute %(cmd)s."),
{'cmd': full_args})
def reset_bridge(self):
self.run_vsctl(["--", "--if-exists", "del-br", self.br_name])

View File

@ -64,19 +64,18 @@ class SchedulerOptions(object):
"""Get the last modified datetime. Broken out for testing."""
try:
return os.path.getmtime(filename)
except os.error as e:
except os.error:
LOG.exception(_LE("Could not stat scheduler options file "
"%(filename)s: '%(e)s'"),
{"filename": filename, "e": e})
"%(filename)s."),
{"filename": filename})
raise
def _load_file(self, handle):
"""Decode the JSON file. Broken out for testing."""
try:
return jsonutils.load(handle)
except ValueError as e:
LOG.exception(_LE("Could not decode scheduler options: "
"'%(e)s'"), {"e": e})
except ValueError:
LOG.exception(_LE("Could not decode scheduler options."))
return {}
def _get_time_now(self):

View File

@ -18,7 +18,7 @@ import uuid
from oslo_log import log
from manila import exception
from manila.i18n import _, _LI
from manila.i18n import _, _LE, _LI
from manila.share import driver
@ -93,8 +93,8 @@ class DockerExecHelper(driver.ExecuteMixin):
LOG.debug("Executing command: %s.", " ".join(cmd))
try:
result = self._execute(*cmd, run_as_root=True)
except Exception as e:
LOG.exception(e)
except Exception:
LOG.exception(_LE("Executing command failed."))
return None
LOG.debug("Execution result: %s.", result)
return result

View File

@ -114,10 +114,10 @@ class UnityStorageConnection(driver.StorageConnection):
try:
nas_server = self.client.get_nas_server(server_name)
except storops_ex.UnityResourceNotFoundError:
message = (_LE("Failed to get NAS server %(server)s when "
"creating the share %(share)s.") %
message = (_("Failed to get NAS server %(server)s when "
"creating the share %(share)s.") %
{'server': server_name, 'share': share_name})
LOG.error(message)
LOG.exception(message)
raise exception.EMCUnityError(err=message)
locations = None
@ -154,10 +154,10 @@ class UnityStorageConnection(driver.StorageConnection):
try:
nas_server = self.client.get_nas_server(server_name)
except storops_ex.UnityResourceNotFoundError:
message = (_LE("Failed to get NAS server %(server)s when "
"creating the share %(share)s.") %
message = (_("Failed to get NAS server %(server)s when "
"creating the share %(share)s.") %
{'server': server_name, 'share': share_name})
LOG.error(message)
LOG.exception(message)
raise exception.EMCUnityError(err=message)
backend_snap = self.client.create_snap_of_snap(snapshot['id'],
@ -324,7 +324,7 @@ class UnityStorageConnection(driver.StorageConnection):
stats_dict['pools'].append(pool_stat)
if not stats_dict.get('pools'):
message = _LE("Failed to update storage pool.")
message = _("Failed to update storage pool.")
LOG.error(message)
raise exception.EMCUnityError(err=message)
@ -355,9 +355,9 @@ class UnityStorageConnection(driver.StorageConnection):
return {'share_server_name': server_name}
except Exception as ex:
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(_LE('Could not setup server. Reason: %s.'), ex)
LOG.exception(_LE('Could not setup server.'))
server_details = {'share_server_name': server_name}
self.teardown_server(
server_details, network_info['security_services'])
@ -397,18 +397,18 @@ class UnityStorageConnection(driver.StorageConnection):
try:
self.nas_server_pool = self.client.get_pool(pool_name)
except storops_ex.UnityResourceNotFoundError:
message = (_LE("The storage pools %s to store NAS server "
"configuration do not exist.") % pool_name)
LOG.error(message)
message = (_("The storage pools %s to store NAS server "
"configuration do not exist.") % pool_name)
LOG.exception(message)
raise exception.BadConfigurationException(reason=message)
def _config_sp(self, sp_name):
self.storage_processor = self.client.get_storage_processor(
sp_name.lower())
if self.storage_processor is None:
message = (_LE("The storage processor %s does not exist or "
"is unavailable. Please reconfigure it in "
"manila.conf.") % sp_name)
message = (_("The storage processor %s does not exist or "
"is unavailable. Please reconfigure it in "
"manila.conf.") % sp_name)
LOG.error(message)
raise exception.BadConfigurationException(reason=message)
@ -547,7 +547,7 @@ class UnityStorageConnection(driver.StorageConnection):
'backend_details', {}).get('share_server_name')
if server_name is None:
msg = (_LE("Name of the share server %s not found.")
msg = (_("Name of the share server %s not found.")
% share_server['id'])
LOG.error(msg)
raise exception.InvalidInput(reason=msg)

View File

@ -691,9 +691,9 @@ class VNXStorageConnection(driver.StorageConnection):
'nfs_if': nfs_interface['ip'],
}
except Exception as ex:
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(_LE('Could not setup server. Reason: %s.'), ex)
LOG.exception(_LE('Could not setup server.'))
server_details = self._construct_backend_details(
vdm_name, allocated_interfaces)
self.teardown_server(

View File

@ -152,12 +152,10 @@ class SSHConnector(object):
self.log_request(command, out, err)
return out, err
except processutils.ProcessExecutionError as e:
except processutils.ProcessExecutionError:
with excutils.save_and_reraise_exception():
msg = (_LE('Error running SSH command: %(cmd)s. '
'Error: %(excmsg)s.'),
{'cmd': command, 'excmsg': six.text_type(e)})
LOG.error(msg)
LOG.exception(_LE('Error running SSH command: %(cmd)s.'),
{'cmd': command})
def log_request(self, cmd, out, err):
if not self.debug:

View File

@ -439,12 +439,11 @@ class FileSystem(StorageObject):
try:
self._execute_cmd(copy_ckpt_cmd, check_exit_code=True)
except processutils.ProcessExecutionError as e:
LOG.error(_LE("Failed to copy content from snapshot %(snap)s to "
"file system %(filesystem)s. Reason: %(err)s."),
{'snap': snap_name,
'filesystem': name,
'err': e})
except processutils.ProcessExecutionError:
LOG.exception(_LE("Failed to copy content from snapshot %(snap)s "
"to file system %(filesystem)s."),
{'snap': snap_name,
'filesystem': name})
# When an error happens during nas_copy, we need to continue
# deleting the checkpoint of the target file system if it exists.

View File

@ -82,8 +82,8 @@ class GlusterfsDirectoryMappedLayout(layout.GlusterfsShareLayoutBase):
except exception.GlusterfsException:
if (self.gluster_manager.
get_vol_option('features.quota')) != 'on':
LOG.error(_LE("Error in tuning GlusterFS volume to enable "
"creation of shares of specific size."))
LOG.exception(_LE("Error in tuning GlusterFS volume to enable "
"creation of shares of specific size."))
raise
self._ensure_gluster_vol_mounted()
@ -106,8 +106,8 @@ class GlusterfsDirectoryMappedLayout(layout.GlusterfsShareLayoutBase):
self.gluster_manager.export, mount_path,
ensure=True)
except exception.GlusterfsException:
LOG.error(_LE('Could not mount the Gluster volume %s'),
self.gluster_manager.volume)
LOG.exception(_LE('Could not mount the Gluster volume %s'),
self.gluster_manager.volume)
raise
def _get_local_share_path(self, share):
@ -182,7 +182,7 @@ class GlusterfsDirectoryMappedLayout(layout.GlusterfsShareLayoutBase):
try:
self.driver._execute(*cmd, run_as_root=True)
except exception.ProcessExecutionError:
LOG.error(_LE('Unable to delete share %s'), share['name'])
LOG.exception(_LE('Unable to delete share %s'), share['name'])
raise
def ensure_share(self, context, share, share_server=None):

View File

@ -378,10 +378,9 @@ class CIFSHelperIPAccess(NASHelperBase):
# Share does not exist, create it
try:
self._ssh_exec(server, create_cmd)
except Exception as child_e:
except Exception:
msg = _("Could not create CIFS export %s.") % share_name
LOG.exception(child_e)
LOG.error(msg)
LOG.exception(msg)
raise exception.ManilaException(reason=msg)
else:
# Share exists
@ -390,10 +389,9 @@ class CIFSHelperIPAccess(NASHelperBase):
server, ['sudo', 'net', 'conf', 'delshare', share_name, ])
try:
self._ssh_exec(server, create_cmd)
except Exception as e:
except Exception:
msg = _("Could not create CIFS export %s.") % share_name
LOG.exception(e)
LOG.error(msg)
LOG.exception(msg)
raise exception.ManilaException(reason=msg)
else:
msg = _('Share section %s already defined.') % share_name

View File

@ -26,7 +26,7 @@ import six
from manila.data import utils as data_utils
from manila import exception
from manila import utils
from manila.i18n import _, _LI, _LW, _LE
from manila.i18n import _, _LE, _LI, _LW
hpe3parclient = importutils.try_import("hpe3parclient")
if hpe3parclient:
@ -1210,11 +1210,10 @@ class HPE3ParMediator(object):
# Try to reclaim the space
try:
self._client.startfsnapclean(fpg, reclaimStrategy='maxspeed')
except Exception as e:
except Exception:
# Remove already happened so only log this.
msg = (_('Unexpected exception calling startfsnapclean for FPG '
'%(fpg)s: %(e)s') % {'fpg': fpg, 'e': six.text_type(e)})
LOG.exception(msg)
LOG.exception(_LE('Unexpected exception calling startfsnapclean '
'for FPG %(fpg)s.'), {'fpg': fpg})
@staticmethod
def _validate_access_type(protocol, access_type):
@ -1655,8 +1654,7 @@ class HPE3ParMediator(object):
try:
result = self._client.getfsip(vfs, fpg=fpg)
LOG.debug("getfsip result: %s", result)
except Exception as e:
LOG.exception(e)
except Exception:
msg = (_('Failed to get FSIPs for FPG/VFS %(fspool)s/%(vfs)s.') %
fsip)
LOG.exception(msg)
@ -1681,8 +1679,7 @@ class HPE3ParMediator(object):
vlantag=vlantag_str)
LOG.debug("createfsip result: %s", result)
except Exception as e:
LOG.exception(e)
except Exception:
msg = (_('Failed to create FSIP for %s') % ip)
LOG.exception(msg)
raise exception.ShareBackendException(msg=msg)
@ -1713,8 +1710,7 @@ class HPE3ParMediator(object):
result = self._client.removefsip(vfs, ip, fpg=fpg)
LOG.debug("removefsip result: %s", result)
except Exception as e:
LOG.exception(e)
except Exception:
msg = (_('Failed to remove FSIP %s') % ip)
LOG.exception(msg)
raise exception.ShareBackendException(msg=msg)

View File

@ -87,9 +87,9 @@ class NetAppBaseClient(object):
def get_licenses(self):
try:
result = self.send_request('license-v2-list-info')
except netapp_api.NaApiError as e:
except netapp_api.NaApiError:
with excutils.save_and_reraise_exception():
LOG.error(_LE("Could not get licenses list. %s."), e)
LOG.exception(_LE("Could not get licenses list."))
return sorted(
[l.get_child_content('package').lower()

View File

@ -28,7 +28,7 @@ import six
from manila.common import constants
from manila import exception
from manila.i18n import _, _LI, _LW
from manila.i18n import _, _LE, _LI, _LW
from manila.share import driver
from manila.share.drivers.ganesha import utils as ganesha_utils
from manila import utils
@ -214,9 +214,8 @@ class NFSviaZFSHelper(ExecuteMixin, NASHelperBase):
msg=_("Utility 'exportfs' is not installed."))
try:
self.execute('sudo', 'exportfs')
except exception.ProcessExecutionError as e:
msg = _("Call of 'exportfs' utility returned error: %s")
LOG.exception(msg, e)
except exception.ProcessExecutionError:
LOG.exception(_LE("Call of 'exportfs' utility returned error."))
raise
# Init that class instance attribute on start of manila-share service

View File

@ -243,10 +243,10 @@ class ShareManager(manager.SchedulerDependentManager):
# knowledge and update the DB.
try:
pool = self.driver.get_pool(share_instance)
except Exception as err:
LOG.error(_LE("Failed to fetch pool name for share: "
"%(share)s. Error: %(error)s."),
{'share': share_instance['id'], 'error': err})
except Exception:
LOG.exception(_LE("Failed to fetch pool name for share: "
"%(share)s."),
{'share': share_instance['id']})
return
if pool:
@ -269,13 +269,12 @@ class ShareManager(manager.SchedulerDependentManager):
try:
self.driver.do_setup(ctxt)
self.driver.check_for_setup_error()
except Exception as e:
except Exception:
LOG.exception(
_LE("Error encountered during initialization of driver "
"'%(name)s' on '%(host)s' host. %(exc)s"), {
"'%(name)s' on '%(host)s' host."), {
"name": self.driver.__class__.__name__,
"host": self.host,
"exc": e,
}
)
self.driver.initialized = False
@ -321,12 +320,10 @@ class ShareManager(manager.SchedulerDependentManager):
try:
export_locations = self.driver.ensure_share(
ctxt, share_instance, share_server=share_server)
except Exception as e:
LOG.error(
_LE("Caught exception trying ensure share '%(s_id)s'. "
"Exception: \n%(e)s."),
{'s_id': share_instance['id'], 'e': e},
)
except Exception:
LOG.exception(_LE("Caught exception trying ensure "
"share '%(s_id)s'."), {'s_id':
share_instance['id']})
continue
if export_locations:
@ -339,12 +336,11 @@ class ShareManager(manager.SchedulerDependentManager):
try:
self.access_helper.update_access_rules(
ctxt, share_instance['id'], share_server=share_server)
except Exception as e:
LOG.error(
except Exception:
LOG.exception(
_LE("Unexpected error occurred while updating access "
"rules for share instance %(s_id)s. "
"Exception: \n%(e)s."),
{'s_id': share_instance['id'], 'e': e},
"rules for share instance %(s_id)s."),
{'s_id': share_instance['id']},
)
self.publish_service_capabilities(ctxt)

View File

@ -54,8 +54,8 @@ def create(context, name, extra_specs=None, is_public=True, projects=None):
extra_specs=extra_specs,
is_public=is_public),
projects=projects)
except db_exception.DBError as e:
LOG.exception(_LE('DB error: %s'), e)
except db_exception.DBError:
LOG.exception(_LE('DB error.'))
raise exception.ShareTypeCreateFailed(name=name,
extra_specs=extra_specs)
return type_ref
@ -87,11 +87,9 @@ def get_all_types(context, inactive=0, search_opts=None):
try:
required_extra_specs = get_valid_required_extra_specs(
type_args['extra_specs'])
except exception.InvalidExtraSpec as e:
except exception.InvalidExtraSpec:
LOG.exception(_LE('Share type %(share_type)s has invalid required'
' extra specs: %(error)s'),
{'share_type': type_name,
'error': e})
' extra specs.'), {'share_type': type_name})
type_args['required_extra_specs'] = required_extra_specs

View File

@ -113,7 +113,7 @@ class GlusterfsDirectoryMappedLayoutTestCase(test.TestCase):
'gluster_call.side_effect': exception.GlusterfsException,
'get_vol_option.return_value': 'off'}
fake_gluster_manager = mock.Mock(**attrs)
self.mock_object(layout_directory.LOG, 'error')
self.mock_object(layout_directory.LOG, 'exception')
methods = ('_check_mount_glusterfs', '_ensure_gluster_vol_mounted')
for method in methods:
self.mock_object(self._layout, method)
@ -133,7 +133,7 @@ class GlusterfsDirectoryMappedLayoutTestCase(test.TestCase):
'volume', 'quota', 'testvol', 'enable')
(self._layout.gluster_manager.get_vol_option.
assert_called_once_with('features.quota'))
layout_directory.LOG.error.assert_called_once_with(mock.ANY)
layout_directory.LOG.exception.assert_called_once_with(mock.ANY)
self._layout._check_mount_glusterfs.assert_called_once_with()
self.assertFalse(self._layout._ensure_gluster_vol_mounted.called)

View File

@ -34,6 +34,9 @@ class NetAppBaseClientTestCase(test.TestCase):
self.mock_object(client_base.LOG,
'error',
mock.Mock(side_effect=mock_logger.error))
self.mock_object(client_base.LOG,
'exception',
mock.Mock(side_effect=mock_logger.error))
self.client = client_base.NetAppBaseClient(**fake.CONNECTION_INFO)
self.client.connection = mock.MagicMock()
@ -133,7 +136,7 @@ class NetAppBaseClientTestCase(test.TestCase):
mock.Mock(side_effect=netapp_api.NaApiError))
self.assertRaises(netapp_api.NaApiError, self.client.get_licenses)
self.assertEqual(1, client_base.LOG.error.call_count)
self.assertEqual(1, client_base.LOG.exception.call_count)
def test_send_ems_log_message(self):

View File

@ -236,8 +236,7 @@ class ShareManagerTestCase(test.TestCase):
manager.LOG.exception.assert_called_once_with(
mock.ANY, {'name': self.share_manager.driver.__class__.__name__,
'host': self.share_manager.host,
'exc': mock.ANY})
'host': self.share_manager.host})
self.assertFalse(self.share_manager.driver.initialized)
def _setup_init_mocks(self, setup_access_rules=True):
@ -425,7 +424,7 @@ class ShareManagerTestCase(test.TestCase):
self.mock_object(smanager, '_get_share_server',
mock.Mock(return_value=share_server))
self.mock_object(smanager, 'publish_service_capabilities')
self.mock_object(manager.LOG, 'error')
self.mock_object(manager.LOG, 'exception')
self.mock_object(manager.LOG, 'info')
self.mock_object(smanager.db, 'share_access_get_all_for_share',
mock.Mock(return_value=rules))
@ -472,7 +471,7 @@ class ShareManagerTestCase(test.TestCase):
mock.call(utils.IsAMatcher(context.RequestContext),
instances[4]['id'], share_server=share_server),
])
manager.LOG.error.assert_has_calls([
manager.LOG.exception.assert_has_calls([
mock.call(mock.ANY, mock.ANY),
])
@ -2778,7 +2777,7 @@ class ShareManagerTestCase(test.TestCase):
with mock.patch.object(manager, 'LOG') as mock_LOG:
self.share_manager._ensure_share_instance_has_pool(
context.get_admin_context(), fake_share)
self.assertEqual(1, mock_LOG.error.call_count)
self.assertEqual(1, mock_LOG.exception.call_count)
def test__form_server_setup_info(self):
def fake_network_allocations_get_for_share_server(*args, **kwargs):