Skip to content

Commit

Permalink
[plugins] Fix some PYLint and PEP8 issues
Browse files Browse the repository at this point in the history
Signed-off-by: Ponnuvel Palaniyappan <[email protected]>
  • Loading branch information
pponnuvel authored and TurboTurtle committed Mar 1, 2024
1 parent 1ca9850 commit 4255d13
Show file tree
Hide file tree
Showing 38 changed files with 136 additions and 118 deletions.
4 changes: 2 additions & 2 deletions sos/report/plugins/activemq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/aide.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions sos/report/plugins/alternatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Alternatives(Plugin):

short_desc = 'System alternatives'
plugin_name = 'alternatives'
alternatives_cmd = None
alternatives_list = None

def setup(self):

Expand Down Expand Up @@ -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',
Expand All @@ -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([
Expand Down
5 changes: 3 additions & 2 deletions sos/report/plugins/apache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+(@.*)",
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/arcconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/auditd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('=')
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/autofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ 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")


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 :
6 changes: 3 additions & 3 deletions sos/report/plugins/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand All @@ -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 '
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 7 additions & 3 deletions sos/report/plugins/candlepin.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 pipes import quote
from re import match
from shlex import quote
from sos.report.plugins import Plugin, RedHatPlugin


class Candlepin(Plugin, RedHatPlugin):
Expand All @@ -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=..
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/ceph_common.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.

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'

Expand Down
3 changes: 2 additions & 1 deletion sos/report/plugins/ceph_mds.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


class CephMDS(Plugin, RedHatPlugin, UbuntuPlugin):

short_desc = 'CEPH mds'
plugin_name = 'ceph_mds'
profiles = ('storage', 'virt', 'container', 'ceph')
Expand Down Expand Up @@ -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([
Expand Down
8 changes: 6 additions & 2 deletions sos/report/plugins/ceph_mon.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,23 @@ 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'
)
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):
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/cgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/chrony.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
21 changes: 12 additions & 9 deletions sos/report/plugins/clear_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# See the LICENSE file in the source distribution for further information.

import re

from sos.report.plugins import Plugin, IndependentPlugin


Expand All @@ -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 = [
Expand All @@ -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'
Expand All @@ -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 :
3 changes: 1 addition & 2 deletions sos/report/plugins/cman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -61,6 +61,5 @@ def postproc(self):
r"(.*secret\s*=\s*)\S+",
r"\1******"
)
return

# vim: et ts=4 sw=4
13 changes: 7 additions & 6 deletions sos/report/plugins/collectd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 4255d13

Please sign in to comment.