Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
654d1f47
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
654d1f47
编写于
12月 16, 2021
作者:
L
liuyq-617
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-12186]<test>import lib from any path in test frame
上级
1a6350de
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
82 addition
and
60 deletion
+82
-60
tests/pytest/test.py
tests/pytest/test.py
+64
-53
tests/pytest/util/cases.py
tests/pytest/util/cases.py
+10
-7
tests/pytest/util/dnodes.py
tests/pytest/util/dnodes.py
+8
-0
未找到文件。
tests/pytest/test.py
浏览文件 @
654d1f47
...
...
@@ -37,68 +37,83 @@ if __name__ == "__main__":
stop
=
0
restart
=
False
windows
=
0
opts
,
args
=
getopt
.
gnu_getopt
(
sys
.
argv
[
1
:],
'f:p:m:l:scghrw'
,
[
'file='
,
'path='
,
'master'
,
'logSql'
,
'stop'
,
'cluster'
,
'valgrind'
,
'help'
,
'windows'
])
opts
,
args
=
getopt
.
gnu_getopt
(
sys
.
argv
[
1
:],
"f:p:m:l:scghrw"
,
[
"file="
,
"path="
,
"master"
,
"logSql"
,
"stop"
,
"cluster"
,
"valgrind"
,
"help"
,
"windows"
,
],
)
for
key
,
value
in
opts
:
if
key
in
[
'-h'
,
'--help'
]:
tdLog
.
printNoPrefix
(
'A collection of test cases written using Python'
)
tdLog
.
printNoPrefix
(
'-f Name of test case file written by Python'
)
tdLog
.
printNoPrefix
(
'-p Deploy Path for Simulator'
)
tdLog
.
printNoPrefix
(
'-m Master Ip for Simulator'
)
tdLog
.
printNoPrefix
(
'-l <True:False> logSql Flag'
)
tdLog
.
printNoPrefix
(
'-s stop All dnodes'
)
tdLog
.
printNoPrefix
(
'-c Test Cluster Flag'
)
tdLog
.
printNoPrefix
(
'-g valgrind Test Flag'
)
tdLog
.
printNoPrefix
(
'-r taosd restart test'
)
tdLog
.
printNoPrefix
(
'-w taos on windows'
)
if
key
in
[
"-h"
,
"--help"
]:
tdLog
.
printNoPrefix
(
"A collection of test cases written using Python"
)
tdLog
.
printNoPrefix
(
"-f Name of test case file written by Python"
)
tdLog
.
printNoPrefix
(
"-p Deploy Path for Simulator"
)
tdLog
.
printNoPrefix
(
"-m Master Ip for Simulator"
)
tdLog
.
printNoPrefix
(
"-l <True:False> logSql Flag"
)
tdLog
.
printNoPrefix
(
"-s stop All dnodes"
)
tdLog
.
printNoPrefix
(
"-c Test Cluster Flag"
)
tdLog
.
printNoPrefix
(
"-g valgrind Test Flag"
)
tdLog
.
printNoPrefix
(
"-r taosd restart test"
)
tdLog
.
printNoPrefix
(
"-w taos on windows"
)
sys
.
exit
(
0
)
if
key
in
[
'-r'
,
'--restart'
]:
if
key
in
[
"-r"
,
"--restart"
]:
restart
=
True
if
key
in
[
'-f'
,
'--file'
]:
if
key
in
[
"-f"
,
"--file"
]:
fileName
=
value
if
key
in
[
'-p'
,
'--path'
]:
if
key
in
[
"-p"
,
"--path"
]:
deployPath
=
value
if
key
in
[
'-m'
,
'--master'
]:
if
key
in
[
"-m"
,
"--master"
]:
masterIp
=
value
if
key
in
[
'-l'
,
'--logSql'
]:
if
(
value
.
upper
()
==
"TRUE"
)
:
if
key
in
[
"-l"
,
"--logSql"
]:
if
value
.
upper
()
==
"TRUE"
:
logSql
=
True
elif
(
value
.
upper
()
==
"FALSE"
)
:
elif
value
.
upper
()
==
"FALSE"
:
logSql
=
False
else
:
tdLog
.
printNoPrefix
(
"logSql value %s is invalid"
%
logSql
)
sys
.
exit
(
0
)
if
key
in
[
'-c'
,
'--cluster'
]:
if
key
in
[
"-c"
,
"--cluster"
]:
testCluster
=
True
if
key
in
[
'-g'
,
'--valgrind'
]:
if
key
in
[
"-g"
,
"--valgrind"
]:
valgrind
=
1
if
key
in
[
'-s'
,
'--stop'
]:
if
key
in
[
"-s"
,
"--stop"
]:
stop
=
1
if
key
in
[
'-w'
,
'--windows'
]:
if
key
in
[
"-w"
,
"--windows"
]:
windows
=
1
if
(
stop
!=
0
)
:
if
(
valgrind
==
0
)
:
if
stop
!=
0
:
if
valgrind
==
0
:
toBeKilled
=
"taosd"
else
:
toBeKilled
=
"valgrind.bin"
killCmd
=
"ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1"
%
toBeKilled
killCmd
=
(
"ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1"
%
toBeKilled
)
psCmd
=
"ps -ef|grep -w %s| grep -v grep | awk '{print $2}'"
%
toBeKilled
processID
=
subprocess
.
check_output
(
psCmd
,
shell
=
True
)
while
(
processID
)
:
while
processID
:
os
.
system
(
killCmd
)
time
.
sleep
(
1
)
processID
=
subprocess
.
check_output
(
psCmd
,
shell
=
True
)
...
...
@@ -115,25 +130,26 @@ if __name__ == "__main__":
if
valgrind
:
time
.
sleep
(
2
)
tdLog
.
info
(
'stop All dnodes'
)
tdLog
.
info
(
"stop All dnodes"
)
if
masterIp
==
""
:
host
=
'127.0.0.1'
host
=
"127.0.0.1"
else
:
host
=
masterIp
tdLog
.
info
(
"Procedures for tdengine deployed in %s"
%
(
host
))
uModule
=
tdDnodes
.
import_module
(
fileName
)
if
windows
:
tdCases
.
logSql
(
logSql
)
tdLog
.
info
(
"Procedures for testing self-deployment"
)
td_clinet
=
TDSimClient
(
"C:
\\
TDengine"
)
td_clinet
.
deploy
()
remote_conn
=
Connection
(
"root@%s"
%
host
)
with
remote_conn
.
cd
(
'/var/lib/jenkins/workspace/TDinternal/community/tests/pytest'
):
remote_conn
=
Connection
(
"root@%s"
%
host
)
with
remote_conn
.
cd
(
"/var/lib/jenkins/workspace/TDinternal/community/tests/pytest"
):
remote_conn
.
run
(
"python3 ./test.py"
)
conn
=
taos
.
connect
(
host
=
"%s"
%
(
host
),
config
=
td_clinet
.
cfgDir
)
conn
=
taos
.
connect
(
host
=
"%s"
%
(
host
),
config
=
td_clinet
.
cfgDir
)
tdCases
.
runOneWindows
(
conn
,
fileName
)
else
:
tdDnodes
.
init
(
deployPath
)
...
...
@@ -141,27 +157,24 @@ if __name__ == "__main__":
tdDnodes
.
setValgrind
(
valgrind
)
tdDnodes
.
stopAll
()
is_test_framework
=
0
key_word
=
'tdCases.addLinux'
key_word
=
"tdCases.addLinux"
try
:
if
key_word
in
open
(
fileName
).
read
():
is_test_framework
=
1
except
:
pass
if
is_test_framework
:
moduleName
=
fileName
.
replace
(
".py"
,
""
).
replace
(
"/"
,
"."
)
uModule
=
importlib
.
import_module
(
moduleName
)
try
:
ucase
=
uModule
.
TDTestCase
()
tdDnodes
.
deploy
(
1
,
ucase
.
updatecfgDict
)
except
:
tdDnodes
.
deploy
(
1
,{})
tdDnodes
.
deploy
(
1
,
ucase
.
updatecfgDict
)
del
uModule
except
:
tdDnodes
.
deploy
(
1
,
{})
else
:
pass
tdDnodes
.
deploy
(
1
,{})
tdDnodes
.
deploy
(
1
,
{})
tdDnodes
.
start
(
1
)
tdCases
.
logSql
(
logSql
)
if
testCluster
:
...
...
@@ -172,23 +185,21 @@ if __name__ == "__main__":
tdCases
.
runOneCluster
(
fileName
)
else
:
tdLog
.
info
(
"Procedures for testing self-deployment"
)
conn
=
taos
.
connect
(
host
,
config
=
tdDnodes
.
getSimCfgPath
())
conn
=
taos
.
connect
(
host
,
config
=
tdDnodes
.
getSimCfgPath
())
if
fileName
==
"all"
:
tdCases
.
runAllLinux
(
conn
)
else
:
tdCases
.
runOne
Windows
(
conn
,
fileNam
e
)
tdCases
.
runOne
Linux
(
conn
,
fileName
,
uModul
e
)
if
restart
:
if
fileName
==
"all"
:
tdLog
.
info
(
"not need to query "
)
else
:
else
:
sp
=
fileName
.
rsplit
(
"."
,
1
)
if
len
(
sp
)
==
2
and
sp
[
1
]
==
"py"
:
tdDnodes
.
stopAll
()
tdDnodes
.
start
(
1
)
time
.
sleep
(
1
)
conn
=
taos
.
connect
(
host
,
config
=
tdDnodes
.
getSimCfgPath
())
time
.
sleep
(
1
)
conn
=
taos
.
connect
(
host
,
config
=
tdDnodes
.
getSimCfgPath
())
tdLog
.
info
(
"Procedures for tdengine deployed in %s"
%
(
host
))
tdLog
.
info
(
"query test after taosd restart"
)
tdCases
.
runOneLinux
(
conn
,
sp
[
0
]
+
"_"
+
"restart.py"
)
...
...
tests/pytest/util/cases.py
浏览文件 @
654d1f47
...
...
@@ -17,6 +17,7 @@ import time
import
datetime
import
inspect
import
importlib
from
util.dnodes
import
*
from
util.log
import
*
...
...
@@ -34,8 +35,9 @@ class TDCases:
self
.
clusterCases
=
[]
def
__dynamicLoadModule
(
self
,
fileName
):
moduleName
=
fileName
.
replace
(
".py"
,
""
).
replace
(
os
.
sep
,
"."
)
return
importlib
.
import_module
(
moduleName
,
package
=
'..'
)
# moduleName = fileName.replace(".py", "").replace(os.sep, ".")
# return importlib.import_module(moduleName, package='..')
return
tdDnodes
.
import_module
(
fileName
)
def
logSql
(
self
,
logSql
):
self
.
_logSql
=
logSql
...
...
@@ -63,10 +65,11 @@ class TDCases:
tdLog
.
info
(
"total %d Linux test case(s) executed"
%
(
runNum
))
def
runOneLinux
(
self
,
conn
,
fileName
):
testModule
=
self
.
__dynamicLoadModule
(
fileName
)
def
runOneLinux
(
self
,
conn
,
fileName
,
testModule
):
# testModule = self.__dynamicLoadModule(fileName)
runNum
=
0
if
fileName
.
startswith
(
".."
):
fileName
=
fileName
[
3
:]
for
tmp
in
self
.
linuxCases
:
if
tmp
.
name
.
find
(
fileName
)
!=
-
1
:
case
=
testModule
.
TDTestCase
()
...
...
@@ -95,7 +98,7 @@ class TDCases:
tdLog
.
notice
(
"total %d Windows test case(s) executed"
%
(
runNum
))
def
runOneWindows
(
self
,
conn
,
fileName
):
testModule
=
self
.
__dynamicLoadModule
(
fileName
)
#
testModule = self.__dynamicLoadModule(fileName)
runNum
=
0
for
tmp
in
self
.
windowsCases
:
...
...
@@ -130,7 +133,7 @@ class TDCases:
tdLog
.
notice
(
"total %d Cluster test case(s) executed"
%
(
runNum
))
def
runOneCluster
(
self
,
fileName
):
testModule
=
self
.
__dynamicLoadModule
(
fileName
)
#
testModule = self.__dynamicLoadModule(fileName)
runNum
=
0
for
tmp
in
self
.
clusterCases
:
...
...
tests/pytest/util/dnodes.py
浏览文件 @
654d1f47
...
...
@@ -18,6 +18,7 @@ import platform
import
pathlib
import
shutil
import
subprocess
import
importlib
from
time
import
sleep
from
util.log
import
*
...
...
@@ -579,6 +580,13 @@ class TDDnodes:
def
check
(
self
,
index
):
if
index
<
1
or
index
>
10
:
tdLog
.
exit
(
"index:%d should on a scale of [1, 10]"
%
(
index
))
def
import_module
(
self
,
fileName
):
module_dir
,
module_file
=
os
.
path
.
split
(
fileName
)
module_name
,
module_ext
=
os
.
path
.
splitext
(
module_file
)
spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
fileName
)
uModule
=
spec
.
loader
.
load_module
()
return
uModule
def
stopAll
(
self
):
tdLog
.
info
(
"stop all dnodes"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录