Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions nodescraper/plugins/inband/dimm/dimm_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from typing import Optional

from nodescraper.base import InBandDataCollector
from nodescraper.connection.inband import TextFileArtifact
from nodescraper.enums import EventCategory, EventPriority, ExecutionStatus, OSFamily
from nodescraper.models import TaskResult

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

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

def collect_data(
self,
Expand Down Expand Up @@ -72,6 +74,25 @@ def collect_data(
self.result.message = "Skipping sudo plugin"
self.result.status = ExecutionStatus.NOT_RAN
return self.result, None

# Collect full dmidecode output as artifact
dmidecode_full_res = self._run_sut_cmd(self.CMD_DMIDECODE_FULL, sudo=True)
if dmidecode_full_res.exit_code == 0 and dmidecode_full_res.stdout:
self.result.artifacts.append(
TextFileArtifact(filename="dmidecode.txt", contents=dmidecode_full_res.stdout)
)
else:
self._log_event(
category=EventCategory.OS,
description="Could not collect full dmidecode output",
data={
"command": dmidecode_full_res.command,
"exit_code": dmidecode_full_res.exit_code,
"stderr": dmidecode_full_res.stderr,
},
priority=EventPriority.WARNING,
)

res = self._run_sut_cmd(self.CMD, sudo=True)
if res.exit_code == 0:
total = 0
Expand Down
34 changes: 24 additions & 10 deletions test/unit/plugin/test_dimms_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ def test_run_linux(collector, system_info):
system_info.os_family = OSFamily.LINUX

collector._run_sut_cmd = MagicMock(
return_value=MagicMock(
exit_code=0,
stdout="Size: 64 GB\nSize: 64 GB\nSize: 128 GB\n",
)
side_effect=[
MagicMock(
exit_code=0,
stdout="Full dmidecode output...",
),
MagicMock(
exit_code=0,
stdout="Size: 64 GB\nSize: 64 GB\nSize: 128 GB\n",
),
]
)

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

collector._run_sut_cmd = MagicMock(
return_value=MagicMock(
exit_code=1,
stderr="Error occurred",
)
side_effect=[
MagicMock(
exit_code=1,
stderr="Error occurred",
command="dmidecode",
),
MagicMock(
exit_code=1,
stderr="Error occurred",
command="sh -c 'dmidecode -t 17 | ...'",
),
]
)

result, data = collector.collect_data()

assert result.status == ExecutionStatus.ERROR
assert data is None
assert result.events[0].category == EventCategory.OS.value
assert result.events[0].description == "Error checking dimms"
assert result.events[1].category == EventCategory.OS.value
assert result.events[1].description == "Error checking dimms"