fix(parser,exporter): reconcile BMC-dump and live-CD exports of the same server

The audit tool that ingests Reanimator exports treats any per-component field
change between imports as a component replacement. Importing an xFusion BMC dump
and an easy_bee BEE-SP bundle for one server produced large spurious diffs.

xfusion:
- parseMemInfo tolerates a stray 0x0A inside the binary SPD "bom number" column
  (it was splitting a DIMM record in two and emitting a phantom "slot s" module)
- DIMM slot from the "dimm name" column ("DIMM071"), mainboard "location" dropped
- GPU slot = BDF (Reanimator contract)
- NIC emitted per PCI function from netcard_info.txt (BDF + per-port MAC, shared
  card serial) instead of one card-level adapter with the wrong BDF, which had
  been colliding with a GPU and vanishing in dedup
- NIC manufacturer left blank when it is the system OEM so the exporter resolves
  the silicon vendor from pci.ids
- "(U6216)" chip designator stripped from firmware versions

easy_bee:
- PSU bay numbers rebased 0-indexed -> 1-indexed; bare single-letter PSU
  "firmware" (a leaked FRU version) cleared
- board.part_number taken from the bundle's ipmitool-fru.txt chassis
  "Product Part Number" to match the BMC value

exporter (cross-vendor):
- canonicalMemorySlot: drop dmidecode "(J)" channel tag, Memory111 -> DIMM111
- canonicalGPUModel: NVIDIA DC GPUs reduce to the bare chip token
- canonicalStorageMediaAndInterface: NVMe is a bus not a medium
- manufacturerFromStorageModel: fill blank drive vendor from the model prefix
- isRemovableUSBStorageDevice: drop live-CD boot sticks
- isOnboardControllerPCIeDevice: drop SATA/NVMe/MegaRAID/PCIe-switch controller
  functions that only an lspci scan reports (keep add-in cards with an identity)

For the reference server every physical component now appears in both exports
keyed identically; residual diffs are one-sided enrichment only.

Refs ADL-061, ADL-062.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VFy4m7cVv4cqp25jJh2gSB
This commit is contained in:
Mikhail Chusavitin
2026-08-31 22:50:07 +03:00
co-authored by Claude Sonnet 5
parent 5b65c99b0e
commit 9b2c654182
7 changed files with 595 additions and 61 deletions
+152 -4
View File
@@ -883,7 +883,7 @@ func convertMemoryFromDevices(devices []models.HardwareDevice, collectedAt strin
meta := buildStatusMeta(status, d.StatusCheckedAt, d.StatusChangedAt, d.StatusHistory, d.ErrorDescription, collectedAt)
presentValue := present
result = append(result, ReanimatorMemory{
Slot: d.Slot,
Slot: canonicalMemorySlot(d.Slot),
Location: d.Location,
Present: &presentValue,
SizeMB: d.SizeMB,
@@ -921,6 +921,9 @@ func convertStorageFromDevices(devices []models.HardwareDevice, collectedAt stri
if isVirtualExportStorageDevice(d) {
continue
}
if isRemovableUSBStorageDevice(d) {
continue
}
if !shouldExportStorageDevice(d) {
continue
}
@@ -931,17 +934,22 @@ func convertStorageFromDevices(devices []models.HardwareDevice, collectedAt stri
}
meta := buildStatusMeta(status, d.StatusCheckedAt, d.StatusChangedAt, d.StatusHistory, d.ErrorDescription, collectedAt)
presentValue := present
mediaType, busInterface := canonicalStorageMediaAndInterface(d.Type, d.Interface)
manufacturer := d.Manufacturer
if manufacturer == "" {
manufacturer = manufacturerFromStorageModel(d.Model)
}
result = append(result, ReanimatorStorage{
Slot: d.Slot,
Type: d.Type,
Type: mediaType,
Model: d.Model,
VendorID: d.VendorID,
DeviceID: d.DeviceID,
SizeGB: d.SizeGB,
SerialNumber: d.SerialNumber,
Manufacturer: d.Manufacturer,
Manufacturer: manufacturer,
Firmware: d.Firmware,
Interface: d.Interface,
Interface: busInterface,
Present: &presentValue,
LogicalBlockSizeBytes: int64FromDetailMap(d.Details, "logical_block_size_bytes"),
PhysicalBlockSizeBytes: int64FromDetailMap(d.Details, "physical_block_size_bytes"),
@@ -981,6 +989,9 @@ func convertPCIeFromDevices(devices []models.HardwareDevice, collectedAt string)
if isStorageEndpointPCIeDevice(d) {
continue
}
if isOnboardControllerPCIeDevice(d) {
continue
}
if isPlaceholderPCIeExportDevice(d) {
continue
}
@@ -1000,6 +1011,9 @@ func convertPCIeFromDevices(devices []models.HardwareDevice, collectedAt string)
if manufacturer == "" && d.VendorID != 0 {
manufacturer = pciids.VendorName(d.VendorID)
}
if isGPUClass(deviceClass) || d.Kind == models.DeviceKindGPU {
model = canonicalGPUModel(model, manufacturer)
}
temperatureC := firstNonZeroFloat(
float64(d.TemperatureC),
floatFromDetailMap(d.Details, "temperature_c"),
@@ -1091,6 +1105,52 @@ func isStorageEndpointPCIeDevice(d models.HardwareDevice) bool {
strings.Contains(joined, "drive")
}
// isRemovableUSBStorageDevice reports whether a storage device is a USB-attached
// removable drive (flash stick, external HDD). These come and go with whoever is
// standing at the machine — a live-CD boot stick, a technician's USB key — and
// are not part of the server's tracked inventory, so an OS-level collector that
// sees one must not make it look like a component was installed.
func isRemovableUSBStorageDevice(d models.HardwareDevice) bool {
if d.Kind != models.DeviceKindStorage {
return false
}
return strings.EqualFold(strings.TrimSpace(d.Interface), "USB") ||
strings.EqualFold(strings.TrimSpace(d.Type), "USB")
}
// isOnboardControllerPCIeDevice reports whether a PCIe entry is an onboard
// storage/switch controller function that only an OS-level PCI enumeration ever
// reports — a BMC add-in-card inventory never lists these. Dropping them keeps
// the pcie_devices set identical between a BMC dump and an lspci-based capture.
// Add-in HBA/RAID cards that carry their own serial or part number are kept.
func isOnboardControllerPCIeDevice(d models.HardwareDevice) bool {
if d.Kind == models.DeviceKindGPU || d.Kind == models.DeviceKindNetwork {
return false
}
class := strings.ToLower(strings.TrimSpace(d.DeviceClass))
model := strings.ToLower(strings.TrimSpace(d.Model))
if strings.Contains(model, "pcie switch") || strings.Contains(model, "switch management") ||
strings.Contains(model, "switch upstream") || strings.Contains(model, "switch downstream") {
return true
}
controllerClass := strings.Contains(class, "sata") ||
strings.Contains(class, "ahci") ||
strings.Contains(class, "ide controller") ||
strings.Contains(class, "nonvolatile") || strings.Contains(class, "non-volatile") ||
strings.Contains(class, "nvme") ||
strings.Contains(class, "mass storage") || strings.Contains(class, "massstorage") ||
class == "storagecontroller" || class == "storage controller"
if !controllerClass {
return false
}
if normalizedSerial(d.SerialNumber) != "" || hasMeaningfulExporterText(d.PartNumber) {
return false
}
return true
}
func isVirtualExportStorageDevice(d models.HardwareDevice) bool {
if d.Kind != models.DeviceKindStorage {
return false
@@ -2233,6 +2293,94 @@ func disambiguatePSUSlots(items []ReanimatorPSU) []ReanimatorPSU {
// BEE-SP versions, which label every module "DIMM 0" regardless of its real
// channel/slot. As with disambiguatePSUSlots, positions within a colliding
// group are assigned by ascending serial number for a deterministic result.
// canonicalMemorySlot normalizes a DIMM slot label so the same physical slot
// reads identically regardless of the collector: it drops a trailing
// channel-letter tag that dmidecode appends ("DIMM111(J)" -> "DIMM111") and
// rewrites a bare BMC-style "Memory111" locator to "DIMM111".
func canonicalMemorySlot(slot string) string {
s := strings.TrimSpace(slot)
if i := strings.LastIndexByte(s, '('); i > 0 && strings.HasSuffix(s, ")") {
s = strings.TrimSpace(s[:i])
}
if rest, ok := strings.CutPrefix(s, "Memory"); ok && isNumericExporterSlot(rest) {
s = "DIMM" + rest
}
return s
}
// canonicalStorageMediaAndInterface separates media type from bus interface so
// the same drive reads identically regardless of collector. "NVMe" is a bus, not
// a medium: an NVMe drive is an SSD on the NVMe interface. A drive reported only
// as PCIe-attached is, in practice, NVMe.
func canonicalStorageMediaAndInterface(mediaType, busInterface string) (string, string) {
t := strings.TrimSpace(mediaType)
b := strings.TrimSpace(busInterface)
if strings.EqualFold(t, "nvme") {
if b == "" || strings.EqualFold(b, "pcie") {
b = "NVMe"
}
t = "SSD"
}
if strings.EqualFold(b, "pcie") {
b = "NVMe"
}
return t, b
}
// manufacturerFromStorageModel pulls a leading brand token out of a drive model
// string ("KIOXIA KCD8XPUG7T68" -> "KIOXIA") for collectors that leave the
// manufacturer field empty.
func manufacturerFromStorageModel(model string) string {
fields := strings.Fields(strings.TrimSpace(model))
if len(fields) < 2 {
return ""
}
switch strings.ToUpper(fields[0]) {
case "KIOXIA", "INTEL", "SAMSUNG", "MICRON", "SEAGATE", "TOSHIBA", "WDC", "HGST", "SK", "SOLIDIGM", "SANDISK":
return strings.ToUpper(fields[0])
}
return ""
}
func isGPUClass(deviceClass string) bool {
switch strings.ToLower(strings.TrimSpace(deviceClass)) {
case "videocontroller", "displaycontroller", "processingaccelerator":
return true
}
return false
}
var gpuChipTokenRegex = regexp.MustCompile(`^[A-Z]{1,3}\d{2,3}[A-Z]?$`)
// canonicalGPUModel reduces an NVIDIA data-center GPU model string to a stable
// bare chip name so a BMC inventory ("H200") and an lspci capture
// ("NVIDIA H200 NVL", "NVIDIA Corporation GH100 [H200 NVL]") describe the same
// card identically. Non-NVIDIA or unrecognized models are returned unchanged.
func canonicalGPUModel(model, manufacturer string) string {
m := strings.TrimSpace(model)
if m == "" {
return m
}
lower := strings.ToLower(m + " " + manufacturer)
if !strings.Contains(lower, "nvidia") {
return m
}
// "GH100 [H200 NVL]" -> keep the bracketed marketing name, it holds the SKU.
if i := strings.IndexByte(m, '['); i >= 0 {
if j := strings.IndexByte(m[i:], ']'); j > 0 {
m = m[i+1 : i+j]
}
}
m = strings.ReplaceAll(m, "NVIDIA Corporation", "")
m = strings.ReplaceAll(m, "NVIDIA", "")
for _, tok := range strings.Fields(m) {
if gpuChipTokenRegex.MatchString(strings.ToUpper(tok)) {
return strings.ToUpper(tok)
}
}
return strings.TrimSpace(model)
}
func disambiguateMemorySlots(items []ReanimatorMemory) []ReanimatorMemory {
if len(items) < 2 {
return items
@@ -2270,3 +2270,75 @@ func TestConvertToReanimator_ExportsLicenses(t *testing.T) {
t.Errorf("Status = %q, want %q", scoped.Status, "Warning")
}
}
func TestCanonicalMemorySlot(t *testing.T) {
cases := map[string]string{
"DIMM111(J)": "DIMM111",
"DIMM111 (J)": "DIMM111",
"Memory111": "DIMM111",
"DIMM111": "DIMM111",
"P1-DIMMA1": "P1-DIMMA1",
"CPU0_C0D0": "CPU0_C0D0",
}
for in, want := range cases {
if got := canonicalMemorySlot(in); got != want {
t.Errorf("canonicalMemorySlot(%q) = %q, want %q", in, got, want)
}
}
}
func TestCanonicalGPUModel(t *testing.T) {
cases := []struct{ model, mfr, want string }{
{"NVIDIA H200 NVL", "NVIDIA Corporation", "H200"},
{"H200", "NVIDIA Corporation", "H200"},
{"NVIDIA H200 141G", "", "H200"},
{"GH100 [H200 NVL]", "NVIDIA Corporation", "H200"},
{"Radeon Instinct MI300X", "AMD", "Radeon Instinct MI300X"},
}
for _, c := range cases {
if got := canonicalGPUModel(c.model, c.mfr); got != c.want {
t.Errorf("canonicalGPUModel(%q,%q) = %q, want %q", c.model, c.mfr, got, c.want)
}
}
}
func TestCanonicalStorageMediaAndInterface(t *testing.T) {
cases := []struct{ inT, inI, wantT, wantI string }{
{"NVMe", "PCIe", "SSD", "NVMe"},
{"NVMe", "", "SSD", "NVMe"},
{"SSD", "PCIe", "SSD", "NVMe"},
{"SSD", "SATA", "SSD", "SATA"},
{"HDD", "SAS", "HDD", "SAS"},
}
for _, c := range cases {
gotT, gotI := canonicalStorageMediaAndInterface(c.inT, c.inI)
if gotT != c.wantT || gotI != c.wantI {
t.Errorf("canonicalStorageMediaAndInterface(%q,%q) = %q,%q want %q,%q", c.inT, c.inI, gotT, gotI, c.wantT, c.wantI)
}
}
}
func TestIsOnboardControllerPCIeDevice(t *testing.T) {
drop := []models.HardwareDevice{
{Kind: models.DeviceKindPCIe, DeviceClass: "SATA controller", Model: "Sapphire Rapids SATA AHCI Controller"},
{Kind: models.DeviceKindPCIe, DeviceClass: "Non-Volatile memory controller", Model: "NVMe SSD Controller CD8P"},
{Kind: models.DeviceKindPCIe, DeviceClass: "MassStorageController", Model: "MegaRAID 12GSAS/PCIe Secure SAS38xx"},
{Kind: models.DeviceKindPCIe, DeviceClass: "StorageController", Model: "PCIe Switch management endpoint"},
}
for _, d := range drop {
if !isOnboardControllerPCIeDevice(d) {
t.Errorf("expected %q/%q to be dropped", d.DeviceClass, d.Model)
}
}
keep := []models.HardwareDevice{
{Kind: models.DeviceKindGPU, DeviceClass: "VideoController", Model: "H200"},
{Kind: models.DeviceKindNetwork, DeviceClass: "EthernetController", Model: "ConnectX-6 Lx"},
{Kind: models.DeviceKindPCIe, DeviceClass: "raid_controller", Model: "RAID Controller", PartNumber: "XC170-M-8i"},
{Kind: models.DeviceKindPCIe, DeviceClass: "MassStorageController", Model: "HBA", SerialNumber: "ABC123"},
}
for _, d := range keep {
if isOnboardControllerPCIeDevice(d) {
t.Errorf("expected %q/%q to be kept", d.DeviceClass, d.Model)
}
}
}
+80 -1
View File
@@ -3,6 +3,7 @@ package easy_bee
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
@@ -122,10 +123,14 @@ func (p *Parser) Parse(files []parser.ExtractedFile) (*models.AnalysisResult, er
GPUs: append([]models.GPU(nil), snapshot.Hardware.GPUs...),
NetworkCards: append([]models.NIC(nil), snapshot.Hardware.NetworkCards...),
NetworkAdapters: normalizeNetworkAdapters(snapshot.Hardware.NetworkAdapters),
PowerSupply: append([]models.PSU(nil), snapshot.Hardware.PowerSupply...),
PowerSupply: normalizePSUSlots(snapshot.Hardware.PowerSupply),
},
}
if pn := chassisProductPartNumber(files, result.Hardware.BoardInfo.ProductName); pn != "" {
result.Hardware.BoardInfo.PartNumber = pn
}
result.Events = append(result.Events, snapshot.Events...)
result.Events = append(result.Events, convertRuntimeToEvents(snapshot.Runtime, result.CollectedAt)...)
result.Events = append(result.Events, convertEventLogs(snapshot.Hardware.EventLogs)...)
@@ -524,6 +529,80 @@ func normalizePCIeDevices(items []models.PCIeDevice) []models.PCIeDevice {
return out
}
// normalizePSUSlots rebases 0-indexed PSU bay numbers to 1-indexed, matching the
// BMC/vendor convention (bays are labelled PSU1..PSUn on the chassis). The
// easy-bee snapshot numbers them from 0; without this, the same server imported
// from a BMC dump vs. a live-CD run would show every PSU as moved to a new bay.
// chassisProductPartNumber pulls the chassis-level "Product Part Number" out of
// the bundle's ipmitool-fru.txt for the FRU whose "Product Name" matches the
// board product name. The easy-bee snapshot records the baseboard's own product
// name ("BC15MBSF") as board.part_number, while a BMC dump reports the chassis
// product part number ("0619KUGG") — this aligns easy-bee to the BMC value.
func chassisProductPartNumber(files []parser.ExtractedFile, boardProductName string) string {
boardProductName = strings.TrimSpace(boardProductName)
if boardProductName == "" {
return ""
}
var fru *parser.ExtractedFile
for i := range files {
if strings.HasSuffix(strings.ToLower(files[i].Path), "ipmitool-fru.txt") {
fru = &files[i]
break
}
}
if fru == nil {
return ""
}
var lastProductName string
for _, line := range strings.Split(string(fru.Content), "\n") {
key, value, ok := strings.Cut(line, ":")
if !ok {
continue
}
key = strings.TrimSpace(key)
value = strings.TrimSpace(value)
switch key {
case "Product Name":
lastProductName = value
case "Product Part Number":
if strings.EqualFold(lastProductName, boardProductName) {
return value
}
}
}
return ""
}
func normalizePSUSlots(items []models.PSU) []models.PSU {
out := append([]models.PSU(nil), items...)
for i := range out {
// The easy-bee snapshot leaks the FRU "Product Version" (a bare letter like
// "B") into the firmware field; that is not a firmware revision.
if fw := strings.TrimSpace(out[i].Firmware); len(fw) == 1 {
out[i].Firmware = ""
}
}
minSlot, allNumeric := -1, len(out) > 0
for _, p := range out {
n, err := strconv.Atoi(strings.TrimSpace(p.Slot))
if err != nil {
allNumeric = false
break
}
if minSlot == -1 || n < minSlot {
minSlot = n
}
}
if !allNumeric || minSlot != 0 {
return out
}
for i := range out {
n, _ := strconv.Atoi(strings.TrimSpace(out[i].Slot))
out[i].Slot = strconv.Itoa(n + 1)
}
return out
}
func normalizeNetworkAdapters(items []models.NetworkAdapter) []models.NetworkAdapter {
out := append([]models.NetworkAdapter(nil), items...)
for i := range out {
+27
View File
@@ -4,6 +4,7 @@ import (
"testing"
"time"
"git.mchus.pro/mchus/logpile/internal/models"
"git.mchus.pro/mchus/logpile/internal/parser"
)
@@ -249,3 +250,29 @@ func TestParseBeeAuditSnapshot(t *testing.T) {
t.Fatal("expected board FRU fallback to be populated")
}
}
func TestNormalizePSUSlots(t *testing.T) {
in := []models.PSU{
{Slot: "0", Firmware: "B"}, {Slot: "1", Firmware: "B"},
{Slot: "2", Firmware: "B"}, {Slot: "3", Firmware: "B"},
}
out := normalizePSUSlots(in)
for i, want := range []string{"1", "2", "3", "4"} {
if out[i].Slot != want {
t.Errorf("psu[%d].Slot = %q, want %q", i, out[i].Slot, want)
}
if out[i].Firmware != "" {
t.Errorf("psu[%d].Firmware = %q, want empty (bare FRU version leak)", i, out[i].Firmware)
}
}
// Already 1-based / non-numeric: leave untouched.
keep := []models.PSU{{Slot: "1"}, {Slot: "2"}}
if got := normalizePSUSlots(keep); got[0].Slot != "1" || got[1].Slot != "2" {
t.Errorf("1-based slots must be untouched, got %q,%q", got[0].Slot, got[1].Slot)
}
psuA := []models.PSU{{Slot: "PSU0"}}
if got := normalizePSUSlots(psuA); got[0].Slot != "PSU0" {
t.Errorf("non-numeric slot must be untouched, got %q", got[0].Slot)
}
}
+146 -40
View File
@@ -285,8 +285,7 @@ func parseCacheSizeKB(s string) int {
// Columns: slot, location, dimmName, manufacturer, size, maxSpeed, curSpeed, type, SN, voltage, rank, bitWidth, tech, bom, partNum, ..., health
func parseMemInfo(content []byte) []models.MemoryDIMM {
var dimms []models.MemoryDIMM
lines := strings.Split(string(content), "\n")
for i, line := range lines {
for i, line := range reassembleMemInfoRows(content) {
if i == 0 {
continue
}
@@ -304,8 +303,13 @@ func parseMemInfo(content []byte) []models.MemoryDIMM {
continue
}
slot := strings.TrimSpace(parts[0])
location := strings.TrimSpace(parts[1])
// Column 3 ("dimm name", e.g. "DIMM071") is the device locator that matches
// dmidecode/OS-level collectors; column 1 ("Memory071") is BMC-internal only.
// Column 2 ("mainboard") carries no cross-source signal, so drop it.
slot := strings.TrimSpace(parts[2])
if slot == "" {
slot = strings.TrimSpace(parts[0])
}
manufacturer := strings.TrimSpace(parts[3])
if strings.ToLower(manufacturer) == "unknown" {
manufacturer = ""
@@ -347,7 +351,6 @@ func parseMemInfo(content []byte) []models.MemoryDIMM {
dimms = append(dimms, models.MemoryDIMM{
Slot: slot,
Location: location,
Present: true,
SizeMB: sizeMB,
Type: memType,
@@ -363,6 +366,43 @@ func parseMemInfo(content []byte) []models.MemoryDIMM {
return dimms
}
// reassembleMemInfoRows splits mem_info into logical rows, rejoining any line
// that is a continuation of the previous one.
//
// The BMC copies the raw SPD "bom number" field into column 14 verbatim, and it
// contains arbitrary binary bytes — including, occasionally, a 0x0A newline that
// splits a DIMM record across two physical lines. A genuine data row always
// starts with the slot token "Memory<digits>"; any line that does not is a
// tail fragment and is folded back into the row above it.
func reassembleMemInfoRows(content []byte) []string {
physical := strings.Split(string(content), "\n")
var rows []string
for _, raw := range physical {
line := strings.TrimRight(raw, "\r")
if len(rows) > 0 && !looksLikeMemInfoRowStart(line) {
rows[len(rows)-1] += line
continue
}
rows = append(rows, line)
}
return rows
}
// looksLikeMemInfoRowStart reports whether a line begins a new mem_info row,
// i.e. starts with "Memory" followed by a digit (after leading whitespace).
// The header line ("slot(col 1), ...") also returns true so it stays row 0.
func looksLikeMemInfoRowStart(line string) bool {
t := strings.TrimLeft(line, " \t")
if strings.HasPrefix(t, "slot(col 1)") {
return true
}
rest, ok := strings.CutPrefix(t, "Memory")
if !ok || rest == "" {
return false
}
return rest[0] >= '0' && rest[0] <= '9'
}
// ── Card Info (GPU + NIC) ─────────────────────────────────────────────────────
// parseCardInfo parses card_info file, extracting GPU and OCP NIC card inventory.
@@ -380,12 +420,8 @@ func parseCardInfo(content []byte) (gpus []models.GPU, nicCards []xfusionNICCard
slotPCIe := make(map[string]pcieEntry)
for _, row := range sections["pcie card info"] {
slot := strings.TrimSpace(row["slot"])
seg := parseHexInt(row["segment number"])
bus := parseHexInt(row["bus number"])
dev := parseHexInt(row["device number"])
fn := parseHexInt(row["function number"])
slotPCIe[slot] = pcieEntry{
bdf: fmt.Sprintf("%04x:%02x:%02x.%d", seg, bus, dev, fn),
bdf: bdfFromCardInfoRow(row),
vendorID: parseHexInt(row["vender id"]),
deviceID: parseHexInt(row["device id"]),
desc: strings.TrimSpace(row["card desc"]),
@@ -405,8 +441,15 @@ func parseCardInfo(content []byte) (gpus []models.GPU, nicCards []xfusionNICCard
fmt.Sscanf(strings.TrimSpace(row["dbe"]), "%d", &dbeCount)
pcie := slotPCIe[slot]
// Reanimator contract: pcie_devices.slot is the BDF. Use it when known so
// the GPU matches the same device seen by an OS-level lspci collection;
// fall back to the physical slot label only when no BDF is available.
gpuSlot := slot
if pcie.bdf != "" {
gpuSlot = pcie.bdf
}
gpu := models.GPU{
Slot: slot,
Slot: gpuSlot,
Model: name,
Manufacturer: manufacturer,
SerialNumber: serial,
@@ -422,17 +465,18 @@ func parseCardInfo(content []byte) (gpus []models.GPU, nicCards []xfusionNICCard
gpus = append(gpus, gpu)
}
// OCP Card Info: NIC cards
// OCP Card Info: NIC cards. The "Pcie Card Info" table only lists GPU slots,
// so slotPCIe[slot] here would resolve to an unrelated GPU's BDF — build the
// BDF from this row's own segment/bus/device/function columns instead.
for _, row := range sections["ocp card info"] {
slot := strings.TrimSpace(row["slot"])
pcie := slotPCIe[slot]
nicCards = append(nicCards, xfusionNICCard{
Slot: slot,
Model: strings.TrimSpace(row["card desc"]),
ProductName: strings.TrimSpace(row["card desc"]),
VendorID: parseHexInt(row["vender id"]),
DeviceID: parseHexInt(row["device id"]),
BDF: pcie.bdf,
BDF: bdfFromCardInfoRow(row),
SerialNumber: strings.TrimSpace(row["serialnumber"]),
PartNumber: strings.TrimSpace(row["partnum"]),
})
@@ -441,6 +485,21 @@ func parseCardInfo(content []byte) (gpus []models.GPU, nicCards []xfusionNICCard
return gpus, nicCards
}
// bdfFromCardInfoRow builds a "0000:bb:dd.f" BDF from a card_info pipe-table row
// that carries segment/bus/device/function columns. Returns "" if the bus column
// is absent (some sections, e.g. "RAID Card Info", have no PCI address columns).
func bdfFromCardInfoRow(row map[string]string) string {
if strings.TrimSpace(row["bus number"]) == "" {
return ""
}
return fmt.Sprintf("%04x:%02x:%02x.%d",
parseHexInt(row["segment number"]),
parseHexInt(row["bus number"]),
parseHexInt(row["device number"]),
parseHexInt(row["function number"]),
)
}
// splitPipeSections parses a multi-section file where each section starts with a
// plain header line (no "|") ending in "Info" or "info", followed by a pipe-table.
// Returns a map from lowercased section name → rows (each row is a map of lowercase header → value).
@@ -640,35 +699,60 @@ func mergeNetworkAdapters(cards []xfusionNICCard, snapshots []xfusionNetcardSnap
description = strings.TrimSpace(snapshot.ProductName)
}
macs := snapshot.macAddresses()
bdf := firstNonEmpty(snapshot.primaryBDF(), card.BDF)
firmware := normalizeXFusionValue(snapshot.Firmware)
manufacturer := firstNonEmpty(snapshot.Manufacturer, card.Vendor)
portCount := len(snapshot.Ports)
if portCount == 0 && len(macs) > 0 {
portCount = len(macs)
}
if portCount == 0 {
portCount = 1
// netcard_info reports the system OEM ("XFUSION") as the NIC manufacturer.
// When the PCI vendor ID is known, leave it blank so the exporter resolves
// the real silicon vendor (Mellanox/Broadcom/Intel) from pci.ids, matching
// what an OS-level collector reports.
if card.VendorID != 0 && isSystemOEMName(manufacturer) {
manufacturer = ""
}
adapters = append(adapters, models.NetworkAdapter{
Slot: slot,
Location: "OCP",
Present: true,
BDF: bdf,
Model: model,
Description: description,
Vendor: manufacturer,
VendorID: card.VendorID,
DeviceID: card.DeviceID,
SerialNumber: card.SerialNumber,
PartNumber: card.PartNumber,
Firmware: firmware,
PortCount: portCount,
PortType: "ethernet",
MACAddresses: macs,
Status: "ok",
})
// Emit one adapter per PCI function (port), keyed by that port's own BDF,
// so the card matches an OS-level lspci view of the same NIC. Ports share
// the physical card's serial/part number. Fall back to a single
// card-level entry only when no per-port BDF is available.
type portEntry struct {
bdf string
mac string
}
var ports []portEntry
for _, p := range snapshot.Ports {
if bdf := strings.TrimSpace(p.BDF); bdf != "" {
ports = append(ports, portEntry{bdf: bdf, mac: firstNonEmpty(normalizeMAC(p.ActualMAC), normalizeMAC(p.MAC))})
}
}
if len(ports) == 0 {
ports = append(ports, portEntry{bdf: card.BDF})
}
for _, p := range ports {
var portMACs []string
if p.mac != "" {
portMACs = []string{p.mac}
} else if len(ports) == 1 {
portMACs = macs
}
adapters = append(adapters, models.NetworkAdapter{
Slot: firstNonEmpty(p.bdf, slot),
Location: "OCP",
Present: true,
BDF: p.bdf,
Model: model,
Description: description,
Vendor: manufacturer,
VendorID: card.VendorID,
DeviceID: card.DeviceID,
SerialNumber: card.SerialNumber,
PartNumber: card.PartNumber,
Firmware: firmware,
PortCount: 1,
PortType: "ethernet",
MACAddresses: portMACs,
Status: "ok",
})
}
legacyNICs = append(legacyNICs, models.NIC{
Name: fmt.Sprintf("OCP%s", slot),
Model: model,
@@ -779,6 +863,14 @@ func (s xfusionNetcardSnapshot) macAddresses() []string {
return out
}
func isSystemOEMName(name string) bool {
switch strings.ToLower(strings.TrimSpace(name)) {
case "xfusion", "huawei", "oem", "":
return true
}
return false
}
func normalizeMAC(value string) string {
value = strings.ToUpper(strings.TrimSpace(value))
switch value {
@@ -904,7 +996,7 @@ func parseAppRevision(content []byte, result *models.AnalysisResult) {
}
for key, meta := range known {
version := normalizeXFusionValue(values[key])
version := stripXFusionChipDesignator(normalizeXFusionValue(values[key]))
if version == "" {
continue
}
@@ -917,6 +1009,20 @@ func parseAppRevision(content []byte, result *models.AnalysisResult) {
}
}
// stripXFusionChipDesignator removes a leading PCB reference-designator tag that
// the iBMC prepends to firmware versions, e.g. "(U6216)01.02.08.17" ->
// "01.02.08.17", so the BIOS/BMC version matches what an in-band tool reports.
func stripXFusionChipDesignator(version string) string {
v := strings.TrimSpace(version)
if !strings.HasPrefix(v, "(U") {
return v
}
if i := strings.IndexByte(v, ')'); i > 0 {
return strings.TrimSpace(v[i+1:])
}
return v
}
func parseAlignedKeyValues(content []byte) map[string]string {
values := make(map[string]string)
for _, rawLine := range strings.Split(string(content), "\n") {
+50 -16
View File
@@ -207,32 +207,37 @@ Product Name: G5500 V7
if result.Hardware == nil {
t.Fatal("Hardware is nil")
}
if len(result.Hardware.NetworkAdapters) != 1 {
t.Fatalf("expected 1 network adapter, got %d", len(result.Hardware.NetworkAdapters))
// One adapter per PCI function, keyed by that port's BDF, matching an
// OS-level lspci view. Ports share the card's serial and firmware.
if len(result.Hardware.NetworkAdapters) != 2 {
t.Fatalf("expected 2 network adapters (one per port), got %d", len(result.Hardware.NetworkAdapters))
}
adapter := result.Hardware.NetworkAdapters[0]
if adapter.BDF != "0000:27:00.0" {
t.Fatalf("expected network adapter BDF 0000:27:00.0, got %q", adapter.BDF)
byBDF := map[string]models.NetworkAdapter{}
for _, a := range result.Hardware.NetworkAdapters {
byBDF[a.BDF] = a
if a.Firmware != "26.39.2048" {
t.Fatalf("adapter %s firmware = %q, want 26.39.2048", a.BDF, a.Firmware)
}
if a.SerialNumber != "02Y238X6RC000058" {
t.Fatalf("adapter %s serial = %q, want 02Y238X6RC000058", a.BDF, a.SerialNumber)
}
}
if adapter.Firmware != "26.39.2048" {
t.Fatalf("expected network adapter firmware 26.39.2048, got %q", adapter.Firmware)
if got := byBDF["0000:27:00.0"].MACAddresses; len(got) != 1 || got[0] != "44:1A:4C:16:E8:03" {
t.Fatalf("port 0 MACs = %#v", got)
}
if adapter.SerialNumber != "02Y238X6RC000058" {
t.Fatalf("expected network adapter serial from card_info, got %q", adapter.SerialNumber)
}
if len(adapter.MACAddresses) != 2 || adapter.MACAddresses[0] != "44:1A:4C:16:E8:03" || adapter.MACAddresses[1] != "44:1A:4C:16:E8:04" {
t.Fatalf("unexpected MAC addresses: %#v", adapter.MACAddresses)
if got := byBDF["0000:27:00.1"].MACAddresses; len(got) != 1 || got[0] != "44:1A:4C:16:E8:04" {
t.Fatalf("port 1 MACs = %#v", got)
}
fwByDevice := make(map[string]models.FirmwareInfo)
for _, fw := range result.Hardware.Firmware {
fwByDevice[fw.DeviceName] = fw
}
if fwByDevice["iBMC"].Version != "(U68)3.08.05.85" {
t.Fatalf("expected iBMC firmware from app_revision.txt, got %#v", fwByDevice["iBMC"])
if fwByDevice["iBMC"].Version != "3.08.05.85" {
t.Fatalf("expected iBMC firmware (chip designator stripped) from app_revision.txt, got %#v", fwByDevice["iBMC"])
}
if fwByDevice["BIOS"].Version != "(U6216)01.02.08.17" {
t.Fatalf("expected BIOS firmware from app_revision.txt, got %#v", fwByDevice["BIOS"])
if fwByDevice["BIOS"].Version != "01.02.08.17" {
t.Fatalf("expected BIOS firmware (chip designator stripped) from app_revision.txt, got %#v", fwByDevice["BIOS"])
}
if result.Hardware.BoardInfo.ProductName != "G5500 V7" {
t.Fatalf("expected board product fallback from app_revision.txt, got %q", result.Hardware.BoardInfo.ProductName)
@@ -330,3 +335,32 @@ func TestParse_G5500V7_FRU(t *testing.T) {
t.Error("mainboard serial 210619KUGGXGS2000015 not found in FRU")
}
}
// TestParseMemInfo_EmbeddedNewlineInBOM guards against the BMC copying a raw SPD
// "bom number" field containing a 0x0A byte, which splits a DIMM record across
// two physical lines. The row must be rejoined, not turned into a phantom DIMM.
func TestParseMemInfo_EmbeddedNewlineInBOM(t *testing.T) {
const header = "slot(col 1), dimm location(col 2), dimm name(col 3),manufacturer(col 4), size(col 5), speed(col 6), current speed(col 7), memory type(col 8), SN(col 9), minimum voltage(col 10), rank(col 11), bit width(col 12), memory technology(col 13), bom number(col 14), part number(col 15),remaining service life(col 16), firmware version(col 17), medium temp(col 18), controller temp(col 19), volatile capacity(col 20), persistent capacity(col 21), health(col 22)\n"
good := "Memory160 , mainboard, DIMM160, Samsung, 65536 MB, 5600 MT/s, 4400 MT/s, DDR5, 13E79B2E, 1100 mV, 2 rank, 64 bit, Synchronous| Registered (Buffered), \x01\x02, M321R8GA0EB2-CWMXH, Unknown, N/A, Unknown, Unknown, Unknown, Unknown, OK\n"
// Memory170: BOM field carries a stray newline mid-record.
split := "Memory170 , mainboard, DIMM170, Samsung, 65536 MB, 5600 MT/s, 4400 MT/s, DDR5, 13E79D42, 1100 mV, 2 rank, 64 bit, Synchronous| Registered (Buffered), \x9d7h!\x8f\n" +
"s, M321R8GA0EB2-CWMXH, Unknown, N/A, Unknown, Unknown, Unknown, Unknown, OK\n"
dimms := parseMemInfo([]byte(header + good + split))
if len(dimms) != 2 {
t.Fatalf("expected 2 DIMMs, got %d: %+v", len(dimms), dimms)
}
m170 := dimms[1]
if m170.Slot != "DIMM170" {
t.Errorf("slot = %q, want DIMM170", m170.Slot)
}
if m170.SerialNumber != "13E79D42" {
t.Errorf("serial = %q, want 13E79D42", m170.SerialNumber)
}
if m170.PartNumber != "M321R8GA0EB2-CWMXH" {
t.Errorf("part number = %q, want M321R8GA0EB2-CWMXH", m170.PartNumber)
}
if m170.SizeMB != 65536 || m170.Type != "DDR5" || m170.CurrentSpeedMHz != 4400 {
t.Errorf("m170 fields not recovered: %+v", m170)
}
}