This program mainly implements the Hive permission test. The system has the Administrator user single and test user tests. Under Path/home/test/, the pre-condition of the use case is written in the input folder, and each use case corresponds to an input file named X-Y~Z.Q (where XYZ is a number), and the statement that needs to be executed in the case folder is named Case_x.q; Write the expected results to the expect folder, named Expect_x, and execute the results in the output folder named X-y~z.q
Execution process: kinit single user, beeline-u-F Login and execute a statement in the input file that corresponds to the role of the test user for the collection and granting of permissions; kinit test user, Beeline-u- F go to the test statement in the case folder and save the execution result to the output folder; According to whether there is a file in expect and the test is a positive or reverse test, and the output content for comparison, to obtain the test pass or fail results, statistical test results.
The program is able to automate the testing of hive permissions, but each use case corresponds to an input file, a cases file, a expect file, an output file, which is too cumbersome to use. The next article is a python-optimized version.
#!/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 folderfor 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/;p rincipal=single " -f $i &>>/home/test/log/$log #${var%%-*}# The purpose of this command is to remove the variable var from the right side of the last '-' character and its right side of the content, returning from the right side of the last '/' (excluding the character) to the left of the content. #${var##*/} #该命令的作用是去掉变量var从左边算起的最后一个 the '/' character and its left side, returning the content to the right of the last '/' (excluding the character) from the left. #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/;p Rincipal=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 doneecho ' Date ' >>/home/test/log/result.txtecho ' $ Pass passed " >>/home/test/log/result.txtecho " $fail failed ">>/home/test/log/ result.txtecho "$block blocked" >>/home/test/log/result.txt#rename log.txt with current timecat /home/test/log/result.txt >> /home/test/log/$LOGRM -f / Home/test/log/result.txt
This article is from the "CVV" blog, make sure to keep this source http://2723554.blog.51cto.com/2713554/1786841
Shell implementation of hive Automation test