Skip to content
/ hotsos Public
forked from canonical/hotsos

Commit

Permalink
Re-enables pylint inconsistent-return-statements check (canonical#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
dosaboy authored Jul 4, 2024
1 parent 7844aac commit bb1e90b
Show file tree
Hide file tree
Showing 57 changed files with 400 additions and 201 deletions.
2 changes: 1 addition & 1 deletion hotsos/core/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def get_event_stats(self):
""" Return common statistics on the dataset of events. """
events = self.data.complete_events
if not events:
return
return {}

events = [s["duration"] for s in events.values()]
stats = {'min': round(min(events), 2),
Expand Down
2 changes: 2 additions & 0 deletions hotsos/core/host_helpers/apparmor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def get_profile_mode(self, name):
if name in profiles['profiles']:
return mode

return None

@property
def profiles_enforce(self):
return self.profiles.get('enforce', {}).get('profiles', [])
Expand Down
8 changes: 7 additions & 1 deletion hotsos/core/host_helpers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ def __call__(self, *args, **kwargs):
log.debug("%s: command with no protocol version failed",
self.__class__.__name__)

return None


class DateBinCmd(BinCmd):

Expand Down Expand Up @@ -661,6 +663,8 @@ def fsource(self, *args, **kwargs):
except SourceNotFound:
pass

return None

def _execute(self, *args, **kwargs):
# always try file sources first
ret = self.fsource(*args, **kwargs)
Expand Down Expand Up @@ -1118,6 +1122,8 @@ def __getattr__(self, cmdname):
except KeyError as exc:
raise CommandNotFound(cmdname, exc) from exc

return None


def get_ps_axo_flags_available():
path = os.path.join(HotSOSConfig.data_root,
Expand All @@ -1129,7 +1135,7 @@ def get_ps_axo_flags_available():
_paths.append(path)

if not _paths:
return
return None

# strip data_root since it will be prepended later
return _paths[0].partition(HotSOSConfig.data_root)[2]
2 changes: 2 additions & 0 deletions hotsos/core/host_helpers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def get_cmd_from_ps_line(self, line, expr):
expr_type)
return cmd

return None

@property
@abc.abstractmethod
def services(self):
Expand Down
11 changes: 10 additions & 1 deletion hotsos/core/host_helpers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def cache_load(self, key):
contents = self.cache.get(key)
if not contents:
log.debug("network port %s not found in cache", self.name)
return
return None

log.debug("loading network port %s from cache", self.name)
return contents
Expand Down Expand Up @@ -189,6 +189,7 @@ def cache_load(self, key, all_namespaces=False, namespace=None):
log.debug("network helper info not available in cache "
"(all_namespaces=%s, namespace=%s)", all_namespaces,
namespace)
return None

def cache_save(self, key, value, all_namespaces=False, namespace=None):
log.debug("saving network helper info to cache (all_namespaces=%s, "
Expand Down Expand Up @@ -321,6 +322,8 @@ def _get_interfaces(self, all_namespaces=False):
for iface in interfaces_raw:
yield NetworkPort(**iface)

return None

@property
def host_interfaces(self):
if self._host_interfaces is not None:
Expand Down Expand Up @@ -348,17 +351,23 @@ def get_interface_with_hwaddr(self, hwaddr):
if iface.hwaddr == hwaddr:
return iface

return None

def get_interface_with_addr(self, addr):
for iface in self.host_interfaces_all:
for _addr in iface.addresses:
if _addr.startswith(addr):
return iface

return None

def get_interface_with_name(self, name):
for iface in self.host_interfaces_all:
if iface.name == name:
return iface

return None

def host_interface_exists(self, name, check_namespaces=True):
names = [_iface.name for _iface in self.host_interfaces]
if name in names:
Expand Down
16 changes: 13 additions & 3 deletions hotsos/core/host_helpers/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def _all(self):
used_images = self.get_container_images()
image_list = self.cli.docker_images()
if not image_list:
return
return None

all_exprs = self.core_image_exprs + self.other_image_exprs
for line in image_list:
Expand Down Expand Up @@ -403,6 +403,8 @@ def get_version(self, pkg):
if name:
return version

return None

def _match_package(self, pkg, entry):
""" Returns tuple of (package name, version) """
expr = self._match_expr_template.format(pkg)
Expand Down Expand Up @@ -489,6 +491,8 @@ def __getattr__(self, name):
if name in helper.all:
return AptPackage(name, helper.all[name])

return None


class SnapPackageHelper(PackageHelperBase):

Expand Down Expand Up @@ -522,7 +526,7 @@ def _get_snap_info_from_line(line, cexpr):
'channel': ret.group(4),
}

return
return None

def get_revision(self, snap):
""" Return revision of package.
Expand All @@ -531,6 +535,8 @@ def get_revision(self, snap):
if info:
return info[0]['revision']

return None

def get_version(self, pkg):
""" Return version of snap package.
Expand All @@ -540,6 +546,8 @@ def get_version(self, pkg):
if info:
return info[0]['version']

return None

def get_channel(self, pkg):
""" Return channel of snap package.
Expand All @@ -549,6 +557,8 @@ def get_channel(self, pkg):
if info:
return info[0]['channel']

return None

def _get_snap_info(self, snap_name_expr):
"""
Return a list of info for snaps matched using the expression.
Expand All @@ -558,7 +568,7 @@ def _get_snap_info(self, snap_name_expr):
@return: a list of snaps and their info.
"""
if not self.snap_list_all:
return
return None

info = []
cexpr = re.compile(self._match_expr_template.format(snap_name_expr))
Expand Down
3 changes: 2 additions & 1 deletion hotsos/core/host_helpers/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def start_time(self):
if len(sections) == 0:
log.warning("no active status found for %s.service (state=%s)",
self.name, self.state)
return
return None

if len(sections) > 1:
log.warning("more than one status found for %s.service",
Expand All @@ -112,6 +112,7 @@ def start_time(self):
tzinfos=self._tzinfos)
log.debug("no start time identified for svc %s (state=%s)", self.name,
self.state)
return None

@cached_property
def start_time_secs(self):
Expand Down
4 changes: 3 additions & 1 deletion hotsos/core/host_helpers/uptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def in_minutes(self):
""" Total uptime in minutes. """
if not self.subgroups:
log.info("uptime not available")
return
return None

if self.subgroups['hour']['value']:
expr = self.subgroups['hour']['expr']
Expand Down Expand Up @@ -90,3 +90,5 @@ def __repr__(self):
def loadavg(self):
if self.subgroups:
return self.subgroups['loadavg']['value']

return None
20 changes: 15 additions & 5 deletions hotsos/core/plugins/juju/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def id(self):
if name:
return name.partition("jujud-machine-")[2]

return None

@cached_property
def config(self):
path = glob.glob(os.path.join(self.juju_lib_path,
Expand All @@ -31,9 +33,12 @@ def config(self):

# NOTE: we only expect one of these to exist
path = path[0]
if not os.path.exists(path):
return None

# filter out 'sanitised' lines since they will not be valid yaml
if os.path.exists(path):
ftmp = utils.mktemp_dump("")
ftmp = utils.mktemp_dump("")
try:
with open(ftmp, 'w') as fdtmp:
expr = re.compile(r"\*{9}")
with open(path) as fd:
Expand All @@ -43,9 +48,10 @@ def config(self):

with open(ftmp) as fd:
cfg = yaml.safe_load(fd)

finally:
os.remove(ftmp)
return cfg

return cfg

@cached_property
def agent_service_name(self):
Expand All @@ -63,6 +69,8 @@ def agent_bin_path(self):
for path in glob.glob(path):
return path

return None

@cached_property
def version(self):
"""
Expand Down Expand Up @@ -136,6 +144,8 @@ def charm_name(self):
# e.g. ch_3a_amd64_2f_focal_2f_mysql-innodb-cluster-30
return manifest_file.split('_')[-1].rpartition('-')[0]

return None

@cached_property
def repo_info(self):
"""
Expand Down Expand Up @@ -176,7 +186,7 @@ def machine(self):
machine = JujuMachine(self.juju_lib_path)
if not machine.config:
log.debug("no juju machine identified")
return
return None

return machine

Expand Down
2 changes: 2 additions & 0 deletions hotsos/core/plugins/kernel/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def boot_parameters(self):

return parameters

return None


class KernelChecksBase(KernelBase, plugintools.PluginPartBase):
plugin_name = 'kernel'
Expand Down
2 changes: 2 additions & 0 deletions hotsos/core/plugins/kernel/kernlog/calltrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,5 @@ def __getattr__(self, name):
for h in self.tracetypes:
if h.name == name.replace('_', '-'):
return h

return None
26 changes: 13 additions & 13 deletions hotsos/core/plugins/kernel/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def _load_slab_info(self):
int(sections[2]),
int(sections[3])])

return None

@property
def major_consumers(self):
top5 = []
Expand Down Expand Up @@ -243,15 +245,15 @@ def block_sizes_available(self):
return self._block_sizes

node_zones = BuddyInfo().get_node_zones(self.zone, self.node)
if node_zones is None:
return
if node_zones:
# start from highest order zone (10) and work down to 0
for order in range(10, -1, -1):
free = int(node_zones.split()[5 + order - 1])
self._block_sizes[order] = free

# start from highest order zone (10) and work down to 0
for order in range(10, -1, -1):
free = int(node_zones.split()[5 + order - 1])
self._block_sizes[order] = free
return self._block_sizes

return self._block_sizes
return None

@property
def empty_order_tally(self):
Expand Down Expand Up @@ -329,11 +331,9 @@ def nodes_with_limited_high_order_memory(self):
"""
nodes = []
_nodes = self.nodes_with_limited_high_order_memory_full
if not _nodes:
return

for node, zones in _nodes['nodes'].items():
for name in zones['zones']:
nodes.append("node{}-{}".format(node, name.lower()))
if _nodes:
for node, zones in _nodes['nodes'].items():
for name in zones['zones']:
nodes.append("node{}-{}".format(node, name.lower()))

return nodes
7 changes: 5 additions & 2 deletions hotsos/core/plugins/kernel/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def _maybe_parse_sysctl_net_ipv4_xmem(self, key):
def _process_file(self, fname):
if not os.path.exists(fname):
log.debug("file not found '%s' - skipping load", fname)
return
return None

log.debug("start processing %s", fname)
with open(fname) as fd:
Expand All @@ -356,6 +356,8 @@ def _process_file(self, fname):
label, stats, e)
continue

return None

@property
def _header(self):
# We do not expect this to be used
Expand Down Expand Up @@ -621,7 +623,8 @@ def all_with_drops(self):
@property
def all_with_drops_str(self):
if not self.all_with_drops:
return
return None

drops_info = [
f"\tnlsock inode `{nlsock.sk_inode_num}`: "
f"procs[{','.join(nlsock.procs)}]"
Expand Down
Loading

0 comments on commit bb1e90b

Please sign in to comment.