Fix log/error message formatting

- Use '%' for variable substitution in the message used for logging a
  call and throwing an exception.

- Use log marker functions(_LI(), _LW(), _LE(), and _LC()) to send
  message directly to the log.

- Use ',' for variable subsitution in the message in a log marker
  function.

Change-Id: Ib925014e79d2c380954d952f5dbc835971a0b320
Closes-Bug: #1439762
This commit is contained in:
Ramana Raja 2015-04-07 18:38:07 +05:30
parent 0ab34e42b2
commit a992aa0013
4 changed files with 40 additions and 40 deletions

View File

@ -311,7 +311,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
'volume', 'stop', gluster_mgr.volume, '--mode=script') 'volume', 'stop', gluster_mgr.volume, '--mode=script')
except exception.ProcessExecutionError as exc: except exception.ProcessExecutionError as exc:
msg = (_("Error stopping gluster volume. " msg = (_("Error stopping gluster volume. "
"Volume: %(volname)s, Error: %(error)s"), "Volume: %(volname)s, Error: %(error)s") %
{'volname': gluster_mgr.volume, 'error': exc.stderr}) {'volname': gluster_mgr.volume, 'error': exc.stderr})
LOG.error(msg) LOG.error(msg)
raise exception.GlusterfsException(msg) raise exception.GlusterfsException(msg)
@ -321,7 +321,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
'volume', 'start', gluster_mgr.volume) 'volume', 'start', gluster_mgr.volume)
except exception.ProcessExecutionError as exc: except exception.ProcessExecutionError as exc:
msg = (_("Error starting gluster volume. " msg = (_("Error starting gluster volume. "
"Volume: %(volname)s, Error: %(error)s"), "Volume: %(volname)s, Error: %(error)s") %
{'volname': gluster_mgr.volume, 'error': exc.stderr}) {'volname': gluster_mgr.volume, 'error': exc.stderr})
LOG.error(msg) LOG.error(msg)
raise exception.GlusterfsException(msg) raise exception.GlusterfsException(msg)
@ -423,7 +423,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
self._execute(*cmd, run_as_root=True) self._execute(*cmd, run_as_root=True)
except exception.ProcessExecutionError as exc: except exception.ProcessExecutionError as exc:
msg = (_("Unable to mount gluster volume. " msg = (_("Unable to mount gluster volume. "
"gluster_export: %(export)s, Error: %(error)s"), "gluster_export: %(export)s, Error: %(error)s") %
{'export': gluster_export, 'error': exc.stderr}) {'export': gluster_export, 'error': exc.stderr})
LOG.error(msg) LOG.error(msg)
raise exception.GlusterfsException(msg) raise exception.GlusterfsException(msg)
@ -435,7 +435,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
self._execute(*cmd, run_as_root=True) self._execute(*cmd, run_as_root=True)
except exception.ProcessExecutionError as exc: except exception.ProcessExecutionError as exc:
msg = (_("Unable to unmount gluster volume. " msg = (_("Unable to unmount gluster volume. "
"mount_dir: %(mntdir)s, Error: %(error)s"), "mount_dir: %(mntdir)s, Error: %(error)s") %
{'mntdir': mntdir, 'error': exc.stderr}) {'mntdir': mntdir, 'error': exc.stderr})
LOG.error(msg) LOG.error(msg)
raise exception.GlusterfsException(msg) raise exception.GlusterfsException(msg)
@ -450,7 +450,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
except exception.ProcessExecutionError as exc: except exception.ProcessExecutionError as exc:
msg = (_("Error in gluster volume set during _wipe_gluster_vol. " msg = (_("Error in gluster volume set during _wipe_gluster_vol. "
"Volume: %(volname)s, Option: %(option)s, " "Volume: %(volname)s, Option: %(option)s, "
"Error: %(error)s"), "Error: %(error)s") %
{'volname': gluster_mgr.volume, {'volname': gluster_mgr.volume,
'option': CLIENT_SSL, 'error': exc.stderr}) 'option': CLIENT_SSL, 'error': exc.stderr})
LOG.error(msg) LOG.error(msg)
@ -463,7 +463,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
except exception.ProcessExecutionError as exc: except exception.ProcessExecutionError as exc:
msg = (_("Error in gluster volume set during _wipe_gluster_vol. " msg = (_("Error in gluster volume set during _wipe_gluster_vol. "
"Volume: %(volname)s, Option: %(option)s, " "Volume: %(volname)s, Option: %(option)s, "
"Error: %(error)s"), "Error: %(error)s") %
{'volname': gluster_mgr.volume, {'volname': gluster_mgr.volume,
'option': SERVER_SSL, 'error': exc.stderr}) 'option': SERVER_SSL, 'error': exc.stderr})
LOG.error(msg) LOG.error(msg)
@ -486,7 +486,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
self._execute(*cmd, run_as_root=True) self._execute(*cmd, run_as_root=True)
except exception.ProcessExecutionError as exc: except exception.ProcessExecutionError as exc:
msg = (_("Error trying to wipe gluster volume. " msg = (_("Error trying to wipe gluster volume. "
"gluster_export: %(export)s, Error: %(error)s"), "gluster_export: %(export)s, Error: %(error)s") %
{'export': gluster_export, 'error': exc.stderr}) {'export': gluster_export, 'error': exc.stderr})
LOG.error(msg) LOG.error(msg)
raise exception.GlusterfsException(msg) raise exception.GlusterfsException(msg)
@ -503,7 +503,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
except exception.ProcessExecutionError as exc: except exception.ProcessExecutionError as exc:
msg = (_("Error in gluster volume set during _wipe_gluster_vol. " msg = (_("Error in gluster volume set during _wipe_gluster_vol. "
"Volume: %(volname)s, Option: %(option)s, " "Volume: %(volname)s, Option: %(option)s, "
"Error: %(error)s"), "Error: %(error)s") %
{'volname': gluster_mgr.volume, {'volname': gluster_mgr.volume,
'option': CLIENT_SSL, 'error': exc.stderr}) 'option': CLIENT_SSL, 'error': exc.stderr})
LOG.error(msg) LOG.error(msg)
@ -516,7 +516,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
except exception.ProcessExecutionError as exc: except exception.ProcessExecutionError as exc:
msg = (_("Error in gluster volume set during _wipe_gluster_vol. " msg = (_("Error in gluster volume set during _wipe_gluster_vol. "
"Volume: %(volname)s, Option: %(option)s, " "Volume: %(volname)s, Option: %(option)s, "
"Error: %(error)s"), "Error: %(error)s") %
{'volname': gluster_mgr.volume, {'volname': gluster_mgr.volume,
'option': SERVER_SSL, 'error': exc.stderr}) 'option': SERVER_SSL, 'error': exc.stderr})
LOG.error(msg) LOG.error(msg)
@ -536,7 +536,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
try: try:
export_location = self._pop_gluster_vol(share['size']) export_location = self._pop_gluster_vol(share['size'])
except exception.GlusterfsException: except exception.GlusterfsException:
msg = (_("Error creating share %(share_id)s"), msg = (_LE("Error creating share %(share_id)s"),
{'share_id': share['id']}) {'share_id': share['id']})
LOG.error(msg) LOG.error(msg)
raise raise
@ -560,8 +560,8 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
# Get the gluster address associated with the export. # Get the gluster address associated with the export.
gmgr = self.gluster_used_vols_dict[exp_locn] gmgr = self.gluster_used_vols_dict[exp_locn]
except KeyError: except KeyError:
msg = (_("Invalid request. Ignoring delete_share request for " msg = (_LW("Invalid request. Ignoring delete_share request for "
"share %(share_id)s"), {'share_id': share['id']},) "share %(share_id)s"), {'share_id': share['id']})
LOG.warn(msg) LOG.warn(msg)
return return
@ -569,8 +569,8 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
self._wipe_gluster_vol(gmgr) self._wipe_gluster_vol(gmgr)
self._push_gluster_vol(exp_locn) self._push_gluster_vol(exp_locn)
except exception.GlusterfsException: except exception.GlusterfsException:
msg = (_("Error during delete_share request for " msg = (_LE("Error during delete_share request for "
"share %(share_id)s"), {'share_id': share['id']},) "share %(share_id)s"), {'share_id': share['id']})
LOG.error(msg) LOG.error(msg)
raise raise
@ -692,7 +692,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
except exception.ProcessExecutionError as exc: except exception.ProcessExecutionError as exc:
msg = (_("Error in gluster volume set during allow access. " msg = (_("Error in gluster volume set during allow access. "
"Volume: %(volname)s, Option: %(option)s, " "Volume: %(volname)s, Option: %(option)s, "
"access_to: %(access_to)s, Error: %(error)s"), "access_to: %(access_to)s, Error: %(error)s") %
{'volname': gluster_mgr.volume, {'volname': gluster_mgr.volume,
'option': AUTH_SSL_ALLOW, 'access_to': access_to, 'option': AUTH_SSL_ALLOW, 'access_to': access_to,
'error': exc.stderr}) 'error': exc.stderr})
@ -737,7 +737,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
except exception.ProcessExecutionError as exc: except exception.ProcessExecutionError as exc:
msg = (_("Error in gluster volume set during deny access. " msg = (_("Error in gluster volume set during deny access. "
"Volume: %(volname)s, Option: %(option)s, " "Volume: %(volname)s, Option: %(option)s, "
"access_to: %(access_to)s, Error: %(error)s"), "access_to: %(access_to)s, Error: %(error)s") %
{'volname': gluster_mgr.volume, {'volname': gluster_mgr.volume,
'option': AUTH_SSL_ALLOW, 'access_to': access_to, 'option': AUTH_SSL_ALLOW, 'access_to': access_to,
'error': exc.stderr}) 'error': exc.stderr})

