unraid: parse dimm/nic/pcie and annotate duplicate serials

This commit is contained in:
2026-03-01 18:14:45 +03:00
parent 7d1a02cb72
commit 206496efae
4 changed files with 653 additions and 10 deletions

View File

@@ -65,6 +65,54 @@ func TestBuildHardwareDevices_SkipsEmptyMemorySlots(t *testing.T) {
}
}
func TestBuildHardwareDevices_MemorySameSerialDifferentSlots_NotDeduped(t *testing.T) {
hw := &models.HardwareConfig{
Memory: []models.MemoryDIMM{
{Slot: "Node0_Dimm1", Location: "Node0_Bank0", Present: true, SizeMB: 16384, SerialNumber: "238F7649", PartNumber: "M393B2G70BH0-"},
{Slot: "Node0_Dimm3", Location: "Node0_Bank0", Present: true, SizeMB: 16384, SerialNumber: "238F7649", PartNumber: "M393B2G70BH0-"},
},
}
devices := BuildHardwareDevices(hw)
memorySlots := make(map[string]bool)
for _, d := range devices {
if d.Kind != models.DeviceKindMemory {
continue
}
memorySlots[d.Slot] = true
}
if len(memorySlots) != 2 {
t.Fatalf("expected 2 memory devices, got %d", len(memorySlots))
}
if !memorySlots["Node0_Dimm1"] || !memorySlots["Node0_Dimm3"] {
t.Fatalf("expected both Node0_Dimm1 and Node0_Dimm3 to remain")
}
}
func TestBuildHardwareDevices_DuplicateSerials_AreAnnotated(t *testing.T) {
hw := &models.HardwareConfig{
Memory: []models.MemoryDIMM{
{Slot: "A1", Location: "BANK0", Present: true, SizeMB: 16384, SerialNumber: "SN-1"},
{Slot: "A2", Location: "BANK1", Present: true, SizeMB: 16384, SerialNumber: "SN-1"},
},
}
devices := BuildHardwareDevices(hw)
var serials []string
for _, d := range devices {
if d.Kind == models.DeviceKindMemory {
serials = append(serials, d.SerialNumber)
}
}
if len(serials) != 2 {
t.Fatalf("expected 2 memory devices, got %d", len(serials))
}
if serials[0] != "SN-1 (DUP#1)" || serials[1] != "SN-1 (DUP#2)" {
t.Fatalf("unexpected annotated serials: %+v", serials)
}
}
func TestBuildHardwareDevices_DedupCrossKindByBDF(t *testing.T) {
hw := &models.HardwareConfig{
PCIeDevices: []models.PCIeDevice{