package inspur import ( "testing" "git.mchus.pro/mchus/logpile/internal/models" ) const componentLogFRUBlock = `RESTful FRU info: [ { "device": { "id": 0, "name": "BMC_FRU", "system_uuid": "4fc4c29c-dfeb-03e6-0010-debf003f9071" }, "chassis": { "version": 1, "type": "Rack Mount Chassis", "part_number": "0", "serial_number": "0" }, "board": { "version": 1, "date": "Wed Dec 27 16:15:00 2023", "manufacturer": "Inspur", "product_name": "NF5280M6", "serial_number": "MBPC16R11762D90", "part_number": "YZMB-01642-102" }, "product": { "version": 1, "manufacturer": "Inspur", "product_name": "NF5280M6", "part_number": "0", "serial_number": "24C319579", "asset_tag": "24C319579" } }, { "device": { "id": 1, "name": "PSU0_FRU", "system_uuid": "4fc4c29c-dfeb-03e6-0010-debf003f9071" }, "chassis": { "version": 0 }, "board": { "version": 0 }, "product": { "version": 1, "manufacturer": "Great Wall", "product_name": "GW-CRPS1300D2WM", "part_number": "V0310AD000000000", "serial_number": "2O01C174959" } } ] BMC kernel version: Linux` func TestParseComponentLogFRU_BoardIdentityAndUUID(t *testing.T) { hw := &models.HardwareConfig{} fru := ParseComponentLogFRU([]byte(componentLogFRUBlock), hw) if len(fru) != 2 { t.Fatalf("expected 2 FRU entries, got %d", len(fru)) } if hw.BoardInfo.UUID != "4fc4c29c-dfeb-03e6-0010-debf003f9071" { t.Errorf("BoardInfo.UUID = %q, want the system_uuid", hw.BoardInfo.UUID) } extractBoardInfo(fru, hw) if hw.BoardInfo.Manufacturer != "Inspur" { t.Errorf("Manufacturer = %q, want Inspur", hw.BoardInfo.Manufacturer) } if hw.BoardInfo.ProductName != "NF5280M6" { t.Errorf("ProductName = %q, want NF5280M6", hw.BoardInfo.ProductName) } // product-area serial (operator-facing), not the board PCB serial. if hw.BoardInfo.SerialNumber != "24C319579" { t.Errorf("SerialNumber = %q, want 24C319579", hw.BoardInfo.SerialNumber) } // "0" product part is a placeholder; fall back to the real board part. if hw.BoardInfo.PartNumber != "YZMB-01642-102" { t.Errorf("PartNumber = %q, want YZMB-01642-102", hw.BoardInfo.PartNumber) } // PSU vendor must not leak into the server manufacturer. if fru[1].Manufacturer != "Great Wall" || fru[1].SerialNumber != "2O01C174959" { t.Errorf("PSU FRU not preserved: %+v", fru[1]) } } func TestParseComponentLogFRU_AbsentSection(t *testing.T) { hw := &models.HardwareConfig{} if fru := ParseComponentLogFRU([]byte("RESTful CPU info:\n{ }\nRESTful Memory info:\n{ }"), hw); fru != nil { t.Fatalf("expected nil for a log with no FRU section, got %+v", fru) } if hw.BoardInfo.UUID != "" { t.Errorf("BoardInfo.UUID set to %q from a log with no FRU section", hw.BoardInfo.UUID) } }