From: Sean McGinnis Date: Tue, 5 May 2015 20:57:30 +0000 (-0500) Subject: Logging not using oslo.i18n guidelines (zonemgr) X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=98dbadc20af6d07c9ab80795c22a913a990ee063;p=openstack-build%2Fcinder-build.git Logging not using oslo.i18n guidelines (zonemgr) Multi-patch set for easier chunks. This one addresses the zonemanager cinder directory. There have been quite a few instances found where the i18n guidelines are not being followed. I believe this has helped lead to some of the confusion around how to correctly do this. Other developers see this code and assume it is an example of the correct usage. This patch attempts to clean up most of those violations in the existing codebase to hopefully help avoid some of that confusion in reviews. Some issues address: * Correct log translation markers for different log levels * Passing format values as arguments to call, not preformatting * Not forcing translation via six.text_type and others Guidelines can be found here: http://docs.openstack.org/developer/oslo.i18n/guidelines.html Hacking checks will not be able to identify all violations of the guidelines, but it could be useful for catching obvious one such as LOG.info("No markers!"). Change-Id: I992234cdbe3ac8c59d4c6a6c5362b009162ba38a Partial-bug: 1433216 --- diff --git a/cinder/hacking/checks.py b/cinder/hacking/checks.py index 00dde6af2..1b11eba59 100644 --- a/cinder/hacking/checks.py +++ b/cinder/hacking/checks.py @@ -217,8 +217,7 @@ def validate_log_translations(logical_line, filename): ignore_dirs = [ "cinder/db", "cinder/openstack", - "cinder/volume", - "cinder/zonemanager"] + "cinder/volume"] for directory in ignore_dirs: if directory in filename: return diff --git a/cinder/zonemanager/drivers/brocade/brcd_fabric_opts.py b/cinder/zonemanager/drivers/brocade/brcd_fabric_opts.py index ef70ecf9e..d9792d5db 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_fabric_opts.py +++ b/cinder/zonemanager/drivers/brocade/brcd_fabric_opts.py @@ -57,7 +57,7 @@ def load_fabric_configurations(fabric_names): fabric_configs = {} for fabric_name in fabric_names: config = configuration.Configuration(brcd_zone_opts, fabric_name) - LOG.debug("Loaded FC fabric config %s" % fabric_name) + LOG.debug("Loaded FC fabric config %s", fabric_name) fabric_configs[fabric_name] = config return fabric_configs diff --git a/cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py b/cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py index 98cb8cc7c..b5246e279 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py +++ b/cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py @@ -19,6 +19,7 @@ from oslo_log import log as logging from oslo_utils import excutils import paramiko +import six from cinder import exception from cinder.i18n import _, _LE @@ -137,7 +138,7 @@ class BrcdFCSanLookupService(fc_service.FCSanLookupService): except exception.FCSanLookupServiceException: with excutils.save_and_reraise_exception(): LOG.error(_LE("Failed collecting name server info from" - " fabric %s") % fabric_ip) + " fabric %s"), fabric_ip) except Exception as e: msg = _("SSH connection failed " "for %(fabric)s with error: %(err)s" @@ -216,7 +217,7 @@ class BrcdFCSanLookupService(fc_service.FCSanLookupService): switch_data = stdout.readlines() except paramiko.SSHException as e: msg = (_("SSH Command failed with error '%(err)s' " - "'%(command)s'") % {'err': e, + "'%(command)s'") % {'err': six.text_type(e), 'command': cmd}) LOG.error(msg) raise exception.FCSanLookupServiceException(message=msg) diff --git a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py index 52eeef1cd..4705cf463 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py +++ b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py @@ -28,6 +28,7 @@ from eventlet import greenthread from oslo_concurrency import processutils from oslo_log import log as logging from oslo_utils import excutils +import six from cinder import exception from cinder.i18n import _, _LE @@ -103,14 +104,13 @@ class BrcdFCZoneClientCLI(object): zone_member_list.append(zone_member) zone_set[ZoneConstant.CFG_ZONES] = zone zone_set[ZoneConstant.ACTIVE_ZONE_CONFIG] = zone_set_name - except Exception as ex: + except Exception: # Incase of parsing error here, it should be malformed cli output. msg = _("Malformed zone configuration: (switch=%(switch)s " "zone_config=%(zone_config)s)." ) % {'switch': self.switch_ip, 'zone_config': switch_data} - LOG.error(msg) - LOG.exception(ex) + LOG.exception(msg) raise exception.FCZoneDriverException(reason=msg) switch_data = None return zone_set @@ -137,9 +137,9 @@ class BrcdFCZoneClientCLI(object): zone_with_sep = '' if not active_zone_set: active_zone_set = self.get_active_zone_set() - LOG.debug("Active zone set:%s", active_zone_set) + LOG.debug("Active zone set: %s", active_zone_set) zone_list = active_zone_set[ZoneConstant.CFG_ZONES] - LOG.debug("zone list:%s", zone_list) + LOG.debug("zone list: %s", zone_list) for zone in zones.keys(): # if zone exists, its an update. Delete & insert # TODO(skolathur): This can be optimized to an update call later @@ -183,7 +183,7 @@ class BrcdFCZoneClientCLI(object): self._cfg_trans_abort() msg = _("Creating and activating zone set failed: " "(Zone set=%(cfg_name)s error=%(err)s)." - ) % {'cfg_name': cfg_name, 'err': e} + ) % {'cfg_name': cfg_name, 'err': six.text_type(e)} LOG.error(msg) raise exception.BrocadeZoningCliException(reason=msg) @@ -227,7 +227,7 @@ class BrcdFCZoneClientCLI(object): % {'active_zoneset_name': active_zoneset_name, 'zone_names': zone_names } - LOG.debug("Delete zones: Config cmd to run:%s", cmd) + LOG.debug("Delete zones: Config cmd to run: %s", cmd) self.apply_zone_change(cmd.split()) for zone in zones: self._zone_delete(zone) @@ -237,7 +237,7 @@ class BrcdFCZoneClientCLI(object): self._cfg_save() except Exception as e: msg = _("Deleting zones failed: (command=%(cmd)s error=%(err)s)." - ) % {'cmd': cmd, 'err': e} + ) % {'cmd': cmd, 'err': six.text_type(e)} LOG.error(msg) self._cfg_trans_abort() raise exception.BrocadeZoningCliException(reason=msg) @@ -323,7 +323,7 @@ class BrcdFCZoneClientCLI(object): if (stdout): for line in stdout: if 'Fabric OS: v' in line: - LOG.debug("Firmware version string:%s", line) + LOG.debug("Firmware version string: %s", line) ver = line.split('Fabric OS: v')[1].split('.') if (ver): firmware = int(ver[0] + ver[1]) @@ -333,7 +333,7 @@ class BrcdFCZoneClientCLI(object): return False except processutils.ProcessExecutionError as e: msg = _("Error while getting data via ssh: (command=%(cmd)s " - "error=%(err)s).") % {'cmd': cmd, 'err': e} + "error=%(err)s).") % {'cmd': cmd, 'err': six.text_type(e)} LOG.error(msg) raise exception.BrocadeZoningCliException(reason=msg) @@ -347,7 +347,7 @@ class BrcdFCZoneClientCLI(object): except processutils.ProcessExecutionError as e: msg = _("Error while getting data via ssh: (command=%(cmd)s " "error=%(err)s).") % {'cmd': cmd_list, - 'err': e} + 'err': six.text_type(e)} LOG.error(msg) raise exception.BrocadeZoningCliException(reason=msg) @@ -397,7 +397,7 @@ class BrcdFCZoneClientCLI(object): command, check_exit_code=check_exit_code) except Exception as e: - LOG.error(e) + LOG.exception(_LE('Error executing SSH command.')) last_exception = e greenthread.sleep(random.randint(20, 500) / 100.0) try: @@ -414,7 +414,7 @@ class BrcdFCZoneClientCLI(object): cmd=command) except Exception: with excutils.save_and_reraise_exception(): - LOG.error(_LE("Error running SSH command: %s") % command) + LOG.error(_LE("Error running SSH command: %s"), command) def _ssh_execute(self, cmd_list, check_exit_code=True, attempts=1): """Execute cli with status update. @@ -433,7 +433,7 @@ class BrcdFCZoneClientCLI(object): min_size=1, max_size=5) stdin, stdout, stderr = None, None, None - LOG.debug("Executing command via ssh: %s" % command) + LOG.debug("Executing command via ssh: %s", command) last_exception = None try: with self.sshpool.item() as ssh: @@ -444,10 +444,10 @@ class BrcdFCZoneClientCLI(object): stdin.write("%s\n" % ZoneConstant.YES) channel = stdout.channel exit_status = channel.recv_exit_status() - LOG.debug("Exit Status from ssh:%s", exit_status) + LOG.debug("Exit Status from ssh: %s", exit_status) # exit_status == -1 if no exit code was returned if exit_status != -1: - LOG.debug('Result was %s' % exit_status) + LOG.debug('Result was %s', exit_status) if check_exit_code and exit_status != 0: raise processutils.ProcessExecutionError( exit_code=exit_status, @@ -459,11 +459,11 @@ class BrcdFCZoneClientCLI(object): else: return True except Exception as e: - LOG.error(e) + LOG.exception(_LE('Error executing SSH command.')) last_exception = e greenthread.sleep(random.randint(20, 500) / 100.0) LOG.debug("Handling error case after " - "SSH:%s", last_exception) + "SSH: %s", last_exception) try: raise processutils.ProcessExecutionError( exit_code=last_exception.exit_code, @@ -507,7 +507,7 @@ class BrcdFCZoneClientCLI(object): min_size=1, max_size=5) with self.sshpool.item() as ssh: - LOG.debug('Running cmd (SSH): %s' % command) + LOG.debug('Running cmd (SSH): %s', command) channel = ssh.invoke_shell() stdin_stream = channel.makefile('wb') stdout_stream = channel.makefile('rb') @@ -525,10 +525,9 @@ exit exit_status = channel.recv_exit_status() # exit_status == -1 if no exit code was returned if exit_status != -1: - LOG.debug('Result was %s' % exit_status) + LOG.debug('Result was %s', exit_status) if exit_status != 0: - msg = "command %s failed" % command - LOG.debug(msg) + LOG.debug("command %s failed", command) raise processutils.ProcessExecutionError( exit_code=exit_status, stdout=stdout, @@ -536,9 +535,9 @@ exit cmd=command) try: channel.close() - except Exception as e: - LOG.exception(e) - LOG.debug("_execute_cmd: stderr to return:%s" % stderr) + except Exception: + LOG.exception(_LE('Error closing channel.')) + LOG.debug("_execute_cmd: stderr to return: %s", stderr) return (stdout, stderr) def cleanup(self): diff --git a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py index f56e92aa7..696af1f12 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py +++ b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py @@ -35,6 +35,7 @@ from oslo_config import cfg from oslo_log import log as logging from oslo_utils import excutils from oslo_utils import importutils +import six from cinder import exception from cinder.i18n import _, _LE, _LI @@ -120,7 +121,7 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver): :param fabric: Fabric name from cinder.conf file :param initiator_target_map: Mapping of initiator to list of targets """ - LOG.debug("Add connection for Fabric:%s", fabric) + LOG.debug("Add connection for Fabric: %s", fabric) LOG.info(_LI("BrcdFCZoneDriver - Add connection " "for I-T map: %s"), initiator_target_map) zoning_policy = self.configuration.zoning_policy @@ -194,9 +195,9 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver): cli_client.cleanup() except exception.BrocadeZoningCliException as brocade_ex: raise exception.FCZoneDriverException(brocade_ex) - except Exception as e: - LOG.error(e) - msg = _("Failed to add zoning configuration %s") % e + except Exception: + msg = _("Failed to add zoning configuration.") + LOG.exception(msg) raise exception.FCZoneDriverException(msg) LOG.debug("Zones added successfully: %s", zone_map) @@ -211,7 +212,7 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver): :param fabric: Fabric name from cinder.conf file :param initiator_target_map: Mapping of initiator to list of targets """ - LOG.debug("Delete connection for fabric:%s", fabric) + LOG.debug("Delete connection for fabric: %s", fabric) LOG.info(_LI("BrcdFCZoneDriver - Delete connection for I-T map: %s"), initiator_target_map) zoning_policy = self.configuration.zoning_policy @@ -278,7 +279,7 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver): # to it and update zone if filtered list is empty, we # remove that zone. LOG.debug("Zone delete - I mode: " - "filtered targets:%s", filtered_members) + "filtered targets: %s", filtered_members) if filtered_members: filtered_members.append(formatted_initiator) LOG.debug("Filtered zone members to " @@ -309,16 +310,16 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver): '%s%s' % ( zone_name_string, zones_to_delete[i])) else: - zone_name_string = '%s%s%s' % ( - zone_name_string, ';', zones_to_delete[i]) + zone_name_string = '%s;%s' % ( + zone_name_string, zones_to_delete[i]) conn.delete_zones( zone_name_string, zone_activate, cfgmap_from_fabric) conn.cleanup() - except Exception as e: - LOG.error(e) + except Exception: msg = _("Failed to update or delete zoning configuration") + LOG.exception(msg) raise exception.FCZoneDriverException(msg) def get_san_context(self, target_wwn_list): @@ -347,9 +348,9 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver): nsinfo = None try: nsinfo = conn.get_nameserver_info() - LOG.debug("name server info from fabric:%s", nsinfo) + LOG.debug("name server info from fabric: %s", nsinfo) conn.cleanup() - except exception.BrocadeZoningCliException as ex: + except exception.BrocadeZoningCliException: if not conn.is_supported_firmware(): msg = _("Unsupported firmware on switch %s. Make sure " "switch is running firmware v6.4 or higher" @@ -357,11 +358,10 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver): LOG.error(msg) raise exception.FCZoneDriverException(msg) with excutils.save_and_reraise_exception(): - LOG.error(_LE("Error getting name server " - "info: %s"), ex) - except Exception as e: - msg = (_("Failed to get name server info:%s") % e) - LOG.error(msg) + LOG.exception(_LE("Error getting name server info.")) + except Exception: + msg = _("Failed to get name server info.") + LOG.exception(msg) raise exception.FCZoneDriverException(msg) visible_targets = filter( lambda x: x in formatted_target_list, @@ -378,7 +378,7 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver): else: LOG.debug("No targets are in the nameserver for SAN %s", fabric_name) - LOG.debug("Return SAN context output:%s", fabric_map) + LOG.debug("Return SAN context output: %s", fabric_map) return fabric_map def _get_active_zone_set(self, conn): @@ -393,8 +393,8 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver): LOG.error(msg) raise exception.FCZoneDriverException(msg) except Exception as e: - LOG.error(e) - msg = _("Failed to retrieve active zoning configuration %s") % e + msg = (_("Failed to retrieve active zoning configuration %s") + % six.text_type(e)) raise exception.FCZoneDriverException(msg) LOG.debug("Active zone set from fabric: %s", cfgmap) return cfgmap diff --git a/cinder/zonemanager/drivers/cisco/cisco_fc_san_lookup_service.py b/cinder/zonemanager/drivers/cisco/cisco_fc_san_lookup_service.py index ba77a7705..8db7743d2 100644 --- a/cinder/zonemanager/drivers/cisco/cisco_fc_san_lookup_service.py +++ b/cinder/zonemanager/drivers/cisco/cisco_fc_san_lookup_service.py @@ -193,7 +193,7 @@ class CiscoFCSanLookupService(fc_service.FCSanLookupService): stdout, stderr, sw_data = None, None, None try: stdout, stderr = self._run_ssh(cmd_list, True, 1) - LOG.debug("CLI output from ssh - output:%s", stdout) + LOG.debug("CLI output from ssh - output: %s", stdout) if (stdout): sw_data = stdout.splitlines() return sw_data @@ -266,7 +266,7 @@ class CiscoFCSanLookupService(fc_service.FCSanLookupService): cmd=command) except Exception: with excutils.save_and_reraise_exception(): - LOG.error(_LE("Error running SSH command: %s") % command) + LOG.error(_LE("Error running SSH command: %s"), command) def _ssh_execute(self, cmd_list, check_exit_code=True, attempts=1): """Execute cli with status update. @@ -294,7 +294,7 @@ class CiscoFCSanLookupService(fc_service.FCSanLookupService): min_size=1, max_size=5) stdin, stdout, stderr = None, None, None - LOG.debug("Executing command via ssh: %s" % command) + LOG.debug("Executing command via ssh: %s", command) last_exception = None try: with self.sshpool.item() as ssh: @@ -308,7 +308,7 @@ class CiscoFCSanLookupService(fc_service.FCSanLookupService): LOG.debug("Exit Status from ssh:%s", exit_status) # exit_status == -1 if no exit code was returned if exit_status != -1: - LOG.debug('Result was %s' % exit_status) + LOG.debug('Result was %s', exit_status) if check_exit_code and exit_status != 0: raise processutils.ProcessExecutionError( exit_code=exit_status, diff --git a/cinder/zonemanager/drivers/cisco/cisco_fc_zone_client_cli.py b/cinder/zonemanager/drivers/cisco/cisco_fc_zone_client_cli.py index f71e99704..266fc3855 100644 --- a/cinder/zonemanager/drivers/cisco/cisco_fc_zone_client_cli.py +++ b/cinder/zonemanager/drivers/cisco/cisco_fc_zone_client_cli.py @@ -125,7 +125,7 @@ class CiscoFCZoneClientCLI(object): 'zone_config': switch_data} LOG.error(msg) exc_msg = _("Exception: %s") % six.text_type(ex) - LOG.exception(exc_msg) + LOG.error(exc_msg) raise exception.FCZoneDriverException(reason=msg) return zone_set @@ -147,10 +147,10 @@ class CiscoFCZoneClientCLI(object): """ LOG.debug("Add Zones - Zones passed: %s", zones) - LOG.debug("Active zone set:%s", active_zone_set) + LOG.debug("Active zone set: %s", active_zone_set) zone_list = active_zone_set[ZoneConstant.CFG_ZONES] - LOG.debug("zone list:%s", zone_list) - LOG.debug("zone status:%s", zone_status) + LOG.debug("zone list: %s", zone_list) + LOG.debug("zone status: %s", zone_status) cfg_name = active_zone_set[ZoneConstant.ACTIVE_ZONE_CONFIG] @@ -184,7 +184,7 @@ class CiscoFCZoneClientCLI(object): zone_cmds.append(['end']) try: - LOG.debug("Add zones: Config cmd to run:%s", zone_cmds) + LOG.debug("Add zones: Config cmd to run: %s", zone_cmds) self._ssh_execute(zone_cmds, True, 1) if activate: @@ -201,7 +201,7 @@ class CiscoFCZoneClientCLI(object): def activate_zoneset(self, cfgname, fabric_vsan, zone_status): """Method to Activate the zone config. Param cfgname - ZonesetName.""" - LOG.debug("zone status:%s", zone_status) + LOG.debug("zone status: %s", zone_status) cmd_list = [['conf'], ['zoneset', 'activate', 'name', cfgname, 'vsan', @@ -246,7 +246,7 @@ class CiscoFCZoneClientCLI(object): 'zone_status': switch_data} LOG.error(msg) exc_msg = _("Exception: %s") % six.text_type(ex) - LOG.exception(exc_msg) + LOG.error(exc_msg) raise exception.FCZoneDriverException(reason=msg) return zone_status @@ -274,7 +274,7 @@ class CiscoFCZoneClientCLI(object): cmds.append(['end']) - LOG.debug("Delete zones: Config cmd to run:%s", cmds) + LOG.debug("Delete zones: Config cmd to run: %s", cmds) self._ssh_execute(cmds, True, 1) if activate: @@ -321,7 +321,7 @@ class CiscoFCZoneClientCLI(object): stdout, stderr, sw_data = None, None, None try: stdout, stderr = self._run_ssh(cmd_list, True, 1) - LOG.debug("CLI output from ssh - output:%s", stdout) + LOG.debug("CLI output from ssh - output: %s", stdout) if (stdout): sw_data = stdout.splitlines() return sw_data @@ -394,7 +394,7 @@ class CiscoFCZoneClientCLI(object): cmd=command) except Exception: with excutils.save_and_reraise_exception(): - LOG.error(_LE("Error running SSH command: %s") % command) + LOG.error(_LE("Error running SSH command: %s"), command) def _ssh_execute(self, cmd_list, check_exit_code=True, attempts=1): """Execute cli with status update. @@ -422,7 +422,7 @@ class CiscoFCZoneClientCLI(object): min_size=1, max_size=5) stdin, stdout, stderr = None, None, None - LOG.debug("Executing command via ssh: %s" % command) + LOG.debug("Executing command via ssh: %s", command) last_exception = None try: with self.sshpool.item() as ssh: @@ -433,10 +433,10 @@ class CiscoFCZoneClientCLI(object): greenthread.sleep(random.randint(20, 500) / 100.0) channel = stdout.channel exit_status = channel.recv_exit_status() - LOG.debug("Exit Status from ssh:%s", exit_status) + LOG.debug("Exit Status from ssh: %s", exit_status) # exit_status == -1 if no exit code was returned if exit_status != -1: - LOG.debug('Result was %s' % exit_status) + LOG.debug('Result was %s', exit_status) if check_exit_code and exit_status != 0: raise processutils.ProcessExecutionError( exit_code=exit_status, @@ -448,11 +448,10 @@ class CiscoFCZoneClientCLI(object): else: return True except Exception as e: - msg = _("Exception: %s") % six.text_type(e) - LOG.error(msg) + LOG.exception(_LE('Error executing SSH command.')) last_exception = e greenthread.sleep(random.randint(20, 500) / 100.0) - LOG.debug("Handling error case after SSH:%s", last_exception) + LOG.debug("Handling error case after SSH: %s", last_exception) try: raise processutils.ProcessExecutionError( exit_code=last_exception.exit_code, @@ -465,11 +464,9 @@ class CiscoFCZoneClientCLI(object): stdout="", stderr="Error running SSH command", cmd=command) - except Exception as e: + except Exception: with excutils.save_and_reraise_exception(): - msg = (_("Error executing command via ssh: %s") % - six.text_type(e)) - LOG.error(msg) + LOG.exception(_LE("Error executing command via ssh.")) finally: if stdin: stdin.flush() diff --git a/cinder/zonemanager/drivers/cisco/cisco_fc_zone_driver.py b/cinder/zonemanager/drivers/cisco/cisco_fc_zone_driver.py index 2878ce3a5..98d453595 100644 --- a/cinder/zonemanager/drivers/cisco/cisco_fc_zone_driver.py +++ b/cinder/zonemanager/drivers/cisco/cisco_fc_zone_driver.py @@ -122,7 +122,7 @@ class CiscoFCZoneDriver(fc_zone_driver.FCZoneDriver): :param initiator_target_map: Mapping of initiator to list of targets """ - LOG.debug("Add connection for Fabric:%s", fabric) + LOG.debug("Add connection for Fabric: %s", fabric) LOG.info(_LI("CiscoFCZoneDriver - Add connection " "for I-T map: %s"), initiator_target_map) fabric_ip = self.fabric_configs[fabric].safe_get( @@ -219,10 +219,9 @@ class CiscoFCZoneDriver(fc_zone_driver.FCZoneDriver): except exception.CiscoZoningCliException as cisco_ex: msg = _("Exception: %s") % six.text_type(cisco_ex) raise exception.FCZoneDriverException(msg) - except Exception as e: - LOG.error(_LE("Exception: %s") % six.text_type(e)) - msg = (_("Failed to add zoning configuration %s") % - six.text_type(e)) + except Exception: + msg = _("Failed to add zoning configuration.") + LOG.exception(msg) raise exception.FCZoneDriverException(msg) LOG.debug("Zones added successfully: %s", zone_map) else: @@ -239,7 +238,7 @@ class CiscoFCZoneDriver(fc_zone_driver.FCZoneDriver): :param fabric: Fabric name from cinder.conf file :param initiator_target_map: Mapping of initiator to list of targets """ - LOG.debug("Delete connection for fabric:%s", fabric) + LOG.debug("Delete connection for fabric: %s", fabric) LOG.info(_LI("CiscoFCZoneDriver - Delete connection for I-T map: %s"), initiator_target_map) fabric_ip = self.fabric_configs[fabric].safe_get( @@ -319,7 +318,7 @@ class CiscoFCZoneDriver(fc_zone_driver.FCZoneDriver): # We find the filtered list and if it is non-empty, # add initiator to it and update zone if filtered # list is empty, we remove that zone. - LOG.debug("Zone delete - I mode: filtered targets:%s", + LOG.debug("Zone delete - I mode: filtered targets: %s", filtered_members) if filtered_members: filtered_members.append(formatted_initiator) @@ -370,10 +369,9 @@ class CiscoFCZoneDriver(fc_zone_driver.FCZoneDriver): zoning_vsan, cfgmap_from_fabric, statusmap_from_fabric) conn.cleanup() - except Exception as e: - msg = _("Exception: %s") % six.text_type(e) - LOG.error(msg) + except Exception: msg = _("Failed to update or delete zoning configuration") + LOG.exception(msg) raise exception.FCZoneDriverException(msg) LOG.debug("Zones deleted successfully: %s", zone_map) else: @@ -419,16 +417,16 @@ class CiscoFCZoneDriver(fc_zone_driver.FCZoneDriver): password=fabric_pwd, port=fabric_port, vsan=zoning_vsan) nsinfo = conn.get_nameserver_info() - LOG.debug("show fcns database info from fabric:%s", nsinfo) + LOG.debug("show fcns database info from fabric: %s", + nsinfo) conn.cleanup() - except exception.CiscoZoningCliException as ex: + except exception.CiscoZoningCliException: with excutils.save_and_reraise_exception(): - LOG.error(_LE("Error getting show fcns database " - "info: %s"), six.text_type(ex)) - except Exception as e: - msg = (_("Failed to get show fcns database info:%s") % - six.text_type(e)) - LOG.error(msg) + LOG.exception(_LE("Error getting show fcns database " + "info.")) + except Exception: + msg = _("Failed to get show fcns database info.") + LOG.exception(msg) raise exception.FCZoneDriverException(msg) visible_targets = filter( lambda x: x in formatted_target_list, nsinfo) @@ -444,7 +442,7 @@ class CiscoFCZoneDriver(fc_zone_driver.FCZoneDriver): else: LOG.debug("No targets are in the fcns info for SAN %s", fabric_name) - LOG.debug("Return SAN context output:%s", fabric_map) + LOG.debug("Return SAN context output: %s", fabric_map) return fabric_map def get_active_zone_set(self, fabric_ip, @@ -462,10 +460,9 @@ class CiscoFCZoneDriver(fc_zone_driver.FCZoneDriver): password=fabric_pwd, port=fabric_port, vsan=zoning_vsan) cfgmap = conn.get_active_zone_set() conn.cleanup() - except Exception as e: - msg = (_("Failed to access active zoning configuration:%s") % - six.text_type(e)) - LOG.error(msg) + except Exception: + msg = _("Failed to access active zoning configuration.") + LOG.exception(msg) raise exception.FCZoneDriverException(msg) LOG.debug("Active zone set from fabric: %s", cfgmap) return cfgmap @@ -484,10 +481,9 @@ class CiscoFCZoneDriver(fc_zone_driver.FCZoneDriver): password=fabric_pwd, port=fabric_port, vsan=zoning_vsan) statusmap = conn.get_zoning_status() conn.cleanup() - except Exception as e: - msg = (_("Failed to access zoneset status:%s") % - six.text_type(e)) - LOG.error(msg) + except Exception: + msg = _("Failed to access zoneset status:%s") + LOG.exception(msg) raise exception.FCZoneDriverException(msg) LOG.debug("Zoneset status from fabric: %s", statusmap) return statusmap diff --git a/cinder/zonemanager/fc_san_lookup_service.py b/cinder/zonemanager/fc_san_lookup_service.py index 88e078079..bbb2122c1 100644 --- a/cinder/zonemanager/fc_san_lookup_service.py +++ b/cinder/zonemanager/fc_san_lookup_service.py @@ -27,7 +27,7 @@ from oslo_log import log as logging from oslo_utils import importutils from cinder import exception -from cinder.i18n import _ +from cinder.i18n import _, _LE from cinder.volume import configuration as config from cinder.zonemanager import fc_common from cinder.zonemanager import fc_zone_manager @@ -88,6 +88,6 @@ class FCSanLookupService(fc_common.FCCommon): device_map = self.lookup_service.get_device_mapping_from_network( initiator_list, target_list) except Exception as e: - LOG.error(e) + LOG.exception(_LE('Unable to get device mapping from network.')) raise exception.FCSanLookupServiceException(e) return device_map diff --git a/cinder/zonemanager/fc_zone_manager.py b/cinder/zonemanager/fc_zone_manager.py index cdc2d130e..ecbbe235f 100644 --- a/cinder/zonemanager/fc_zone_manager.py +++ b/cinder/zonemanager/fc_zone_manager.py @@ -34,6 +34,7 @@ detach operation. from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils +import six from cinder import exception from cinder.i18n import _, _LI @@ -152,7 +153,7 @@ class ZoneManager(fc_common.FCCommon): except Exception as e: msg = _("Failed adding connection for fabric=%(fabric)s: " "Error: %(err)s") % {'fabric': connected_fabric, - 'err': e} + 'err': six.text_type(e)} LOG.error(msg) raise exception.ZoneManagerException(reason=msg) @@ -199,7 +200,7 @@ class ZoneManager(fc_common.FCCommon): except Exception as e: msg = _("Failed removing connection for fabric=%(fabric)s: " "Error: %(err)s") % {'fabric': connected_fabric, - 'err': e} + 'err': six.text_type(e)} LOG.error(msg) raise exception.ZoneManagerException(reason=msg) diff --git a/cinder/zonemanager/utils.py b/cinder/zonemanager/utils.py index c1f4d6b71..b359b215a 100644 --- a/cinder/zonemanager/utils.py +++ b/cinder/zonemanager/utils.py @@ -76,8 +76,8 @@ def AddFCZone(initialize_connection): def decorator(self, *args, **kwargs): conn_info = initialize_connection(self, *args, **kwargs) if not conn_info: - LOG.warn(_LW("Driver didn't return connection info, " - "can't add zone.")) + LOG.warning(_LW("Driver didn't return connection info, " + "can't add zone.")) return None vol_type = conn_info.get('driver_volume_type', None) @@ -101,8 +101,8 @@ def RemoveFCZone(terminate_connection): def decorator(self, *args, **kwargs): conn_info = terminate_connection(self, *args, **kwargs) if not conn_info: - LOG.warn(_LW("Driver didn't return connection info from " - "terminate_connection call.")) + LOG.warning(_LW("Driver didn't return connection info from " + "terminate_connection call.")) return None vol_type = conn_info.get('driver_volume_type', None)