fix(exporter): populate Present on exported Memory/PSU so reanimator re-import keeps them
ReanimatorMemory.Present and ReanimatorPSU.Present were already declared as *bool fields (matching ReanimatorStorage.Present), but convertMemoryFromDevices and convertPSUsFromDevices never set them, unlike convertStorageFromDevices. Exported JSON therefore had "present" for storage but not for memory/PSU items. Re-importing a previously exported reanimator.json via parseUploadedSnapshot (a direct json.Unmarshal into models.AnalysisResult) left Present=false on those two categories, and the existing IsInstalledInventory()/present-required filters then dropped them on the next /chart/current render — reproduced live: fresh TSR upload showed Memory and Power Supplies correctly, re-uploading the exported reanimator.json for the same result did not. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
f599215760
commit
eb6cc207ce
@@ -43,12 +43,12 @@ func ConvertToReanimator(result *models.AnalysisResult) (*ReanimatorExport, erro
|
||||
TargetHost: targetHost,
|
||||
CollectedAt: collectedAt,
|
||||
Hardware: ReanimatorHardware{
|
||||
Board: convertBoard(result.Hardware.BoardInfo),
|
||||
Firmware: dedupeFirmware(convertFirmware(result.Hardware.Firmware)),
|
||||
CPUs: dedupeCPUs(convertCPUsFromDevices(devices, collectedAt, result.Hardware.BoardInfo.SerialNumber, buildCPUMicrocodeBySocket(result.Hardware.Firmware))),
|
||||
Memory: dedupeMemory(convertMemoryFromDevices(devices, collectedAt)),
|
||||
Storage: dedupeStorage(convertStorageFromDevices(devices, collectedAt)),
|
||||
PCIeDevices: dedupePCIe(convertPCIeFromDevices(devices, collectedAt)),
|
||||
Board: convertBoard(result.Hardware.BoardInfo),
|
||||
Firmware: dedupeFirmware(convertFirmware(result.Hardware.Firmware)),
|
||||
CPUs: dedupeCPUs(convertCPUsFromDevices(devices, collectedAt, result.Hardware.BoardInfo.SerialNumber, buildCPUMicrocodeBySocket(result.Hardware.Firmware))),
|
||||
Memory: dedupeMemory(convertMemoryFromDevices(devices, collectedAt)),
|
||||
Storage: dedupeStorage(convertStorageFromDevices(devices, collectedAt)),
|
||||
PCIeDevices: dedupePCIe(convertPCIeFromDevices(devices, collectedAt)),
|
||||
PowerSupplies: dedupePSUs(convertPSUsFromDevices(devices, collectedAt)),
|
||||
Sensors: convertSensors(result.Sensors),
|
||||
BMCEventSummary: buildBMCEventSummary(result.Events, collectedAt),
|
||||
@@ -716,9 +716,11 @@ func convertMemoryFromDevices(devices []models.HardwareDevice, collectedAt strin
|
||||
continue
|
||||
}
|
||||
meta := buildStatusMeta(status, d.StatusCheckedAt, d.StatusChangedAt, d.StatusHistory, d.ErrorDescription, collectedAt)
|
||||
presentValue := present
|
||||
result = append(result, ReanimatorMemory{
|
||||
Slot: d.Slot,
|
||||
Location: d.Location,
|
||||
Present: &presentValue,
|
||||
SizeMB: d.SizeMB,
|
||||
Type: d.Type,
|
||||
MaxSpeedMHz: intFromDetailMap(d.Details, "max_speed_mhz"),
|
||||
@@ -990,8 +992,10 @@ func convertPSUsFromDevices(devices []models.HardwareDevice, collectedAt string)
|
||||
}
|
||||
status := normalizeStatus(d.Status, false)
|
||||
meta := buildStatusMeta(status, d.StatusCheckedAt, d.StatusChangedAt, d.StatusHistory, d.ErrorDescription, collectedAt)
|
||||
presentValue := present
|
||||
result = append(result, ReanimatorPSU{
|
||||
Slot: d.Slot,
|
||||
Present: &presentValue,
|
||||
Model: d.Model,
|
||||
Vendor: d.Manufacturer,
|
||||
WattageW: d.WattageW,
|
||||
|
||||
@@ -2013,3 +2013,67 @@ func TestIsDeviceBoundFirmwareFQDD(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestConvertToReanimator_MemoryAndPSURoundTripSurvivesReimport is a regression guard
|
||||
// for a bug where re-uploading a previously exported reanimator.json (the "Reanimator"
|
||||
// round-trip: export, then re-import the same file) silently dropped Memory and Power
|
||||
// Supplies from the chart view. convertMemoryFromDevices/convertPSUsFromDevices never
|
||||
// set the already-declared ReanimatorMemory.Present / ReanimatorPSU.Present output
|
||||
// field, so the exported JSON omitted "present" for those two sections (unlike
|
||||
// Storage, which did set it). Re-importing that JSON via parseUploadedSnapshot
|
||||
// (a direct json.Unmarshal into models.AnalysisResult) left Present=false on the
|
||||
// round-tripped items, and IsInstalledInventory()/the PSU present check then dropped
|
||||
// them on the next ConvertToReanimator call. (2026-08-11)
|
||||
func TestConvertToReanimator_MemoryAndPSURoundTripSurvivesReimport(t *testing.T) {
|
||||
original := &models.AnalysisResult{
|
||||
Filename: "test.zip",
|
||||
CollectedAt: time.Date(2026, 7, 22, 4, 16, 0, 0, time.UTC),
|
||||
Hardware: &models.HardwareConfig{
|
||||
BoardInfo: models.BoardInfo{
|
||||
Manufacturer: "Dell Inc.",
|
||||
ProductName: "PowerEdge R7715",
|
||||
SerialNumber: "1TVFYL4",
|
||||
},
|
||||
Memory: []models.MemoryDIMM{
|
||||
{Slot: "A1", Present: true, SizeMB: 32768, SerialNumber: "37CC7641", Status: "OK"},
|
||||
},
|
||||
PowerSupply: []models.PSU{
|
||||
{Slot: "PSU.Slot.1", Present: true, Model: "PWR SPLY,1500W", SerialNumber: "CNDED0064K2RKW", Status: "OK"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
exported, err := ConvertToReanimator(original)
|
||||
if err != nil {
|
||||
t.Fatalf("ConvertToReanimator() failed: %v", err)
|
||||
}
|
||||
if len(exported.Hardware.Memory) != 1 || exported.Hardware.Memory[0].Present == nil || !*exported.Hardware.Memory[0].Present {
|
||||
t.Fatalf("expected exported memory to carry present=true, got %+v", exported.Hardware.Memory)
|
||||
}
|
||||
if len(exported.Hardware.PowerSupplies) != 1 || exported.Hardware.PowerSupplies[0].Present == nil || !*exported.Hardware.PowerSupplies[0].Present {
|
||||
t.Fatalf("expected exported PSU to carry present=true, got %+v", exported.Hardware.PowerSupplies)
|
||||
}
|
||||
|
||||
// Simulate the round trip: marshal the exported reanimator JSON, then unmarshal
|
||||
// it straight into models.AnalysisResult the way parseUploadedSnapshot does when
|
||||
// a user re-uploads a previously downloaded reanimator.json.
|
||||
raw, err := json.Marshal(exported)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal exported: %v", err)
|
||||
}
|
||||
var reimported models.AnalysisResult
|
||||
if err := json.Unmarshal(raw, &reimported); err != nil {
|
||||
t.Fatalf("unmarshal into AnalysisResult: %v", err)
|
||||
}
|
||||
|
||||
reconverted, err := ConvertToReanimator(&reimported)
|
||||
if err != nil {
|
||||
t.Fatalf("ConvertToReanimator() on reimported result failed: %v", err)
|
||||
}
|
||||
if len(reconverted.Hardware.Memory) != 1 {
|
||||
t.Fatalf("memory did not survive reanimator round trip, got %+v", reconverted.Hardware.Memory)
|
||||
}
|
||||
if len(reconverted.Hardware.PowerSupplies) != 1 {
|
||||
t.Fatalf("power supplies did not survive reanimator round trip, got %+v", reconverted.Hardware.PowerSupplies)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,28 +12,28 @@ type ReanimatorExport struct {
|
||||
|
||||
// ReanimatorHardware contains all hardware components
|
||||
type ReanimatorHardware struct {
|
||||
Board ReanimatorBoard `json:"board"`
|
||||
Firmware []ReanimatorFirmware `json:"firmware,omitempty"`
|
||||
CPUs []ReanimatorCPU `json:"cpus,omitempty"`
|
||||
Memory []ReanimatorMemory `json:"memory,omitempty"`
|
||||
Storage []ReanimatorStorage `json:"storage,omitempty"`
|
||||
PCIeDevices []ReanimatorPCIe `json:"pcie_devices,omitempty"`
|
||||
PowerSupplies []ReanimatorPSU `json:"power_supplies,omitempty"`
|
||||
Sensors *ReanimatorSensors `json:"sensors,omitempty"`
|
||||
BMCEventSummary []ReanimatorBMCEventRow `json:"bmc_event_summary,omitempty"`
|
||||
EventLogs []ReanimatorEventLog `json:"event_logs,omitempty"`
|
||||
PlatformConfig map[string]any `json:"platform_config,omitempty"`
|
||||
Board ReanimatorBoard `json:"board"`
|
||||
Firmware []ReanimatorFirmware `json:"firmware,omitempty"`
|
||||
CPUs []ReanimatorCPU `json:"cpus,omitempty"`
|
||||
Memory []ReanimatorMemory `json:"memory,omitempty"`
|
||||
Storage []ReanimatorStorage `json:"storage,omitempty"`
|
||||
PCIeDevices []ReanimatorPCIe `json:"pcie_devices,omitempty"`
|
||||
PowerSupplies []ReanimatorPSU `json:"power_supplies,omitempty"`
|
||||
Sensors *ReanimatorSensors `json:"sensors,omitempty"`
|
||||
BMCEventSummary []ReanimatorBMCEventRow `json:"bmc_event_summary,omitempty"`
|
||||
EventLogs []ReanimatorEventLog `json:"event_logs,omitempty"`
|
||||
PlatformConfig map[string]any `json:"platform_config,omitempty"`
|
||||
}
|
||||
|
||||
// ReanimatorBMCEventRow is one row in the BMC critical/warning event summary table.
|
||||
type ReanimatorBMCEventRow struct {
|
||||
Severity string `json:"severity"`
|
||||
Component string `json:"component"`
|
||||
MessageID string `json:"message_id"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Severity string `json:"severity"`
|
||||
Component string `json:"component"`
|
||||
MessageID string `json:"message_id"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Description string `json:"description"`
|
||||
Status string `json:"status"`
|
||||
ResolvedAt string `json:"resolved_at,omitempty"`
|
||||
Status string `json:"status"`
|
||||
ResolvedAt string `json:"resolved_at,omitempty"`
|
||||
}
|
||||
|
||||
// ReanimatorBoard represents motherboard/server information
|
||||
@@ -128,25 +128,25 @@ type ReanimatorStorage struct {
|
||||
MetadataBytesPerBlock int64 `json:"metadata_bytes_per_block,omitempty"`
|
||||
TemperatureC float64 `json:"temperature_c,omitempty"`
|
||||
PowerOnHours int64 `json:"power_on_hours,omitempty"`
|
||||
PowerCycles int64 `json:"power_cycles,omitempty"`
|
||||
UnsafeShutdowns int64 `json:"unsafe_shutdowns,omitempty"`
|
||||
MediaErrors int64 `json:"media_errors,omitempty"`
|
||||
ErrorLogEntries int64 `json:"error_log_entries,omitempty"`
|
||||
WrittenBytes int64 `json:"written_bytes,omitempty"`
|
||||
ReadBytes int64 `json:"read_bytes,omitempty"`
|
||||
LifeUsedPct float64 `json:"life_used_pct,omitempty"`
|
||||
RemainingEndurancePct *int `json:"remaining_endurance_pct,omitempty"`
|
||||
LifeRemainingPct float64 `json:"life_remaining_pct,omitempty"`
|
||||
AvailableSparePct float64 `json:"available_spare_pct,omitempty"`
|
||||
ReallocatedSectors int64 `json:"reallocated_sectors,omitempty"`
|
||||
CurrentPendingSectors int64 `json:"current_pending_sectors,omitempty"`
|
||||
OfflineUncorrectable int64 `json:"offline_uncorrectable,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
StatusCheckedAt string `json:"status_checked_at,omitempty"`
|
||||
StatusChangedAt string `json:"status_changed_at,omitempty"`
|
||||
ManufacturedYearWeek string `json:"manufactured_year_week,omitempty"`
|
||||
StatusHistory []ReanimatorStatusHistoryEntry `json:"status_history,omitempty"`
|
||||
ErrorDescription string `json:"error_description,omitempty"`
|
||||
PowerCycles int64 `json:"power_cycles,omitempty"`
|
||||
UnsafeShutdowns int64 `json:"unsafe_shutdowns,omitempty"`
|
||||
MediaErrors int64 `json:"media_errors,omitempty"`
|
||||
ErrorLogEntries int64 `json:"error_log_entries,omitempty"`
|
||||
WrittenBytes int64 `json:"written_bytes,omitempty"`
|
||||
ReadBytes int64 `json:"read_bytes,omitempty"`
|
||||
LifeUsedPct float64 `json:"life_used_pct,omitempty"`
|
||||
RemainingEndurancePct *int `json:"remaining_endurance_pct,omitempty"`
|
||||
LifeRemainingPct float64 `json:"life_remaining_pct,omitempty"`
|
||||
AvailableSparePct float64 `json:"available_spare_pct,omitempty"`
|
||||
ReallocatedSectors int64 `json:"reallocated_sectors,omitempty"`
|
||||
CurrentPendingSectors int64 `json:"current_pending_sectors,omitempty"`
|
||||
OfflineUncorrectable int64 `json:"offline_uncorrectable,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
StatusCheckedAt string `json:"status_checked_at,omitempty"`
|
||||
StatusChangedAt string `json:"status_changed_at,omitempty"`
|
||||
ManufacturedYearWeek string `json:"manufactured_year_week,omitempty"`
|
||||
StatusHistory []ReanimatorStatusHistoryEntry `json:"status_history,omitempty"`
|
||||
ErrorDescription string `json:"error_description,omitempty"`
|
||||
}
|
||||
|
||||
// ReanimatorPCIe represents a PCIe device
|
||||
|
||||
Reference in New Issue
Block a user