Skip to content

Commit

Permalink
[plugins] Fix Pylint and PEP8 issues - part4
Browse files Browse the repository at this point in the history
Continuation of sosreport#3530.
Likewise excludes C0114, C0115, and C0209.

Signed-off-by: Ponnuvel Palaniyappan <[email protected]>
  • Loading branch information
pponnuvel authored and TurboTurtle committed Mar 18, 2024
1 parent 36bfd6d commit 6112224
Show file tree
Hide file tree
Showing 54 changed files with 301 additions and 298 deletions.
17 changes: 11 additions & 6 deletions sos/report/plugins/pacemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#
# See the LICENSE file in the source distribution for further information.

import re
from datetime import datetime, timedelta
from sos.report.plugins import (Plugin, RedHatPlugin, DebianPlugin,
UbuntuPlugin, PluginOpt)
from sos.utilities import sos_parse_version
from datetime import datetime, timedelta
import re


class Pacemaker(Plugin):
Expand All @@ -34,15 +34,18 @@ class Pacemaker(Plugin):
envfile = ""

def setup_crm_mon(self):
""" Get cluster summary """
self.add_cmd_output("crm_mon -1 -A -n -r -t")

def setup_crm_shell(self):
""" Get cluster status and configuration """
self.add_cmd_output([
"crm status",
"crm configure show",
])

def setup_pcs(self):
""" Get pacemaker/corosync configuration """
pcs_pkg = self.policy.package_manager.pkg_by_name('pcs')
if pcs_pkg is None:
return
Expand All @@ -65,13 +68,15 @@ def setup_pcs(self):
self.add_cmd_output("pcs status --full", tags="pcs_status")

def postproc_crm_shell(self):
""" Clear password """
self.do_cmd_output_sub(
"crm configure show",
r"passw([^\s=]*)=\S+",
r"passw\1=********"
)

