From a992aa00130a56ce5c0a513553a1fe563b705972 Mon Sep 17 00:00:00 2001 From: Ramana Raja Date: Tue, 7 Apr 2015 18:38:07 +0530 Subject: [PATCH] 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 --- manila/share/drivers/glusterfs_native.py | 32 +++++++++++------------ manila/share/drivers/huawei/huawei_nas.py | 4 +-- manila/share/drivers/ibm/ganesha_utils.py | 26 +++++++++--------- manila/share/drivers/ibm/gpfs.py | 18 ++++++------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/manila/share/drivers/glusterfs_native.py b/manila/share/drivers/glusterfs_native.py index 4d94717b9f..d653813c58 100644 --- a/manila/share/drivers/glusterfs_native.py +++ b/manila/share/drivers/glusterfs_native.py @@ -311,7 +311,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): 'volume', 'stop', gluster_mgr.volume, '--mode=script') except exception.ProcessExecutionError as exc: msg = (_("Error stopping gluster volume. " - "Volume: %(volname)s, Error: %(error)s"), + "Volume: %(volname)s, Error: %(error)s") % {'volname': gluster_mgr.volume, 'error': exc.stderr}) LOG.error(msg) raise exception.GlusterfsException(msg) @@ -321,7 +321,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): 'volume', 'start', gluster_mgr.volume) except exception.ProcessExecutionError as exc: msg = (_("Error starting gluster volume. " - "Volume: %(volname)s, Error: %(error)s"), + "Volume: %(volname)s, Error: %(error)s") % {'volname': gluster_mgr.volume, 'error': exc.stderr}) LOG.error(msg) raise exception.GlusterfsException(msg) @@ -423,7 +423,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): self._execute(*cmd, run_as_root=True) except exception.ProcessExecutionError as exc: 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}) LOG.error(msg) raise exception.GlusterfsException(msg) @@ -435,7 +435,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): self._execute(*cmd, run_as_root=True) except exception.ProcessExecutionError as exc: 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}) LOG.error(msg) raise exception.GlusterfsException(msg) @@ -450,7 +450,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): except exception.ProcessExecutionError as exc: msg = (_("Error in gluster volume set during _wipe_gluster_vol. " "Volume: %(volname)s, Option: %(option)s, " - "Error: %(error)s"), + "Error: %(error)s") % {'volname': gluster_mgr.volume, 'option': CLIENT_SSL, 'error': exc.stderr}) LOG.error(msg) @@ -463,7 +463,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): except exception.ProcessExecutionError as exc: msg = (_("Error in gluster volume set during _wipe_gluster_vol. " "Volume: %(volname)s, Option: %(option)s, " - "Error: %(error)s"), + "Error: %(error)s") % {'volname': gluster_mgr.volume, 'option': SERVER_SSL, 'error': exc.stderr}) LOG.error(msg) @@ -486,7 +486,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): self._execute(*cmd, run_as_root=True) except exception.ProcessExecutionError as exc: 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}) LOG.error(msg) raise exception.GlusterfsException(msg) @@ -503,7 +503,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): except exception.ProcessExecutionError as exc: msg = (_("Error in gluster volume set during _wipe_gluster_vol. " "Volume: %(volname)s, Option: %(option)s, " - "Error: %(error)s"), + "Error: %(error)s") % {'volname': gluster_mgr.volume, 'option': CLIENT_SSL, 'error': exc.stderr}) LOG.error(msg) @@ -516,7 +516,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): except exception.ProcessExecutionError as exc: msg = (_("Error in gluster volume set during _wipe_gluster_vol. " "Volume: %(volname)s, Option: %(option)s, " - "Error: %(error)s"), + "Error: %(error)s") % {'volname': gluster_mgr.volume, 'option': SERVER_SSL, 'error': exc.stderr}) LOG.error(msg) @@ -536,7 +536,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): try: export_location = self._pop_gluster_vol(share['size']) except exception.GlusterfsException: - msg = (_("Error creating share %(share_id)s"), + msg = (_LE("Error creating share %(share_id)s"), {'share_id': share['id']}) LOG.error(msg) raise @@ -560,8 +560,8 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): # Get the gluster address associated with the export. gmgr = self.gluster_used_vols_dict[exp_locn] except KeyError: - msg = (_("Invalid request. Ignoring delete_share request for " - "share %(share_id)s"), {'share_id': share['id']},) + msg = (_LW("Invalid request. Ignoring delete_share request for " + "share %(share_id)s"), {'share_id': share['id']}) LOG.warn(msg) return @@ -569,8 +569,8 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): self._wipe_gluster_vol(gmgr) self._push_gluster_vol(exp_locn) except exception.GlusterfsException: - msg = (_("Error during delete_share request for " - "share %(share_id)s"), {'share_id': share['id']},) + msg = (_LE("Error during delete_share request for " + "share %(share_id)s"), {'share_id': share['id']}) LOG.error(msg) raise @@ -692,7 +692,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): except exception.ProcessExecutionError as exc: msg = (_("Error in gluster volume set during allow access. " "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, 'option': AUTH_SSL_ALLOW, 'access_to': access_to, 'error': exc.stderr}) @@ -737,7 +737,7 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver): except exception.ProcessExecutionError as exc: msg = (_("Error in gluster volume set during deny access. " "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, 'option': AUTH_SSL_ALLOW, 'access_to': access_to, 'error': exc.stderr}) diff --git a/manila/share/drivers/huawei/huawei_nas.py b/manila/share/drivers/huawei/huawei_nas.py index 14642a133c..714b6dfded 100644 --- a/manila/share/drivers/huawei/huawei_nas.py +++ b/manila/share/drivers/huawei/huawei_nas.py @@ -237,8 +237,8 @@ class HuaweiNasDriver(driver.ShareDriver): raise loopingcall.LoopingCallDone() if int(time.time()) - int(start_time) > int(timeout): - msg = (_('_wait_for_condition: %s timed out.'), - func.__name__) + msg = (_('_wait_for_condition: %s timed out.') + % func.__name__) LOG.error(msg) raise exception.InvalidShare(data=msg) diff --git a/manila/share/drivers/ibm/ganesha_utils.py b/manila/share/drivers/ibm/ganesha_utils.py index 7ae6e4b7ee..b11d59b78f 100644 --- a/manila/share/drivers/ibm/ganesha_utils.py +++ b/manila/share/drivers/ibm/ganesha_utils.py @@ -151,10 +151,10 @@ def parse_ganesha_config(configpath): if export_count != len(exports): msg = (_('Invalid export config file %(configpath)s: ' '%(exports)s export clauses found, but ' - '%(export_ids)s export_ids.'), - {"configpath": configpath, - "exports": str(export_count), - "export_ids": str(len(exports))}) + '%(export_ids)s export_ids.') + % {"configpath": configpath, + "exports": str(export_count), + "export_ids": str(len(exports))}) LOG.error(msg) raise exception.GPFSGaneshaException(msg) @@ -201,7 +201,7 @@ def _convert_ipstring_to_ipn(ipstring): try: ipns = [netaddr.IPNetwork(ipstring)] except netaddr.AddrFormatError: - msg = (_('Invalid IP access string %s.'), ipstring) + msg = (_('Invalid IP access string %s.') % ipstring) LOG.error(msg) raise exception.GPFSGaneshaException(msg) return ipns @@ -241,7 +241,7 @@ def _publish_local_config(configpath, pre_lines, exports): utils.execute(*cpcmd, run_as_root=True) except exception.ProcessExecutionError as e: msg = (_('Failed while publishing ganesha config locally. ' - 'Error: %s.'), six.text_type(e)) + 'Error: %s.') % six.text_type(e)) LOG.error(msg) raise exception.GPFSGaneshaException(msg) @@ -252,7 +252,7 @@ def _publish_local_config(configpath, pre_lines, exports): utils.execute(*chmodcmd, run_as_root=True) except exception.ProcessExecutionError as e: msg = (_('Failed while publishing ganesha config locally. ' - 'Error: %s.'), six.text_type(e)) + 'Error: %s.') % six.text_type(e)) LOG.error(msg) raise exception.GPFSGaneshaException(msg) @@ -270,7 +270,7 @@ def _publish_local_config(configpath, pre_lines, exports): utils.execute(*mvcmd, run_as_root=True) except exception.ProcessExecutionError as e: msg = (_('Failed while publishing ganesha config locally. ' - 'Error: %s.'), six.text_type(e)) + 'Error: %s.') % six.text_type(e)) LOG.error(msg) raise exception.GPFSGaneshaException(msg) 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) except exception.ProcessExecutionError as e: msg = (_('Failed while publishing ganesha config on remote server. ' - 'Error: %s.'), six.text_type(e)) + 'Error: %s.') % six.text_type(e)) LOG.error(msg) raise exception.GPFSGaneshaException(msg) 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) except exception.ProcessExecutionError as e: msg = (_('Could not restart service %(service)s on ' - '%(server)s: %(excmsg)s'), - {'service': service, - 'server': server, - 'excmsg': six.text_type(e)}) + '%(server)s: %(excmsg)s') + % {'service': service, + 'server': server, + 'excmsg': six.text_type(e)}) LOG.error(msg) raise exception.GPFSGaneshaException(msg) diff --git a/manila/share/drivers/ibm/gpfs.py b/manila/share/drivers/ibm/gpfs.py index 05574afcc1..afa45e6434 100644 --- a/manila/share/drivers/ibm/gpfs.py +++ b/manila/share/drivers/ibm/gpfs.py @@ -511,25 +511,25 @@ class GPFSShareDriver(driver.ExecuteMixin, driver.GaneshaMixin, gpfs_base_dir = self.configuration.gpfs_mount_point_base 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) raise exception.GPFSException(msg) 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) raise exception.GPFSException(msg) if not self._is_gpfs_path(gpfs_base_dir): - msg = (_('%s is not on GPFS. Perhaps GPFS not mounted.'), - gpfs_base_dir) + msg = (_('%s is not on GPFS. Perhaps GPFS not mounted.') + % gpfs_base_dir) LOG.error(msg) raise exception.GPFSException(msg) if self.configuration.gpfs_nfs_server_type not in ['KNFS', 'GNFS']: msg = (_('Invalid gpfs_nfs_server_type value: %s. ' - 'Valid values are: "KNFS", "GNFS".'), - self.configuration.gpfs_nfs_server_type) + 'Valid values are: "KNFS", "GNFS".') + % self.configuration.gpfs_nfs_server_type) LOG.error(msg) raise exception.InvalidParameterValue(err=msg) @@ -559,8 +559,8 @@ class GPFSShareDriver(driver.ExecuteMixin, driver.GaneshaMixin, if share['share_proto'] == 'NFS': return self._helpers[self.configuration.gpfs_nfs_server_type] else: - msg = (_('Share protocol %s not supported by GPFS driver.'), - share['share_proto']) + msg = (_('Share protocol %s not supported by GPFS driver.') + % share['share_proto']) LOG.error(msg) raise exception.InvalidShare(reason=msg) @@ -642,7 +642,7 @@ class KNFSHelper(NASHelperBase): if item['key'] == 'export_options': options = item['value'] else: - msg = (_('Unknown metadata key %s.'), item['key']) + msg = (_('Unknown metadata key %s.') % item['key']) LOG.error(msg) raise exception.InvalidInput(reason=msg) if not options: