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>
95 lines
3.8 KiB
Go
95 lines
3.8 KiB
Go
package inspur
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"git.mchus.pro/mchus/logpile/internal/models"
|
|
)
|
|
|
|
func TestApplyMemoryStatusFromEvents_UsesLatestJournalAssert(t *testing.T) {
|
|
loc := time.FixedZone("+08", 8*3600)
|
|
assert1 := time.Date(2026, 8, 12, 18, 52, 12, 0, loc)
|
|
deassert := time.Date(2026, 8, 12, 19, 23, 39, 0, loc)
|
|
assert2 := time.Date(2026, 8, 12, 19, 23, 50, 0, loc)
|
|
hw := &models.HardwareConfig{Memory: []models.MemoryDIMM{
|
|
{Slot: "CPU0_C2D1", Status: "Warning"},
|
|
{Slot: "CPU0_C3D1", Status: "OK"},
|
|
}}
|
|
events := []models.Event{
|
|
{Timestamp: assert2, SensorType: "memory", SensorName: "CPU0_C2D1", EventType: "Assert", Severity: models.SeverityWarning, Description: "CPU0_C2D1 Memory Device Disabled POR Mapout"},
|
|
{Timestamp: assert1, SensorType: "memory", SensorName: "CPU0_C2D1", EventType: "Assert", Severity: models.SeverityWarning, Description: "CPU0_C2D1 Memory Device Disabled"},
|
|
{Timestamp: deassert, SensorType: "memory", SensorName: "CPU0_C2D1", EventType: "Deassert", Severity: models.SeverityInfo, Description: "CPU0_C2D1 Memory Device Disabled"},
|
|
}
|
|
|
|
applyMemoryStatusFromEvents(hw, events)
|
|
|
|
dimm := hw.Memory[0]
|
|
if dimm.Status != "Warning" {
|
|
t.Fatalf("snapshot status must stay authoritative, got %q", dimm.Status)
|
|
}
|
|
if dimm.StatusChangedAt == nil || !dimm.StatusChangedAt.Equal(assert2) {
|
|
t.Fatalf("expected status_changed_at from latest assert %s, got %v", assert2, dimm.StatusChangedAt)
|
|
}
|
|
if dimm.ErrorDescription != "CPU0_C2D1 Memory Device Disabled POR Mapout" {
|
|
t.Fatalf("unexpected error description %q", dimm.ErrorDescription)
|
|
}
|
|
if len(dimm.StatusHistory) != 3 {
|
|
t.Fatalf("expected Warning/OK/Warning history, got %+v", dimm.StatusHistory)
|
|
}
|
|
if hw.Memory[1].ErrorDescription != "" || len(hw.Memory[1].StatusHistory) != 0 {
|
|
t.Fatalf("healthy DIMM without journal entries must stay untouched: %+v", hw.Memory[1])
|
|
}
|
|
}
|
|
|
|
func TestApplyMemoryStatusFromEvents_SnapshotFaultWithoutJournal(t *testing.T) {
|
|
hw := &models.HardwareConfig{Memory: []models.MemoryDIMM{{Slot: "CPU1_C0D0", Status: "Critical"}}}
|
|
|
|
applyMemoryStatusFromEvents(hw, nil)
|
|
|
|
if hw.Memory[0].StatusChangedAt != nil {
|
|
t.Fatalf("no journal entry: change time must stay unknown, got %v", hw.Memory[0].StatusChangedAt)
|
|
}
|
|
if hw.Memory[0].ErrorDescription == "" {
|
|
t.Fatalf("expected note that the fault was seen at log collection")
|
|
}
|
|
}
|
|
|
|
func TestParseComponentLogEvents_NoSyntheticMemoryEvents(t *testing.T) {
|
|
text := `RESTful Memory info:
|
|
{ "mem_modules": [ { "mem_mod_id": 5, "mem_mod_slot": "CPU0_C2D1", "mem_mod_status": 1, "mem_mod_size": 0, "status": "Warning" } ] }
|
|
RESTful HDD info:
|
|
{}`
|
|
if events := ParseComponentLogEvents([]byte(text)); len(events) != 0 {
|
|
t.Fatalf("DIMM snapshot state must not be written to the event log, got %+v", events)
|
|
}
|
|
}
|
|
|
|
func TestDropFanSnapshotEventsCoveredByJournal(t *testing.T) {
|
|
ts := time.Date(2026, 8, 12, 10, 0, 0, 0, time.UTC)
|
|
events := []models.Event{
|
|
{EventType: "Fan Status", SensorName: "FAN3_R_Speed", Description: "FAN3_R_Speed reports Critical"},
|
|
{EventType: "Fan Status", SensorName: "FAN4_R_Speed", Description: "FAN4_R_Speed reports Critical"},
|
|
{Timestamp: ts, SensorType: "fan", SensorName: "FAN3_R_Speed", EventType: "Assert"},
|
|
{Timestamp: ts.Add(-time.Hour), SensorType: "fan", SensorName: "FAN4_R_Speed", EventType: "Assert"},
|
|
{Timestamp: ts, SensorType: "fan", SensorName: "FAN4_R_Speed", EventType: "Deassert"},
|
|
}
|
|
|
|
out := dropFanSnapshotEventsCoveredByJournal(events)
|
|
|
|
for _, e := range out {
|
|
if e.EventType == "Fan Status" && e.SensorName == "FAN3_R_Speed" {
|
|
t.Fatalf("fan state already asserted in journal must not be duplicated")
|
|
}
|
|
}
|
|
found := false
|
|
for _, e := range out {
|
|
if e.EventType == "Fan Status" && e.SensorName == "FAN4_R_Speed" {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("fan state not asserted in journal must be kept")
|
|
}
|
|
}
|