adaptec_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package adaptec
  15. import (
  16. "strings"
  17. "testing"
  18. "github.com/stretchr/testify/assert"
  19. )
  20. func Test_getAdaptorIndex(t *testing.T) {
  21. tests := []struct {
  22. name string
  23. args string
  24. want int
  25. }{
  26. {
  27. name: "Controllers found: 1",
  28. args: "Controllers found: 1",
  29. want: -1,
  30. },
  31. {
  32. name: " Controller 1: : Optimal, Slot 4, RAID (Expose RAW), Adaptec ASR8805, 6A2263667CA, 50000D1701B47780",
  33. args: " Controller 1: : Optimal, Slot 4, RAID (Expose RAW), Adaptec ASR8805, 6A2263667CA, 50000D1701B47780",
  34. want: 1,
  35. },
  36. }
  37. for _, tt := range tests {
  38. t.Run(tt.name, func(t *testing.T) {
  39. if got := getAdaptorIndex(tt.args); got != tt.want {
  40. t.Errorf("getAdaptorIndex() = %v, want %v", got, tt.want)
  41. }
  42. })
  43. }
  44. }
  45. func Test_getAdaptorInfo(t *testing.T) {
  46. input := `Controllers found: 1
  47. ----------------------------------------------------------------------
  48. Controller information
  49. ----------------------------------------------------------------------
  50. Controller Status : Optimal
  51. Controller Mode : RAID (Expose RAW)
  52. Channel description : SAS/SATA
  53. Controller Model : Adaptec ASR8805
  54. Controller Serial Number : 6A2263667CA
  55. Controller World Wide Name : 50000D1701B47780
  56. Controller Alarm : Disabled
  57. Physical Slot : 4
  58. Temperature : 42 C/ 107 F (Normal)
  59. Installed memory : 1024 MB
  60. Host bus type : PCIe
  61. Host bus speed : 8000 MHz
  62. Host bus link width : 8 bit(s)/link(s)
  63. Global task priority : High
  64. Performance Mode : Default/Dynamic
  65. PCI Device ID : 653
  66. Stayawake period : Disabled
  67. Spinup limit internal drives : 0
  68. Spinup limit external drives : 0
  69. Defunct disk drive count : 0
  70. NCQ status : Enabled
  71. Statistics data collection mode : Disabled
  72. Monitor Log Severity Level : Informational
  73. Global Max SAS Phy Link Rate : 12 Gbps
  74. Verify Write Setting : Not Applicable
  75. Save Custom Defaults Setting : Disabled
  76. Smart Poll : Enabled
  77. Error Tunable Profile : Normal
  78. --------------------------------------------------------
  79. Cache Properties
  80. --------------------------------------------------------
  81. Controller Cache Preservation : Disabled
  82. Global Physical Device Write Cache Policy: Drive Specific
  83. --------------------------------------------------------
  84. RAID Properties
  85. --------------------------------------------------------
  86. Logical devices/Failed/Degraded : 0/0/0
  87. Copyback : Disabled
  88. Automatic Failover : Enabled
  89. Background consistency check : Disabled
  90. Background consistency check period : 0
  91. --------------------------------------------------------
  92. Controller BIOS Setting Information
  93. --------------------------------------------------------
  94. Runtime BIOS : Enabled
  95. Array BBS Support : Disabled
  96. Physical Drives Displayed during POST : Disabled
  97. Backplane Mode : IBPI
  98. BIOS Halt on Missing Drive Count : 255
  99. --------------------------------------------------------
  100. Controller Version Information
  101. --------------------------------------------------------
  102. BIOS : 7.18-0 (33556)
  103. Firmware : 7.18-0 (33556)
  104. Driver : 1.2-1 (50983)
  105. Boot Flash : 7.18-0 (33556)
  106. CPLD (Load version/ Flash version) : 8/ 11
  107. SEEPROM (Load version/ Flash version) : 1/ 1
  108. FCT Custom Init String Version : 0x0
  109. --------------------------------------------------------
  110. Controller Cache Backup Unit Information
  111. --------------------------------------------------------
  112. Overall Backup Unit Status : Not Present
  113. --------------------------------------------------------
  114. Connector information
  115. --------------------------------------------------------
  116. Connector #0
  117. Connector Name : CN0
  118. --------------------------------------
  119. Lane Information
  120. --------------------------------------
  121. Lane #0
  122. Channel ID : 0
  123. Device ID : 0
  124. SAS Address : 50000D1701B47780
  125. PHY Identifier : 3
  126. -----------------------------------
  127. Lane SAS Phy Information
  128. -----------------------------------
  129. SAS Address : 50000D1701B47780
  130. Lane #1
  131. Channel ID : 0
  132. Device ID : 1
  133. SAS Address : 50000D1701B47780
  134. PHY Identifier : 2
  135. -----------------------------------
  136. Lane SAS Phy Information
  137. -----------------------------------
  138. SAS Address : 50000D1701B47780
  139. Lane #2
  140. Channel ID : 0
  141. Device ID : 2
  142. SAS Address : 50000D1701B47780
  143. PHY Identifier : 0
  144. -----------------------------------
  145. Lane SAS Phy Information
  146. -----------------------------------
  147. SAS Address : 50000D1701B47780
  148. Lane #3
  149. Channel ID : 0
  150. Device ID : 3
  151. SAS Address : 50000D1701B47780
  152. PHY Identifier : 1
  153. -----------------------------------
  154. Lane SAS Phy Information
  155. -----------------------------------
  156. SAS Address : 50000D1701B47780
  157. Connector #1
  158. Connector Name : CN1
  159. --------------------------------------
  160. Lane Information
  161. --------------------------------------
  162. Lane #0
  163. Channel ID : 0
  164. Device ID : 4
  165. SAS Address : 50000D1701B47780
  166. PHY Identifier : 5
  167. -----------------------------------
  168. Lane SAS Phy Information
  169. -----------------------------------
  170. SAS Address : 50000D1701B47780
  171. Lane #1
  172. Channel ID : 0
  173. Device ID : 5
  174. SAS Address : 50000D1701B47780
  175. PHY Identifier : 6
  176. -----------------------------------
  177. Lane SAS Phy Information
  178. -----------------------------------
  179. SAS Address : 50000D1701B47780
  180. Lane #2
  181. Channel ID : 0
  182. Device ID : 6
  183. SAS Address : 50000D1701B47780
  184. PHY Identifier : 4
  185. -----------------------------------
  186. Lane SAS Phy Information
  187. -----------------------------------
  188. SAS Address : 50000D1701B47780
  189. Attached PHY Identifier : 0
  190. Attached SAS Address : 5000C50077893141
  191. Negotiated Logical Link Rate : PHY enabled - 6 Gbps
  192. Lane #3
  193. Channel ID : 0
  194. Device ID : 7
  195. SAS Address : 50000D1701B47780
  196. PHY Identifier : 7
  197. -----------------------------------
  198. Lane SAS Phy Information
  199. -----------------------------------
  200. SAS Address : 50000D1701B47780
  201. Attached PHY Identifier : 0
  202. Attached SAS Address : 50000395B839D9AE
  203. Negotiated Logical Link Rate : PHY enabled - 6 Gbps
  204. Command completed successfully.`
  205. lines := strings.Split(input, "\n")
  206. info, err := getAdaptorInfo(lines)
  207. if err != nil {
  208. t.Errorf("getAdaptorInfo: %v", err)
  209. }
  210. assert := assert.New(t)
  211. assert.Equal("Optimal", info.status)
  212. assert.Equal("RAID (Expose RAW)", info.mode)
  213. assert.Equal(true, info.isRaidExposeRawMode(), "should be raid expose raw mode")
  214. assert.Equal("Adaptec ASR8805", info.name)
  215. assert.Equal("6A2263667CA", info.sn)
  216. assert.Equal("50000D1701B47780", info.wwn)
  217. assert.Equal("4", info.slot)
  218. }
  219. func Test_getPhyDevices(t *testing.T) {
  220. input := `Controllers found: 1
  221. ----------------------------------------------------------------------
  222. Physical Device information
  223. ----------------------------------------------------------------------
  224. Device #0
  225. Device is a Hard drive
  226. State : Online
  227. Block Size : 512 Bytes
  228. Supported : Yes
  229. Programmed Max Speed : SAS 6.0 Gb/s
  230. Transfer Speed : SAS 6.0 Gb/s
  231. Reported Channel,Device(T:L) : 0,6(6:0)
  232. Reported Location : Connector 1, Device 2
  233. Vendor : SEAGATE
  234. Model : ST300MM0006
  235. Firmware : LS0A
  236. Serial number : S0K30A4N
  237. World-wide name : 5000C50077893140
  238. Reserved Size : 415982 KB
  239. Used Size : 285696 MB
  240. Unused Size : 64 KB
  241. Total Size : 286102 MB
  242. Write Cache : Disabled (write-through)
  243. FRU : None
  244. S.M.A.R.T. : No
  245. S.M.A.R.T. warnings : 0
  246. Power State : Full rpm
  247. Supported Power States : Full rpm,Powered off
  248. SSD : No
  249. Temperature : 34 C/ 93 F
  250. ----------------------------------------------------------------
  251. Device Phy Information
  252. ----------------------------------------------------------------
  253. Phy #0
  254. PHY Identifier : 0
  255. SAS Address : 5000C50077893141
  256. Attached PHY Identifier : 4
  257. Attached SAS Address : 50000D1701B47780
  258. Phy #1
  259. PHY Identifier : 1
  260. SAS Address : 5000C50077893142
  261. ----------------------------------------------------------------
  262. Runtime Error Counters
  263. ----------------------------------------------------------------
  264. Hardware Error Count : 0
  265. Medium Error Count : 0
  266. Parity Error Count : 0
  267. Link Failure Count : 0
  268. Aborted Command Count : 0
  269. SMART Warning Count : 0
  270. Device #1
  271. Device is a Hard drive
  272. State : Online
  273. Block Size : 512 Bytes
  274. Supported : Yes
  275. Programmed Max Speed : SAS 6.0 Gb/s
  276. Transfer Speed : SAS 6.0 Gb/s
  277. Reported Channel,Device(T:L) : 0,7(7:0)
  278. Reported Location : Connector 1, Device 3
  279. Vendor : TOSHIBA
  280. Model : AL13SEB300
  281. Firmware : DE0D
  282. Serial number : 84T0A31SFRD6
  283. World-wide name : 50000395B839D9AC
  284. Reserved Size : 415982 KB
  285. Used Size : 285696 MB
  286. Unused Size : 64 KB
  287. Total Size : 286102 MB
  288. Write Cache : Disabled (write-through)
  289. FRU : None
  290. S.M.A.R.T. : No
  291. S.M.A.R.T. warnings : 0
  292. Power State : Full rpm
  293. Supported Power States : Full rpm,Powered off
  294. SSD : No
  295. Temperature : 33 C/ 91 F
  296. ----------------------------------------------------------------
  297. Device Phy Information
  298. ----------------------------------------------------------------
  299. Phy #0
  300. PHY Identifier : 0
  301. SAS Address : 50000395B839D9AE
  302. Attached PHY Identifier : 7
  303. Attached SAS Address : 50000D1701B47780
  304. Phy #1
  305. PHY Identifier : 1
  306. SAS Address : 50000395B839D9AF
  307. ----------------------------------------------------------------
  308. Runtime Error Counters
  309. ----------------------------------------------------------------
  310. Hardware Error Count : 0
  311. Medium Error Count : 0
  312. Parity Error Count : 0
  313. Link Failure Count : 0
  314. Aborted Command Count : 0
  315. SMART Warning Count : 0
  316. Command completed successfully.`
  317. lines := strings.Split(input, "\n")
  318. devs := getPhyDevices(1, lines)
  319. assert := assert.New(t)
  320. assert.Equal(2, len(devs), "physical devices should be 2")
  321. dev1 := devs[0]
  322. assert.Equal("0", dev1.channelId)
  323. assert.Equal("6", dev1.deviceId)
  324. assert.Equal("Online", dev1.Status)
  325. assert.Equal("ST300MM0006", dev1.Model)
  326. assert.Equal(true, dev1.Rotate.Bool())
  327. dev2 := devs[1]
  328. assert.Equal("0", dev2.channelId)
  329. assert.Equal("7", dev2.deviceId)
  330. assert.Equal("Online", dev2.Status)
  331. assert.Equal("AL13SEB300", dev2.Model)
  332. assert.Equal(true, dev2.Rotate.Bool())
  333. }
  334. func Test_getLogicalVolums(t *testing.T) {
  335. input := `Controllers found: 1
  336. ----------------------------------------------------------------------
  337. Logical device information
  338. ----------------------------------------------------------------------
  339. Logical Device number 0
  340. Logical Device name : LogicalDrv 0
  341. Block Size of member drives : 512 Bytes
  342. RAID level : 1
  343. Unique Identifier : 7D30DCD4
  344. Status of Logical Device : Optimal
  345. Additional details : Quick initialized
  346. Size : 285686 MB
  347. Parity space : 285696 MB
  348. Interface Type : Serial Attached SCSI
  349. Device Type : HDD
  350. Read-cache setting : Enabled
  351. Read-cache status : On
  352. Write-cache setting : Enabled
  353. Write-cache status : On
  354. Partitioned : No
  355. Protected by Hot-Spare : No
  356. Bootable : Yes
  357. Failed stripes : No
  358. Power settings : Disabled
  359. --------------------------------------------------------
  360. Logical Device segment information
  361. --------------------------------------------------------
  362. Segment 0 : Present (286102MB, SAS, HDD, Connector:1, Device:2) S0K30A4N
  363. Segment 1 : Present (286102MB, SAS, HDD, Connector:1, Device:3) 84T0A31SFRD6
  364. Command completed successfully.`
  365. lines := strings.Split(input, "\n")
  366. lvs, err := getLogicalVolumes(1, lines)
  367. if err != nil {
  368. t.Errorf("getLogicalVolumes: %v", err)
  369. }
  370. assert := assert.New(t)
  371. assert.Equal(1, len(lvs), "logical volume len should be 1")
  372. lv := lvs[0]
  373. assert.Equal(1, lv.Adapter)
  374. assert.Equal(0, lv.Index)
  375. inputNoLV := `Controllers found: 1
  376. ----------------------------------------------------------------------
  377. Logical device information
  378. ----------------------------------------------------------------------
  379. No logical devices configured
  380. Command completed successfully.`
  381. lines = strings.Split(inputNoLV, "\n")
  382. lvs, err = getLogicalVolumes(1, lines)
  383. if err != nil {
  384. t.Errorf("getLogicalVolumes: %v", err)
  385. }
  386. assert.Equal(0, len(lvs), "logical volume len should be 0")
  387. }