Skip to content

Commit 1bc0aad

Browse files
Merge pull request #79 from amd/alex_dmidecode
DimmPlugin update
2 parents 95d6ac9 + 6288e8b commit 1bc0aad

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

nodescraper/plugins/inband/dimm/dimm_collector.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from typing import Optional
2727

2828
from nodescraper.base import InBandDataCollector
29+
from nodescraper.connection.inband import TextFileArtifact
2930
from nodescraper.enums import EventCategory, EventPriority, ExecutionStatus, OSFamily
3031
from nodescraper.models import TaskResult
3132

@@ -40,6 +41,7 @@ class DimmCollector(InBandDataCollector[DimmDataModel, DimmCollectorArgs]):
4041

4142
CMD_WINDOWS = "wmic memorychip get Capacity"
4243
CMD = """sh -c 'dmidecode -t 17 | tr -s " " | grep -v "Volatile\\|None\\|Module" | grep Size' 2>/dev/null"""
44+
CMD_DMIDECODE_FULL = "dmidecode"
4345

4446
def collect_data(
4547
self,
@@ -72,6 +74,25 @@ def collect_data(
7274
self.result.message = "Skipping sudo plugin"
7375
self.result.status = ExecutionStatus.NOT_RAN
7476
return self.result, None
77+
78+
# Collect full dmidecode output as artifact
79+
dmidecode_full_res = self._run_sut_cmd(self.CMD_DMIDECODE_FULL, sudo=True)
80+
if dmidecode_full_res.exit_code == 0 and dmidecode_full_res.stdout:
81+
self.result.artifacts.append(
82+
TextFileArtifact(filename="dmidecode.txt", contents=dmidecode_full_res.stdout)
83+
)
84+
else:
85+
self._log_event(
86+
category=EventCategory.OS,
87+
description="Could not collect full dmidecode output",
88+
data={
89+
"command": dmidecode_full_res.command,
90+
"exit_code": dmidecode_full_res.exit_code,
91+
"stderr": dmidecode_full_res.stderr,
92+
},
93+
priority=EventPriority.WARNING,
94+
)
95+
7596
res = self._run_sut_cmd(self.CMD, sudo=True)
7697
if res.exit_code == 0:
7798
total = 0

test/unit/plugin/test_dimms_collector.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,16 @@ def test_run_linux(collector, system_info):
6868
system_info.os_family = OSFamily.LINUX
6969

7070
collector._run_sut_cmd = MagicMock(
71-
return_value=MagicMock(
72-
exit_code=0,
73-
stdout="Size: 64 GB\nSize: 64 GB\nSize: 128 GB\n",
74-
)
71+
side_effect=[
72+
MagicMock(
73+
exit_code=0,
74+
stdout="Full dmidecode output...",
75+
),
76+
MagicMock(
77+
exit_code=0,
78+
stdout="Size: 64 GB\nSize: 64 GB\nSize: 128 GB\n",
79+
),
80+
]
7581
)
7682

7783
result, data = collector.collect_data()
@@ -84,15 +90,23 @@ def test_run_linux_error(collector, system_info):
8490
system_info.os_family = OSFamily.LINUX
8591

8692
collector._run_sut_cmd = MagicMock(
87-
return_value=MagicMock(
88-
exit_code=1,
89-
stderr="Error occurred",
90-
)
93+
side_effect=[
94+
MagicMock(
95+
exit_code=1,
96+
stderr="Error occurred",
97+
command="dmidecode",
98+
),
99+
MagicMock(
100+
exit_code=1,
101+
stderr="Error occurred",
102+
command="sh -c 'dmidecode -t 17 | ...'",
103+
),
104+
]
91105
)
92106

93107
result, data = collector.collect_data()
94108

95109
assert result.status == ExecutionStatus.ERROR
96110
assert data is None
97-
assert result.events[0].category == EventCategory.OS.value
98-
assert result.events[0].description == "Error checking dimms"
111+
assert result.events[1].category == EventCategory.OS.value
112+
assert result.events[1].description == "Error checking dimms"

0 commit comments

Comments
 (0)