您好,登錄后才能下訂單哦!
本程序主要實現hive權限測試。系統中有管理員用戶single和測試用戶test。在路徑/home/test/下,將用例的預置條件寫在input文件夾內,每個用例對應一個input文件,命名為x-y~z.q(其中xyz都是數字);將用例需要執行的語句放在case文件夾內,命名為case_x.q;將預期結果寫入expect文件夾,命名為expect_x;執行結果輸出到output文件夾中,命名為x-y~z.q
執行過程:kinit single用戶,beeline -u -f登錄并執行input文件中對test用戶對應角色回收和賦予權限的語句;kinit test用戶,beeline -u -f去執行case文件夾中的測試語句并保存執行結果到output文件夾中;根據expect中是否有文件及該測試為正向或逆向測試,和output內容作比較,得出該測試pass還是fail的結果,統計測試結果。
該程序能夠實現hive的權限自動化測試,但每個用例對應一個input文件、一個case文件、一個expect文件、一個output文件,太過繁雜,不好用。下一篇出python優化版本。
#!/bin/bash #by cvv54 #rename existed log.txt # if [ -f "/home/test/log/log.txt" ] ;then # mv /home/test/log/log.txt /home/test/log/`date "+%Y-%m-%d~%H-%M-%S"` # fi #To create log file date>>/home/test/log/`date "+%Y-%m-%d~%H-%M-%S"` log=`ls /home/test/log/ -rt |tail -1` pass=0; fail=0; block=0; #To traversal files in input folder for i in /home/test/input/*.q do #To login system with user single to grant proper privileges to user test #$i here is name of input file,it looks like this: /path/to/file/x-y~z.q #(x:case number;y:item number;z:can be 1 or 2,means Positive testing or Negative Testing;end with .q:sql file) kdestroy kinit -kt /etc/security/keytabs/single.keytab single beeline -u "jdbc:hive2://gateway.xxx.xxx:10000/;principal=single" -f $i &>>/home/test/log/$log #${var%%-*} #該命令的作用是去掉變量var從右邊算起的最后一個'-'字符及其右邊的內容,返回從右邊算起的最后一個'/'(不含該字符)的左邊的內容。 #${var##*/} #該命令的作用是去掉變量var從左邊算起的最后一個'/'字符及其左邊的內容,返回從左邊算起的最后一個'/'(不含該字符)的右邊的內容。 #To drop path,only filename left j=${i##*/} #only for debug echo "j=$j" #To get last number in filename to distinguish Positive testing from Negative Testing k=${i##*~} #only for debug echo "k=$k" #get case number m=${j%%-*} #only for debug echo "m=$m" #To login system with user test to execute query statement #filename in folder case looks like this: case_x.q(x is varable) #filename in folder output will be named like output_x-y~z.q(it is not a sql file...) kdestroy kinit -kt /etc/security/keytabs/test.keytab test beeline -u "jdbc:hive2://gateway.xxx.xxx:10000/;principal=single" -f /home/test/case/case_$m.q &>>/home/test/output/output_$j #To check results #filename in folder expect looks like this: expect_x(x is varable) if [ $k = "1.q" ];then if [ -f "/home/test/expect/expect_$m" ];then eval $(/bin/grep ok /home/test/expect/expect_$m) eval $(/bin/grep nok /home/test/expect/expect_$m) if [ -n "`grep -w $ok /home/test/output/output_$j`"];then echo "$i pass">>/home/test/log/result.txt ((pass++)) elif [ -n "`grep -w $nok /home/test/output/output_$j`"];then echo "$i failed">>/home/test/log/result.txt ((fail++)) else echo "$i block">>/home/test/log/result.txt ((block++)) fi elif [ -n "`grep -w "seconds" /home/test/output/output_$j`" ];then echo "$i pass">>/home/test/log/result.txt ((pass++)) elif [ -n "`grep -w "FAILED: SemanticException No valid privileges" /home/test/output/output_$j`" ];then echo "$i failed">>/home/test/log/result.txt ((fail++)) else echo "$i block">>/home/test/log/result.txt ((block++)) fi else if [ -f "/home/test/expect/expect_$m" ];then eval $(/bin/grep ok /home/test/expect/expect_$m) eval $(/bin/grep nok /home/test/expect/expect_$m) if [ -n "`grep -w $nok /home/test/output/output_$j`" ];then echo "$i pass">>/home/test/log/result.txt ((pass++)) elif [ -n "`grep -w $ok /home/test/output/output_$j`" ];then echo "$i failed">>/home/test/log/result.txt ((fail++)) else echo "$i block">>/home/test/log/result.txt ((block++)) fi elif [ -n "`grep -w "seconds" /home/test/output/output_$j`" ];then echo "$i failed">>/home/test/log/result.txt ((fail++)) elif [ -n "`grep -w "FAILED: SemanticException No valid privileges" /home/test/output/output_$j`" ];then echo "$i pass">>/home/test/log/result.txt ((pass++)) else echo "$i block">>/home/test/log/result.txt ((block++)) fi fi done echo `date` >>/home/test/log/result.txt echo "$pass passed" >>/home/test/log/result.txt echo "$fail failed">>/home/test/log/result.txt echo "$block blocked">>/home/test/log/result.txt #rename log.txt with current time cat /home/test/log/result.txt >> /home/test/log/$log rm -f /home/test/log/result.txt
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。