From 969c01c3b1e8c54f86346c49ed32c8d727ca94ed Mon Sep 17 00:00:00 2001 From: junxiawang Date: Wed, 12 Jul 2017 09:18:24 -0400 Subject: [PATCH] modify rpower testcase if ipmi using wrong passwd --- xCAT-test/autotest/testcase/rpower/cases0 | 12 ++ .../rpower/rpower_ipmi_wrongpasswd_test.sh | 118 ++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100755 xCAT-test/autotest/testcase/rpower/rpower_ipmi_wrongpasswd_test.sh diff --git a/xCAT-test/autotest/testcase/rpower/cases0 b/xCAT-test/autotest/testcase/rpower/cases0 index 143806ba7..40dfa7a08 100644 --- a/xCAT-test/autotest/testcase/rpower/cases0 +++ b/xCAT-test/autotest/testcase/rpower/cases0 @@ -180,4 +180,16 @@ cmd:rpower $$CN ddd check:output=~Unsupported command: check:rc==1 end +start:rpower_ipmi_wrongpasswd +description:rpower ipmi and its password wrong +Attribute: $$CN-The operation object of rpower command +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/rpower/rpower_ipmi_wrongpasswd_test.sh -pt $$CN $$ipmipasswd $$ipminame +check:rc==0 +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/rpower/rpower_ipmi_wrongpasswd_test.sh -c $$CN +check:rc==0 +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/rpower/rpower_ipmi_wrongpasswd_test.sh -apt $$CN $$ipmipasswd $$ipminame +check:rc==0 +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/rpower/rpower_ipmi_wrongpasswd_test.sh -c $$CN +check:rc==0 +end diff --git a/xCAT-test/autotest/testcase/rpower/rpower_ipmi_wrongpasswd_test.sh b/xCAT-test/autotest/testcase/rpower/rpower_ipmi_wrongpasswd_test.sh new file mode 100755 index 000000000..a0b176bb0 --- /dev/null +++ b/xCAT-test/autotest/testcase/rpower/rpower_ipmi_wrongpasswd_test.sh @@ -0,0 +1,118 @@ +#!/bin/bash +function check_passwd_table(){ +tabdump passwd |grep ipmi + if [ $? -eq 0 ];then + `tabdump passwd |grep ipmi>/tmp/xcat_test_rpower_ipmi_wrongpasswd` + else + return 1; + fi +} +function modify_passwd_table(){ +Username=`cat /tmp/xcat_test_rpower_ipmi_wrongpasswd |awk -F "\"" '{print $4}'`; +Passwd=`cat /tmp/xcat_test_rpower_ipmi_wrongpasswd |awk -F "\"" '{print $6}'`; +`chtab key=ipmi passwd.password=$Passwd.wrong passwd.username=$Username`; +tabdump passwd; +} +function add_passwd_table() +{ +echo i is $1,$2,$3 +`chtab key=ipmi passwd.password=$2 passwd.username=$3`; +rpower $1 stat + if [ $? -eq 0 ];then + `chtab key=ipmi passwd.password=$2.wrong passwd.username=$3`; + tabdump passwd; + else + echo "wrong password"; + fi +} +function modify_node_definition() +{ +echo node is $1,$2,$3 +chdef $1 bmcpassword=$2 bmcusername=$3 +rpower $1 stat + if [ $? -eq 0 ];then + chdef $1 bmcpassword=$2.wrong bmcusername=$3; + tabdump passwd; + else + echo "wrong password"; + fi +} +function clear_env(){ + if [ -f /tmp/xcat_test_rpower_ipmi_wrongpasswd ];then + Username=`cat /tmp/xcat_test_rpower_ipmi_wrongpasswd |awk -F "\"" '{print $4}'`; + Passwd=`cat /tmp/xcat_test_rpower_ipmi_wrongpasswd |awk -F "\"" '{print $6}'`; + chtab key=ipmi passwd.password=$Passwd passwd.username=$Username;tabdump passwd; + rm -rf /tmp/xcat_test_rpower_ipmi_wrongpasswd; + else + `chtab -d key=ipmi passwd`; + chdef $1 bmcpassword= bmcusername=; + fi +} +function check_result(){ +echo node is $1; +output=$(rpower $1 stat /dev/null 2>&1) +echo output is $output + if [[ $output =~ "Incorrect password provided" ]];then + return 0; + else + return 1; + fi +} +while [ "$#" -gt "0" ] +do + case $1 in + "-pt"|"--passwdtable" ) + check_passwd_table + if [[ $? -eq 0 ]];then + modify_passwd_table + check_result $2 + if [[ $? -eq 1 ]];then + exit 1 + else + exit 0 + fi + + else + add_passwd_table $2 $3 $4 + check_result $2 + if [[ $? -eq 1 ]];then + exit 1 + else + exit 0 + fi + fi + ;; + "-apt"|"--addpasswdtable" ) + check_passwd_table + if [[ $? -eq 0 ]];then + `chtab -d key=ipmi passwd`; + if [[ $? -eq 1 ]];then + exit 1 + fi + fi + modify_node_definition $2 $3 $4 + check_result $2 + if [[ $? -eq 1 ]];then + exit 1 + else + exit 0 + fi + ;; + "-c"|"--clear" ) + clear_env $2 + if [[ $? -eq 1 ]];then + exit 1 + else + exit 0 + fi + ;; + *) + echo + echo "Please Insert $0: -pt|-apt|-c" + echo + exit 1; + ;; + esac +done + +