def postproc_pcs(self):
""" Clear password """
self.do_cmd_output_sub(
"pcs config",
r"passw([^\s=]*)=\S+",
Expand Down Expand Up @@ -128,8 +133,8 @@ def setup(self):
pattern = r'^\s*PCMK_logfile=[\'\"]?(\S+)[\'\"]?\s*(\s#.*)?$'
if self.path_isfile(self.envfile):
self.add_copy_spec(self.envfile)
with open(self.envfile) as f:
for line in f:
with open(self.envfile, 'r', encoding='UTF-8') as file:
for line in file:
if re.match(pattern, line):
# remove trailing and leading quote marks, in case the
# line is e.g. PCMK_logfile="/var/log/pacemaker.log"
Expand All @@ -144,7 +149,7 @@ def setup(self):
self.envfile = self.path_join("/etc/default/pacemaker")
self.setup_crm_shell()
self.setup_pcs()
super(DebianPacemaker, self).setup()
super().setup()

def postproc(self):
self.postproc_crm_shell()
Expand All @@ -156,7 +161,7 @@ def setup(self):
self.envfile = self.path_join("/etc/sysconfig/pacemaker")
self.setup_pcs()
self.add_copy_spec("/etc/sysconfig/sbd")
super(RedHatPacemaker, self).setup()
super().setup()

def postproc(self):
self.postproc_pcs()
Expand Down
28 changes: 10 additions & 18 deletions sos/report/plugins/pcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
#
# See the LICENSE file in the source distribution for further information.

from sos.report.plugins import Plugin, RedHatPlugin, DebianPlugin, PluginOpt
import os
from socket import gethostname
from sos.report.plugins import Plugin, RedHatPlugin, DebianPlugin, PluginOpt


class Pcp(Plugin, RedHatPlugin, DebianPlugin):
Expand All @@ -37,17 +36,10 @@ class Pcp(Plugin, RedHatPlugin, DebianPlugin):

pcp_hostname = ''

def get_size(self, path):
total_size = 0
for dirpath, dirnames, filenames in os.walk(path):
for f in filenames:
fp = self.path_join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size

def pcp_parse_conffile(self):
""" Parse PCP configuration """
try:
with open(self.pcp_conffile, "r") as pcpconf:
with open(self.pcp_conffile, "r", encoding='UTF-8') as pcpconf:
lines = pcpconf.readlines()
except IOError:
return False
Expand All @@ -65,17 +57,17 @@ def pcp_parse_conffile(self):
self.pcp_sysconf_dir = env_vars['PCP_SYSCONF_DIR']
self.pcp_var_dir = env_vars['PCP_VAR_DIR']
self.pcp_log_dir = env_vars['PCP_LOG_DIR']
except Exception:
except Exception: # pylint: disable=broad-except
# Fail if all three env variables are not found
return False

return True

def setup(self):
self.sizelimit = (None if self.get_option("all_logs")
else self.get_option("pmmgrlogs"))
self.countlimit = (None if self.get_option("all_logs")
else self.get_option("pmloggerfiles"))
sizelimit = (None if self.get_option("all_logs")
else self.get_option("pmmgrlogs"))
countlimit = (None if self.get_option("all_logs")
else self.get_option("pmloggerfiles"))

if not self.pcp_parse_conffile():
self._log_warn("could not parse %s" % self.pcp_conffile)
Expand Down Expand Up @@ -122,7 +114,7 @@ def setup(self):
# collect pmmgr logs up to 'pmmgrlogs' size limit
path = self.path_join(self.pcp_log_dir, 'pmmgr',
self.pcp_hostname, '*')
self.add_copy_spec(path, sizelimit=self.sizelimit, tailit=False)
self.add_copy_spec(path, sizelimit=sizelimit, tailit=False)
# collect newest pmlogger logs up to 'pmloggerfiles' count
files_collected = 0
path = self.path_join(self.pcp_log_dir, 'pmlogger',
Expand All @@ -132,7 +124,7 @@ def setup(self):
for line in pmlogger_ls['output'].splitlines():
self.add_copy_spec(line, sizelimit=0)
files_collected = files_collected + 1
if self.countlimit and files_collected == self.countlimit:
if countlimit and files_collected == countlimit:
break

self.add_copy_spec([
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/peripety.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#
# See the LICENSE file in the source distribution for further information.

from sos.report.plugins import Plugin, RedHatPlugin
from re import match
import glob
from sos.report.plugins import Plugin, RedHatPlugin


class Peripety(Plugin, RedHatPlugin):
Expand Down
47 changes: 22 additions & 25 deletions sos/report/plugins/pmem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sos.report.plugins import Plugin, IndependentPlugin


class pmem(Plugin, IndependentPlugin):
class PMem(Plugin, IndependentPlugin):
"""This plugin collects data from Persistent Memory devices,
commonly referred to as NVDIMM's or Storage Class Memory (SCM)
"""
Expand All @@ -30,42 +30,39 @@ def setup(self):
"/var/log/ipmctl"
])

""" Use the ndctl-list(1) command to collect:
-i Include idle (not enabled) devices in the listing
-vvv Increase verbosity of the output
-B Include bus info in the listing
-D Include dimm info in the listing
-F Include dimm firmware info in the listing
-H Include dimm health info in the listing
-M Include media errors (badblocks) in the listing
-N Include namespace info in the listing
-R Include region info in the listing
-X Include device-dax info in the listing
Output is JSON formatted
"""
# Use the ndctl-list(1) command to collect:
# -i Include idle (not enabled) devices in the listing
# -vvv Increase verbosity of the output
# -B Include bus info in the listing
# -D Include dimm info in the listing
# -F Include dimm firmware info in the listing
# -H Include dimm health info in the listing
# -M Include media errors (badblocks) in the listing
# -N Include namespace info in the listing
# -R Include region info in the listing
# -X Include device-dax info in the listing
#
# Output is JSON formatted
self.add_cmd_output([
"ndctl --version",
"ndctl list -vvv",
"ndctl list -iBDFHMNRX",
"ndctl read-labels -j all"
])

""" Use the daxctl-list(1) command to collect:
-i Include idle (not enabled / zero-sized) devices in the listing
-D Include device-dax instance info in the listing
-R Include region info in the listing
Output is JSON formatted
"""
# Use the daxctl-list(1) command to collect:
# -i Include idle (not enabled / zero-sized) devices in the listing
# -D Include device-dax instance info in the listing
# -R Include region info in the listing
#
# Output is JSON formatted
self.add_cmd_output([
"daxctl list",
"daxctl list -iDR"
])

""" Use the ipmctl(1) command to collect data from
Intel(R) Optane(TM) Persistent Memory Modules.
"""
# Use the ipmctl(1) command to collect data from
# Intel(R) Optane(TM) Persistent Memory Modules.
self.add_cmd_output([
"ipmctl version",
"ipmctl show -cap",
Expand Down
38 changes: 20 additions & 18 deletions sos/report/plugins/postfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
#
# See the LICENSE file in the source distribution for further information.

from sos.report.plugins import Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin

import re
from sos.report.plugins import Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin


class Postfix(Plugin):
Expand All @@ -20,8 +19,9 @@ class Postfix(Plugin):
packages = ('postfix',)

def forbidden_ssl_keys_files(self):
# list of attributes defining a location of a SSL key file
# we must forbid from collection
""" list of attributes defining a location of a SSL key file
we must forbid from collection
"""
forbid_attributes = [
"lmtp_tls_dkey_file",
"lmtp_tls_eckey_file",
Expand All @@ -41,31 +41,35 @@ def forbidden_ssl_keys_files(self):
"tlsproxy_tls_dh1024_param_file",
"tlsproxy_tls_dh512_param_file",
]
fp = []
fpaths = []
try:
with open(self.path_join('/etc/postfix/main.cf'), 'r') as cffile:
with open(self.path_join('/etc/postfix/main.cf'), 'r',
encoding='UTF-8') as cffile:
for line in cffile.readlines():
# ignore comments and take the first word after '='
if line.startswith('#'):
continue
words = line.split('=')
if words[0].strip() in forbid_attributes:
fp.append(words[1].split()[0])
finally:
return fp
fpaths.append(words[1].split()[0])
except Exception: # pylint: disable=broad-except
pass
return fpaths

def forbidden_password_files(self):
""" Get the list of password to exclude """
forbid_attributes = (
"lmtp_sasl_password_maps",
"smtp_sasl_password_maps",
"postscreen_dnsbl_reply_map",
"smtp_sasl_auth_cache_name",
)
fp = []
fpaths = []
prefix = 'hash:'
option_format = re.compile(r"^(.*)=(.*)")
try:
with open(self.path_join('/etc/postfix/main.cf'), 'r') as cffile:
with open(self.path_join('/etc/postfix/main.cf'), 'r',
encoding='UTF-8') as cffile:
for line in cffile.readlines():
# ignore comment and check option format
line = re.sub('#.*', '', line)
Expand All @@ -83,12 +87,12 @@ def forbidden_password_files(self):
# remove prefix
if filepath.startswith(prefix):
filepath = filepath[len(prefix):]
fp.append(filepath)
except Exception as e:
fpaths.append(filepath)
except Exception as err: # pylint: disable=broad-except
# error log
msg = f"Error parsing main.cf: {e.args[0]}"
msg = f"Error parsing main.cf: {err.args[0]}"
self._log_error(msg)
return fp
return fpaths

def setup(self):
self.add_copy_spec([
Expand All @@ -114,15 +118,13 @@ class RedHatPostfix(Postfix, RedHatPlugin):
packages = ('postfix',)

def setup(self):
super(RedHatPostfix, self).setup()
super().setup()
self.add_copy_spec("/etc/mail")


class DebianPostfix(Postfix, DebianPlugin, UbuntuPlugin):

packages = ('postfix',)

def setup(self):
super(DebianPostfix, self).setup()

# vim: set et ts=4 sw=4 :
9 changes: 5 additions & 4 deletions sos/report/plugins/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class PostgreSQL(Plugin):
]

def do_pg_dump(self, filename="pgdump.tar"):
""" Extract PostgreSQL database into a tar file """
if self.get_option("dbname"):
if self.get_option("password") or "PGPASSWORD" in os.environ:
# We're only modifying this for ourself and our children so
Expand Down Expand Up @@ -86,7 +87,7 @@ def setup(self):
class RedHatPostgreSQL(PostgreSQL, RedHatPlugin):

def setup(self):
super(RedHatPostgreSQL, self).setup()
super().setup()

pghome = self.get_option("pghome")
dirs = [pghome]
Expand All @@ -101,14 +102,14 @@ def setup(self):
self.add_copy_spec(filename)

# copy PG_VERSION and postmaster.opts
for f in ["PG_VERSION", "postmaster.opts"]:
self.add_copy_spec(self.path_join(_dir, "data", f))
for file in ["PG_VERSION", "postmaster.opts"]:
self.add_copy_spec(self.path_join(_dir, "data", file))


class DebianPostgreSQL(PostgreSQL, DebianPlugin, UbuntuPlugin):

def setup(self):
super(DebianPostgreSQL, self).setup()
super().setup()

self.add_copy_spec([
"/var/log/postgresql/*.log",
Expand Down
Loading

0 comments on commit 6112224

Please sign in to comment.