Add flake8-logging-format extension

Automated logging format checking was added to cinder in ussuri
by change I1dedc0b31f78f518c, but it wasn't added to os-brick and
a few infelicities have crept into the code.  Enable the extension
and correct the issues.

To be consistent with cinder, we don't enable G200 ("Logging
statement uses exception in arguments").

Change-Id: I650b92bde5509b654d16301ffe50056e1e5ba579
This commit is contained in:
Brian Rosmaita 2022-08-09 16:08:40 -04:00
parent 871c28f536
commit e768fb5ca6
6 changed files with 24 additions and 19 deletions

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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