| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673 |
- // Copyright 2019 Yunion
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package megactl
- import (
- "testing"
- "github.com/stretchr/testify/assert"
- )
- func Test_parseStorcliControllers(t *testing.T) {
- input := `
- {
- "Controllers":[
- {
- "Command Status" : {
- "CLI Version" : "007.1907.0000.0000 Sep 13, 2021",
- "Operating system" : "Linux 5.14.0-4-arm64",
- "Controller" : 0,
- "Status" : "Success",
- "Description" : "Show Drive Information Succeeded."
- },
- "Response Data" : {
- "Drive Information" : [
- {
- "EID:Slt" : "65:0",
- "DID" : 6,
- "State" : "Onln",
- "DG" : 0,
- "Size" : "1.089 TB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST1200MM0009 ",
- "Sp" : "U",
- "Type" : "-"
- },
- {
- "EID:Slt" : "65:1",
- "DID" : 8,
- "State" : "Onln",
- "DG" : 0,
- "Size" : "1.089 TB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST1200MM0009 ",
- "Sp" : "U",
- "Type" : "-"
- },
- {
- "EID:Slt" : "65:2",
- "DID" : 9,
- "State" : "Onln",
- "DG" : 0,
- "Size" : "1.089 TB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST1200MM0009 ",
- "Sp" : "U",
- "Type" : "-"
- },
- {
- "EID:Slt" : "65:3",
- "DID" : 7,
- "State" : "Onln",
- "DG" : 0,
- "Size" : "1.089 TB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST1200MM0009 ",
- "Sp" : "U",
- "Type" : "-"
- },
- {
- "EID:Slt" : "65:4",
- "DID" : 14,
- "State" : "Onln",
- "DG" : 0,
- "Size" : "1.089 TB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST1200MM0009 ",
- "Sp" : "U",
- "Type" : "-"
- },
- {
- "EID:Slt" : "65:5",
- "DID" : 13,
- "State" : "Onln",
- "DG" : 0,
- "Size" : "1.089 TB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST1200MM0009 ",
- "Sp" : "U",
- "Type" : "-"
- },
- {
- "EID:Slt" : "65:6",
- "DID" : 19,
- "State" : "UGood",
- "DG" : "F",
- "Size" : "1.745 TB",
- "Intf" : "SATA",
- "Med" : "SSD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "INTEL SSDSC2KB019T8",
- "Sp" : "U",
- "Type" : "-"
- },
- {
- "EID:Slt" : "65:7",
- "DID" : 20,
- "State" : "JBOD",
- "DG" : "-",
- "Size" : "1.746 TB",
- "Intf" : "SATA",
- "Med" : "SSD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "INTEL SSDSC2KB019T8",
- "Sp" : "U",
- "Type" : "-"
- },
- {
- "EID:Slt" : "65:9",
- "DID" : 15,
- "State" : "Onln",
- "DG" : 1,
- "Size" : "3.637 TB",
- "Intf" : "SATA",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "MG04ACA400N",
- "Sp" : "U",
- "Type" : "-"
- },
- {
- "EID:Slt" : "65:10",
- "DID" : 17,
- "State" : "Onln",
- "DG" : 1,
- "Size" : "3.637 TB",
- "Intf" : "SATA",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "MG04ACA400N",
- "Sp" : "U",
- "Type" : "-"
- },
- {
- "EID:Slt" : "65:11",
- "DID" : 16,
- "State" : "Onln",
- "DG" : 1,
- "Size" : "3.637 TB",
- "Intf" : "SATA",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "MG04ACA400N",
- "Sp" : "U",
- "Type" : "-"
- }
- ]
- }
- }
- ]
- }
- `
- info, err := parseStorcliControllers(input)
- if err != nil {
- t.Fatalf("parseStorcliControllers error: %v", err)
- }
- assert := assert.New(t)
- assert.Equal(1, len(info.Controllers))
- assert.Equal("ST1200MM0009 ", info.Controllers[0].ResponseData.Info[0].Model)
- assert.Equal("1.089 TB", info.Controllers[0].ResponseData.Info[0].Size)
- pds := info.Controllers[0].ResponseData.Info
- for _, pd := range pds {
- d, err := pd.toMegaraidDev()
- if err != nil {
- t.Fatalf("toMegaraidDev error: %v", err)
- }
- t.Logf("convert megaraid device: %#v", d)
- }
- }
- func TestStorcliLogicalVolumes_GetLogicalVolumes(t *testing.T) {
- input := `
- {
- "Controllers":[
- {
- "Command Status" : {
- "CLI Version" : "007.1907.0000.0000 Sep 13, 2021",
- "Operating system" : "Linux 5.14.0-4-arm64",
- "Controller" : 0,
- "Status" : "Success",
- "Description" : "None"
- },
- "Response Data" : {
- "/c0/v0" : [
- {
- "DG/VD" : "0/0",
- "TYPE" : "RAID1",
- "State" : "Optl",
- "Access" : "RW",
- "Consist" : "No",
- "Cache" : "RWBD",
- "Cac" : "-",
- "sCC" : "ON",
- "Size" : "446.625 GB",
- "Name" : ""
- }
- ],
- "PDs for VD 0" : [
- {
- "EID:Slt" : "8:0",
- "DID" : 16,
- "State" : "Onln",
- "DG" : 0,
- "Size" : "446.625 GB",
- "Intf" : "SATA",
- "Med" : "SSD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "SAMSUNG MZ7LH480HAHQ-00005",
- "Sp" : "U",
- "Type" : "-"
- },
- {
- "EID:Slt" : "8:1",
- "DID" : 17,
- "State" : "Onln",
- "DG" : 0,
- "Size" : "446.625 GB",
- "Intf" : "SATA",
- "Med" : "SSD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "SAMSUNG MZ7LH480HAHQ-00005",
- "Sp" : "U",
- "Type" : "-"
- }
- ],
- "VD0 Properties" : {
- "Strip Size" : "256 KB",
- "Number of Blocks" : 936640512,
- "VD has Emulated PD" : "Yes",
- "Span Depth" : 1,
- "Number of Drives Per Span" : 2,
- "Write Cache(initial setting)" : "WriteBack",
- "Disk Cache Policy" : "Disk's Default",
- "Encryption" : "None",
- "Data Protection" : "Disabled",
- "Active Operations" : "None",
- "Exposed to OS" : "Yes",
- "OS Drive Name" : "/dev/sda",
- "Creation Date" : "08-06-2022",
- "Creation Time" : "02:46:23 PM",
- "Emulation type" : "default",
- "Cachebypass size" : "Cachebypass-64k",
- "Cachebypass Mode" : "Cachebypass Intelligent",
- "Is LD Ready for OS Requests" : "Yes",
- "SCSI NAA Id" : "600605b010e943702a3372bf4d29f6a7",
- "Unmap Enabled" : "N/A"
- },
- "/c0/v1" : [
- {
- "DG/VD" : "1/1",
- "TYPE" : "RAID1",
- "State" : "Optl",
- "Access" : "RW",
- "Consist" : "No",
- "Cache" : "RWBD",
- "Cac" : "-",
- "sCC" : "ON",
- "Size" : "558.406 GB",
- "Name" : ""
- }
- ],
- "PDs for VD 1" : [
- {
- "EID:Slt" : "8:2",
- "DID" : 15,
- "State" : "Onln",
- "DG" : 1,
- "Size" : "558.406 GB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST600MP0006 ",
- "Sp" : "U",
- "Type" : "-"
- },
- {
- "EID:Slt" : "8:3",
- "DID" : 12,
- "State" : "Onln",
- "DG" : 1,
- "Size" : "558.406 GB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST600MP0006 ",
- "Sp" : "U",
- "Type" : "-"
- }
- ],
- "VD1 Properties" : {
- "Strip Size" : "256 KB",
- "Number of Blocks" : 1171062784,
- "VD has Emulated PD" : "No",
- "Span Depth" : 1,
- "Number of Drives Per Span" : 2,
- "Write Cache(initial setting)" : "WriteBack",
- "Disk Cache Policy" : "Disk's Default",
- "Encryption" : "None",
- "Data Protection" : "Disabled",
- "Active Operations" : "None",
- "Exposed to OS" : "Yes",
- "OS Drive Name" : "/dev/sdb",
- "Creation Date" : "08-06-2022",
- "Creation Time" : "02:46:24 PM",
- "Emulation type" : "default",
- "Cachebypass size" : "Cachebypass-64k",
- "Cachebypass Mode" : "Cachebypass Intelligent",
- "Is LD Ready for OS Requests" : "Yes",
- "SCSI NAA Id" : "600605b010e943702a3372c04d2fb6b9",
- "Unmap Enabled" : "N/A"
- },
- "/c0/v2" : [
- {
- "DG/VD" : "2/2",
- "TYPE" : "RAID0",
- "State" : "Optl",
- "Access" : "RW",
- "Consist" : "Yes",
- "Cache" : "NRWTD",
- "Cac" : "-",
- "sCC" : "ON",
- "Size" : "1.090 TB",
- "Name" : ""
- }
- ],
- "PDs for VD 2" : [
- {
- "EID:Slt" : "8:4",
- "DID" : 14,
- "State" : "Onln",
- "DG" : 2,
- "Size" : "1.090 TB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST1200MM0129 ",
- "Sp" : "U",
- "Type" : "-"
- }
- ],
- "VD2 Properties" : {
- "Strip Size" : "256 KB",
- "Number of Blocks" : 2343174144,
- "VD has Emulated PD" : "Yes",
- "Span Depth" : 1,
- "Number of Drives Per Span" : 1,
- "Write Cache(initial setting)" : "WriteThrough",
- "Disk Cache Policy" : "Disk's Default",
- "Encryption" : "None",
- "Data Protection" : "Disabled",
- "Active Operations" : "None",
- "Exposed to OS" : "Yes",
- "OS Drive Name" : "/dev/sdc",
- "Creation Date" : "08-06-2022",
- "Creation Time" : "02:46:24 PM",
- "Emulation type" : "default",
- "Cachebypass size" : "Cachebypass-64k",
- "Cachebypass Mode" : "Cachebypass Intelligent",
- "Is LD Ready for OS Requests" : "Yes",
- "SCSI NAA Id" : "600605b010e943702a3372c04d3ad143",
- "Unmap Enabled" : "N/A"
- },
- "/c0/v3" : [
- {
- "DG/VD" : "3/3",
- "TYPE" : "RAID0",
- "State" : "Optl",
- "Access" : "RW",
- "Consist" : "Yes",
- "Cache" : "NRWTD",
- "Cac" : "-",
- "sCC" : "ON",
- "Size" : "1.090 TB",
- "Name" : ""
- }
- ],
- "PDs for VD 3" : [
- {
- "EID:Slt" : "8:5",
- "DID" : 10,
- "State" : "Onln",
- "DG" : 3,
- "Size" : "1.090 TB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST1200MM0129 ",
- "Sp" : "U",
- "Type" : "-"
- }
- ],
- "VD3 Properties" : {
- "Strip Size" : "256 KB",
- "Number of Blocks" : 2343174144,
- "VD has Emulated PD" : "Yes",
- "Span Depth" : 1,
- "Number of Drives Per Span" : 1,
- "Write Cache(initial setting)" : "WriteThrough",
- "Disk Cache Policy" : "Disk's Default",
- "Encryption" : "None",
- "Data Protection" : "Disabled",
- "Active Operations" : "None",
- "Exposed to OS" : "Yes",
- "OS Drive Name" : "/dev/sdd",
- "Creation Date" : "08-06-2022",
- "Creation Time" : "02:46:25 PM",
- "Emulation type" : "default",
- "Cachebypass size" : "Cachebypass-64k",
- "Cachebypass Mode" : "Cachebypass Intelligent",
- "Is LD Ready for OS Requests" : "Yes",
- "SCSI NAA Id" : "600605b010e943702a3372c14d48b67e",
- "Unmap Enabled" : "N/A"
- },
- "/c0/v4" : [
- {
- "DG/VD" : "4/4",
- "TYPE" : "RAID0",
- "State" : "Optl",
- "Access" : "RW",
- "Consist" : "Yes",
- "Cache" : "NRWTD",
- "Cac" : "-",
- "sCC" : "ON",
- "Size" : "1.090 TB",
- "Name" : ""
- }
- ],
- "PDs for VD 4" : [
- {
- "EID:Slt" : "8:6",
- "DID" : 9,
- "State" : "Onln",
- "DG" : 4,
- "Size" : "1.090 TB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST1200MM0129 ",
- "Sp" : "U",
- "Type" : "-"
- }
- ],
- "VD4 Properties" : {
- "Strip Size" : "256 KB",
- "Number of Blocks" : 2343174144,
- "VD has Emulated PD" : "Yes",
- "Span Depth" : 1,
- "Number of Drives Per Span" : 1,
- "Write Cache(initial setting)" : "WriteThrough",
- "Disk Cache Policy" : "Disk's Default",
- "Encryption" : "None",
- "Data Protection" : "Disabled",
- "Active Operations" : "None",
- "Exposed to OS" : "Yes",
- "OS Drive Name" : "/dev/sde",
- "Creation Date" : "08-06-2022",
- "Creation Time" : "02:46:26 PM",
- "Emulation type" : "default",
- "Cachebypass size" : "Cachebypass-64k",
- "Cachebypass Mode" : "Cachebypass Intelligent",
- "Is LD Ready for OS Requests" : "Yes",
- "SCSI NAA Id" : "600605b010e943702a3372c24d57b796",
- "Unmap Enabled" : "N/A"
- },
- "/c0/v5" : [
- {
- "DG/VD" : "5/5",
- "TYPE" : "RAID0",
- "State" : "Optl",
- "Access" : "RW",
- "Consist" : "Yes",
- "Cache" : "NRWTD",
- "Cac" : "-",
- "sCC" : "ON",
- "Size" : "1.090 TB",
- "Name" : ""
- }
- ],
- "PDs for VD 5" : [
- {
- "EID:Slt" : "8:7",
- "DID" : 11,
- "State" : "Onln",
- "DG" : 5,
- "Size" : "1.090 TB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST1200MM0129 ",
- "Sp" : "U",
- "Type" : "-"
- }
- ],
- "VD5 Properties" : {
- "Strip Size" : "256 KB",
- "Number of Blocks" : 2343174144,
- "VD has Emulated PD" : "Yes",
- "Span Depth" : 1,
- "Number of Drives Per Span" : 1,
- "Write Cache(initial setting)" : "WriteThrough",
- "Disk Cache Policy" : "Disk's Default",
- "Encryption" : "None",
- "Data Protection" : "Disabled",
- "Active Operations" : "None",
- "Exposed to OS" : "Yes",
- "OS Drive Name" : "/dev/sdf",
- "Creation Date" : "08-06-2022",
- "Creation Time" : "02:46:27 PM",
- "Emulation type" : "default",
- "Cachebypass size" : "Cachebypass-64k",
- "Cachebypass Mode" : "Cachebypass Intelligent",
- "Is LD Ready for OS Requests" : "Yes",
- "SCSI NAA Id" : "600605b010e943702a3372c34d665ecf",
- "Unmap Enabled" : "N/A"
- },
- "/c0/v6" : [
- {
- "DG/VD" : "6/6",
- "TYPE" : "RAID0",
- "State" : "Optl",
- "Access" : "RW",
- "Consist" : "Yes",
- "Cache" : "NRWTD",
- "Cac" : "-",
- "sCC" : "ON",
- "Size" : "1.090 TB",
- "Name" : ""
- }
- ],
- "PDs for VD 6" : [
- {
- "EID:Slt" : "8:8",
- "DID" : 13,
- "State" : "Onln",
- "DG" : 6,
- "Size" : "1.090 TB",
- "Intf" : "SAS",
- "Med" : "HDD",
- "SED" : "N",
- "PI" : "N",
- "SeSz" : "512B",
- "Model" : "ST1200MM0129 ",
- "Sp" : "U",
- "Type" : "-"
- }
- ],
- "VD6 Properties" : {
- "Strip Size" : "256 KB",
- "Number of Blocks" : 2343174144,
- "VD has Emulated PD" : "Yes",
- "Span Depth" : 1,
- "Number of Drives Per Span" : 1,
- "Write Cache(initial setting)" : "WriteThrough",
- "Disk Cache Policy" : "Disk's Default",
- "Encryption" : "None",
- "Data Protection" : "Disabled",
- "Active Operations" : "None",
- "Exposed to OS" : "Yes",
- "OS Drive Name" : "/dev/sdg",
- "Creation Date" : "08-06-2022",
- "Creation Time" : "02:46:28 PM",
- "Emulation type" : "default",
- "Cachebypass size" : "Cachebypass-64k",
- "Cachebypass Mode" : "Cachebypass Intelligent",
- "Is LD Ready for OS Requests" : "Yes",
- "SCSI NAA Id" : "600605b010e943702a3372c44d751bab",
- "Unmap Enabled" : "N/A"
- }
- }
- }
- ]
- }`
- parser, err := parseStorcliLVs(input)
- if err != nil {
- t.Fatalf("parseStorcliLVs: %v", err)
- }
- lvs, err := parser.GetLogicalVolumes(0)
- if err != nil {
- t.Fatalf("GetLogicalVolumes: %v", err)
- }
- assert := assert.New(t)
- assert.Equal(7, len(lvs), "Should 7 logical volumes")
- for i := range lvs {
- switch lvs[i].Index {
- case 0:
- first2SDDs := lvs[i].PDs
- assert.Equal("SSD", first2SDDs[0].Med)
- assert.Equal("446.625 GB", first2SDDs[0].Size)
- assert.Equal("SSD", first2SDDs[1].Med)
- assert.Equal("446.625 GB", first2SDDs[1].Size)
- assert.Equal(true, lvs[i].IsSSD())
- assert.Equal("/dev/sda", lvs[i].Properties.DeviceName)
- case 6:
- assert.Equal("/dev/sdg", lvs[i].Properties.DeviceName)
- }
- }
- }
|