Skip to content

Commit a79ea7e

Browse files
committed
Merge branch 'alex_nvme' into alex_filemodel
2 parents 65a6ebe + 83a20be commit a79ea7e

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

nodescraper/cli/cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,10 @@ def main(arg_input: Optional[list[str]] = None):
437437

438438
if parsed_args.reference_config:
439439
ref_config = generate_reference_config(results, plugin_reg, logger)
440-
path = os.path.join(os.getcwd(), "reference_config.json")
440+
if log_path:
441+
path = os.path.join(log_path, "reference_config.json")
442+
else:
443+
path = os.path.join(os.getcwd(), "reference_config.json")
441444
try:
442445
with open(path, "w") as f:
443446
json.dump(

nodescraper/pluginexecutor.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,26 @@ def apply_global_args_to_plugin(
243243
else:
244244
run_args[key] = global_args[key]
245245

246-
if "collection_args" in global_args and hasattr(plugin_class, "COLLECTOR_ARGS"):
247-
plugin_fields = set(plugin_class.COLLECTOR_ARGS.__fields__.keys())
246+
if (
247+
"collection_args" in global_args
248+
and hasattr(plugin_class, "COLLECTOR_ARGS")
249+
and plugin_class.COLLECTOR_ARGS is not None
250+
):
251+
252+
plugin_fields = set(plugin_class.COLLECTOR_ARGS.model_fields.keys())
248253
filtered = {
249254
k: v for k, v in global_args["collection_args"].items() if k in plugin_fields
250255
}
251256
if filtered:
252257
run_args["collection_args"] = filtered
253258

254-
if "analysis_args" in global_args and hasattr(plugin_class, "ANALYZER_ARGS"):
255-
plugin_fields = set(plugin_class.ANALYZER_ARGS.__fields__.keys())
259+
if (
260+
"analysis_args" in global_args
261+
and hasattr(plugin_class, "ANALYZER_ARGS")
262+
and plugin_class.ANALYZER_ARGS is not None
263+
):
264+
265+
plugin_fields = set(plugin_class.ANALYZER_ARGS.model_fields.keys())
256266
filtered = {k: v for k, v in global_args["analysis_args"].items() if k in plugin_fields}
257267
if filtered:
258268
run_args["analysis_args"] = filtered

nodescraper/plugins/inband/nvme/nvme_collector.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
###############################################################################
2626
import os
2727
import re
28+
import traceback
2829

2930
from pydantic import ValidationError
3031

@@ -107,11 +108,11 @@ def collect_data(
107108
if all_device_data:
108109
try:
109110
nvme_data = NvmeDataModel(devices=all_device_data)
110-
except ValidationError as e:
111+
except ValidationError as exp:
111112
self._log_event(
112113
category=EventCategory.SW_DRIVER,
113114
description="Validation error while building NvmeDataModel",
114-
data={"error": str(e)},
115+
data={"errors": traceback.format_tb(exp.__traceback__)},
115116
priority=EventPriority.ERROR,
116117
)
117118
self.result.message = "NVMe data invalid format"
@@ -139,9 +140,19 @@ def collect_data(
139140

140141
def _get_nvme_devices(self) -> list[str]:
141142
nvme_devs = []
142-
for entry in os.listdir("/dev"):
143-
full_path = os.path.join("/dev", entry)
144143

145-
if re.fullmatch(r"nvme\d+$", entry) and os.path.exists(full_path):
146-
nvme_devs.append(full_path)
144+
res = self._run_sut_cmd("ls /dev", sudo=False)
145+
if res.exit_code != 0:
146+
self._log_event(
147+
category=EventCategory.SW_DRIVER,
148+
description="Failed to list /dev directory",
149+
data={"exit_code": res.exit_code, "stderr": res.stderr},
150+
priority=EventPriority.ERROR,
151+
)
152+
return []
153+
154+
for entry in res.stdout.strip().splitlines():
155+
if re.fullmatch(r"nvme\d+$", entry):
156+
nvme_devs.append(f"/dev/{entry}")
157+
147158
return nvme_devs

test/unit/plugin/test_nvme_collector.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,12 @@ def test_no_data_collected(collector):
107107
call.kwargs["priority"] == EventPriority.ERROR
108108
for call in collector._log_event.call_args_list
109109
)
110+
111+
112+
def test_get_nvme_devices_filters_partitions(collector):
113+
fake_ls_output = "\n".join(["nvme0", "nvme0n1", "nvme1", "nvme1n1", "sda", "loop0", "nvme2"])
114+
collector._run_sut_cmd.return_value = MagicMock(exit_code=0, stdout=fake_ls_output)
115+
116+
devices = collector._get_nvme_devices()
117+
118+
assert devices == ["/dev/nvme0", "/dev/nvme1", "/dev/nvme2"]

0 commit comments

Comments
 (0)