Skip to content

Commit

Permalink
pylintrc: re-enable too-few-public-methods (#961)
Browse files Browse the repository at this point in the history
converted classes without any public methods to dataclasses
suppressed the warning where it's a legitimate use case (e.g. issue types)

set the min-public-methods to 1

Signed-off-by: Mustafa Kemal Gilor <[email protected]>
  • Loading branch information
xmkg authored Jul 30, 2024
1 parent 5782eb7 commit 98d5c44
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 95 deletions.
14 changes: 8 additions & 6 deletions hotsos/core/config.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import abc
import copy
from collections import UserDict
from dataclasses import dataclass

from hotsos.core.exceptions import (
NameAlreadyRegisteredError,
)


class ConfigOpt():
@dataclass
class ConfigOpt:
""" Basic information required to define a config option. """
def __init__(self, name, description, default_value, value_type):
self.name = name
self.description = description
self.default_value = default_value
self.value_type = value_type

name: str
description: str
default_value: str
value_type: type


class ConfigOptGroupBase(UserDict):
Expand Down
1 change: 1 addition & 0 deletions hotsos/core/factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import abc


# pylint: disable-next= too-few-public-methods
class FactoryBase(abc.ABC):
"""
Provide a common way to implement factory objects.
Expand Down
10 changes: 7 additions & 3 deletions hotsos/core/host_helpers/apparmor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from functools import cached_property
from dataclasses import dataclass, field

# NOTE: we import direct from searchkit rather than hotsos.core.search to
# avoid circular dependency issues.
Expand All @@ -11,11 +12,14 @@
from hotsos.core.host_helpers.cli import CLIHelperFile


@dataclass
class AAProfile():
""" Representation of an Apparmor profile. """
def __init__(self, name):
self.name = name
self.mode = ApparmorHelper().get_profile_mode(name)
name: str
mode: str = field(init=False)

def __post_init__(self):
self.mode = ApparmorHelper().get_profile_mode(self.name)


class ApparmorHelper():
Expand Down
20 changes: 12 additions & 8 deletions hotsos/core/host_helpers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,17 @@ def __call__(self, *args, **kwargs):
return out


class OVSOFCtlCmdBase():
""" Base class for implementations of ovs-ofctl command. """
OFPROTOCOL_VERSIONS = ['OpenFlow15', 'OpenFlow14', 'OpenFlow13',
'OpenFlow12', 'OpenFlow11', 'OpenFlow10']
OFPROTOCOL_VERSIONS = [
"OpenFlow15",
"OpenFlow14",
"OpenFlow13",
"OpenFlow12",
"OpenFlow11",
"OpenFlow10",
]


class OVSOFCtlBinCmd(OVSOFCtlCmdBase, BinCmd):
class OVSOFCtlBinCmd(BinCmd):
""" Implementation of ovs-ofctl binary command. """
def __call__(self, *args, **kwargs):
"""
Expand All @@ -347,7 +351,7 @@ def __call__(self, *args, **kwargs):
# catch_exceptions decorator and [] returned. We have no way of knowing
# if that was the actual return or an exception was raised so we just
# go ahead and retry with specific OF versions until we get a result.
for ver in self.OFPROTOCOL_VERSIONS:
for ver in OFPROTOCOL_VERSIONS:
log.debug("%s: trying again with protocol version %s",
self.__class__.__name__, ver)
self.reset()
Expand All @@ -361,14 +365,14 @@ def __call__(self, *args, **kwargs):
return CmdOutput([])


class OVSOFCtlFileCmd(OVSOFCtlCmdBase, FileCmd):
class OVSOFCtlFileCmd(FileCmd):
""" Implementation of ovs-ofctl file-based command. """
def __call__(self, *args, **kwargs):
"""
We do this in reverse order to bin command since it won't actually
raise an error.
"""
for ver in self.OFPROTOCOL_VERSIONS:
for ver in OFPROTOCOL_VERSIONS:
log.debug("%s: trying again with protocol version %s",
self.__class__.__name__, ver)
self.reset()
Expand Down
14 changes: 7 additions & 7 deletions hotsos/core/host_helpers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pickle
import re
from functools import cached_property
from dataclasses import dataclass

from searchkit.utils import MPCache
from hotsos.core.config import HotSOSConfig
Expand Down Expand Up @@ -194,15 +195,14 @@ def __call__(self, *args, **kwargs):
return CmdOutput([])


@dataclass(frozen=True)
class CmdOutput():
""" Representation of the output of a command. """
def __init__(self, value, source=None):
"""
@param value: output value.
@param source: optional command source path.
"""
self.value = value
self.source = source

# Output value.
value: str
# Optional command source path.
source: str = None


class SourceRunner():
Expand Down
9 changes: 5 additions & 4 deletions hotsos/core/host_helpers/packaging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import abc
import re
import subprocess
from dataclasses import dataclass

from hotsos.core.factory import FactoryBase
from hotsos.core.host_helpers.cli import CLIHelper
Expand Down Expand Up @@ -476,11 +477,11 @@ def core(self):
return self._core_packages


class AptPackage():
@dataclass(frozen=True)
class AptPackage:
""" Representation of an APT package. """
def __init__(self, name, version):
self.name = name
self.version = version
name: str
version: str


class AptFactory(FactoryBase):
Expand Down
2 changes: 2 additions & 0 deletions hotsos/core/issues/issue_types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: disable=too-few-public-methods

import abc


Expand Down
38 changes: 29 additions & 9 deletions hotsos/core/issues/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import abc
import os
from dataclasses import dataclass, field
from typing import Any

import yaml
from hotsos.core.config import HotSOSConfig
Expand All @@ -23,14 +25,21 @@ def to_dict(self):
return self.context


class IssueEntry():
@dataclass(frozen=True)
class IssueEntry:
""" A single issue object as stored for later use. """
def __init__(self, ref, message, key, context=None):
self.key = key
self.context = context
self.ref = ref
self.message = message
self.origin = f"{HotSOSConfig.plugin_name}.{HotSOSConfig.part_name}"

ref: str
message: str
key: str
context: Any = None
origin: str = field(
# We're using default_factory here to defer the evaluation of
# the "default" value to runtime.
default_factory=(
lambda: f"{HotSOSConfig.plugin_name}.{HotSOSConfig.part_name}"
)
)

@property
def content(self):
Expand Down Expand Up @@ -87,7 +96,13 @@ def load(self):
return {}

def add(self, issue, context=None):
entry = IssueEntry(issue.url, issue.msg, 'id', context=context)
# def __init__(self, ref, message, key, context=None):
entry = IssueEntry(
ref=issue.url,
message=issue.msg,
key='id',
context=context
)
current = self.load()
if current:
current[IssuesManager.SUMMARY_OUT_BUGS_ROOT].append(entry.content)
Expand Down Expand Up @@ -123,7 +138,12 @@ def add(self, issue, context=None):
"""
Fetch the current plugin issues.yaml if it exists and add new issue.
"""
entry = IssueEntry(issue.name, issue.msg, 'type', context=context)
entry = IssueEntry(
ref=issue.name,
message=issue.msg,
key='type',
context=context
)
current = self.load()
key = IssuesManager.SUMMARY_OUT_ISSUES_ROOT
if current:
Expand Down
10 changes: 6 additions & 4 deletions hotsos/core/plugins/juju/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import subprocess
from functools import cached_property
from dataclasses import dataclass

import yaml
from hotsos.core.config import HotSOSConfig
Expand Down Expand Up @@ -167,11 +168,12 @@ def repo_info(self):
return info


class JujuCharm():
@dataclass(frozen=True)
class JujuCharm:
""" Juju charm interface. """
def __init__(self, name, version):
self.name = name
self.version = int(version)

name: str
version: int


class JujuBase():
Expand Down
10 changes: 5 additions & 5 deletions hotsos/core/plugins/kernel/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _pcent_of(self, field_count, total):

return round((count * 100.0) / total, 2)

def _process_file(self, fname):
def process_file(self, fname):
if not os.path.exists(fname):
log.debug("file not found '%s' - skipping load", fname)
return
Expand Down Expand Up @@ -104,8 +104,8 @@ class SNMPBase(ProcNetBase):
""" Base class for /proc/net/snmp interface implementations. """
def __init__(self):
super().__init__()
self._process_file(os.path.join(HotSOSConfig.data_root,
'proc/net/snmp'))
self.process_file(os.path.join(HotSOSConfig.data_root,
'proc/net/snmp'))


class SNMPTcp(SNMPBase):
Expand Down Expand Up @@ -202,8 +202,8 @@ class NetStatBase(ProcNetBase):
""" Base class for /proc/net/netstat implementations. """
def __init__(self):
super().__init__()
self._process_file(os.path.join(HotSOSConfig.data_root,
'proc/net/netstat'))
self.process_file(os.path.join(HotSOSConfig.data_root,
'proc/net/netstat'))
self.net_snmp_tcp = SNMPTcp()


Expand Down
12 changes: 7 additions & 5 deletions hotsos/core/plugins/openstack/neutron.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import re
from functools import cached_property
from dataclasses import dataclass

from hotsos.core.config import HotSOSConfig
from hotsos.core.factory import FactoryBase
Expand Down Expand Up @@ -67,12 +68,13 @@ def ovs_cleanup_run_manually(self):
return run_manually


class NeutronRouter():
@dataclass
class NeutronRouter:
""" Representation of a Neutron router. """
def __init__(self, uuid, ha_state):
self.uuid = uuid
self.ha_state = ha_state
self.vr_id = None

uuid: str
ha_state: str
vr_id: str = None


class NeutronHAInfo():
Expand Down
12 changes: 7 additions & 5 deletions hotsos/core/plugins/openvswitch/ovn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import abc
from functools import cached_property
from dataclasses import dataclass

from hotsos.core.log import log
from hotsos.core.search import (
Expand All @@ -14,11 +15,12 @@
from hotsos.core.plugins.openvswitch.common import OVS_SERVICES_EXPRS


class OVNSBDBPort():
@dataclass
class OVNSBDBPort:
""" Representation of OVS SBDB port """
def __init__(self, name, port_type):
self.name = name
self.type = port_type

name: str
port_type: str


class OVNSBDBChassis():
Expand Down Expand Up @@ -47,7 +49,7 @@ def ports(self):

@cached_property
def cr_ports(self):
return [p for p in self._ports if p.type == 'cr-lrp']
return [p for p in self._ports if p.port_type == 'cr-lrp']


class OVNDBBase():
Expand Down
Loading

0 comments on commit 98d5c44

Please sign in to comment.