Fix NVIDIA GPU/NVSwitch parsing and Reanimator export statuses

This commit is contained in:
2026-02-15 21:00:30 +03:00
parent 0af3cee9b6
commit c7b2a7ab29
12 changed files with 695 additions and 92 deletions

View File

@@ -111,42 +111,39 @@ func TestInferCPUManufacturer(t *testing.T) {
}
}
func TestGeneratePCIeSerialNumber(t *testing.T) {
func TestNormalizedSerial(t *testing.T) {
tests := []struct {
name string
boardSerial string
slot string
bdf string
want string
name string
in string
want string
}{
{
name: "with slot",
boardSerial: "TEST123",
slot: "PCIeCard1",
bdf: "0000:18:00.0",
want: "TEST123-PCIE-PCIeCard1",
name: "empty",
in: "",
want: "",
},
{
name: "without slot, with bdf",
boardSerial: "TEST123",
slot: "",
bdf: "0000:18:00.0",
want: "TEST123-PCIE-0000-18-00-0",
name: "n_a",
in: "N/A",
want: "",
},
{
name: "without slot and bdf",
boardSerial: "TEST123",
slot: "",
bdf: "",
want: "TEST123-PCIE-UNKNOWN",
name: "unknown",
in: "unknown",
want: "",
},
{
name: "normal",
in: "SN123",
want: "SN123",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := generatePCIeSerialNumber(tt.boardSerial, tt.slot, tt.bdf)
got := normalizedSerial(tt.in)
if got != tt.want {
t.Errorf("generatePCIeSerialNumber() = %q, want %q", got, tt.want)
t.Errorf("normalizedSerial() = %q, want %q", got, tt.want)
}
})
}
@@ -184,6 +181,15 @@ func TestInferStorageStatus(t *testing.T) {
}
}
func TestNormalizeStatus_PassFail(t *testing.T) {
if got := normalizeStatus("PASS", false); got != "OK" {
t.Fatalf("expected PASS -> OK, got %q", got)
}
if got := normalizeStatus("FAIL", false); got != "Critical" {
t.Fatalf("expected FAIL -> Critical, got %q", got)
}
}
func TestConvertCPUs(t *testing.T) {
cpus := []models.CPU{
{
@@ -323,17 +329,16 @@ func TestConvertPCIeDevices(t *testing.T) {
},
}
boardSerial := "TEST123"
result := convertPCIeDevices(hw, boardSerial)
result := convertPCIeDevices(hw)
// Should have: 2 PCIe devices + 1 GPU + 1 NIC = 4 total
if len(result) != 4 {
t.Fatalf("expected 4 PCIe devices total, got %d", len(result))
}
// Check that serial was generated for second PCIe device
if result[1].SerialNumber != "TEST123-PCIE-PCIeCard2" {
t.Errorf("expected generated serial TEST123-PCIE-PCIeCard2, got %q", result[1].SerialNumber)
// Check that serial is empty for second PCIe device (no auto-generation)
if result[1].SerialNumber != "" {
t.Errorf("expected empty serial for missing device serial, got %q", result[1].SerialNumber)
}
// Check GPU was included
@@ -352,6 +357,29 @@ func TestConvertPCIeDevices(t *testing.T) {
}
}
func TestConvertPCIeDevices_NVSwitchWithoutSerialRemainsEmpty(t *testing.T) {
hw := &models.HardwareConfig{
PCIeDevices: []models.PCIeDevice{
{
Slot: "NVSWITCH1",
DeviceClass: "NVSwitch",
BDF: "0000:06:00.0",
// SerialNumber empty on purpose; should remain empty.
},
},
}
result := convertPCIeDevices(hw)
if len(result) != 1 {
t.Fatalf("expected 1 PCIe device, got %d", len(result))
}
if result[0].SerialNumber != "" {
t.Fatalf("expected empty NVSwitch serial, got %q", result[0].SerialNumber)
}
}
func TestConvertPowerSupplies(t *testing.T) {
psus := []models.PSU{
{