2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-07-11 07:11:30 +00:00

modify rspconfig testcase for get more debug information

This commit is contained in:
junxiawang
2017-09-11 09:48:17 -04:00
parent e9a8d0121c
commit 5255b79a13

View File

@ -1,4 +1,39 @@
#!/bin/bash
function usage()
{
local script="${0##*/}"
while read -r ; do echo "${REPLY}" ; done <<-EOF
Usage: ${script} [OPTION]... [ACTION]
Test rspconfig automatically
Options:
Mandatory arguments to long options are mandatory for short options too.
-h, --help display this help and exit
-i|--ip To test rspconfig could change bmc's ip
-lip|--list ip To test rspconfig could get bmc's ip
-g|--gateway To test rspconfig could change bmc's gateway
-lg|--list gateway To test rspconfig could list bmc's gateway
-n|--netmask To test rspconfig could change bmc's netmask
-ln|--list netmask To test rspconfig could list bmc's netmask
-v|--vlan To test rspconfig could change bmc's vlan
-lv|--list vlan To test rspconfig could list bmc's vlan
-a|--all To test rspconfig could change bmc's ip,gateway,netmask,vlan
-la|--list all To test rspconfig could list bmc's ip,gateway,netmask,vlan
-c|--clear To clear test environment
Examples:
${script} -i noderange nodeip=node's ip
${script} -n noderange netmask
${script} -g noderange gateway
${script} -v noderange vlan
${script} -lip noderange
${script} -ln noderange
${script} -lg noderange
${script} -lv noderange
${script} -a noderange
${script} -la noderange
EOF
}
function test_ip()
{
IP=$1
@ -20,27 +55,26 @@ function net()
FIRSTIP=`echo "$1 $2"|awk -F '[ .]+' 'BEGIN{OFS="."} END{print and($1,$5),and($2,$6),and($3,$7),and($4,$8)}'`
echo lastip is $LASTIP
echo first ip is $FIRSTIP
}
function change_ip()
{
echo "Prepare to change ip."
echo "Start to check ip valid."
NODEIP=$4;
echo "Prepare to change ip."
echo "Start to check ip valid."
NODEIP=$4;
test_ip $1;
if [[ $? -ne 0 ]];then echo "ip is invalid";return 1;fi
echo "ip is valid.";
echo "ip is valid.";
echo $1 > /tmp/BMCIP
net $1 $3
net $1 $3
ip1=`echo $1|awk -F. '{print $1}'`
ip2=`echo $1|awk -F. '{print $2}'`
ip3=`echo $1|awk -F. '{print $3}'`
ip4=`echo $1|awk -F. '{print $4}'`
ip4=`echo $1|awk -F. '{print $4}'`
ipfirst=`echo $FIRSTIP|awk -F. '{print $4}'`
ip=`expr "$ipfirst" "+" "1"`
ip=`expr "$ipfirst" "+" "1"`
iplast=`echo $LASTIP|awk -F. '{print $4}'`
ip5=`expr "$iplast" "-" "1"`
echo ip is $ip ,ip5 is $ip5
ip5=`expr "$iplast" "-" "1"`
echo ip is $ip ,ip5 is $ip5
while true;
do [[ $ip == "$ip5" ]] && echo "exit for using last ip."&&return 1;
ping $ip1.$ip2.$ip3.$ip -c 2 >/dev/null ;
@ -48,23 +82,23 @@ function change_ip()
coutip="$ip1.$ip2.$ip3.$ip"
BMCNEWIP=$coutip;
echo $1,$2,$3
echo "Start to set ip for node."
echo "Start to set ip for node."
rspconfig $2 ip=$BMCNEWIP
if [[ $? -eq 0 ]];then
echo "Could set bmc's ip for node using rspconfig.";
else
echo "Could not set bmc's ip for node using rspconfig.";
echo "Could not set bmc's ip for node using rspconfig.";
return 1;
fi
chdef $2 bmc=$BMCNEWIP
echo "Start to check bmc's ip setted successfully or not."
echo "Start to check bmc's ip setting."
check_result $2 ip $BMCNEWIP
if [[ $? -ne 0 ]] ;then
echo "Set bmc's ip failed.";
echo "Set bmc's ip failed.";
return 1;
else
echo "Set bmc's ip successfully.";
return 0;
return 0;
fi
fi
ip=`expr "$ip" "+" "1"`
@ -114,8 +148,8 @@ function clear_env()
}
function change_nonip
{
echo "Prepare to change $4.";
echo "Start to check $4 valid or not.";
echo "Prepare to change $4.";
echo "Start to check $4 valid or not.";
if [[ $4 =~ "gateway" ]]||[[ $4 =~ "netmask" ]];then
test_ip $1;
if [[ $? -ne 0 ]];then
@ -126,45 +160,45 @@ echo "Start to check $4 valid or not.";
echo "Start to change bmc's $4.";
rspconfig $2 $4=$1;
if [[ $? -eq 0 ]];then
echo "Could set bmc's $4.";
else
echo "Could not set bmc's $4.";
return 1;
fi
echo "Start to check $4 setting successfully or not.";
check_result $2 $3 $1
if [[ $? -ne 0 ]] ;then
echo "Set bmc's $4 failed.";
return 1;
else
echo "Set bmc's $4 successfully.";
return 0;
fi
echo "Could set bmc's $4.";
else
echo "Could not set bmc's $4.";
return 1;
fi
echo "Start to check $4 setting.";
check_result $2 $3 $1
if [[ $? -ne 0 ]] ;then
echo "Set bmc's $4 failed.";
return 1;
else
echo "Set bmc's $4 successfully.";
return 0;
fi
}
function change_all
{
echo "Prepare to change all for bmc."
echo "Start to change all for bmc."
echo "Prepare to change all for bmc."
echo "Start to change all for bmc."
rspconfig $2 gateway netmask vlan ip
if [[ $? -eq 0 ]];then
BMCIP=`rspconfig $2 ip |awk -F":" '{print $3}'`;
BMCNETMASK=`rspconfig $2 netmask |awk -F":" '{print $3}'`;
BMCGGATEWAY=`rspconfig $2 gateway |awk -F":" '{print $3}'`;
output=`rspconfig $2 vlan`
if [[ $output =~ "BMC VLAN ID enabled" ]];then
BMCVLAN=`rspconfig $2 vlan |awk -F":" '{print $3}'`
else
echo "------------------Bmc vlan disabled so could not change vlan id using rspconfig.--------------------"
return 1;
fi
output=`rspconfig $2 vlan`
if [[ $output =~ "BMC VLAN ID enabled" ]];then
BMCVLAN=`rspconfig $2 vlan |awk -F":" '{print $3}'`
else
echo "------------------Bmc vlan disabled so could not change vlan id using rspconfig.--------------------"
return 1;
fi
rspconfig $2 ip=$BMCIP netmask=$BMCNETMASK gateway=$BMCGGATEWAY vlan=$BMCVLAN
if [[ $? -eq 0 ]];then
echo "Could set bmc's all options.";
else
echo "Could not set bmc's all options.";
return 1;
fi
echo "Could set BMC IP/netmask/gateway/vlan.";
else
echo "Could not set BMC IP/netmask/gateway/vlan.";
return 1;
fi
fi
}
@ -198,11 +232,11 @@ do
fi
;;
"-lip"|"--list ip" )
echo "--------------------To test bmc ip could be listed using rspconfig.--------------------"
BMCIP_LSDEF=`lsdef $2 |grep "bmc=" |awk -F "=" '{print $2}'`
rspconfig $2 ip
if [[ $? -eq 0 ]];then
BMCIP=`rspconfig $2 ip |awk -F":" '{print $3}'`
echo "--------------------To test bmc ip could be listed using rspconfig.--------------------"
BMCIP_LSDEF=`lsdef $2 |grep "bmc=" |awk -F "=" '{print $2}'`
rspconfig $2 ip
if [[ $? -eq 0 ]];then
BMCIP=`rspconfig $2 ip |awk -F":" '{print $3}'`
if [[ $BMCIP =~ "$BMCIP_LSDEF" ]];then
echo "-----------------To test bmc ip could be listed using rspconfig successfully.-----------------"
exit 0;
@ -210,11 +244,11 @@ do
echo "-------------------To test bmc ip could be listed using rspconfig failed.----------------"
exit 1;
fi
else
else
echo "------------------To test bmc ip could be listed using rspconfig failed.-------------------"
exit 1;
fi
;;
exit 1;
fi
;;
"-g"|"--gateway" )
echo "--------------------To test bmc gateway could be changed using rspconfig.---------------------"
@ -222,11 +256,11 @@ do
if [[ $? -eq 0 ]];then
BMCGATEWAYE=`rspconfig $2 gateway |awk -F":" '{print $3}'`
else
exit 1;
exit 1;
fi
change_nonip $BMCGATEWAYE $2 $3 gateway
if [[ $? -eq 1 ]];then
echo "--------------------To test bmc gateway could be changed using rspconfig failed.--------------------"
echo "--------------------To test bmc gateway could be changed using rspconfig failed.--------------------"
exit 1
else
echo "--------------------To test bmc gateway could be changed using rspconfig successfully.--------------------"
@ -235,7 +269,6 @@ do
;;
"-lg"|"--list gateway" )
output=`rspconfig $2 gateway`
echo "output is $output"
if [[ $? -eq 0 ]];then
if [[ $output =~ "$2: BMC Gateway:" ]];then
echo "--1-----------------To test bmc gateway could be listed using rspconfig successfully.-----------------"
@ -266,70 +299,69 @@ echo "output is $output"
exit 0
fi
;;
"-ln"|"--list netmask" )
output=`rspconfig $2 netmask`
if [[ $? -eq 0 ]];then
if [[ $output =~ "$2: BMC Netmask:" ]];then
echo "-------------------To test bmc Netmask could be listed using rspconfig successfully.-----------------"
exit 0;
else
echo "-----------------To test bmc Netmask could be listed using rsconfig failed.-------------------"
exit 1;
fi
else
echo "-------------------To test bmc Netmask could be listed using rspconfig failed.---------------"
exit 1;
fi
;;
"-v"|"--vlan" )
output=`rspconfig $2 vlan`
echo "---------------------To test bmc vlan could be changed using rspconfig.--------------------"
if [[ $? -eq 0 ]]&&[[ $output =~ "BMC VLAN ID enabled" ]];then
BMCVLAN=`rspconfig $2 vlan |awk -F":" '{print $3}'`
else
echo "------------------Bmc vlan disabled so could not change vlan id using rspconfig.--------------------"
"-ln"|"--list netmask" )
output=`rspconfig $2 netmask`
if [[ $? -eq 0 ]];then
if [[ $output =~ "$2: BMC Netmask:" ]];then
echo "-------------------To test bmc Netmask could be listed using rspconfig successfully.-----------------"
exit 0;
else
echo "-----------------To test bmc Netmask could be listed using rsconfig failed.-------------------"
exit 1;
fi
else
echo "-------------------To test bmc Netmask could be listed using rspconfig failed.---------------"
exit 1;
fi
change_nonip $BMCVLAN $2 $3 vlan
if [[ $? -eq 1 ]];then
echo "--------------------To test bmc vlan could be changed using rspconfig failed.------------------"
exit 1
else
echo "--------------------To test bmc vlan could be changed using rspconfig successfully.-------------------"
exit 0
fi
;;
"-lv"|"--list vlan" )
output=`rspconfig $2 vlan`
if [[ $? -eq 0 ]];then
if [[ $output =~ "$2: BMC VLAN ID" ]];then
echo "-------------------To test bmc Vlan could be listed using rspconfig successfully.-----------------"
exit 0;
else
echo "-----------------To test bmc Vlan could be listed using rsconfig failed.-------------------"
exit 1;
fi
else
echo "-------------------To test bmc Vlan could be listed using rspconfig failed.---------------"
exit 1;
fi
;;
"-a"|"--all" )
change_all $2
fi
;;
"-v"|"--vlan" )
output=`rspconfig $2 vlan`
echo "---------------------To test bmc vlan could be changed using rspconfig.--------------------"
if [[ $? -eq 0 ]]&&[[ $output =~ "BMC VLAN ID enabled" ]];then
BMCVLAN=`rspconfig $2 vlan |awk -F":" '{print $3}'`
else
echo "------------------Bmc vlan disabled so could not change vlan id using rspconfig.--------------------"
exit 1;
fi
change_nonip $BMCVLAN $2 $3 vlan
if [[ $? -eq 1 ]];then
echo "--------------------To test bmc's all options could be changed using rspconfig failed.------------------"
exit 1
echo "--------------------To test bmc vlan could be changed using rspconfig failed.------------------"
exit 1
else
echo "--------------------To test bmc vlan could be changed using rspconfig successfully.-------------------"
exit 0
fi
;;
"-lv"|"--list vlan" )
output=`rspconfig $2 vlan`
if [[ $? -eq 0 ]];then
if [[ $output =~ "$2: BMC VLAN ID" ]];then
echo "-------------------To test bmc Vlan could be listed using rspconfig successfully.-----------------"
exit 0;
else
echo "-----------------To test bmc Vlan could be listed using rsconfig failed.-------------------"
exit 1;
fi
else
echo "-------------------To test bmc Vlan could be listed using rspconfig failed.---------------"
exit 1;
fi
;;
"-a"|"--all" )
change_all $2
if [[ $? -eq 1 ]];then
echo "--------------------To test BMC IP/netmask/gateway/vlan could be changed using rspconfig failed.------------------"
exit 1
else
echo "--------------------To test bmc's all options could be changed using rspconfig successfully.-------------------"
exit 0
fi
echo "--------------------To test BMC IP/netmask/gateway/vlan could be changed using rspconfig successfully.-------------------"
exit 0
fi
;;
"-la"|"--list all" )
BMCIP_LSDEF=`lsdef $2 |grep "bmc=" |awk -F "=" '{print $2}'`
BMCIP=`rspconfig $2 ip |awk -F":" '{print $3}'`
output=`rspconfig $2 ip gateway netmask vlan`
if [[ $? -eq 0 ]];then
#if [[ $output =~ "BMC VLAN ID:" ]]&&[[ $output =~ "BMC Netmask:" ]]&&[[ $output =~ "BMC Gateway:" ]]&&[[ $BMCIP =~ "$BMCIP_LSDEF" ]];then
if [[ $output =~ "$2: BMC VLAN ID" ]]&&[[ $output =~ "BMC Netmask:" ]]&&[[ $output =~ "BMC Gateway:" ]]&&[[ $BMCIP =~ "$BMCIP_LSDEF" ]];then
echo "------------------To test bmc's all option could be listed using rspconfig succssfully.-----------------"
exit 0
@ -340,7 +372,7 @@ echo "output is $output"
fi
;;
"-c"|"--clear" )
echo "--------------------To clear the test envionment.--------------------"
echo "--------------------To clear the test envionment.--------------------"
clear_env $1 $2 $3
if [[ $? -eq 1 ]];then
echo "--------------------To clear the test environment failed.-----------------"
@ -350,11 +382,16 @@ echo "output is $output"
exit 0
fi
;;
"-h"|"--help" )
usage
exit 0
;;
*)
echo
echo "Please Insert $0: -i|-g|-n|-c"
echo "Please Insert $0: -i|-lip|-g|-lg|-n|-ln|-v|-lv|-c|-a|-la"
echo
exit 1;
;;
esac
shift
done