日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python自动测试e_python实现hive自动化测试

發布時間:2025/4/16 python 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python自动测试e_python实现hive自动化测试 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本程序主要實現hive權限測試。系統中有管理員用戶single和測試用戶test。在路徑/home/test/下,將用例和預期結果寫在xml文件中。

行過程:kinit single用戶,beeline -u -e登錄并執行對test用戶對應角色回收和賦予權限的語句;kinit

test用戶,beeline -u

-e去執行測試語句并保存執行結果到tmp文件中;在tmp文件中查找預期關鍵字,得出該測試pass還是fail的結果,統計測試結果。

#!/usr/bin/python

#coding:utf-8

#by?cvv54

import?sys

import?os

import?re

try:

import?xml.etree.cElementTree?as?ET

except?ImportError:

import?xml.etree.ElementTree?as?ET

try:

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.attrib

for?child?in?root:

print?child.tag,"---",child.attrib

passed=0

failed=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/;principal=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/;principal=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?passed

print?"failed:"

print?failed

os.system('mv?log?`date?"+%Y-%m-%d~%H-%M-%S"`')

我的xml是這樣寫的:<?xml ?version="1.0"?encoding="utf-8"?>

REVOKE?ALL?ON?SERVER?server1?FROM?ROLE?test_role;?GRANT?ALL?ON?URI?TO?ROLE?test_role;

SHOW?TABLES;

tab_name

REVOKE?ALL?ON?SERVER?server1?FROM?ROLE?test_role;

SHOW?TABLES;

FAILED:?SemanticException?No?valid?privileges

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;

SHOW?CREATE?TABLE?test_table1;

createtab_stmt

REVOKE?ALL?ON?SERVER?server1?FROM?ROLE?test_role;GRANT?INSERT?ON?TABLE?test_table1?TO?ROLE?test_role;

SHOW?CREATE?TABLE?test_table1;

createtab_stmt

REVOKE?ALL?ON?SERVER?server1?FROM?ROLE?test_role;

SHOW?CREATE?TABLE?test_table1;

FAILED:?SemanticException?No?valid?privileges

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的python自动测试e_python实现hive自动化测试的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。