2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-30 09:36:41 +00:00

Add test case for openbmc rspconfig command #2912

This commit is contained in:
junxiawang 2017-05-11 07:22:33 -04:00
parent 2f284f566e
commit 37e96693cf

View File

@ -7,104 +7,184 @@ function test_ip()
if [ ${VALID_CHECK:-no} == "yes" ]; then
echo $1;
else
return 1;
exit 1;
fi
else
return 1;
exit 1;
fi
return 0;
}
function net()
{
a=$(echo "$1" | awk -F "." '{print $1" "$2" "$3" "$4}')
for num in $a;
do
while (($num!=0));do
echo -n $(($num%2)) >> /tmp/$$.num;
num=$(($num/2));
done
done
rc=$(grep -o "1" /tmp/$$.num | wc -l)
rm /tmp/$$.num
ip="$2/$rc"
A=($(echo "$ip"|sed 's/[./;]/ /g'))
B=$(echo $((2**(32-${A[4]})-1)))
C=($(echo "obase=256;ibase=10; $B"|bc|awk '{if(NF==4)a=$0;if(NF==3)a="0"$0;if(NF==2)a="0 0"$0;if(NF==1)a="0 0 0"$0;print a}'))
D=$(echo ${A[*]} ${C[*]})
rc2=echo echo $D|awk 'BEGIN{OFS="."}{print $1,$2,$3,$4"-"$1+$6,$2+$7,$3+$8,$4+$9}' |awk -F '-' '{print $2}'
}
function change_ip()
{
test_ip $1;
if [[ $? -eq 1 ]]; then
echo ipvalue is invalid
exit 1;
fi
if [[ $? -eq 0 ]];then
echo $1 > /tmp/BMCIP
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}'`
echo ip is $ip1.$ip2.$ip3.$ip4
ip=$ip4;
while [[ $ip != "254" ]]; do
ping $ip1.$ip2.$ip3.$ip -c 2 > /dev/null;
if [[ $? != 0 ]]; then
rc=$(net $3 $1)
rc4=`echo $rc |awk -F. '{print $4}'`
rc4=`expr "$rc4"`
if [[ $rc4 > 255 ]];then
rc4=255
fi
ip=$ip4; while true;
do [[ $ip == "$rc4" ]] && exit 1;
ping $ip1.$ip2.$ip3.$ip -c 2 > /dev/null;
if [[ $? != 0 ]]; then
coutip="$ip1.$ip2.$ip3.$ip"
BMCNEWIP=$coutip;
echo $1,$2,$3
rspconfig $2 ip=$BMCNEWIP
if [[ $? -eq 0 ]];then
if [[ $? -eq 0 ]];then
echo right command;
else
else
exit 1;
fi
chdef $2 bmc=$BMCNEWIP
check_result $2 ip
check_result $2 ip $BMCNEWIP
if [[ $? -ne 0 ]] ;then
exit 1;
else
echo need to return ;
break 3;
fi
fi
ip=`expr "$ip" "+" "1"`
done
return 0
fi
}
function check_result {
function check_result()
{
a=0; while true;
do [ $a -eq 10 ] && exit 1;
echo $a
sleep 20
output=$(rspconfig $1 $2 );
if [[ $? -eq 0 ]] ;then
echo $output;exit 0;
else
a=$[$a+1];
sleep 1;
fi
do [ $a -eq 20 ] && exit 1;
output=`rspconfig $1 $2 |awk -F: '{print $3}'`;
echo output is $output;
if [[ $(echo $output|tr '.' '+'|bc) -eq $(echo $3|tr '.' '+'|bc) ]];then
echo checkresult is $output;
break 3;
else
a=$[$a+1];
sleep 1;
fi
done
return 0
}
function clear_env {
function clear_env()
{
if [[ -f /tmp/BMCIP ]];then
echo need to clear env;
originip=$(cat /tmp/BMCIP);
echo originip is $originip;
rspconfig $2 ip=$originip
if [[ $? -eq 0 ]];then
echo right command;
else
exit 1;
fi
echo $2,$3
rm -rf /tmp/BMCIP
chdef $2 bmc=$originip
check_result $2 $3
check_result $2 $3 $originip
if [[ $? -ne 0 ]] ;then
exit 1;
else
echo "need to return" ;
break 1;
fi
return 0
fi
return 1
}
function change_gateway {
test_ip $1;
rspconfig $2 gateway=$1;
check_result $2 $3
if [[ $? -eq 0 ]];then
echo set gateway ok;
else
exit 1;
fi
check_result $2 $3 $1
return 0
}
function change_netmask {
test_ip $1;
rspconfig $2 netmask=$1;
if [[ $? -eq 0 ]];then
echo set netmask ok;
else
exit 1;
fi
echo $2 ,$3
check_result $2 $3
check_result $2 $3 $1
return 0
}
BMCIP=""
BMCNETWORK=""
BMCGATEWAY=""
BMCIP=`rspconfig $2 ip |awk -F":" '{print $3}'`
BMCGATEWAYE=`rspconfig $2 gateway |awk -F":" '{print $3}'`
BMCNETMASK=`rspconfig $2 netmask |awk -F":" '{print $3}'`
BMCGTEWAT=""
BMCNETMASK=""
while [ "$#" -gt "0" ]
do
case $1 in
"-i"|"--ip" )
change_ip $BMCIP $2
rspconfig $2 ip
if [[ $? -eq 0 ]];then
echo get ip ok;
BMCIP=`rspconfig $2 ip |awk -F":" '{print $3}'`
BMCNETMASK=`rspconfig $2 netmask |awk -F":" '{print $3}'`
else
exit 1;
fi
change_ip $BMCIP $2 $BMCNETMASK
;;
"-g"|"--gateway" )
rspconfig $2 gateway
if [[ $? -eq 0 ]];then
echo get gateway ok;
BMCGATEWAYE=`rspconfig $2 gateway |awk -F":" '{print $3}'`
else
exit 1;
fi
change_gateway $BMCGATEWAYE $2 $3
;;
"-n"|"--netmask" )
change_netmask $BMCNETMASK $2 $3
rspconfig $2 netmask
if [[ $? -eq 0 ]];then
echo get netmask ok;
BMCNETMASK=`rspconfig $2 netmask |awk -F":" '{print $3}'`
else
exit 1;
fi
change_netmask $BMCNETMASK $2 $3
;;
"-c"|"--clear" )
clear_env $1 $2
clear_env $1 $2 $3
if [[ $? -ne 0 ]] ;then
exit 1
fi
;;
*)
echo