Skip to content

Commit 565fc7e

Browse files
committed
added docstrings
1 parent 1357cbe commit 565fc7e

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

nodescraper/plugins/inband/kernel_module/analyzer_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class KernelModuleAnalyzerArgs(AnalyzerArgs):
3939

4040
@classmethod
4141
def build_from_model(cls, datamodel: KernelModuleDataModel) -> "KernelModuleAnalyzerArgs":
42-
"""build analyzer args from data model
42+
"""build analyzer args from data model and filter by datamodel.regex_filter
4343
4444
Args:
4545
datamodel (KernelModuleDataModel): data model for plugin

nodescraper/plugins/inband/kernel_module/kernel_module_analyzer.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ class KernelModuleAnalyzer(DataAnalyzer[KernelModuleDataModel, KernelModuleAnaly
4242
def filter_modules_by_pattern(
4343
self, modules: dict[str, dict], patterns: list[str] = None
4444
) -> tuple[dict[str, dict], list[str]]:
45+
"""Filter modules by pattern
46+
47+
Args:
48+
modules (dict[str, dict]): modules to be filtered
49+
patterns (list[str], optional): pattern to us. Defaults to None.
50+
51+
Returns:
52+
tuple[dict[str, dict], list[str]]: tuple - dict of modules filtered,
53+
list of unmatched pattern
54+
"""
4555
if patterns is None:
4656
return modules, []
4757

@@ -64,6 +74,16 @@ def filter_modules_by_pattern(
6474
def filter_modules_by_name_and_param(
6575
self, modules: dict[str, dict], to_match: dict[str, dict]
6676
) -> tuple[dict[str, dict], dict[str, dict]]:
77+
"""Filter modules by name, param and value
78+
79+
Args:
80+
modules (dict[str, dict]): modules to be filtered
81+
to_match (dict[str, dict]): modules to match
82+
83+
Returns:
84+
tuple[dict[str, dict], dict[str, dict]]: tuple - dict of modules filtered,
85+
dict of modules unmatched
86+
"""
6787
if not to_match:
6888
return modules, {}
6989

@@ -75,7 +95,6 @@ def filter_modules_by_name_and_param(
7595
actual_data = modules.get(mod_name)
7696

7797
if not actual_data:
78-
# Module completely missing
7998
unmatched[mod_name] = expected_data
8099
continue
81100

nodescraper/plugins/inband/kernel_module/kernel_module_collector.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#
2525
###############################################################################
2626
from nodescraper.base import InBandDataCollector
27+
from nodescraper.connection.inband.inband import CommandArtifact
2728
from nodescraper.enums import EventCategory, EventPriority, ExecutionStatus, OSFamily
2829
from nodescraper.models import TaskResult
2930

@@ -35,8 +36,15 @@ class KernelModuleCollector(InBandDataCollector[KernelModuleDataModel, None]):
3536

3637
DATA_MODEL = KernelModuleDataModel
3738

38-
def parse_proc_modules(self, output):
39-
"""Parses the output of /proc/modules into a dictionary."""
39+
def parse_proc_modules(self, output: dict) -> dict:
40+
"""Parse command output and return dict of modules
41+
42+
Args:
43+
output (dict): sut cmd output
44+
45+
Returns:
46+
dict: parsed modules
47+
"""
4048
modules = {}
4149
for line in output.strip().splitlines():
4250
parts = line.split()
@@ -48,8 +56,15 @@ def parse_proc_modules(self, output):
4856
}
4957
return modules
5058

51-
def get_module_parameters(self, module_name):
52-
"""Fetches parameter names and values for a given kernel module using _run_sut_cmd."""
59+
def get_module_parameters(self, module_name: str) -> dict:
60+
"""Fetches parameter names and values for a given kernel module using _run_sut_cmd
61+
62+
Args:
63+
module_name (str): name of module to fetch params for
64+
65+
Returns:
66+
dict: param dict of module
67+
"""
5368
param_dict = {}
5469
param_dir = f"/sys/module/{module_name}/parameters"
5570

@@ -66,7 +81,15 @@ def get_module_parameters(self, module_name):
6681

6782
return param_dict
6883

69-
def collect_all_module_info(self):
84+
def collect_all_module_info(self) -> tuple[dict, CommandArtifact]:
85+
"""Get all modules and its associated params and values
86+
87+
Raises:
88+
RuntimeError: error for failing to get modules
89+
90+
Returns:
91+
tuple[dict, CommandArtifact]: modules found and exit code
92+
"""
7093
res = self._run_sut_cmd("cat /proc/modules")
7194
if res.exit_code != 0:
7295
raise RuntimeError("Failed to read /proc/modules")
@@ -78,10 +101,7 @@ def collect_all_module_info(self):
78101

79102
return modules, res
80103

81-
def collect_data(
82-
self,
83-
args=None,
84-
) -> tuple[TaskResult, KernelModuleDataModel | None]:
104+
def collect_data(self, args=None) -> tuple[TaskResult, KernelModuleDataModel | None]:
85105
"""
86106
Collect kernel modules data.
87107

0 commit comments

Comments
 (0)