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>
85 lines
3.1 KiB
Go
85 lines
3.1 KiB
Go
package webui
|
|
|
|
import "testing"
|
|
|
|
// Fixture shape matches Broadcom's published storcli2 drive-info-schema.json
|
|
// (Controllers[].Response Data.Drive Information[]), which is the same shape
|
|
// storcli64 already uses — confirmed by comparing the two tools' schemas.
|
|
func TestParseStorcli2DriveInformation(t *testing.T) {
|
|
raw := []byte(`{
|
|
"Controllers": [
|
|
{
|
|
"Command Status": {"Controller": 0, "Status": "Success"},
|
|
"Response Data": {
|
|
"Drive Information": [
|
|
{"EID:Slt": "252:0", "State": "Onln", "Size": "1.746 TB", "Intf": "NVMe", "Med": "SSD", "Model": "SAMSUNG MZQL21T9HCJR", "SN": "S6EYNE0T123456"},
|
|
{"EID:Slt": "252:1", "State": "UGood", "Size": "1.746 TB", "Intf": "NVMe", "Med": "SSD", "Model": "SAMSUNG MZQL21T9HCJR", "SN": "S6EYNE0T654321"}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}`)
|
|
|
|
all, foreign, free := parseStorcli2DriveInformation(raw)
|
|
if len(all) != 2 {
|
|
t.Fatalf("all=%d want 2 (%#v)", len(all), all)
|
|
}
|
|
if len(foreign) != 0 {
|
|
t.Fatalf("foreign=%d want 0", len(foreign))
|
|
}
|
|
if len(free) != 1 || free[0].Serial != "S6EYNE0T654321" {
|
|
t.Fatalf("free=%#v want one UGood drive", free)
|
|
}
|
|
if all[0].Slot != "252:0" || all[0].SizeGB <= 0 {
|
|
t.Fatalf("all[0]=%#v want populated slot/size", all[0])
|
|
}
|
|
}
|
|
|
|
func TestParseStorcli2DriveInformationEmptyOrMalformed(t *testing.T) {
|
|
if all, foreign, free := parseStorcli2DriveInformation(nil); all != nil || foreign != nil || free != nil {
|
|
t.Fatalf("nil input should return nil slices, got %#v %#v %#v", all, foreign, free)
|
|
}
|
|
if all, _, _ := parseStorcli2DriveInformation([]byte("not json")); all != nil {
|
|
t.Fatalf("malformed JSON should return nil, got %#v", all)
|
|
}
|
|
// Valid JSON but no Controllers (e.g. tool ran but found nothing) must not panic.
|
|
if all, _, _ := parseStorcli2DriveInformation([]byte(`{"Controllers":[]}`)); all != nil {
|
|
t.Fatalf("empty Controllers should return nil, got %#v", all)
|
|
}
|
|
}
|
|
|
|
// TestParseStorcliResponseDataDrivesPerSlotKeys 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). This is what made "RAID Controller Management" show
|
|
// "No drives detected" for a controller storcli64 could clearly see.
|
|
func TestParseStorcliResponseDataDrivesPerSlotKeys(t *testing.T) {
|
|
raw := []byte(`{
|
|
"Controllers": [
|
|
{
|
|
"Command Status": {"Status": "Success"},
|
|
"Response Data": {
|
|
"Drive /c0/e69/s0": [
|
|
{"EID:Slt": "69:0", "State": "JBOD", "Size": "447.130 GB", "Model": "SAMSUNG MZ7L3480HCHQ-00B7C"}
|
|
],
|
|
"Drive /c0/e69/s0 - Detailed Information": {
|
|
"Drive /c0/e69/s0 State": {"Shield Counter": 0}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}`)
|
|
|
|
all, _, free := parseStorcli2DriveInformation(raw)
|
|
if len(all) != 1 {
|
|
t.Fatalf("all=%d want 1 (%#v)", len(all), all)
|
|
}
|
|
if all[0].Model != "SAMSUNG MZ7L3480HCHQ-00B7C" || all[0].Slot != "69:0" {
|
|
t.Fatalf("all[0]=%#v want model/slot populated", all[0])
|
|
}
|
|
if len(free) != 1 {
|
|
t.Fatalf("free=%d want 1 (JBOD is a free drive)", len(free))
|
|
}
|
|
}
|