@tony-yin
2018-03-09T14:31:26.000000Z
字数 3432
阅读 619
Test
最近在做一个feature
,测试的时候需要硬件环境的支撑。一般我们开发环境都是虚拟机,所以针对这种开发工作的自测无法进行,比如虚拟机上没有物理磁盘,没有raid
卡等,为了一个小功能的测试,需要出build
,需要硬件环境的部署和安装,这个工作量着实不小。
往往针对这种情况,作为开发人员可以针对硬件环境的具体需求,尽可能在自己的环境上做模拟,也就是我们俗称的“打桩”。
就拿我这次做的需求来说吧,我想获取磁盘的相关信息,获取方式是通过raid
卡工具,可能是megacli
,也可能是sas3ircu
等等,这个取决于lspci
查看raid
卡的型号,然后还要通过lsblk
和lsscsi
工具获取相关信息。
我的做法是针对这些工具,自己写一个简易的小工具,就比如lsblk
我也写一个lsblk
的脚本,里面的代码也很简单,先找一个硬件环境,将lsblk
读取的内容重定向到文件中,这时候我们自己写的脚本直接去读这个文件就可以了。务必要保证各个软件工具的一致性。
以lsblk
为例,我可能需求两种情况lsblk
和lsblk -l
:
lsblk
:
#! /bin/bash
lsblk_path=$(dirname $0)
if [ $# -eq 0 ]; then
echo "$(cat $lsblk_path"/lsblk.txt")"
fi
while getopts ":l" opt; do
case $opt in
l)
echo "$(cat $lsblk_path"/lsblk_list.txt")"
;;
\?)
echo "Invalid option: -$OPTARG"
;;
esac
done
lsblk.txt
:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 3.7T 0 disk
├─sda1 8:1 0 30.5M 0 part ar
├─sda2 8:2 0 488.3M 0 part ar
├─sda3 8:3 0 93.1G 0 part /rt
├─sda4 8:4 0 256G 0 part [SWAP]WA
└─sda5 8:5 0 3.3T 0 part /data/osd.0sd
sdb 8:16 0 372.1G 0 disk
└─sdb1 8:17 0 372.1G 0 part ar
sdc 8:32 0 2.7T 0 disk
└─sdc1 8:33 0 2.7T 0 part /data/osd.1sd
sdd 8:48 0 2.7T 0 disk
└─sdd1 8:49 0 2.7T 0 part /data/osd.2sd
sde 8:64 0 2.7T 0 disk
└─sde1 8:65 0 2.7T 0 part /data/osd.3sd
sdf 8:80 0 2.7T 0 disk
└─sdf1 8:81 0 2.7T 0 part /data/osd.11d.
sdg 8:96 0 2.7T 0 disk
└─sdg1 8:97 0 2.7T 0 part /data/osd.12d.
sdh 8:112 0 2.7T 0 disk
└─sdh1 8:113 0 2.7T 0 part ar
sdi 8:128 0 2.7T 0 disk
└─sdi1 8:129 0 2.7T 0 part /data/osd.8sd
sdj 8:144 0 2.7T 0 disk
└─sdj1 8:145 0 2.7T 0 part /data/osd.9sd
sdk 8:160 0 2.7T 0 disk
└─sdk1 8:161 0 2.7T 0 part /data/osd.10d.
sdl 8:176 0 2.7T 0 disk
└─sdl1 8:177 0 2.7T 0 part ar
sdm 8:192 0 2.7T 0 disk
└─sdm1 8:193 0 2.7T 0 part ar
sdn 8:208 0 2.7T 0 disk
└─sdn1 8:209 0 2.7T 0 part ar
sdo 8:224 0 2.7T 0 disk
└─sdo1 8:225 0 2.7T 0 part
sdp 8:240 0 2.7T 0 disk
└─sdp1 8:241 0 2.7T 0 part
sdq 65:0 0 2.7T 0 disk
└─sdq1 65:1 0 2.7T 0 part
sdr 65:16 0 2.7T 0 disk
└─sdr1 65:17 0 2.7T 0 part
sds 65:32 0 2.7T 0 disk
└─sds1 65:33 0 2.7T 0 part
sdt 65:48 0 2.7T 0 disk
└─sdt1 65:49 0 2.7T 0 part
sdu 65:64 0 2.7T 0 disk
└─sdu1 65:65 0 2.7T 0 part
sdv 65:80 0 744.7G 0 disk
├─sdv1 65:81 0 50G 0 part
├─sdv2 65:82 0 50G 0 part
├─sdv3 65:83 0 50G 0 part
├─sdv4 65:84 0 50G 0 part
├─sdv5 65:85 0 50G 0 part
├─sdv6 65:86 0 50G 0 part
├─sdv7 65:87 0 50G 0 part
├─sdv8 65:88 0 50G 0 part
├─sdv9 65:89 0 50G 0 part
├─sdv10 65:90 0 50G 0 part
├─sdv11 65:91 0 50G 0 part
└─sdv12 65:92 0 50G 0 part
lsblk_list.txt
:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 3.7T 0 disk
sda1 8:1 0 30.5M 0 part
sda2 8:2 0 488.3M 0 part
sda3 8:3 0 93.1G 0 part /
sda4 8:4 0 256G 0 part [SWAP]
sda5 8:5 0 3.3T 0 part /data/osd.0
sdb 8:16 0 372.1G 0 disk
sdb1 8:17 0 372.1G 0 part
sdc 8:32 0 2.7T 0 disk
sdc1 8:33 0 2.7T 0 part /data/osd.1
sdd 8:48 0 2.7T 0 disk
sdd1 8:49 0 2.7T 0 part /data/osd.2
sde 8:64 0 2.7T 0 disk
sde1 8:65 0 2.7T 0 part /data/osd.3
sdf 8:80 0 2.7T 0 disk
sdf1 8:81 0 2.7T 0 part /data/osd.11
sdg 8:96 0 2.7T 0 disk
sdg1 8:97 0 2.7T 0 part /data/osd.12
sdh 8:112 0 2.7T 0 disk
sdh1 8:113 0 2.7T 0 part
sdi 8:128 0 2.7T 0 disk
sdi1 8:129 0 2.7T 0 part /data/osd.8
sdj 8:144 0 2.7T 0 disk
sdj1 8:145 0 2.7T 0 part /data/osd.9
sdk 8:160 0 2.7T 0 disk
sdk1 8:161 0 2.7T 0 part /data/osd.10
sdl 8:176 0 2.7T 0 disk
sdl1 8:177 0 2.7T 0 part
sdm 8:192 0 2.7T 0 disk
sdm1 8:193 0 2.7T 0 part
sdn 8:208 0 2.7T 0 disk
sdn1 8:209 0 2.7T 0 part
sdo 8:224 0 2.7T 0 disk
sdo1 8:225 0 2.7T 0 part
sdp 8:240 0 2.7T 0 disk
sdp1 8:241 0 2.7T 0 part
sdq 65:0 0 2.7T 0 disk
sdq1 65:1 0 2.7T 0 part
sdr 65:16 0 2.7T 0 disk
sdr1 65:17 0 2.7T 0 part
sds 65:32 0 2.7T 0 disk
sds1 65:33 0 2.7T 0 part
sdt 65:48 0 2.7T 0 disk
sdt1 65:49 0 2.7T 0 part
sdu 65:64 0 2.7T 0 disk
sdu1 65:65 0 2.7T 0 part
sdv 65:80 0 744.7G 0 disk
sdv1 65:81 0 50G 0 part
sdv2 65:82 0 50G 0 part
sdv3 65:83 0 50G 0 part
sdv4 65:84 0 50G 0 part
sdv5 65:85 0 50G 0 part
sdv6 65:86 0 50G 0 part
sdv7 65:87 0 50G 0 part
sdv8 65:88 0 50G 0 part
sdv9 65:89 0 50G 0 part
sdv10 65:90 0 50G 0 part
sdv11 65:91 0 50G 0 part
sdv12 65:92 0 50G 0 part
还有一些其他工具我就不详细贴代码了,具体请去github
上查看。
项目地址:https://github.com/tony-yin/Hardware_Test_Tool
操作步骤:
1.下载代码
git clone git@github.com:tony-yin/Hardware_Test_Tool.git
2.安装工具
./build install
3.卸载工具
./build uninstall