diff --git a/nodescraper/cli/helper.py b/nodescraper/cli/helper.py index aa6ea854..b07c1696 100644 --- a/nodescraper/cli/helper.py +++ b/nodescraper/cli/helper.py @@ -344,11 +344,13 @@ def generate_reference_config( plugin = plugin_reg.plugins.get(obj.source) - args = extract_analyzer_args_from_model(plugin, data_model, logger) - if not args: - continue - plugins[obj.source] = {"analysis_args": {}} - plugins[obj.source]["analysis_args"] = args.model_dump(exclude_none=True) + if obj.source not in plugins: + plugins[obj.source] = {} + + a_args = extract_analyzer_args_from_model(plugin, data_model, logger) + if a_args: + plugins[obj.source]["analysis_args"] = a_args.model_dump(exclude_none=True) + plugin_config.plugins = plugins return plugin_config diff --git a/nodescraper/models/__init__.py b/nodescraper/models/__init__.py index 55a8f286..af9673c1 100644 --- a/nodescraper/models/__init__.py +++ b/nodescraper/models/__init__.py @@ -24,6 +24,7 @@ # ############################################################################### from .analyzerargs import AnalyzerArgs +from .collectorargs import CollectorArgs from .datamodel import DataModel from .datapluginresult import DataPluginResult from .event import Event @@ -35,6 +36,7 @@ __all__ = [ "AnalyzerArgs", + "CollectorArgs", "DataModel", "TaskResult", "Event", diff --git a/nodescraper/models/collectorargs.py b/nodescraper/models/collectorargs.py new file mode 100644 index 00000000..ebc84952 --- /dev/null +++ b/nodescraper/models/collectorargs.py @@ -0,0 +1,30 @@ +############################################################################### +# +# MIT License +# +# Copyright (c) 2025 Advanced Micro Devices, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +############################################################################### +from pydantic import BaseModel + + +class CollectorArgs(BaseModel): + model_config = {"extra": "forbid", "exclude_none": True} diff --git a/nodescraper/plugins/inband/process/collector_args.py b/nodescraper/plugins/inband/process/collector_args.py index e0d54652..87a65ba5 100644 --- a/nodescraper/plugins/inband/process/collector_args.py +++ b/nodescraper/plugins/inband/process/collector_args.py @@ -23,10 +23,9 @@ # SOFTWARE. # ############################################################################### -from pydantic import BaseModel +from nodescraper.models import CollectorArgs -class ProcessCollectorArgs(BaseModel): - top_n_process: int = 10 - model_config = {"extra": "forbid"} +class ProcessCollectorArgs(CollectorArgs): + top_n_process: int = 10 diff --git a/nodescraper/plugins/inband/process/process_plugin.py b/nodescraper/plugins/inband/process/process_plugin.py index 2bfcf7e0..d2549dca 100644 --- a/nodescraper/plugins/inband/process/process_plugin.py +++ b/nodescraper/plugins/inband/process/process_plugin.py @@ -42,3 +42,5 @@ class ProcessPlugin(InBandDataPlugin[ProcessDataModel, ProcessCollectorArgs, Pro ANALYZER = ProcessAnalyzer ANALYZER_ARGS = ProcessAnalyzerArgs + + COLLECTOR_ARGS = ProcessCollectorArgs diff --git a/test/unit/framework/common/shared_utils.py b/test/unit/framework/common/shared_utils.py index 7ebe6720..1ffda40d 100644 --- a/test/unit/framework/common/shared_utils.py +++ b/test/unit/framework/common/shared_utils.py @@ -72,11 +72,11 @@ class TestModelArg(AnalyzerArgs): @classmethod def build_from_model(cls, model): - return cls(model_attr=int(model.some_version)) + return cls(model_attr=int(model.foo)) class DummyDataModel(DataModel): - some_version: str = None + foo: str = None class TestPluginA(PluginInterface[MockConnectionManager, None]): diff --git a/test/unit/framework/test_cli_helper.py b/test/unit/framework/test_cli_helper.py index 8ff75f5f..b78ed9ca 100644 --- a/test/unit/framework/test_cli_helper.py +++ b/test/unit/framework/test_cli_helper.py @@ -31,11 +31,16 @@ from types import SimpleNamespace import pytest -from common.shared_utils import DummyDataModel + +# from common.shared_utils import DummyDataModel +from conftest import DummyDataModel from pydantic import BaseModel from nodescraper.cli import cli -from nodescraper.cli.helper import build_config, find_datamodel_and_result +from nodescraper.cli.helper import ( + build_config, + find_datamodel_and_result, +) from nodescraper.configregistry import ConfigRegistry from nodescraper.enums import ExecutionStatus, SystemInteractionLevel from nodescraper.models import PluginConfig, TaskResult @@ -50,7 +55,7 @@ def test_generate_reference_config(plugin_registry): source="TestPluginA", message="Plugin tasks completed successfully", result_data=DataPluginResult( - system_data=DummyDataModel(some_version="17"), + system_data=DummyDataModel(foo="17"), collection_result=TaskResult( status=ExecutionStatus.OK, message="BIOS: 17",