diff --git a/os_brick/initiator/connectors/lightos.py b/os_brick/initiator/connectors/lightos.py index f405b5214..ed371607a 100644 --- a/os_brick/initiator/connectors/lightos.py +++ b/os_brick/initiator/connectors/lightos.py @@ -95,7 +95,7 @@ class LightOSConnector(base.BaseLinuxConnector): resp = conn.getresponse() return 'found' if resp.status == http.client.OK else '' except Exception as e: - LOG.debug(f'LIGHTOS: {e}') + LOG.debug('LIGHTOS: %s', e) out = '' return out @@ -124,8 +124,8 @@ class LightOSConnector(base.BaseLinuxConnector): priv_lightos.move_dsc_file(dscfile.name, dest_name) except Exception: LOG.warning( - "LIGHTOS: Failed to create dsc file for connection with" - f" uuid:{uuid}") + "LIGHTOS: Failed to create dsc file for connection with " + "uuid:%s", uuid) raise def dsc_disconnect_volume(self, connection_info): @@ -133,7 +133,7 @@ class LightOSConnector(base.BaseLinuxConnector): try: priv_lightos.delete_dsc_file(self.dsc_file_name(uuid)) except Exception: - LOG.warning("LIGHTOS: Failed delete dsc file uuid:{}".format(uuid)) + LOG.warning("LIGHTOS: Failed delete dsc file uuid:%s", uuid) raise def monitor_db(self, lightos_db): @@ -231,7 +231,7 @@ class LightOSConnector(base.BaseLinuxConnector): if device: return device except Exception as e: - LOG.debug(f'LIGHTOS: {e}') + LOG.debug('LIGHTOS: %s', e) device = self._check_device_exists_reading_block_class(uuid) if device: return device diff --git a/os_brick/initiator/connectors/nvmeof.py b/os_brick/initiator/connectors/nvmeof.py index fa3b0b433..ada8a3e2a 100644 --- a/os_brick/initiator/connectors/nvmeof.py +++ b/os_brick/initiator/connectors/nvmeof.py @@ -792,7 +792,7 @@ class NVMeOFConnector(base.BaseLinuxConnector): return lines.split('\n')[0] except putils.ProcessExecutionError as e: LOG.warning( - "Process execution error in _get_host_uuid: %s" % str(e)) + "Process execution error in _get_host_uuid: %s", e) return None def _get_system_uuid(self) -> str: @@ -1265,7 +1265,7 @@ class NVMeOFConnector(base.BaseLinuxConnector): 'cat /proc/mdstat | grep ' + device_name + ' | awk \'{print $1;}\'') cmd = ['bash', '-c', get_md_cmd] - LOG.debug("[!] cmd = " + str(cmd)) + LOG.debug("[!] cmd = %s", cmd) cmd_output = None try: @@ -1282,7 +1282,7 @@ class NVMeOFConnector(base.BaseLinuxConnector): return cmd_output except putils.ProcessExecutionError as ex: - LOG.warning("[!] Could not run cmd: %s", str(ex)) + LOG.warning("[!] Could not run cmd: %s", ex) return None def stop_and_assemble_raid(self, @@ -1303,8 +1303,9 @@ class NVMeOFConnector(base.BaseLinuxConnector): if md_name and md_name == link: return LOG.debug( - "sleeping 1 sec -allow auto assemble link = " + - link + " md path = " + md_path) + "sleeping 1 sec -allow auto assemble link = %(link)s " + "md path = %(md_path)s", + {'link': link, 'md_path': md_path}) time.sleep(1) if md_name and md_name != link: @@ -1366,7 +1367,7 @@ class NVMeOFConnector(base.BaseLinuxConnector): for i in range(len(drives)): cmd.append(drives[i]) - LOG.debug('[!] cmd = ' + str(cmd)) + LOG.debug('[!] cmd = %s', cmd) self.run_mdadm(cmd) # sometimes under load, md is not created right away so we wait for i in range(60): @@ -1405,20 +1406,20 @@ class NVMeOFConnector(base.BaseLinuxConnector): md_path: str, raise_exception: bool = False) -> Optional[str]: cmd = ['mdadm', '--stop', md_path] - LOG.debug("[!] cmd = " + str(cmd)) + LOG.debug("[!] cmd = %s", cmd) cmd_out = self.run_mdadm(cmd, raise_exception) return cmd_out def is_raid_exists(self, device_path: str) -> bool: cmd = ['mdadm', '--detail', device_path] - LOG.debug("[!] cmd = " + str(cmd)) + LOG.debug("[!] cmd = %s", cmd) raid_expected = device_path + ':' try: lines, err = self._execute( *cmd, run_as_root=True, root_helper=self._root_helper) for line in lines.split('\n'): - LOG.debug("[!] line = " + line) + LOG.debug("[!] line = %s", line) if line == raid_expected: return True else: @@ -1429,7 +1430,7 @@ class NVMeOFConnector(base.BaseLinuxConnector): def remove_raid(self, device_path: str) -> None: cmd = ['mdadm', '--remove', device_path] - LOG.debug("[!] cmd = " + str(cmd)) + LOG.debug("[!] cmd = %s", cmd) self.run_mdadm(cmd) def _is_raid_device(self, device: str) -> bool: @@ -1437,7 +1438,7 @@ class NVMeOFConnector(base.BaseLinuxConnector): def _get_fs_type(self, device_path: str) -> Optional[str]: cmd = ['blkid', device_path, '-s', 'TYPE', '-o', 'value'] - LOG.debug("[!] cmd = " + str(cmd)) + LOG.debug("[!] cmd = %s", cmd) fs_type = None # We don't care about errors, on error lines will be '' so it's ok diff --git a/os_brick/initiator/linuxfc.py b/os_brick/initiator/linuxfc.py index d7c809441..975ff8c00 100644 --- a/os_brick/initiator/linuxfc.py +++ b/os_brick/initiator/linuxfc.py @@ -157,7 +157,8 @@ class LinuxFibreChannel(linuxscsi.LinuxSCSI): hba[attribute] = f.read().strip() hbas.append(hba) except Exception as exc: - LOG.warning(f'Could not read attributes for {hostpath}: {exc}') + LOG.warning('Could not read attributes for %(hp)s: %(exc)s', + {'hp': hostpath, 'exc': exc}) return hbas def get_fc_hbas_info(self): diff --git a/os_brick/privileged/nvmeof.py b/os_brick/privileged/nvmeof.py index 05af268e0..6ddc38629 100644 --- a/os_brick/privileged/nvmeof.py +++ b/os_brick/privileged/nvmeof.py @@ -68,6 +68,6 @@ def create_hostnqn(): f.write(host_nqn) os.chmod('/etc/nvme/hostnqn', 0o644) except Exception as e: - LOG.warning("Could not generate host nqn: %s" % str(e)) + LOG.warning("Could not generate host nqn: %s", e) return host_nqn diff --git a/test-requirements.txt b/test-requirements.txt index 626c405e9..a7e2c3064 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -4,6 +4,7 @@ hacking>=4.0.0,<4.1.0 # Apache-2.0 flake8-import-order # LGPLv3 +flake8-logging-format>=0.6.0 # Apache-2.0 coverage>=5.5 # Apache-2.0 ddt>=1.4.1 # MIT oslotest>=4.5.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index 470604f85..5d2323eca 100644 --- a/tox.ini +++ b/tox.ini @@ -111,9 +111,11 @@ commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasen # tools from getting in our way with regards to this. # H101 include name with TODO # reason: no real benefit +# G200 Logging statements should not include the exception +# reason: Many existing cases of this that may be legitimate # show-source = True -ignore = E251,W503,W504,H101 +ignore = E251,W503,W504,H101,G200 enable-extensions=H106,H203,H204,H205 builtins = _ exclude=.venv,.git,.tox,dist,*lib/python*,*egg,build