Skip to content

Commit 80f65b9

Browse files
committed
added build_from_model for MemoryPlugin, to overwrite upper bound with --gen-plugin-config
1 parent 5c380e0 commit 80f65b9

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

nodescraper/plugins/inband/memory/analyzer_args.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,21 @@
2525
###############################################################################
2626
from nodescraper.models.analyzerargs import AnalyzerArgs
2727

28+
from .memorydata import MemoryDataModel
29+
2830

2931
class MemoryAnalyzerArgs(AnalyzerArgs):
3032
ratio: float = 0.66
3133
memory_threshold: str = "30Gi"
34+
35+
@classmethod
36+
def build_from_model(cls, datamodel: MemoryDataModel) -> "MemoryAnalyzerArgs":
37+
"""build analyzer args from data model
38+
39+
Args:
40+
datamodel (MemoryDataModel): data model for plugin
41+
42+
Returns:
43+
MemoryAnalyzerArgs: instance of analyzer args class
44+
"""
45+
return cls(memory_threshold=datamodel.mem_total)

nodescraper/plugins/inband/memory/memory_plugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ class MemoryPlugin(InBandDataPlugin[MemoryDataModel, None, MemoryAnalyzerArgs]):
3939
COLLECTOR = MemoryCollector
4040

4141
ANALYZER = MemoryAnalyzer
42+
43+
ANALYZER_ARGS = MemoryAnalyzerArgs

test/functional/test_reference_config_workflow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def test_reference_config_with_analysis_args(run_cli_command, tmp_path):
234234
"DkmsPlugin",
235235
"KernelPlugin",
236236
"KernelModulePlugin",
237+
"MemoryPlugin",
237238
"OsPlugin",
238239
"PackagePlugin",
239240
"ProcessPlugin",

test/unit/plugin/test_analyzer_args_build_from_model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
from nodescraper.plugins.inband.kernel_module.kernel_module_data import (
4949
KernelModuleDataModel,
5050
)
51+
from nodescraper.plugins.inband.memory.analyzer_args import MemoryAnalyzerArgs
52+
from nodescraper.plugins.inband.memory.memorydata import MemoryDataModel
5153
from nodescraper.plugins.inband.os.analyzer_args import OsAnalyzerArgs
5254
from nodescraper.plugins.inband.os.osdata import OsDataModel
5355
from nodescraper.plugins.inband.package.analyzer_args import PackageAnalyzerArgs
@@ -207,3 +209,12 @@ def test_kernel_module_analyzer_args_build_from_model():
207209
assert "amd_iommu" in args.kernel_modules
208210
assert "other_module" not in args.kernel_modules
209211
assert args.regex_filter == []
212+
213+
214+
def test_memory_analyzer_args_build_from_model():
215+
"""Test MemoryAnalyzerArgs.build_from_model includes all fields"""
216+
datamodel = MemoryDataModel(mem_free="128Gi", mem_total="256Gi")
217+
args = MemoryAnalyzerArgs.build_from_model(datamodel)
218+
219+
assert isinstance(args, MemoryAnalyzerArgs)
220+
assert args.memory_threshold == "256Gi"

0 commit comments

Comments
 (0)