storcli64 enumerates these controllers but reports zero drives; storcli2 is the tool Broadcom ships for Tri-Mode/MegaRAID8 hardware and uses a compatible JSON schema for drive listing. Wires storcli2 into both the collector (structured drive data) and the webui RAID Management page (dedup so a controller isn't double-listed if storcli64 already sees it with zero drives), plus techdump raw collection and the ISO vendor-tool build step. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
50 lines
1.9 KiB
Go
50 lines
1.9 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)
|
|
}
|
|
}
|