raid: parse storcli64/storcli2's actual per-slot drive JSON shape

RAID Controller Management showed "No drives detected" for a live
SAS3808-iMR controller even though storcli64 clearly enumerates its
drives. Root cause: the "eall/sall show all J" drive-listing parser
(collector/raid.go and its webui/raid_mgmt.go duplicate) assumed
drives are reported as a single "Drive Information" array, but real
storcli64/storcli2 output nests each drive under its own dynamically
named key ("Drive /c0/e69/s0", paired with a "... - Detailed
Information" key) — confirmed against a live techdump/storcli64-drives.json
capture. The assumed shape was never actually produced by the tool, so
this affected every storcli64/storcli2 controller, not just Tri-Mode
ones (the storcli2 fallback added in b7f015c never got a chance to
mask it in practice, since storcli2 itself reports zero controllers on
this hardware — a separate, unrelated tool-side gap).

Both parsers now read "Response Data" as a raw key map and pull drives
from either shape, so older storcli output using the array form still
works alongside the real per-slot form.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Mikhail Chusavitin
2026-07-07 17:21:05 +03:00
co-authored by Claude Sonnet 5
parent 2d84ddb577
commit 4e306ff78c
4 changed files with 213 additions and 109 deletions
@@ -73,3 +73,38 @@ func TestCollectStorcli2DrivesEndToEnd(t *testing.T) {
t.Fatalf("drives[0]=%#v want serial S6EYNE0T123456", drives[0])
}
}
// TestParseStorcliDrivesJSONPerSlotKeys regression-tests against a live
// SAS3808-iMR "storcli64 /call/eall/sall show all J" dump: "Response Data"
// has no "Drive Information" array at all, only per-slot keys like
// "Drive /c0/e69/s0" (plus a paired "... - Detailed Information" key that
// must be skipped). The previous parser, which only looked for "Drive
// Information", silently returned zero drives against this real output.
func TestParseStorcliDrivesJSONPerSlotKeys(t *testing.T) {
raw := []byte(`{
"Controllers": [
{
"Command Status": {"Status": "Success"},
"Response Data": {
"Drive /c0/e69/s0": [
{"EID:Slt": "69:0", "DID": 0, "State": "JBOD", "DG": "-", "Size": "447.130 GB", "Intf": "SATA", "Med": "SSD", "Model": "SAMSUNG MZ7L3480HCHQ-00B7C", "Sp": "U", "Type": "-"}
],
"Drive /c0/e69/s0 - Detailed Information": {
"Drive /c0/e69/s0 State": {"Shield Counter": 0}
}
}
}
]
}`)
drives := parseStorcliDrivesJSON(raw)
if len(drives) != 1 {
t.Fatalf("drives=%d want 1 (%#v)", len(drives), drives)
}
if drives[0].Model == nil || *drives[0].Model != "SAMSUNG MZ7L3480HCHQ-00B7C" {
t.Fatalf("drives[0]=%#v want model SAMSUNG MZ7L3480HCHQ-00B7C", drives[0])
}
if drives[0].Slot == nil || *drives[0].Slot != "69:0" {
t.Fatalf("drives[0].Slot=%v want 69:0", drives[0].Slot)
}
}