2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-08-21 10:40:24 +00:00

Add test case for openbmc rspconfig command #2912

This commit is contained in:
junxiawang
2017-05-05 04:47:06 -04:00
parent f3531240d3
commit 1aa7a97236
2 changed files with 170 additions and 0 deletions

View File

@@ -40,3 +40,56 @@ cmd:rspconfig __GETNODEATTR($$CN,hcp)__ sshcfg
check:rc==0
check:output=~__GETNODEATTR($$CN,hcp)__: \w+
end
start:rspconfig_ip
description:rspconfig change openbmc ip
Attribute: $$CN-The operation object of rspconfig command
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/rspconfig/rspconfig.sh -i $$CN
check:rc==0
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/rspconfig/rspconfig.sh -c $$CN ip
check:rc==0
end
start:rspconfig_ip_invalid
description:rspconfig could not change openbmc ip using invalid ip
Attribute: $$CN-The operation object of rspconfig command
cmd:rspconfig $$CN ip=ddd
check:rc!=0
end
start:rspconfig_ip_null
description:rspconfig could not set ip to null
Attribute: $$CN-The operation object of rspconfig command
cmd:rspconfig $$CN ip=
check:rc!=0
end
start:rspconfig_netmask
description:rspconfig change openbmc netmask
Attribute: $$CN-The operation object of rspconfig command
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/rspconfig/rspconfig.sh -n $$CN netmask
check:rc==0
end
start:rspconfig_netmask_invalid
despcription:rspconfig could not change openbmc netmask using invalid netmask
Attribute: $$CN-The operation object of rspconfig command
cmd:rspconfig $$CN netmask=ddd
check:rc!=0
end
start:rspconfig_gateway
description:rspconfig change openbmc gateway
Attribute: $$CN-The operation object of rspconfig command
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/rspconfig/rspconfig.sh -g $$CN gateway
check:rc==0
end
start:rspconfig_gateway_invalid
despcription:rspconfig could not change openbmc gatway using invalid gateway
Attribute: $$CN-The operation object of rspconfig command
cmd:rspconfig $$CN gateway=ddd
check:rc!=0
end

View File

@@ -0,0 +1,117 @@
#!/bin/bash
function test_ip()
{
IP=$1
VALID_CHECK=$(echo $IP|awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}')
if echo $IP|grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$">/dev/null; then
if [ ${VALID_CHECK:-no} == "yes" ]; then
echo $1;
else
return 1;
fi
else
return 1;
fi
}
function change_ip()
{
test_ip $1;
if [[ $? -eq 1 ]]; then
echo ipvalue is invalid
exit 1;
fi
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 != "10" ]]; do
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
echo right command;
else
exit 1;
fi
chdef $2 bmc=$BMCNEWIP
check_result $2 ip
fi
ip=`expr "$ip" "+" "1"`
done
}
function check_result {
a=0; while true;
do [ $a -eq 3 ] && 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
done
}
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
echo $2,$3
rm -rf /tmp/BMCIP
chdef $2 bmc=$originip
check_result $2 $3
fi
}
function change_gateway {
test_ip $1;
rspconfig $2 gateway=$1;
check_result $2 $3
}
function change_netmask {
test_ip $1;
rspconfig $2 netmask=$1;
echo $2 ,$3
check_result $2 $3
}
BMCIP=""
BMCNETWORK=""
BMCGATEWAY=""
BMCIP=`rspconfig frame45cn07 ip |awk -F":" '{print $3}'`
BMCGATEWAYE=`rspconfig frame45cn07 gateway |awk -F":" '{print $3}'`
BMCNETMASK=`rspconfig frame45cn07 netmask |awk -F":" '{print $3}'`
while [ "$#" -gt "0" ]
do
case $1 in
"-i"|"--ip" )
change_ip $BMCIP $2
;;
"-g"|"--gateway" )
change_gateway $BMCGATEWAYE $2 $3
;;
"-n"|"--netmask" )
change_netmask $BMCNETMASK $2 $3
;;
"-c"|"--clear" )
clear_env $1 $2
;;
*)
echo
echo "Please Insert $0: -i|-g|-n|-c"
echo
exit 1;
;;
esac
done