Python Automated testing for Hive

Source: Internet
Author: User
Tags tmp file kinit

This program mainly implements the Hive permission test. The system has the Administrator user single and test user tests. Under Path/home/test/, write the use case and expected results in an XML file.

Execution procedure: kinit single user, beeline-u-e Login and execute the statement for the test user to reclaim and grant permissions for the role, kinit test user, Beeline-u-E to execute the test statement and save the execution result into the TMP file , find the expected keyword in the TMP file, get the result of the test pass or fail, and count the test results.


#!/usr/bin/python#coding:utf-8#by cvv54import sysimport osimport retry:     import xml.etree.celementtree as etexcept importerror:    import  xml.etree.elementtree as ettry:    tree = et.parse ("/home/test/ Case/usecase.xml ")      #root  = et.fromstring (country_string)      root = tree.getroot () except exception,e:    print  "Error:cannot  parse file:usecase.xml. "     sys.exit (1) print root.tag, "---", root.attribfor child in root:     print child.tag, "---", child.attribpassed=0failed=0    for  case in root.findall (' case '):     pre = case.find (' pre '). Text     perform = case.find (' Perform '). text    expect  = case.find (' expect '). Text.strip (' \ n ')     id = case.get ("id")      print  "KEY WORDS ARE :"         print  expect    for each in pre.split (';'):#         print each        if not each.strip () = = ':             command = each.strip (' \ n ')             os.environ[' command ']=str (command)             print command                      Os.system ("Kdestroy")             os.system ("Kinit  -kt /etc/securiTy/keytabs/single.keytab single ")              Os.system (' beeline -u  ' jdbc:hive2://gateway.xxx.xxx:10000/;p rincipal=single " -e " $command; "  &>>log ')     for each in perform.split (';'):#         print each        if not  each.strip () = = ":             command =  each.strip (' \ n ')             os.environ[' Command ']=str (command)             print  command                     os.system ("Kdestroy")              os.system ("kinit -kt /etc/security/keytabs/test.keytab test ")              os.system (' beeline -u  ' jdbc:hive2://gateway.xxx.xxx:10000/;p rincipal=single "  -e  "$command;"  &>tmp ')        f=open (' tmp ')     flag=0     for line in f:#        print   "LINE IS :" #        print line         match=re.findall (Expect,line)         if  match != []:            passed+=1             flag=1             if flag == 0:         failed+=1                     print (ID)         os.system ("cat tmp> >log ")     os.system (" rm -f tmp ") print " passed: "Print passedprint   "failed:" Print failedos.system (' mv log  ' date  "+%y-%m-%d~%h-%m-%s")



My XML is written like this:

<?xml version= "1.0"  encoding= "Utf-8"? ><test><case id= "001"  name= "SHOW  TABLES "><pre>REVOKE ALL ON SERVER server1 FROM ROLE test_role;  GRANT ALL ON URI TO ROLE test_role;</pre><perform>SHOW  Tables;</perform><expect>tab_name</expect></case><case id= "002"  name= " Show tables "><pre>revoke all on server server1 from role test _role; </pre><perform>show tables;</perform><expect>failed:  Semanticexception no valid privileges</expect></case><case id= "003"   Name= "show create table"  privilege= "select" ><pre>create table if not  EXISTS test_table1   (Id int,name string,salary float,street string, City string,state string,ziP int)  PARTITIONED BY  (address string)  row format delimited  fields terminated by  '   '; revoke all on server server1 from role test_role; Grant select on table test_table1 to role test_role;</pre><perform >show create table test_table1;</perform><expect>createtab_stmt </expect ></case><case id= "004"  name= "show create table"  privilege= "INSERT" > <pre>REVOKE ALL ON SERVER server1 FROM ROLE test_role; Grant insert on table test_table1 to role test_role;</pre><perform >show create table test_table1;</perform><expect>createtab_stmt </expect ></case><case id= "005"  name= "show create table"  ><pre>REVOKE  all on&nbsp Server server1 from role test_role;</pre><perform>show create table  test_table1;</perform><expect>FAILED: SemanticException No valid  Privileges</expect></case></test>


This article is from the "CVV" blog, make sure to keep this source http://2723554.blog.51cto.com/2713554/1786974

Python Automated testing for Hive

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.