View File

@ -237,8 +237,8 @@ class HuaweiNasDriver(driver.ShareDriver):
raise loopingcall.LoopingCallDone() raise loopingcall.LoopingCallDone()
if int(time.time()) - int(start_time) > int(timeout): if int(time.time()) - int(start_time) > int(timeout):
msg = (_('_wait_for_condition: %s timed out.'), msg = (_('_wait_for_condition: %s timed out.')
func.__name__) % func.__name__)
LOG.error(msg) LOG.error(msg)
raise exception.InvalidShare(data=msg) raise exception.InvalidShare(data=msg)

View File

@ -151,10 +151,10 @@ def parse_ganesha_config(configpath):
if export_count != len(exports): if export_count != len(exports):
msg = (_('Invalid export config file %(configpath)s: ' msg = (_('Invalid export config file %(configpath)s: '
'%(exports)s export clauses found, but ' '%(exports)s export clauses found, but '
'%(export_ids)s export_ids.'), '%(export_ids)s export_ids.')
{"configpath": configpath, % {"configpath": configpath,
"exports": str(export_count), "exports": str(export_count),
"export_ids": str(len(exports))}) "export_ids": str(len(exports))})
LOG.error(msg) LOG.error(msg)
raise exception.GPFSGaneshaException(msg) raise exception.GPFSGaneshaException(msg)
@ -201,7 +201,7 @@ def _convert_ipstring_to_ipn(ipstring):
try: try:
ipns = [netaddr.IPNetwork(ipstring)] ipns = [netaddr.IPNetwork(ipstring)]
except netaddr.AddrFormatError: except netaddr.AddrFormatError:
msg = (_('Invalid IP access string %s.'), ipstring) msg = (_('Invalid IP access string %s.') % ipstring)
LOG.error(msg) LOG.error(msg)
raise exception.GPFSGaneshaException(msg) raise exception.GPFSGaneshaException(msg)
return ipns return ipns
@ -241,7 +241,7 @@ def _publish_local_config(configpath, pre_lines, exports):
utils.execute(*cpcmd, run_as_root=True) utils.execute(*cpcmd, run_as_root=True)
except exception.ProcessExecutionError as e: except exception.ProcessExecutionError as e:
msg = (_('Failed while publishing ganesha config locally. ' msg = (_('Failed while publishing ganesha config locally. '
'Error: %s.'), six.text_type(e)) 'Error: %s.') % six.text_type(e))
LOG.error(msg) LOG.error(msg)
raise exception.GPFSGaneshaException(msg) raise exception.GPFSGaneshaException(msg)
@ -252,7 +252,7 @@ def _publish_local_config(configpath, pre_lines, exports):
utils.execute(*chmodcmd, run_as_root=True) utils.execute(*chmodcmd, run_as_root=True)
except exception.ProcessExecutionError as e: except exception.ProcessExecutionError as e:
msg = (_('Failed while publishing ganesha config locally. ' msg = (_('Failed while publishing ganesha config locally. '
'Error: %s.'), six.text_type(e)) 'Error: %s.') % six.text_type(e))
LOG.error(msg) LOG.error(msg)
raise exception.GPFSGaneshaException(msg) raise exception.GPFSGaneshaException(msg)
@ -270,7 +270,7 @@ def _publish_local_config(configpath, pre_lines, exports):
utils.execute(*mvcmd, run_as_root=True) utils.execute(*mvcmd, run_as_root=True)
except exception.ProcessExecutionError as e: except exception.ProcessExecutionError as e:
msg = (_('Failed while publishing ganesha config locally. ' msg = (_('Failed while publishing ganesha config locally. '
'Error: %s.'), six.text_type(e)) 'Error: %s.') % six.text_type(e))
LOG.error(msg) LOG.error(msg)
raise exception.GPFSGaneshaException(msg) raise exception.GPFSGaneshaException(msg)
LOG.info(_LI('Ganesha config %s published locally.'), configpath) LOG.info(_LI('Ganesha config %s published locally.'), configpath)
@ -283,7 +283,7 @@ def _publish_remote_config(server, sshlogin, sshkey, configpath):
utils.execute(*scpcmd, run_as_root=False) utils.execute(*scpcmd, run_as_root=False)
except exception.ProcessExecutionError as e: except exception.ProcessExecutionError as e:
msg = (_('Failed while publishing ganesha config on remote server. ' msg = (_('Failed while publishing ganesha config on remote server. '
'Error: %s.'), six.text_type(e)) 'Error: %s.') % six.text_type(e))
LOG.error(msg) LOG.error(msg)
raise exception.GPFSGaneshaException(msg) raise exception.GPFSGaneshaException(msg)
LOG.info(_LI('Ganesha config %(path)s published to %(server)s.'), LOG.info(_LI('Ganesha config %(path)s published to %(server)s.'),
@ -333,9 +333,9 @@ def reload_ganesha_config(servers, sshlogin, service='ganesha.nfsd'):
utils.execute(*reload_cmd, run_as_root=run_local) utils.execute(*reload_cmd, run_as_root=run_local)
except exception.ProcessExecutionError as e: except exception.ProcessExecutionError as e:
msg = (_('Could not restart service %(service)s on ' msg = (_('Could not restart service %(service)s on '
'%(server)s: %(excmsg)s'), '%(server)s: %(excmsg)s')
{'service': service, % {'service': service,
'server': server, 'server': server,
'excmsg': six.text_type(e)}) 'excmsg': six.text_type(e)})
LOG.error(msg) LOG.error(msg)
raise exception.GPFSGaneshaException(msg) raise exception.GPFSGaneshaException(msg)

View File

@ -511,25 +511,25 @@ class GPFSShareDriver(driver.ExecuteMixin, driver.GaneshaMixin,
gpfs_base_dir = self.configuration.gpfs_mount_point_base gpfs_base_dir = self.configuration.gpfs_mount_point_base
if not gpfs_base_dir.startswith('/'): if not gpfs_base_dir.startswith('/'):
msg = (_('%s must be an absolute path.'), gpfs_base_dir) msg = (_('%s must be an absolute path.') % gpfs_base_dir)
LOG.error(msg) LOG.error(msg)
raise exception.GPFSException(msg) raise exception.GPFSException(msg)
if not self._is_dir(gpfs_base_dir): if not self._is_dir(gpfs_base_dir):
msg = (_('%s is not a directory.'), gpfs_base_dir) msg = (_('%s is not a directory.') % gpfs_base_dir)
LOG.error(msg) LOG.error(msg)
raise exception.GPFSException(msg) raise exception.GPFSException(msg)
if not self._is_gpfs_path(gpfs_base_dir): if not self._is_gpfs_path(gpfs_base_dir):
msg = (_('%s is not on GPFS. Perhaps GPFS not mounted.'), msg = (_('%s is not on GPFS. Perhaps GPFS not mounted.')
gpfs_base_dir) % gpfs_base_dir)
LOG.error(msg) LOG.error(msg)
raise exception.GPFSException(msg) raise exception.GPFSException(msg)
if self.configuration.gpfs_nfs_server_type not in ['KNFS', 'GNFS']: if self.configuration.gpfs_nfs_server_type not in ['KNFS', 'GNFS']:
msg = (_('Invalid gpfs_nfs_server_type value: %s. ' msg = (_('Invalid gpfs_nfs_server_type value: %s. '
'Valid values are: "KNFS", "GNFS".'), 'Valid values are: "KNFS", "GNFS".')
self.configuration.gpfs_nfs_server_type) % self.configuration.gpfs_nfs_server_type)
LOG.error(msg) LOG.error(msg)
raise exception.InvalidParameterValue(err=msg) raise exception.InvalidParameterValue(err=msg)
@ -559,8 +559,8 @@ class GPFSShareDriver(driver.ExecuteMixin, driver.GaneshaMixin,
if share['share_proto'] == 'NFS': if share['share_proto'] == 'NFS':
return self._helpers[self.configuration.gpfs_nfs_server_type] return self._helpers[self.configuration.gpfs_nfs_server_type]
else: else:
msg = (_('Share protocol %s not supported by GPFS driver.'), msg = (_('Share protocol %s not supported by GPFS driver.')
share['share_proto']) % share['share_proto'])
LOG.error(msg) LOG.error(msg)
raise exception.InvalidShare(reason=msg) raise exception.InvalidShare(reason=msg)
@ -642,7 +642,7 @@ class KNFSHelper(NASHelperBase):
if item['key'] == 'export_options': if item['key'] == 'export_options':
options = item['value'] options = item['value']
else: else:
msg = (_('Unknown metadata key %s.'), item['key']) msg = (_('Unknown metadata key %s.') % item['key'])
LOG.error(msg) LOG.error(msg)
raise exception.InvalidInput(reason=msg) raise exception.InvalidInput(reason=msg)
if not options: if not options: