From 1aa7a97236da4b1bc8539b0df15fea63718503aa Mon Sep 17 00:00:00 2001 From: junxiawang Date: Fri, 5 May 2017 04:47:06 -0400 Subject: [PATCH 1/6] Add test case for openbmc rspconfig command #2912 --- xCAT-test/autotest/testcase/rspconfig/cases0 | 53 ++++++++ .../autotest/testcase/rspconfig/rspconfig.sh | 117 ++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100755 xCAT-test/autotest/testcase/rspconfig/rspconfig.sh diff --git a/xCAT-test/autotest/testcase/rspconfig/cases0 b/xCAT-test/autotest/testcase/rspconfig/cases0 index d44e21732..516f2a4bf 100644 --- a/xCAT-test/autotest/testcase/rspconfig/cases0 +++ b/xCAT-test/autotest/testcase/rspconfig/cases0 @@ -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 + + diff --git a/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh b/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh new file mode 100755 index 000000000..7b3a8b33f --- /dev/null +++ b/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh @@ -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 + From 983c6a92298ba52cbfd8fa7b3944218b1635d9b3 Mon Sep 17 00:00:00 2001 From: junxiawang Date: Fri, 5 May 2017 06:22:25 -0400 Subject: [PATCH 2/6] Add test case for openbmc rspconfig command #2912 --- xCAT-test/autotest/testcase/rspconfig/rspconfig.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh b/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh index 7b3a8b33f..b80d0dadf 100755 --- a/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh +++ b/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh @@ -88,9 +88,9 @@ function change_netmask { 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}'` +BMCIP=`rspconfig $2 ip |awk -F":" '{print $3}'` +BMCGATEWAYE=`rspconfig $2 gateway |awk -F":" '{print $3}'` +BMCNETMASK=`rspconfig $2 netmask |awk -F":" '{print $3}'` while [ "$#" -gt "0" ] do case $1 in From 2f284f566e4dfda128defadaa2fad6b018a531fa Mon Sep 17 00:00:00 2001 From: junxiawang Date: Fri, 5 May 2017 06:35:24 -0400 Subject: [PATCH 3/6] Add test case for openbmc rspconfig command #2912 --- xCAT-test/autotest/testcase/rspconfig/rspconfig.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh b/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh index b80d0dadf..cc9714d5e 100755 --- a/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh +++ b/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh @@ -28,7 +28,7 @@ function change_ip() ip4=`echo $1|awk -F. '{print $4}'` echo ip is $ip1.$ip2.$ip3.$ip4 ip=$ip4; - while [[ $ip != "10" ]]; do + while [[ $ip != "254" ]]; do ping $ip1.$ip2.$ip3.$ip -c 2 > /dev/null; if [[ $? != 0 ]]; then coutip="$ip1.$ip2.$ip3.$ip" @@ -49,7 +49,7 @@ function change_ip() function check_result { a=0; while true; - do [ $a -eq 3 ] && exit 1; + do [ $a -eq 10 ] && exit 1; echo $a sleep 20 output=$(rspconfig $1 $2 ); From 37e96693cfc440eae2141e4229ff62690d3c5d04 Mon Sep 17 00:00:00 2001 From: junxiawang Date: Thu, 11 May 2017 07:22:33 -0400 Subject: [PATCH 4/6] Add test case for openbmc rspconfig command #2912 --- .../autotest/testcase/rspconfig/rspconfig.sh | 156 +++++++++++++----- 1 file changed, 118 insertions(+), 38 deletions(-) diff --git a/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh b/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh index cc9714d5e..fa53dfdbd 100755 --- a/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh +++ b/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh @@ -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 From 4db46093ea25c4582e0298d29ba2fff82696e5da Mon Sep 17 00:00:00 2001 From: junxiawang Date: Fri, 12 May 2017 04:38:32 -0400 Subject: [PATCH 5/6] Add test case for openbmc rspconfig command #2912 --- .../autotest/testcase/rspconfig/rspconfig.sh | 351 +++++++++--------- 1 file changed, 183 insertions(+), 168 deletions(-) diff --git a/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh b/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh index fa53dfdbd..c56dbdca5 100755 --- a/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh +++ b/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh @@ -1,197 +1,212 @@ #!/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; + 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 - exit 1; + return 1; fi - else - exit 1; - fi - return 0; + 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}' + 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 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 - 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 - echo right command; - else - exit 1; - fi - chdef $2 bmc=$BMCNEWIP - 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 + test_ip $1; + if [[ $? -ne 0 ]];then return 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 + 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" ]] && return 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 + echo right command; + else + return 1; + fi + chdef $2 bmc=$BMCNEWIP + check_result $2 ip $BMCNEWIP + if [[ $? -ne 0 ]] ;then + return 1; + else + return 0; + fi + fi + ip=`expr "$ip" "+" "1"` + done } function check_result() -{ - a=0; while true; - 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 +{ + a=0; while true; + do [ $a -eq 20 ] && return 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; + return 0 ; + else + a=$[$a+1]; + sleep 1; + fi + done + return 1; } 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 $originip - if [[ $? -ne 0 ]] ;then - exit 1; - else - echo "need to return" ; - break 1; - fi - return 0 - fi - return 1 + if [[ -f /tmp/BMCIP ]];then + originip=$(cat /tmp/BMCIP); + echo originip is $originip; + rspconfig $2 ip=$originip + if [[ $? -eq 0 ]];then + echo right command; + else + return 1; + fi + rm -rf /tmp/BMCIP + chdef $2 bmc=$originip + check_result $2 $3 $originip + if [[ $? -ne 0 ]] ;then + return 1; + else + return 0; + fi + fi + return 1; } function change_gateway { - test_ip $1; - rspconfig $2 gateway=$1; - if [[ $? -eq 0 ]];then - echo set gateway ok; - else - exit 1; - fi - check_result $2 $3 $1 - return 0 + test_ip $1; + if [[ $? -ne 0 ]];then return 1;fi + rspconfig $2 gateway=$1; + if [[ $? -eq 0 ]];then + echo set gateway ok; + else + return 1; + fi + check_result $2 $3 $1 + if [[ $? -ne 0 ]] ;then + return 1; + else + return 0; + fi + } 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 $1 - return 0 + test_ip $1; + if [[ $? -ne 0 ]];then return 1;fi + rspconfig $2 netmask=$1; + if [[ $? -eq 0 ]];then + echo set netmask ok; + else + return 1; + fi + check_result $2 $3 $1 + if [[ $? -ne 0 ]] ;then + return 1; + else + return 0; + fi } BMCIP="" BMCGTEWAT="" BMCNETMASK="" while [ "$#" -gt "0" ] do -case $1 in - "-i"|"--ip" ) - 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" ) - 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 $3 - if [[ $? -ne 0 ]] ;then - exit 1 - fi -;; - *) - echo - echo "Please Insert $0: -i|-g|-n|-c" - echo - exit 1; -;; -esac + case $1 in + "-i"|"--ip" ) + rspconfig $2 ip + if [[ $? -eq 0 ]];then + 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 + if [[ $? -eq 1 ]];then + exit 1 + else + exit 0 + fi + ;; + "-g"|"--gateway" ) + rspconfig $2 gateway + if [[ $? -eq 0 ]];then + BMCGATEWAYE=`rspconfig $2 gateway |awk -F":" '{print $3}'` + else + exit 1; + fi + change_gateway $BMCGATEWAYE $2 $3 + if [[ $? -eq 1 ]];then + exit 1 + else + exit 0 + fi + ;; + "-n"|"--netmask" ) + rspconfig $2 netmask + if [[ $? -eq 0 ]];then + BMCNETMASK=`rspconfig $2 netmask |awk -F":" '{print $3}'` + else + exit 1; + fi + change_netmask $BMCNETMASK $2 $3 + if [[ $? -eq 1 ]];then + exit 1 + else + exit 0 + fi + ;; + "-c"|"--clear" ) + clear_env $1 $2 $3 + if [[ $? -eq 1 ]];then + exit 1 + else + exit 0 + fi + ;; + *) + echo + echo "Please Insert $0: -i|-g|-n|-c" + echo + exit 1; + ;; + esac done From 91cc1fbb4ef09a0134040db9a75ee65768454bda Mon Sep 17 00:00:00 2001 From: junxiawang Date: Fri, 12 May 2017 06:06:56 -0400 Subject: [PATCH 6/6] Add test case for openbmc rspconfig command #2912 --- .../autotest/testcase/rspconfig/rspconfig.sh | 237 +++++++++--------- 1 file changed, 118 insertions(+), 119 deletions(-) diff --git a/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh b/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh index c56dbdca5..35cebceed 100755 --- a/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh +++ b/xCAT-test/autotest/testcase/rspconfig/rspconfig.sh @@ -2,83 +2,82 @@ function test_ip() { IP=$1 - VALID_CHECK=$(echo $IP|awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}') + 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 + else + return 1; + fi + else + return 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 + 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}' + 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 [[ $? -ne 0 ]];then return 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 - 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" ]] && return 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 - echo right command; - else - return 1; - fi - chdef $2 bmc=$BMCNEWIP - check_result $2 ip $BMCNEWIP - if [[ $? -ne 0 ]] ;then - return 1; - else - return 0; - fi - fi - ip=`expr "$ip" "+" "1"` - done + 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 + 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" ]] && return 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 + echo right command; + else + return 1; + fi + chdef $2 bmc=$BMCNEWIP + check_result $2 ip $BMCNEWIP + if [[ $? -ne 0 ]] ;then + return 1; + else + return 0; + fi + fi + ip=`expr "$ip" "+" "1"` + done } function check_result() { - a=0; while true; - do [ $a -eq 20 ] && return 1; - output=`rspconfig $1 $2 |awk -F: '{print $3}'`; - echo output is $output; + a=0; while true; + do [ $a -eq 20 ] && return 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; return 0 ; @@ -111,38 +110,39 @@ function clear_env() fi return 1; } -function change_gateway { +function change_gateway +{ test_ip $1; if [[ $? -ne 0 ]];then return 1;fi - rspconfig $2 gateway=$1; + rspconfig $2 gateway=$1; if [[ $? -eq 0 ]];then - echo set gateway ok; - else - return 1; - fi - check_result $2 $3 $1 - if [[ $? -ne 0 ]] ;then - return 1; - else - return 0; - fi - + echo set gateway ok; + else + return 1; + fi + check_result $2 $3 $1 + if [[ $? -ne 0 ]] ;then + return 1; + else + return 0; + fi } -function change_netmask { +function change_netmask +{ test_ip $1; if [[ $? -ne 0 ]];then return 1;fi rspconfig $2 netmask=$1; - if [[ $? -eq 0 ]];then - echo set netmask ok; - else - return 1; - fi + if [[ $? -eq 0 ]];then + echo set netmask ok; + else + return 1; + fi check_result $2 $3 $1 - if [[ $? -ne 0 ]] ;then - return 1; - else - return 0; - fi + if [[ $? -ne 0 ]] ;then + return 1; + else + return 0; + fi } BMCIP="" BMCGTEWAT="" @@ -150,13 +150,13 @@ BMCNETMASK="" while [ "$#" -gt "0" ] do case $1 in - "-i"|"--ip" ) - rspconfig $2 ip + "-i"|"--ip" ) + rspconfig $2 ip if [[ $? -eq 0 ]];then - BMCIP=`rspconfig $2 ip |awk -F":" '{print $3}'` - BMCNETMASK=`rspconfig $2 netmask |awk -F":" '{print $3}'` - else - exit 1; + 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 if [[ $? -eq 1 ]];then @@ -167,46 +167,45 @@ do ;; "-g"|"--gateway" ) rspconfig $2 gateway - if [[ $? -eq 0 ]];then + if [[ $? -eq 0 ]];then BMCGATEWAYE=`rspconfig $2 gateway |awk -F":" '{print $3}'` else exit 1; fi - change_gateway $BMCGATEWAYE $2 $3 - if [[ $? -eq 1 ]];then - exit 1 - else - exit 0 - fi + change_gateway $BMCGATEWAYE $2 $3 + if [[ $? -eq 1 ]];then + exit 1 + else + exit 0 + fi ;; - "-n"|"--netmask" ) - rspconfig $2 netmask + "-n"|"--netmask" ) + rspconfig $2 netmask if [[ $? -eq 0 ]];then BMCNETMASK=`rspconfig $2 netmask |awk -F":" '{print $3}'` else - exit 1; - fi - change_netmask $BMCNETMASK $2 $3 - if [[ $? -eq 1 ]];then - exit 1 - else - exit 0 - fi + exit 1; + fi + change_netmask $BMCNETMASK $2 $3 + if [[ $? -eq 1 ]];then + exit 1 + else + exit 0 + fi ;; - "-c"|"--clear" ) - clear_env $1 $2 $3 - if [[ $? -eq 1 ]];then - exit 1 - else - exit 0 - fi + "-c"|"--clear" ) + clear_env $1 $2 $3 + if [[ $? -eq 1 ]];then + exit 1 + else + exit 0 + fi ;; - *) - echo - echo "Please Insert $0: -i|-g|-n|-c" - echo - exit 1; + *) + echo + echo "Please Insert $0: -i|-g|-n|-c" + echo + exit 1; ;; esac done -