Files
logpile/internal/parser/vendors/inspur/maintenance_test.go
T
Mikhail ChusavitinandClaude Opus 5.5 693906ceba feat(inspur): keep DIMM state on the DIMM, parse maintenance.log installs
component.log memory status produced synthetic "Memory module … not
detected (capacity 0GB)" events that duplicated IDL/SEL "Memory Device
Disabled … POR Mapout" Asserts already in the journal, with a wrong text
(the modules are present).

- Drop synthetic memory events. The snapshot status stays authoritative
  on the DIMM; the journal Assert/Deassert supplies status_history, the
  fault description and status_changed_at (latest active Assert).
- Drop a component.log fan state event when the journal already holds an
  active Assert for that fan.
- Parse "Component Replace <dev> SN changed from X to Y" from
  maintenance.log and rotated maintenance.log.N.gz into Info events,
  mapping DIMM<cpu><ch><dimm> to the inventory slot (DIMM021 -> CPU0_C2D1).

ADL-071.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 13:01:30 +03:00

64 lines
2.7 KiB
Go

package inspur
import (
"bytes"
"compress/gzip"
"testing"
"git.mchus.pro/mchus/logpile/internal/models"
)
const maintenanceSample = `<182> 2026-08-12T15:35:22.950000+08:00 24C319575 commerDiagnose: [1846 : 1897 INFO]|2026-08-12T15:35:22+08:00|MEMORY|Assert|Info|0CFFB300|Component Replace DIMM021 SN changed from NULL to H0KN000308444EA65D! - Assert|
<182> 2024-03-22T17:09:44.000000+08:00 24C319575 commerDiagnose: [1846 : 1897 INFO]|2024-03-22T17:09:44+08:00|CPU|Assert|Info|07FFB000|Component Replace CPU0 changed from NULL to 23300E51079AF0AB! - Assert|
<182> 2026-08-12T15:35:30.000000+08:00 24C319575 commerDiagnose: [1846 : 1897 INFO]|2026-08-12T15:35:30+08:00|PSU|Assert|Info|08FFB100|Component Replace PSU1 SN changed from 2O01C154667 to 2O01C999999! - Assert|
<182> 2024-03-22T16:58:34.580000+08:00 24C319575 commerDiagnose: [2212 : 2261 INFO]IDLProgressTask:Init local eeprom info......
`
func TestParseMaintenanceLog_ComponentReplace(t *testing.T) {
events := ParseMaintenanceLog([]byte(maintenanceSample))
if len(events) != 3 {
t.Fatalf("expected 3 component replace events, got %d: %+v", len(events), events)
}
dimm := events[0]
if dimm.SensorType != "memory" || dimm.SensorName != "CPU0_C2D1" {
t.Fatalf("DIMM021 must map to memory/CPU0_C2D1, got %s/%s", dimm.SensorType, dimm.SensorName)
}
if dimm.EventType != componentReplaceEventType || dimm.Severity != models.SeverityInfo {
t.Fatalf("unexpected type/severity %q/%q", dimm.EventType, dimm.Severity)
}
if dimm.Description != "CPU0_C2D1 (DIMM021) installed: SN NULL → H0KN000308444EA65D" {
t.Fatalf("unexpected description %q", dimm.Description)
}
if dimm.Timestamp.IsZero() {
t.Fatalf("expected journal timestamp")
}
if events[1].Description != "CPU0 installed: SN NULL → 23300E51079AF0AB" {
t.Fatalf("unexpected CPU description %q", events[1].Description)
}
if events[2].Description != "PSU1 replaced: SN 2O01C154667 → 2O01C999999" {
t.Fatalf("unexpected PSU description %q", events[2].Description)
}
}
func TestParseMaintenanceLog_DoesNotAffectDIMMFaultState(t *testing.T) {
hw := &models.HardwareConfig{Memory: []models.MemoryDIMM{{Slot: "CPU0_C2D1", Status: "Warning"}}}
applyMemoryStatusFromEvents(hw, ParseMaintenanceLog([]byte(maintenanceSample)))
if len(hw.Memory[0].StatusHistory) != 0 || hw.Memory[0].StatusChangedAt != nil {
t.Fatalf("installation record must not be read as a fault transition: %+v", hw.Memory[0])
}
}
func TestDecodeGzipLog(t *testing.T) {
var buf bytes.Buffer
gz := gzip.NewWriter(&buf)
_, _ = gz.Write([]byte(maintenanceSample))
_ = gz.Close()
if got := ParseMaintenanceLog(decodeGzipLog(buf.Bytes())); len(got) != 3 {
t.Fatalf("expected rotated maintenance log to decode, got %d events", len(got))
}
}