From 4255d1309ec097c7b44f4d3838812e7d9ebe6c98 Mon Sep 17 00:00:00 2001 From: Ponnuvel Palaniyappan Date: Sat, 17 Feb 2024 17:01:28 +0000 Subject: [PATCH] [plugins] Fix some PYLint and PEP8 issues Signed-off-by: Ponnuvel Palaniyappan --- sos/report/plugins/activemq.py | 4 ++-- sos/report/plugins/aide.py | 4 ++-- sos/report/plugins/alternatives.py | 6 ++++-- sos/report/plugins/apache.py | 5 +++-- sos/report/plugins/apt.py | 2 +- sos/report/plugins/arcconf.py | 2 +- sos/report/plugins/auditd.py | 4 ++-- sos/report/plugins/autofs.py | 4 ++-- sos/report/plugins/azure.py | 6 +++--- sos/report/plugins/boot.py | 2 +- sos/report/plugins/candlepin.py | 10 +++++++--- sos/report/plugins/ceph_common.py | 4 ++-- sos/report/plugins/ceph_mds.py | 3 ++- sos/report/plugins/ceph_mon.py | 8 ++++++-- sos/report/plugins/cgroups.py | 2 +- sos/report/plugins/chrony.py | 4 ++-- sos/report/plugins/clear_containers.py | 21 +++++++++++--------- sos/report/plugins/cman.py | 3 +-- sos/report/plugins/collectd.py | 13 ++++++------ sos/report/plugins/container_log.py | 6 +++--- sos/report/plugins/containers_common.py | 2 +- sos/report/plugins/convert2rhel.py | 2 +- sos/report/plugins/corosync.py | 20 ++++++++----------- sos/report/plugins/cs.py | 14 ++++++++----- sos/report/plugins/ctdb.py | 2 +- sos/report/plugins/cxl.py | 9 +++------ sos/report/plugins/dellrac.py | 8 +++++--- sos/report/plugins/dhcp.py | 4 ++-- sos/report/plugins/dlm.py | 3 ++- sos/report/plugins/dnf.py | 5 +++-- sos/report/plugins/docker.py | 8 ++++---- sos/report/plugins/docker_distribution.py | 6 +++--- sos/report/plugins/dovecot.py | 8 ++------ sos/report/plugins/drbd.py | 2 +- sos/report/plugins/ds.py | 13 +++++++----- sos/report/plugins/ebpf.py | 24 ++++++++++++----------- sos/report/plugins/elastic.py | 9 +++++---- sos/report/plugins/etcd.py | 2 +- 38 files changed, 136 insertions(+), 118 deletions(-) diff --git a/sos/report/plugins/activemq.py b/sos/report/plugins/activemq.py index de8dcef679..3589cf07f0 100644 --- a/sos/report/plugins/activemq.py +++ b/sos/report/plugins/activemq.py @@ -42,7 +42,7 @@ def postproc(self): class RedHatActiveMq(ActiveMq, RedHatPlugin): def setup(self): - super(RedHatActiveMq, self).setup() + super().setup() self.add_copy_spec([ '/etc/sysconfig/activemq', '/etc/activemq/activemq.xml' @@ -51,7 +51,7 @@ def setup(self): class UbuntuActiveMq(ActiveMq, UbuntuPlugin): def setup(self): - super(UbuntuActiveMq, self).setup() + super().setup() self.add_copy_spec([ '/etc/activemq', '/etc/default/activemq' diff --git a/sos/report/plugins/aide.py b/sos/report/plugins/aide.py index 9c76d0fa46..866ff7dd22 100644 --- a/sos/report/plugins/aide.py +++ b/sos/report/plugins/aide.py @@ -36,7 +36,7 @@ class RedHatAide(Aide, RedHatPlugin): conf_file = "/etc/aide.conf" def setup(self): - super(RedHatAide, self).setup() + super().setup() self.add_copy_spec([ "/etc/aide.conf", "/etc/logrotate.d/aide" @@ -47,7 +47,7 @@ class DebianAide(Aide, DebianPlugin, UbuntuPlugin): conf_file = "/etc/aide/aide.conf" def setup(self): - super(DebianAide, self).setup() + super().setup() self.add_copy_spec([ "/etc/aide/", "/etc/default/aide" diff --git a/sos/report/plugins/alternatives.py b/sos/report/plugins/alternatives.py index e3b3911e1f..7c4dc1ae14 100644 --- a/sos/report/plugins/alternatives.py +++ b/sos/report/plugins/alternatives.py @@ -15,6 +15,8 @@ class Alternatives(Plugin): short_desc = 'System alternatives' plugin_name = 'alternatives' + alternatives_cmd = None + alternatives_list = None def setup(self): @@ -49,7 +51,7 @@ class RedHatAlternatives(Alternatives, RedHatPlugin): def setup(self): - super(RedHatAlternatives, self).setup() + super().setup() self.add_cmd_tags({ "alternatives --display java.*": 'display_java', @@ -68,7 +70,7 @@ class UbuntuAlternatives(Alternatives, UbuntuPlugin): def setup(self): - super(UbuntuAlternatives, self).setup() + super().setup() if self.get_option("all_logs"): self.add_copy_spec([ diff --git a/sos/report/plugins/apache.py b/sos/report/plugins/apache.py index 529210a7e2..3088355b65 100644 --- a/sos/report/plugins/apache.py +++ b/sos/report/plugins/apache.py @@ -30,6 +30,7 @@ class Apache(Plugin): profiles = ('webserver', 'openshift') packages = ('httpd',) files = ('/var/www/',) + apachepkg = None option_list = [ PluginOpt(name="log", default=False, desc="gathers all apache logs") @@ -90,7 +91,7 @@ def setup(self): "/var/log/httpd/ssl_error_log": 'httpd_ssl_error_log' }) - super(RedHatApache, self).setup() + super().setup() # httpd versions, including those used for JBoss Web Server vers = ['', '22', '24'] @@ -137,7 +138,7 @@ class DebianApache(Apache, DebianPlugin, UbuntuPlugin): apachepkg = 'apache2' def setup(self): - super(DebianApache, self).setup() + super().setup() self.add_copy_spec([ "/etc/apache2/*", "/etc/default/apache2" diff --git a/sos/report/plugins/apt.py b/sos/report/plugins/apt.py index 0bdaf894d2..36b3bf1cfb 100644 --- a/sos/report/plugins/apt.py +++ b/sos/report/plugins/apt.py @@ -46,7 +46,7 @@ def setup(self): ) def postproc(self): - super(Apt, self).postproc() + super().postproc() self.do_file_sub( "/etc/apt/sources.list", r"(deb\shttp(s)?://)\S+:\S+(@.*)", diff --git a/sos/report/plugins/arcconf.py b/sos/report/plugins/arcconf.py index 8eb9cd7b41..1cfcf5a8c2 100644 --- a/sos/report/plugins/arcconf.py +++ b/sos/report/plugins/arcconf.py @@ -15,7 +15,7 @@ from sos.report.plugins import Plugin, IndependentPlugin -class arcconf(Plugin, IndependentPlugin): +class ArcConf(Plugin, IndependentPlugin): short_desc = 'arcconf Integrated RAID adapter information' diff --git a/sos/report/plugins/auditd.py b/sos/report/plugins/auditd.py index 5a1e15243d..59bb206b2d 100644 --- a/sos/report/plugins/auditd.py +++ b/sos/report/plugins/auditd.py @@ -37,8 +37,8 @@ def setup(self): config_file = "/etc/audit/auditd.conf" log_file = "/var/log/audit/audit.log" try: - with open(config_file, 'r') as cf: - for line in cf.read().splitlines(): + with open(config_file, 'r', encoding='UTF-8') as cfile: + for line in cfile.read().splitlines(): if not line: continue words = line.split('=') diff --git a/sos/report/plugins/autofs.py b/sos/report/plugins/autofs.py index bf333ba8af..2d7c3a9dc5 100644 --- a/sos/report/plugins/autofs.py +++ b/sos/report/plugins/autofs.py @@ -85,7 +85,7 @@ def postproc(self): class RedHatAutofs(Autofs, RedHatPlugin): def setup(self): - super(RedHatAutofs, self).setup() + super().setup() if self.get_option("verify"): self.add_cmd_output("rpm -qV autofs") @@ -93,7 +93,7 @@ def setup(self): class DebianAutofs(Autofs, DebianPlugin, UbuntuPlugin): def setup(self): - super(DebianAutofs, self).setup() + super().setup() self.add_cmd_output("dpkg-query -s autofs") # vim: set et ts=4 sw=4 : diff --git a/sos/report/plugins/azure.py b/sos/report/plugins/azure.py index 253b9e7f62..3939f47ad4 100644 --- a/sos/report/plugins/azure.py +++ b/sos/report/plugins/azure.py @@ -8,8 +8,8 @@ # # See the LICENSE file in the source distribution for further information. -from sos.report.plugins import Plugin, UbuntuPlugin, RedHatPlugin import os +from sos.report.plugins import Plugin, UbuntuPlugin, RedHatPlugin class Azure(Plugin, UbuntuPlugin): @@ -36,7 +36,7 @@ def setup(self): # extensions and there is no standard log filename format limit = self.get_option("log_size") - for path, subdirs, files in os.walk("/var/log/azure"): + for path, _, files in os.walk("/var/log/azure"): for name in files: self.add_copy_spec(self.path_join(path, name), sizelimit=limit) @@ -50,7 +50,7 @@ def setup(self): class RedHatAzure(Azure, RedHatPlugin): def setup(self): - super(RedHatAzure, self).setup() + super().setup() if self.path_isfile('/etc/yum.repos.d/rh-cloud.repo'): curl_cmd = ('curl -s -m 5 -vvv ' diff --git a/sos/report/plugins/boot.py b/sos/report/plugins/boot.py index 8752eab286..9bb1b28e05 100644 --- a/sos/report/plugins/boot.py +++ b/sos/report/plugins/boot.py @@ -6,8 +6,8 @@ # # See the LICENSE file in the source distribution for further information. -from sos.report.plugins import Plugin, IndependentPlugin, PluginOpt from glob import glob +from sos.report.plugins import Plugin, IndependentPlugin, PluginOpt class Boot(Plugin, IndependentPlugin): diff --git a/sos/report/plugins/candlepin.py b/sos/report/plugins/candlepin.py index 9c14ea2d63..a4961ced74 100644 --- a/sos/report/plugins/candlepin.py +++ b/sos/report/plugins/candlepin.py @@ -8,9 +8,9 @@ # # See the LICENSE file in the source distribution for further information. -from sos.report.plugins import Plugin, RedHatPlugin -from pipes import quote from re import match +from shlex import quote +from sos.report.plugins import Plugin, RedHatPlugin class Candlepin(Plugin, RedHatPlugin): @@ -20,6 +20,10 @@ class Candlepin(Plugin, RedHatPlugin): plugin_name = 'candlepin' packages = ('candlepin',) + dbhost = None + dbpasswd = None + env = None + def setup(self): # for external DB, search in /etc/candlepin/candlepin.conf for: # org.quartz.dataSource.myDS.URL=.. @@ -30,7 +34,7 @@ def setup(self): self.dbpasswd = "" cfg_file = "/etc/candlepin/candlepin.conf" try: - with open(cfg_file, 'r') as cfile: + with open(cfg_file, 'r', encoding='UTF--8') as cfile: candle_lines = cfile.read().splitlines() for line in candle_lines: # skip empty lines and lines with comments diff --git a/sos/report/plugins/ceph_common.py b/sos/report/plugins/ceph_common.py index 444e0f52ba..eb4282bd22 100644 --- a/sos/report/plugins/ceph_common.py +++ b/sos/report/plugins/ceph_common.py @@ -6,11 +6,11 @@ # # See the LICENSE file in the source distribution for further information. -from sos.report.plugins import Plugin, RedHatPlugin, UbuntuPlugin from socket import gethostname +from sos.report.plugins import Plugin, RedHatPlugin, UbuntuPlugin -class Ceph_Common(Plugin, RedHatPlugin, UbuntuPlugin): +class CephCommon(Plugin, RedHatPlugin, UbuntuPlugin): short_desc = 'CEPH common' diff --git a/sos/report/plugins/ceph_mds.py b/sos/report/plugins/ceph_mds.py index 94f0f69c81..a5a5edebcd 100644 --- a/sos/report/plugins/ceph_mds.py +++ b/sos/report/plugins/ceph_mds.py @@ -10,6 +10,7 @@ class CephMDS(Plugin, RedHatPlugin, UbuntuPlugin): + short_desc = 'CEPH mds' plugin_name = 'ceph_mds' profiles = ('storage', 'virt', 'container', 'ceph') @@ -84,7 +85,7 @@ def setup(self): # If containerized, run commands in containers try: cname = self.get_all_containers_by_regex("ceph-mds*")[0][1] - except Exception: + except Exception: # pylint: disable=broad-except cname = None self.add_cmd_output([ diff --git a/sos/report/plugins/ceph_mon.py b/sos/report/plugins/ceph_mon.py index fea3b08b8d..8a41d463fa 100644 --- a/sos/report/plugins/ceph_mon.py +++ b/sos/report/plugins/ceph_mon.py @@ -161,12 +161,14 @@ def setup(self): ) def get_ceph_version(self): + """ Get the versions of running daemons """ + ver = self.exec_cmd('ceph --version') if ver['status'] == 0: try: _ver = ver['output'].split()[2] return int(_ver.split('.')[0]) - except Exception as err: + except Exception as err: # pylint: disable=broad-except self._log_debug(f"Could not determine ceph version: {err}") self._log_error( 'Failed to find ceph version, command collection will be limited' @@ -174,6 +176,8 @@ def get_ceph_version(self): return 0 def get_ceph_ids(self): + """ Get the IDs of the Ceph daemons """ + ceph_ids = [] # ceph version 14 correlates to RHCS 4 if self.ceph_version in (14, 15): @@ -200,7 +204,7 @@ def get_ceph_ids(self): ret = re.search(r'(\s*mon: .* quorum) (.*) (\(.*\))', stats['output']) ceph_ids.extend(ret.groups()[1].split(',')) - except Exception as err: + except Exception as err: # pylint: disable=broad-except self._log_debug(f"id determination failed: {err}") return ceph_ids diff --git a/sos/report/plugins/cgroups.py b/sos/report/plugins/cgroups.py index cc1bf20b75..35075d83ca 100644 --- a/sos/report/plugins/cgroups.py +++ b/sos/report/plugins/cgroups.py @@ -38,7 +38,7 @@ def setup(self): class RedHatCgroups(Cgroups, RedHatPlugin): def setup(self): - super(RedHatCgroups, self).setup() + super().setup() self.add_copy_spec([ "/etc/sysconfig/cgconfig", "/etc/sysconfig/cgred", diff --git a/sos/report/plugins/chrony.py b/sos/report/plugins/chrony.py index d8ff3d7e5c..476b655bdf 100644 --- a/sos/report/plugins/chrony.py +++ b/sos/report/plugins/chrony.py @@ -32,7 +32,7 @@ def setup(self): class RedHatChrony(Chrony, RedHatPlugin): def setup(self): - super(RedHatChrony, self).setup() + super().setup() self.add_copy_spec([ "/etc/chrony.conf", "/var/lib/chrony/drift" @@ -42,7 +42,7 @@ def setup(self): class DebianChrony(Chrony, DebianPlugin, UbuntuPlugin): def setup(self): - super(DebianChrony, self).setup() + super().setup() self.add_copy_spec([ "/etc/chrony/chrony.conf", "/etc/chrony/conf.d", diff --git a/sos/report/plugins/clear_containers.py b/sos/report/plugins/clear_containers.py index 068d42554a..7f1f2dfb52 100644 --- a/sos/report/plugins/clear_containers.py +++ b/sos/report/plugins/clear_containers.py @@ -7,7 +7,6 @@ # See the LICENSE file in the source distribution for further information. import re - from sos.report.plugins import Plugin, IndependentPlugin @@ -21,8 +20,10 @@ class ClearContainers(Plugin, IndependentPlugin): runtime = 'cc-runtime' packages = (runtime,) services = ('cc-proxy',) + loglimit = None - def attach_cc_config_files(self): + def collect_cc_config_files(self): + """ Collect Clear Containers config files """ # start with the default file locations config_files = [ @@ -43,7 +44,9 @@ def attach_cc_config_files(self): self.add_copy_spec(config_files) - def attach_cc_log_files(self): + def collect_cc_log_files(self): + """ Collect Clear Containers log files """ + # start with the default global log log_files = [ '/var/lib/clear-containers/runtime/runtime.log' @@ -63,19 +66,19 @@ def attach_cc_log_files(self): # get a unique list of log files log_files = set(log_files) - self.add_copy_spec(log_files, self.limit) + self.add_copy_spec(log_files, self.loglimit) def setup(self): - self.limit = self.get_option("log_size") + self.loglimit = self.get_option("log_size") if self.get_option("all_logs"): - # no limit on amount of data recorded - self.limit = None + # no loglimit on amount of data recorded + self.loglimit = None self.add_cmd_output(f"{self.runtime} cc-env") - self.attach_cc_config_files() + self.collect_cc_config_files() - self.attach_cc_log_files() + self.collect_cc_log_files() self.add_journal(identifier="cc-shim") # vim: set et ts=4 sw=4 : diff --git a/sos/report/plugins/cman.py b/sos/report/plugins/cman.py index f749a6bb87..7582572002 100644 --- a/sos/report/plugins/cman.py +++ b/sos/report/plugins/cman.py @@ -6,8 +6,8 @@ # # See the LICENSE file in the source distribution for further information. -from sos.report.plugins import Plugin, RedHatPlugin from glob import glob +from sos.report.plugins import Plugin, RedHatPlugin class Cman(Plugin, RedHatPlugin): @@ -61,6 +61,5 @@ def postproc(self): r"(.*secret\s*=\s*)\S+", r"\1******" ) - return # vim: et ts=4 sw=4 diff --git a/sos/report/plugins/collectd.py b/sos/report/plugins/collectd.py index 653555430f..0ecb19bfff 100644 --- a/sos/report/plugins/collectd.py +++ b/sos/report/plugins/collectd.py @@ -34,15 +34,16 @@ def setup(self): + '*.conf', ]) - p = re.compile('^LoadPlugin.*') + plugin = re.compile('^LoadPlugin.*') try: - with open(self.path_join("/etc/collectd.conf"), 'r') as f: - for line in f: - if p.match(line): + cfile = self.path_join("/etc/collectd.conf") + with open(cfile, 'r', encoding='UTF-8') as file: + for line in file: + if plugin.match(line): self.add_alert("Active Plugin found: %s" % line.split()[-1]) - except IOError as e: - self._log_warn("could not open /etc/collectd.conf: %s" % e) + except IOError as err: + self._log_warn("could not open /etc/collectd.conf: %s" % err) def postproc(self): # add these to protect_keys if need be: diff --git a/sos/report/plugins/container_log.py b/sos/report/plugins/container_log.py index e8dedad229..98d9637ace 100644 --- a/sos/report/plugins/container_log.py +++ b/sos/report/plugins/container_log.py @@ -8,8 +8,8 @@ # # See the LICENSE file in the source distribution for further information. -from sos.report.plugins import Plugin, IndependentPlugin import os +from sos.report.plugins import Plugin, IndependentPlugin class ContainerLog(Plugin, IndependentPlugin): @@ -28,7 +28,7 @@ def setup(self): def collect_subdirs(self, root=logdir): """Collect *.log files from subdirs of passed root path """ - for dirName, _, _ in os.walk(root): - self.add_copy_spec(self.path_join(dirName, '*.log')) + for dir_name, _, _ in os.walk(root): + self.add_copy_spec(self.path_join(dir_name, '*.log')) # vim: set et ts=4 sw=4 : diff --git a/sos/report/plugins/containers_common.py b/sos/report/plugins/containers_common.py index a6e577e985..39e9b1a01c 100644 --- a/sos/report/plugins/containers_common.py +++ b/sos/report/plugins/containers_common.py @@ -8,8 +8,8 @@ # # See the LICENSE file in the source distribution for further information. -from sos.report.plugins import Plugin, RedHatPlugin, UbuntuPlugin, PluginOpt import os +from sos.report.plugins import Plugin, RedHatPlugin, UbuntuPlugin, PluginOpt class ContainersCommon(Plugin, RedHatPlugin, UbuntuPlugin): diff --git a/sos/report/plugins/convert2rhel.py b/sos/report/plugins/convert2rhel.py index 1f9670bd16..2ea2c523d1 100644 --- a/sos/report/plugins/convert2rhel.py +++ b/sos/report/plugins/convert2rhel.py @@ -9,7 +9,7 @@ from sos.report.plugins import Plugin, RedHatPlugin -class convert2rhel(Plugin, RedHatPlugin): +class Convert2RHEL(Plugin, RedHatPlugin): short_desc = 'Convert2RHEL' plugin_name = 'convert2rhel' diff --git a/sos/report/plugins/corosync.py b/sos/report/plugins/corosync.py index 2742f12997..35afbe8531 100644 --- a/sos/report/plugins/corosync.py +++ b/sos/report/plugins/corosync.py @@ -6,8 +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 Corosync(Plugin): @@ -48,12 +48,13 @@ def setup(self): # (it isnt precise but sufficient) pattern = r'^\s*(logging.)?logfile:\s*(\S+)$' try: - with open(self.path_join("/etc/corosync/corosync.conf"), 'r') as f: - for line in f: + cconf = self.path_join("/etc/corosync/corosync.conf") + with open(cconf, 'r', encoding='UTF-8') as file: + for line in file: if re.match(pattern, line): self.add_copy_spec(re.search(pattern, line).group(2)) - except IOError as e: - self._log_warn("could not read from %s: %s" % (corosync_conf, e)) + except IOError as err: # pylint: disable=broad-except + self._log_warn("could not read from %s: %s" % (corosync_conf, err)) def postproc(self): self.do_cmd_output_sub( @@ -64,16 +65,11 @@ def postproc(self): class RedHatCorosync(Corosync, RedHatPlugin): - - def setup(self): - super(RedHatCorosync, self).setup() + """ Parent class Corosync's setup() will be called """ class DebianCorosync(Corosync, DebianPlugin, UbuntuPlugin): - - def setup(self): - super(DebianCorosync, self).setup() - + """ Parent class Corosync's setup() will be called """ files = ('/usr/sbin/corosync',) # vim: set et ts=4 sw=4 : diff --git a/sos/report/plugins/cs.py b/sos/report/plugins/cs.py index 9a2d964fd3..2a1e0821fd 100644 --- a/sos/report/plugins/cs.py +++ b/sos/report/plugins/cs.py @@ -10,8 +10,8 @@ # # See the LICENSE file in the source distribution for further information. -from sos.report.plugins import Plugin, RedHatPlugin from glob import glob +from sos.report.plugins import Plugin, RedHatPlugin class CertificateSystem(Plugin, RedHatPlugin): @@ -37,19 +37,23 @@ class CertificateSystem(Plugin, RedHatPlugin): ) def checkversion(self): + """ Get Certificate System version """ if (self.is_installed("redhat-cs") or self.path_exists("/opt/redhat-cs")): return 71 - elif self.is_installed("rhpki-common") or \ - len(glob("/var/lib/rhpki-*")): + + if self.is_installed("rhpki-common") or glob("/var/lib/rhpki-*"): return 73 + # 8 should cover dogtag - elif self.is_installed("pki-common"): + if self.is_installed("pki-common"): return 8 - elif self.is_installed("redhat-pki") or \ + + if self.is_installed("redhat-pki") or \ self.is_installed("dogtag-pki") or \ self.is_installed("pki-base"): return 9 + return False def setup(self): diff --git a/sos/report/plugins/ctdb.py b/sos/report/plugins/ctdb.py index 3def321e62..a25c43edbf 100644 --- a/sos/report/plugins/ctdb.py +++ b/sos/report/plugins/ctdb.py @@ -44,7 +44,7 @@ def setup(self): class RedHatCtdb(Ctdb, RedHatPlugin): def setup(self): - super(RedHatCtdb, self).setup() + super().setup() self.add_copy_spec("/etc/sysconfig/ctdb") # vim: set et ts=4 sw=4 : diff --git a/sos/report/plugins/cxl.py b/sos/report/plugins/cxl.py index 908a14b088..7d01d6bf5f 100644 --- a/sos/report/plugins/cxl.py +++ b/sos/report/plugins/cxl.py @@ -9,7 +9,7 @@ from sos.report.plugins import Plugin, IndependentPlugin -class cxl(Plugin, IndependentPlugin): +class Cxl(Plugin, IndependentPlugin): """This plugin collects data from Compute Express Link (CXL) devices """ @@ -32,11 +32,8 @@ def setup(self): "daxctl list -iDRM" ]) - """ Use the cxl-list(1) command to collect data about - all CXL devices. - - Output is JSON formatted - """ + # Use the cxl-list(1) command to collect data about all CXL devices. + # Output is JSON formatted. self.add_cmd_output([ "cxl version", "cxl list", diff --git a/sos/report/plugins/dellrac.py b/sos/report/plugins/dellrac.py index cf6bd219f9..00f92aa0e0 100644 --- a/sos/report/plugins/dellrac.py +++ b/sos/report/plugins/dellrac.py @@ -34,9 +34,11 @@ def setup(self): self.do_debug() def do_debug(self): - # ensure the sos_commands/dellrac directory does exist in either case - # as we will need to run the command at that dir, and also ensure - # logpath is properly populated in either case as well + """ + Ensure the sos_commands/dellrac directory does exist in either case + as we will need to run the command at that dir, and also ensure + logpath is properly populated in either case as well. + """ try: logpath = self.get_cmd_output_path() except FileExistsError: diff --git a/sos/report/plugins/dhcp.py b/sos/report/plugins/dhcp.py index 33906b1258..329bd8250e 100644 --- a/sos/report/plugins/dhcp.py +++ b/sos/report/plugins/dhcp.py @@ -23,7 +23,7 @@ class RedHatDhcp(Dhcp, RedHatPlugin): packages = ('dhcp',) def setup(self): - super(RedHatDhcp, self).setup() + super().setup() self.add_copy_spec([ "/etc/dhcpd.conf", "/etc/dhcp" @@ -36,7 +36,7 @@ class UbuntuDhcp(Dhcp, UbuntuPlugin): packages = ('udhcpd',) def setup(self): - super(UbuntuDhcp, self).setup() + super().setup() self.add_copy_spec([ "/etc/default/udhcpd", "/etc/udhcpd.conf" diff --git a/sos/report/plugins/dlm.py b/sos/report/plugins/dlm.py index b34b5b74f8..b492c2a405 100644 --- a/sos/report/plugins/dlm.py +++ b/sos/report/plugins/dlm.py @@ -6,8 +6,8 @@ # # See the LICENSE file in the source distribution for further information. -from sos.report.plugins import Plugin, IndependentPlugin, PluginOpt import re +from sos.report.plugins import Plugin, IndependentPlugin, PluginOpt class Dlm(Plugin, IndependentPlugin): @@ -34,6 +34,7 @@ def setup(self): self.do_lockdump() def do_lockdump(self): + """ Do dlm lock dumps """ dlm_tool = "dlm_tool ls" result = self.collect_cmd_output(dlm_tool) if result["status"] != 0: diff --git a/sos/report/plugins/dnf.py b/sos/report/plugins/dnf.py index 5250e2cb6c..11f7ec6601 100644 --- a/sos/report/plugins/dnf.py +++ b/sos/report/plugins/dnf.py @@ -38,6 +38,7 @@ class DNFPlugin(Plugin, RedHatPlugin): ] def get_modules_info(self, modules): + """ Get DN module information """ if not modules: return # take just lines with the module names, i.e. containing "[i]" and @@ -134,8 +135,8 @@ def postproc(self): # Whitespace around '=' is allowed. regexp = r"(password(\s)*=(\s)*)(\S+)\n" repl = r"\1********\n" - for f in ["/etc/yum.repos.d/*", "/etc/dnf/vars/*"]: - self.do_path_regex_sub(f, regexp, repl) + for file in ["/etc/yum.repos.d/*", "/etc/dnf/vars/*"]: + self.do_path_regex_sub(file, regexp, repl) # Scrub password and proxy_password from /etc/dnf/dnf.conf. # This uses the same regex patterns as above. diff --git a/sos/report/plugins/docker.py b/sos/report/plugins/docker.py index b6cadfb4df..a483b292ab 100644 --- a/sos/report/plugins/docker.py +++ b/sos/report/plugins/docker.py @@ -74,8 +74,8 @@ def setup(self): nets = self.collect_cmd_output('docker network ls') if nets['status'] == 0: - n = [n.split()[1] for n in nets['output'].splitlines()[1:]] - for net in n: + networks = [n.split()[1] for n in nets['output'].splitlines()[1:]] + for net in networks: self.add_cmd_output("docker network inspect %s" % net) containers = [ @@ -126,7 +126,7 @@ class RedHatDocker(Docker, RedHatPlugin): 'docker-ce', 'docker-ee') def setup(self): - super(RedHatDocker, self).setup() + super().setup() self.add_copy_spec([ "/etc/udev/rules.d/80-docker.rules", @@ -139,7 +139,7 @@ class UbuntuDocker(Docker, UbuntuPlugin, DebianPlugin): packages = ('docker.io', 'docker-engine', 'docker-ce', 'docker-ee') def setup(self): - super(UbuntuDocker, self).setup() + super().setup() self.add_copy_spec([ "/etc/default/docker", "/run/docker/libcontainerd/containerd/events.log" diff --git a/sos/report/plugins/docker_distribution.py b/sos/report/plugins/docker_distribution.py index e760f252f4..31301092e0 100644 --- a/sos/report/plugins/docker_distribution.py +++ b/sos/report/plugins/docker_distribution.py @@ -21,8 +21,8 @@ def setup(self): self.add_journal('docker-distribution') conf = self.path_join('/etc/docker-distribution/registry/config.yml') if self.path_exists(conf): - with open(conf) as f: - for line in f: + with open(conf, encoding='UTF-8') as file: + for line in file: if 'rootdirectory' in line: loc = line.split()[1] self.add_cmd_output('tree ' + loc) @@ -34,4 +34,4 @@ class RedHatDockerDistribution(DockerDistribution, RedHatPlugin): def setup(self): self.add_forbidden_path('/etc/docker-distribution/registry/*passwd') - super(RedHatDockerDistribution, self).setup() + super().setup() diff --git a/sos/report/plugins/dovecot.py b/sos/report/plugins/dovecot.py index 334e787dac..8ee6a9d72f 100644 --- a/sos/report/plugins/dovecot.py +++ b/sos/report/plugins/dovecot.py @@ -22,18 +22,14 @@ def setup(self): class RedHatDovecot(Dovecot, RedHatPlugin): - - def setup(self): - super(RedHatDovecot, self).setup() + """ Parent class Dovecot's setup() will be called """ packages = ('dovecot', ) files = ('/etc/dovecot.conf',) class DebianDovecot(Dovecot, DebianPlugin, UbuntuPlugin): - - def setup(self): - super(DebianDovecot, self).setup() + """ Parent class Dovecot's setup() will be called """ files = ('/etc/dovecot/README',) diff --git a/sos/report/plugins/drbd.py b/sos/report/plugins/drbd.py index 0293f43a4f..ecd68177fa 100644 --- a/sos/report/plugins/drbd.py +++ b/sos/report/plugins/drbd.py @@ -9,7 +9,7 @@ from sos.report.plugins import Plugin, RedHatPlugin, UbuntuPlugin -class drbd(Plugin, RedHatPlugin, UbuntuPlugin): +class DRDB(Plugin, RedHatPlugin, UbuntuPlugin): short_desc = 'Distributed Replicated Block Device (DRBD)' diff --git a/sos/report/plugins/ds.py b/sos/report/plugins/ds.py index 3fc8514558..b05a04919d 100644 --- a/sos/report/plugins/ds.py +++ b/sos/report/plugins/ds.py @@ -24,12 +24,15 @@ class DirectoryServer(Plugin, RedHatPlugin): packages = ('redhat-ds-base', 'redhat-ds-7') def check_version(self): + """ Get Directory Server version """ if self.is_installed("redhat-ds-base") or \ self.path_exists("/etc/dirsrv"): return "ds8" - elif self.is_installed("redhat-ds-7") or \ + + if self.is_installed("redhat-ds-7") or \ self.path_exists("/opt/redhat-ds"): return "ds7" + return False def setup(self): @@ -44,11 +47,11 @@ def setup(self): ]) try: - for d in self.listdir("/etc/dirsrv"): - if d[0:5] == 'slapd': - certpath = self.path_join("/etc/dirsrv", d) + for dsrv in self.listdir("/etc/dirsrv"): + if dsrv[0:5] == 'slapd': + certpath = self.path_join("/etc/dirsrv", dsrv) self.add_cmd_output("certutil -L -d %s" % certpath) - self.add_cmd_output("dsctl %s healthcheck" % d) + self.add_cmd_output("dsctl %s healthcheck" % dsrv) except OSError: self._log_warn("could not list /etc/dirsrv") diff --git a/sos/report/plugins/ebpf.py b/sos/report/plugins/ebpf.py index 6c5f7deea8..4bd6a65746 100644 --- a/sos/report/plugins/ebpf.py +++ b/sos/report/plugins/ebpf.py @@ -6,8 +6,8 @@ # # See the LICENSE file in the source distribution for further information. -from sos.report.plugins import Plugin, IndependentPlugin, PluginOpt import json +from sos.report.plugins import Plugin, IndependentPlugin, PluginOpt class Ebpf(Plugin, IndependentPlugin): @@ -22,27 +22,29 @@ class Ebpf(Plugin, IndependentPlugin): ] def get_bpftool_prog_ids(self, prog_json): + """ Collect the list of program IDs """ out = [] try: prog_data = json.loads(prog_json) - except Exception as e: - self._log_info("Could not parse bpftool prog list as JSON: %s" % e) + except Exception as err: # pylint: disable=broad-except + self._log_info("Couldn't parse bpftool prog list: %s" % err) return out - for item in range(len(prog_data)): - if "id" in prog_data[item]: - out.append(prog_data[item]["id"]) + for _, item in enumerate(prog_data): + if "id" in item: + out.append(item["id"]) return out def get_bpftool_map_ids(self, map_json): + """ Collect the list of mapIDs """ out = [] try: map_data = json.loads(map_json) - except Exception as e: - self._log_info("Could not parse bpftool map list as JSON: %s" % e) + except Exception as err: # pylint: disable=broad-except + self._log_info("Could not parse bpftool map list: %s" % err) return out - for item in range(len(map_data)): - if "id" in map_data[item]: - out.append(map_data[item]["id"]) + for _, item in enumerate(map_data): + if "id" in item: + out.append(item["id"]) return out def setup(self): diff --git a/sos/report/plugins/elastic.py b/sos/report/plugins/elastic.py index edb8015967..1a8803d53c 100644 --- a/sos/report/plugins/elastic.py +++ b/sos/report/plugins/elastic.py @@ -8,8 +8,8 @@ # # See the LICENSE file in the source distribution for further information. -from sos.report.plugins import Plugin, IndependentPlugin import re +from sos.report.plugins import Plugin, IndependentPlugin class Elastic(Plugin, IndependentPlugin): @@ -21,10 +21,11 @@ class Elastic(Plugin, IndependentPlugin): packages = ('elasticsearch',) def get_hostname_port(self, els_config_file): + """ Get hostname and port number """ hostname = "localhost" port = "9200" try: - with open(els_config_file) as fread: + with open(els_config_file, encoding='UTF-8') as fread: for line in fread: network_host = re.search(r'(^network.host):(.*)', line) network_port = re.search(r'(^http.port):(.*)', line) @@ -34,8 +35,8 @@ def get_hostname_port(self, els_config_file): continue if network_port and len(network_port.groups()) == 2: port = network_port.groups()[-1].strip() - except Exception as e: - self._log_info("Failed to parse %s: %s" % (els_config_file, e)) + except Exception as err: # pylint: disable=broad-except + self._log_info("Failed to parse %s: %s" % (els_config_file, err)) return hostname, port def setup(self): diff --git a/sos/report/plugins/etcd.py b/sos/report/plugins/etcd.py index 6b76674bad..08cd19d3d4 100644 --- a/sos/report/plugins/etcd.py +++ b/sos/report/plugins/etcd.py @@ -12,7 +12,7 @@ from sos.report.plugins import Plugin, RedHatPlugin -class etcd(Plugin, RedHatPlugin): +class Etcd(Plugin, RedHatPlugin): """The etcd plugin collects information from the etcd key-value store. It is primarily used by Kubernetes/OpenShift clusters and is often run inside a container within the cluster.