From b9cab6b06255fc9e3fe8c16d4660e665da27f9ef Mon Sep 17 00:00:00 2001 From: Alexandra Bara Date: Fri, 19 Dec 2025 09:38:09 -0600 Subject: [PATCH 1/4] adding collector arg to disable writing full dmesg log to disk --- .../plugins/inband/dmesg/collector_args.py | 1 + test/unit/plugin/test_dmesg_collector.py | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/nodescraper/plugins/inband/dmesg/collector_args.py b/nodescraper/plugins/inband/dmesg/collector_args.py index a2313c54..9c443ffb 100644 --- a/nodescraper/plugins/inband/dmesg/collector_args.py +++ b/nodescraper/plugins/inband/dmesg/collector_args.py @@ -36,3 +36,4 @@ class DmesgCollectorArgs(CollectorArgs): collect_rotated_logs: bool = False skip_sudo: bool = False + collect_dmesg_log: bool = True diff --git a/test/unit/plugin/test_dmesg_collector.py b/test/unit/plugin/test_dmesg_collector.py index d3c4553a..1884fb85 100644 --- a/test/unit/plugin/test_dmesg_collector.py +++ b/test/unit/plugin/test_dmesg_collector.py @@ -32,6 +32,7 @@ from nodescraper.enums.systeminteraction import SystemInteractionLevel from nodescraper.interfaces.task import SystemCompatibilityError from nodescraper.models.systeminfo import OSFamily +from nodescraper.plugins.inband.dmesg.collector_args import DmesgCollectorArgs from nodescraper.plugins.inband.dmesg.dmesg_collector import DmesgCollector from nodescraper.plugins.inband.dmesg.dmesgdata import DmesgData @@ -276,3 +277,27 @@ def run_map(cmd, **kwargs): assert isinstance(data, DmesgData) assert data.dmesg_content == "DMESG OUTPUT\n" + + +def test_collect_data_with_args(conn_mock, system_info): + """Test collect_data accepts DmesgCollectorArgs""" + dmesg = "2023-06-01T01:00:00,685236-05:00 test message1\n" + conn_mock.run_command.return_value = CommandArtifact( + exit_code=0, + stdout=dmesg, + stderr="", + command="dmesg --time-format iso", + ) + + collector = DmesgCollector( + system_info=system_info, + system_interaction_level=SystemInteractionLevel.INTERACTIVE, + connection=conn_mock, + ) + + args = DmesgCollectorArgs(collect_dmesg_log=False) + res, data = collector.collect_data(args=args) + + assert res.status == ExecutionStatus.OK + assert data is not None + assert data.dmesg_content == dmesg From 8ab3f297f0cbde0a2d99d6aa6d2b24f02f2038eb Mon Sep 17 00:00:00 2001 From: Alexandra Bara Date: Fri, 19 Dec 2025 10:14:13 -0600 Subject: [PATCH 2/4] skipping logging to file --- nodescraper/plugins/inband/dmesg/dmesg_collector.py | 4 +++- nodescraper/plugins/inband/dmesg/dmesgdata.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/nodescraper/plugins/inband/dmesg/dmesg_collector.py b/nodescraper/plugins/inband/dmesg/dmesg_collector.py index 5e7148f1..b5bf0e0d 100644 --- a/nodescraper/plugins/inband/dmesg/dmesg_collector.py +++ b/nodescraper/plugins/inband/dmesg/dmesg_collector.py @@ -155,7 +155,9 @@ def collect_data( self._collect_dmesg_rotations() if dmesg_content: - dmesg_data = DmesgData(dmesg_content=dmesg_content) + dmesg_data = DmesgData( + dmesg_content=dmesg_content, skip_log_file=not args.collect_dmesg_log + ) self.result.message = "Dmesg data collected" return self.result, dmesg_data diff --git a/nodescraper/plugins/inband/dmesg/dmesgdata.py b/nodescraper/plugins/inband/dmesg/dmesgdata.py index 541b3ea0..26c7f9f3 100644 --- a/nodescraper/plugins/inband/dmesg/dmesgdata.py +++ b/nodescraper/plugins/inband/dmesg/dmesgdata.py @@ -35,6 +35,7 @@ class DmesgData(DataModel): """Data model for in band dmesg log""" dmesg_content: str + skip_log_file: bool = False @classmethod def get_new_dmesg_lines(cls, current_dmesg: str, new_dmesg: str) -> str: @@ -83,6 +84,8 @@ def log_model(self, log_path: str): Args: log_path (str): log path """ + if self.skip_log_file: + return log_name = os.path.join(log_path, get_unique_filename(log_path, "dmesg.log")) with open(log_name, "w", encoding="utf-8") as log_file: log_file.write(self.dmesg_content) From 65111e90940d7bc44ed1462334e235ede96d190b Mon Sep 17 00:00:00 2001 From: Alexandra Bara Date: Fri, 19 Dec 2025 10:20:53 -0600 Subject: [PATCH 3/4] functional test update --- test/functional/test_plugin_configs.py | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/functional/test_plugin_configs.py b/test/functional/test_plugin_configs.py index 501b707b..7577dcce 100644 --- a/test/functional/test_plugin_configs.py +++ b/test/functional/test_plugin_configs.py @@ -283,3 +283,54 @@ def test_all_plugin_config_files_exist(plugin_config_files): config = json.load(f) assert "plugins" in config assert plugin_name in config["plugins"] + + +def test_dmesg_plugin_collect_dmesg_log_false(run_cli_command, tmp_path): + """Test DmesgPlugin with collect_dmesg_log=false doesn't write dmesg.log.""" + config = { + "name": "DmesgNoLogConfig", + "desc": "DmesgPlugin config with collect_dmesg_log disabled", + "global_args": {}, + "plugins": {"DmesgPlugin": {"collection_args": {"collect_dmesg_log": False}}}, + "result_collators": {}, + } + config_file = tmp_path / "dmesg_no_log_config.json" + config_file.write_text(json.dumps(config, indent=2)) + + log_path = str(tmp_path / "logs_dmesg_no_log") + result = run_cli_command( + ["--log-path", log_path, "--plugin-configs", str(config_file)], check=False + ) + + assert result.returncode in [0, 1, 2] + + dmesg_plugin_dir = Path(log_path) / "dmesg_plugin" / "dmesg_collector" + if dmesg_plugin_dir.exists(): + dmesg_log_files = list(dmesg_plugin_dir.glob("dmesg*.log")) + assert ( + len(dmesg_log_files) == 0 + ), f"Found dmesg log files when collect_dmesg_log=False: {dmesg_log_files}" + + +def test_dmesg_plugin_collect_dmesg_log_true(run_cli_command, tmp_path): + """Test DmesgPlugin with collect_dmesg_log=true writes dmesg.log.""" + config = { + "name": "DmesgWithLogConfig", + "desc": "DmesgPlugin config with collect_dmesg_log enabled", + "global_args": {}, + "plugins": {"DmesgPlugin": {"collection_args": {"collect_dmesg_log": True}}}, + "result_collators": {}, + } + config_file = tmp_path / "dmesg_with_log_config.json" + config_file.write_text(json.dumps(config, indent=2)) + + log_path = str(tmp_path / "logs_dmesg_with_log") + result = run_cli_command( + ["--log-path", log_path, "--plugin-configs", str(config_file)], check=False + ) + + if result.returncode in [0, 1]: + dmesg_plugin_dir = Path(log_path) / "dmesg_plugin" / "dmesg_collector" + if dmesg_plugin_dir.exists(): + dmesg_log_files = list(dmesg_plugin_dir.glob("dmesg*.log")) + assert len(dmesg_log_files) > 0, "Expected dmesg.log file when collect_dmesg_log=True" From c8c5106f4e0463b117603168a14f703600ba1b40 Mon Sep 17 00:00:00 2001 From: Alexandra Bara Date: Fri, 19 Dec 2025 11:22:28 -0600 Subject: [PATCH 4/4] var rename --- .../plugins/inband/dmesg/collector_args.py | 2 +- .../plugins/inband/dmesg/dmesg_collector.py | 2 +- test/functional/test_plugin_configs.py | 20 +++++++++---------- test/unit/plugin/test_dmesg_collector.py | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/nodescraper/plugins/inband/dmesg/collector_args.py b/nodescraper/plugins/inband/dmesg/collector_args.py index 9c443ffb..22d85f17 100644 --- a/nodescraper/plugins/inband/dmesg/collector_args.py +++ b/nodescraper/plugins/inband/dmesg/collector_args.py @@ -36,4 +36,4 @@ class DmesgCollectorArgs(CollectorArgs): collect_rotated_logs: bool = False skip_sudo: bool = False - collect_dmesg_log: bool = True + log_dmesg_data: bool = True diff --git a/nodescraper/plugins/inband/dmesg/dmesg_collector.py b/nodescraper/plugins/inband/dmesg/dmesg_collector.py index b5bf0e0d..c280d7d2 100644 --- a/nodescraper/plugins/inband/dmesg/dmesg_collector.py +++ b/nodescraper/plugins/inband/dmesg/dmesg_collector.py @@ -156,7 +156,7 @@ def collect_data( if dmesg_content: dmesg_data = DmesgData( - dmesg_content=dmesg_content, skip_log_file=not args.collect_dmesg_log + dmesg_content=dmesg_content, skip_log_file=not args.log_dmesg_data ) self.result.message = "Dmesg data collected" return self.result, dmesg_data diff --git a/test/functional/test_plugin_configs.py b/test/functional/test_plugin_configs.py index 7577dcce..d42382ce 100644 --- a/test/functional/test_plugin_configs.py +++ b/test/functional/test_plugin_configs.py @@ -285,13 +285,13 @@ def test_all_plugin_config_files_exist(plugin_config_files): assert plugin_name in config["plugins"] -def test_dmesg_plugin_collect_dmesg_log_false(run_cli_command, tmp_path): - """Test DmesgPlugin with collect_dmesg_log=false doesn't write dmesg.log.""" +def test_dmesg_plugin_log_dmesg_data_false(run_cli_command, tmp_path): + """Test DmesgPlugin with log_dmesg_data=false doesn't write dmesg.log.""" config = { "name": "DmesgNoLogConfig", - "desc": "DmesgPlugin config with collect_dmesg_log disabled", + "desc": "DmesgPlugin config with log_dmesg_data disabled", "global_args": {}, - "plugins": {"DmesgPlugin": {"collection_args": {"collect_dmesg_log": False}}}, + "plugins": {"DmesgPlugin": {"collection_args": {"log_dmesg_data": False}}}, "result_collators": {}, } config_file = tmp_path / "dmesg_no_log_config.json" @@ -309,16 +309,16 @@ def test_dmesg_plugin_collect_dmesg_log_false(run_cli_command, tmp_path): dmesg_log_files = list(dmesg_plugin_dir.glob("dmesg*.log")) assert ( len(dmesg_log_files) == 0 - ), f"Found dmesg log files when collect_dmesg_log=False: {dmesg_log_files}" + ), f"Found dmesg log files when log_dmesg_data=False: {dmesg_log_files}" -def test_dmesg_plugin_collect_dmesg_log_true(run_cli_command, tmp_path): - """Test DmesgPlugin with collect_dmesg_log=true writes dmesg.log.""" +def test_dmesg_plugin_log_dmesg_data_true(run_cli_command, tmp_path): + """Test DmesgPlugin with log_dmesg_data=true writes dmesg.log.""" config = { "name": "DmesgWithLogConfig", - "desc": "DmesgPlugin config with collect_dmesg_log enabled", + "desc": "DmesgPlugin config with log_dmesg_data enabled", "global_args": {}, - "plugins": {"DmesgPlugin": {"collection_args": {"collect_dmesg_log": True}}}, + "plugins": {"DmesgPlugin": {"collection_args": {"log_dmesg_data": True}}}, "result_collators": {}, } config_file = tmp_path / "dmesg_with_log_config.json" @@ -333,4 +333,4 @@ def test_dmesg_plugin_collect_dmesg_log_true(run_cli_command, tmp_path): dmesg_plugin_dir = Path(log_path) / "dmesg_plugin" / "dmesg_collector" if dmesg_plugin_dir.exists(): dmesg_log_files = list(dmesg_plugin_dir.glob("dmesg*.log")) - assert len(dmesg_log_files) > 0, "Expected dmesg.log file when collect_dmesg_log=True" + assert len(dmesg_log_files) > 0, "Expected dmesg.log file when log_dmesg_data=True" diff --git a/test/unit/plugin/test_dmesg_collector.py b/test/unit/plugin/test_dmesg_collector.py index 1884fb85..4202c0f9 100644 --- a/test/unit/plugin/test_dmesg_collector.py +++ b/test/unit/plugin/test_dmesg_collector.py @@ -295,7 +295,7 @@ def test_collect_data_with_args(conn_mock, system_info): connection=conn_mock, ) - args = DmesgCollectorArgs(collect_dmesg_log=False) + args = DmesgCollectorArgs(log_dmesg_data=False) res, data = collector.collect_data(args=args) assert res.status == ExecutionStatus.OK