Probe Supermicro NVMe Disk.Bay endpoints for drive inventory

This commit is contained in:
Mikhail Chusavitin
2026-02-24 18:22:02 +03:00
parent 2e348751f3
commit a6c90b6e77
3 changed files with 299 additions and 4 deletions

View File

@@ -238,3 +238,124 @@ func TestParsePCIeDeviceSlot_EmptyMapFallsBackToID(t *testing.T) {
t.Fatalf("slot should not stringify empty map")
}
}
func TestEnrichNICFromPCIeFunctions(t *testing.T) {
nic := parseNIC(map[string]interface{}{
"Id": "1",
"Model": "MCX75310AAS-NEAT",
"Manufacturer": "Supermicro",
"SerialNumber": "NIC-SN-1",
"Controllers": []interface{}{
map[string]interface{}{
"Links": map[string]interface{}{
"PCIeDevices": []interface{}{
map[string]interface{}{"@odata.id": "/redfish/v1/Chassis/1/PCIeDevices/NIC1"},
},
},
"Location": map[string]interface{}{
"PartLocation": map[string]interface{}{"ServiceLabel": "PCIe Slot 1 (1)"},
},
},
},
})
pcieDoc := map[string]interface{}{
"Id": "NIC1",
"PCIeFunctions": map[string]interface{}{
"@odata.id": "/redfish/v1/Chassis/1/PCIeDevices/NIC1/PCIeFunctions",
},
}
functionDocs := []map[string]interface{}{
{
"VendorId": "0x15b3",
"DeviceId": "0x1021",
},
}
enrichNICFromPCIe(&nic, pcieDoc, functionDocs)
if nic.VendorID != 0x15b3 || nic.DeviceID != 0x1021 {
t.Fatalf("unexpected NIC IDs: vendor=%#x device=%#x", nic.VendorID, nic.DeviceID)
}
if nic.Location != "PCIe Slot 1 (1)" {
t.Fatalf("unexpected NIC location: %q", nic.Location)
}
}
func TestParsePCIeDevice_PrefersFunctionClassOverDeviceType(t *testing.T) {
doc := map[string]interface{}{
"Id": "NIC1",
"DeviceType": "SingleFunction",
"Model": "MCX75310AAS-NEAT",
"PartNumber": "MCX75310AAS-NEAT",
}
functionDocs := []map[string]interface{}{
{
"DeviceClass": "NetworkController",
"VendorId": "0x15b3",
"DeviceId": "0x1021",
},
}
got := parsePCIeDevice(doc, functionDocs)
if got.DeviceClass == "SingleFunction" {
t.Fatalf("device class should not keep generic redfish DeviceType")
}
if got.DeviceClass == "" {
t.Fatalf("device class should be resolved")
}
}
func TestReplayCollectStorage_ProbesSupermicroNVMeDiskBayWhenCollectionEmpty(t *testing.T) {
r := redfishSnapshotReader{tree: map[string]interface{}{
"/redfish/v1/Systems": map[string]interface{}{
"Members": []interface{}{
map[string]interface{}{"@odata.id": "/redfish/v1/Systems/1"},
},
},
"/redfish/v1/Systems/1/Storage": map[string]interface{}{
"Members": []interface{}{
map[string]interface{}{"@odata.id": "/redfish/v1/Systems/1/Storage/NVMeSSD"},
},
},
"/redfish/v1/Systems/1/Storage/NVMeSSD": map[string]interface{}{
"Drives": map[string]interface{}{"@odata.id": "/redfish/v1/Systems/1/Storage/NVMeSSD/Drives"},
},
"/redfish/v1/Systems/1/Storage/NVMeSSD/Drives": map[string]interface{}{
"Members": []interface{}{},
},
"/redfish/v1/Chassis": map[string]interface{}{
"Members": []interface{}{
map[string]interface{}{"@odata.id": "/redfish/v1/Chassis/NVMeSSD.0.Group.0.StorageBackplane"},
},
},
"/redfish/v1/Chassis/NVMeSSD.0.Group.0.StorageBackplane": map[string]interface{}{
"Drives": map[string]interface{}{"@odata.id": "/redfish/v1/Chassis/NVMeSSD.0.Group.0.StorageBackplane/Drives"},
},
"/redfish/v1/Chassis/NVMeSSD.0.Group.0.StorageBackplane/Drives": map[string]interface{}{
"Members@odata.count": 0,
"Members": []interface{}{},
},
"/redfish/v1/Chassis/NVMeSSD.0.Group.0.StorageBackplane/Drives/Disk.Bay.0": map[string]interface{}{
"Id": "Disk.Bay.0",
"Name": "Disk.Bay.0",
"Manufacturer": "INTEL",
"SerialNumber": "BTLJ035203XT1P0FGN",
"Model": "INTEL SSDPE2KX010T8",
"CapacityBytes": int64(1000204886016),
"Protocol": "NVMe",
"MediaType": "SSD",
"Status": map[string]interface{}{"State": "Enabled", "Health": "OK"},
},
}}
got := r.collectStorage("/redfish/v1/Systems/1")
if len(got) != 1 {
t.Fatalf("expected one drive from direct Disk.Bay probe, got %d", len(got))
}
if got[0].SerialNumber != "BTLJ035203XT1P0FGN" {
t.Fatalf("unexpected serial: %q", got[0].SerialNumber)
}
if got[0].SizeGB == 0 {
t.Fatalf("expected size to be parsed from CapacityBytes")
}
}