Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
68429598
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
68429598
编写于
4月 28, 2022
作者:
P
plum-lihui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[test: add test case for taos shell]
上级
04d59ab8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
280 addition
and
0 deletion
+280
-0
tests/system-test/0-others/taosShellError.py
tests/system-test/0-others/taosShellError.py
+280
-0
未找到文件。
tests/system-test/0-others/taosShellError.py
0 → 100644
浏览文件 @
68429598
import
taos
import
sys
import
time
import
socket
import
pexpect
import
os
from
util.log
import
*
from
util.sql
import
*
from
util.cases
import
*
from
util.dnodes
import
*
def
taos_command
(
buildPath
,
key
,
value
,
expectString
,
cfgDir
,
sqlString
=
''
,
key1
=
''
,
value1
=
''
):
if
len
(
key
)
==
0
:
tdLog
.
exit
(
"taos test key is null!"
)
taosCmd
=
buildPath
+
'/build/bin/taos '
if
len
(
cfgDir
)
!=
0
:
taosCmd
=
taosCmd
+
'-c '
+
cfgDir
taosCmd
=
taosCmd
+
' -'
+
key
if
len
(
value
)
!=
0
:
if
key
==
'p'
:
taosCmd
=
taosCmd
+
value
else
:
taosCmd
=
taosCmd
+
' '
+
value
if
len
(
key1
)
!=
0
:
taosCmd
=
taosCmd
+
' -'
+
key1
if
key1
==
'p'
:
taosCmd
=
taosCmd
+
value1
else
:
if
len
(
value1
)
!=
0
:
taosCmd
=
taosCmd
+
' '
+
value1
tdLog
.
info
(
"taos cmd: %s"
%
taosCmd
)
child
=
pexpect
.
spawn
(
taosCmd
,
timeout
=
3
)
#output = child.readline()
#print (output.decode())
if
len
(
expectString
)
!=
0
:
i
=
child
.
expect
([
expectString
,
pexpect
.
TIMEOUT
,
pexpect
.
EOF
],
timeout
=
6
)
else
:
i
=
child
.
expect
([
pexpect
.
TIMEOUT
,
pexpect
.
EOF
],
timeout
=
6
)
retResult
=
child
.
before
.
decode
()
print
(
"cmd return result:
\n
%s
\n
"
%
retResult
)
#print(child.after.decode())
if
i
==
0
:
print
(
'taos login success! Here can run sql, taos> '
)
if
len
(
sqlString
)
!=
0
:
child
.
sendline
(
sqlString
)
w
=
child
.
expect
([
"Query OK"
,
pexpect
.
TIMEOUT
,
pexpect
.
EOF
],
timeout
=
1
)
retResult
=
child
.
before
.
decode
()
if
w
==
0
:
return
"TAOS_OK"
,
retResult
else
:
return
"TAOS_FAIL"
,
retResult
else
:
if
key
==
'A'
or
key1
==
'A'
or
key
==
'C'
or
key1
==
'C'
or
key
==
'V'
or
key1
==
'V'
:
return
"TAOS_OK"
,
retResult
else
:
return
"TAOS_OK"
,
retResult
else
:
if
key
==
'A'
or
key1
==
'A'
or
key
==
'C'
or
key1
==
'C'
or
key
==
'V'
or
key1
==
'V'
:
return
"TAOS_OK"
,
retResult
else
:
return
"TAOS_FAIL"
,
retResult
class
TDTestCase
:
#updatecfgDict = {'clientCfg': {'serverPort': 7080, 'firstEp': 'trd02:7080', 'secondEp':'trd02:7080'},\
# 'serverPort': 7080, 'firstEp': 'trd02:7080'}
hostname
=
socket
.
gethostname
()
serverPort
=
'7080'
rpcDebugFlagVal
=
'143'
clientCfgDict
=
{
'serverPort'
:
''
,
'firstEp'
:
''
,
'secondEp'
:
''
,
'rpcDebugFlag'
:
'135'
}
clientCfgDict
[
"serverPort"
]
=
serverPort
clientCfgDict
[
"firstEp"
]
=
hostname
+
':'
+
serverPort
clientCfgDict
[
"secondEp"
]
=
hostname
+
':'
+
serverPort
clientCfgDict
[
"rpcDebugFlag"
]
=
rpcDebugFlagVal
updatecfgDict
=
{
'clientCfg'
:
{},
'serverPort'
:
''
,
'firstEp'
:
''
,
'secondEp'
:
''
}
updatecfgDict
[
"clientCfg"
]
=
clientCfgDict
updatecfgDict
[
"serverPort"
]
=
serverPort
updatecfgDict
[
"firstEp"
]
=
hostname
+
':'
+
serverPort
updatecfgDict
[
"secondEp"
]
=
hostname
+
':'
+
serverPort
print
(
"===================: "
,
updatecfgDict
)
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to excute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
())
def
getBuildPath
(
self
):
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
projPath
=
selfPath
[:
selfPath
.
find
(
"community"
)]
else
:
projPath
=
selfPath
[:
selfPath
.
find
(
"tests"
)]
for
root
,
dirs
,
files
in
os
.
walk
(
projPath
):
if
(
"taosd"
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/build/bin"
)]
break
return
buildPath
def
run
(
self
):
# sourcery skip: extract-duplicate-method, remove-redundant-fstring
tdSql
.
prepare
()
# time.sleep(2)
tdSql
.
query
(
"create user testpy pass 'testpy'"
)
#hostname = socket.gethostname()
#tdLog.info ("hostname: %s" % hostname)
buildPath
=
self
.
getBuildPath
()
if
(
buildPath
==
""
):
tdLog
.
exit
(
"taosd not found!"
)
else
:
tdLog
.
info
(
"taosd found in %s"
%
buildPath
)
cfgPath
=
buildPath
+
"/../sim/psim/cfg"
tdLog
.
info
(
"cfgPath: %s"
%
cfgPath
)
checkNetworkStatus
=
[
'0: unavailable'
,
'1: network ok'
,
'2: service ok'
,
'3: service degraded'
,
'4: exiting'
]
netrole
=
[
'client'
,
'server'
]
keyDict
=
{
'h'
:
''
,
'P'
:
'6030'
,
'p'
:
'testpy'
,
'u'
:
'testpy'
,
'a'
:
''
,
'A'
:
''
,
'c'
:
''
,
'C'
:
''
,
's'
:
''
,
'r'
:
''
,
'f'
:
''
,
\
'k'
:
''
,
't'
:
''
,
'n'
:
''
,
'l'
:
'1024'
,
'N'
:
'100'
,
'V'
:
''
,
'd'
:
'db'
,
'w'
:
'30'
,
'-help'
:
''
,
'-usage'
:
''
,
'?'
:
''
}
keyDict
[
'h'
]
=
self
.
hostname
keyDict
[
'c'
]
=
cfgPath
keyDict
[
'P'
]
=
self
.
serverPort
tdLog
.
printNoPrefix
(
"================================ parameter: -h wiht error value"
)
#newDbName="dbh"
#sqlString = 'create database ' + newDbName + ';'
keyDict
[
'h'
]
=
'abc'
retCode
,
retVal
=
taos_command
(
buildPath
,
"h"
,
keyDict
[
'h'
],
"taos>"
,
keyDict
[
'c'
],
''
)
if
(
retCode
==
"TAOS_FAIL"
)
and
(
"Unable to establish connection"
in
retVal
):
tdLog
.
info
(
"taos -h %s test suceess"
%
keyDict
[
'h'
])
else
:
tdLog
.
exit
(
"taos -h %s fail"
%
keyDict
[
'h'
])
keyDict
[
'h'
]
=
'
\'
abc
\'
'
retCode
,
retVal
=
taos_command
(
buildPath
,
"h"
,
keyDict
[
'h'
],
"taos>"
,
keyDict
[
'c'
],
''
)
if
(
retCode
==
"TAOS_FAIL"
)
and
(
"Unable to establish connection"
in
retVal
):
tdLog
.
info
(
"taos -h %s test suceess"
%
keyDict
[
'h'
])
else
:
tdLog
.
exit
(
"taos -h %s fail"
%
keyDict
[
'h'
])
keyDict
[
'h'
]
=
'3'
retCode
,
retVal
=
taos_command
(
buildPath
,
"h"
,
keyDict
[
'h'
],
"taos>"
,
keyDict
[
'c'
],
''
)
if
(
retCode
==
"TAOS_FAIL"
)
and
(
"Unable to establish connection"
in
retVal
):
tdLog
.
info
(
"taos -h %s test suceess"
%
keyDict
[
'h'
])
else
:
tdLog
.
exit
(
"taos -h %s fail"
%
keyDict
[
'h'
])
keyDict
[
'h'
]
=
'
\'
3
\'
'
retCode
,
retVal
=
taos_command
(
buildPath
,
"h"
,
keyDict
[
'h'
],
"taos>"
,
keyDict
[
'c'
],
''
)
if
(
retCode
==
"TAOS_FAIL"
)
and
(
"Unable to establish connection"
in
retVal
):
tdLog
.
info
(
"taos -h %s test suceess"
%
keyDict
[
'h'
])
else
:
tdLog
.
exit
(
"taos -h %s fail"
%
keyDict
[
'h'
])
tdLog
.
printNoPrefix
(
"================================ parameter: -P wiht error value"
)
#newDbName="dbh"
#sqlString = 'create database ' + newDbName + ';'
keyDict
[
'P'
]
=
'abc'
retCode
,
retVal
=
taos_command
(
buildPath
,
"P"
,
keyDict
[
'P'
],
"taos>"
,
keyDict
[
'c'
],
''
)
if
(
retCode
==
"TAOS_FAIL"
)
and
(
"Invalid port"
in
retVal
):
tdLog
.
info
(
"taos -P %s test suceess"
%
keyDict
[
'P'
])
else
:
tdLog
.
exit
(
"taos -P %s fail"
%
keyDict
[
'P'
])
keyDict
[
'P'
]
=
'
\'
abc
\'
'
retCode
,
retVal
=
taos_command
(
buildPath
,
"P"
,
keyDict
[
'P'
],
"taos>"
,
keyDict
[
'c'
],
''
)
if
(
retCode
==
"TAOS_FAIL"
)
and
(
"Invalid port"
in
retVal
):
tdLog
.
info
(
"taos -P %s test suceess"
%
keyDict
[
'P'
])
else
:
tdLog
.
exit
(
"taos -P %s fail"
%
keyDict
[
'P'
])
keyDict
[
'P'
]
=
'3'
retCode
,
retVal
=
taos_command
(
buildPath
,
"P"
,
keyDict
[
'P'
],
"taos>"
,
keyDict
[
'c'
],
''
)
if
(
retCode
==
"TAOS_FAIL"
)
and
(
"Unable to establish connection"
in
retVal
):
tdLog
.
info
(
"taos -P %s test suceess"
%
keyDict
[
'P'
])
else
:
tdLog
.
exit
(
"taos -P %s fail"
%
keyDict
[
'P'
])
keyDict
[
'P'
]
=
'
\'
3
\'
'
retCode
,
retVal
=
taos_command
(
buildPath
,
"P"
,
keyDict
[
'P'
],
"taos>"
,
keyDict
[
'c'
],
''
)
if
(
retCode
==
"TAOS_FAIL"
)
and
(
"Unable to establish connection"
in
retVal
):
tdLog
.
info
(
"taos -P %s test suceess"
%
keyDict
[
'P'
])
else
:
tdLog
.
exit
(
"taos -P %s fail"
%
keyDict
[
'P'
])
keyDict
[
'P'
]
=
'12ab'
retCode
,
retVal
=
taos_command
(
buildPath
,
"P"
,
keyDict
[
'P'
],
"taos>"
,
keyDict
[
'c'
],
''
)
if
(
retCode
==
"TAOS_FAIL"
)
and
(
"Unable to establish connection"
in
retVal
):
tdLog
.
info
(
"taos -P %s test suceess"
%
keyDict
[
'P'
])
else
:
tdLog
.
exit
(
"taos -P %s fail"
%
keyDict
[
'P'
])
keyDict
[
'P'
]
=
'
\'
12ab
\'
'
retCode
,
retVal
=
taos_command
(
buildPath
,
"P"
,
keyDict
[
'P'
],
"taos>"
,
keyDict
[
'c'
],
''
)
if
(
retCode
==
"TAOS_FAIL"
)
and
(
"Unable to establish connection"
in
retVal
):
tdLog
.
info
(
"taos -P %s test suceess"
%
keyDict
[
'P'
])
else
:
tdLog
.
exit
(
"taos -P %s fail"
%
keyDict
[
'P'
])
tdLog
.
printNoPrefix
(
"================================ parameter: -f with error sql "
)
pwd
=
os
.
getcwd
()
newDbName
=
"dbf"
sqlFile
=
pwd
+
"/0-others/sql.txt"
sql1
=
"echo 'create database "
+
newDbName
+
"' > "
+
sqlFile
sql2
=
"echo 'use "
+
newDbName
+
"' >> "
+
sqlFile
sql3
=
"echo 'create table ntbf (ts timestamp, c binary(40)) no this item' >> "
+
sqlFile
sql4
=
"echo 'insert into ntbf values (
\"
2021-04-01 08:00:00.000
\"
,
\"
test taos -f1
\"
)(
\"
2021-04-01 08:00:01.000
\"
,
\"
test taos -f2
\"
)' >> "
+
sqlFile
sql5
=
"echo 'show databases' >> "
+
sqlFile
os
.
system
(
sql1
)
os
.
system
(
sql2
)
os
.
system
(
sql3
)
os
.
system
(
sql4
)
os
.
system
(
sql5
)
keyDict
[
'f'
]
=
pwd
+
"/0-others/sql.txt"
retCode
,
retVal
=
taos_command
(
buildPath
,
"f"
,
keyDict
[
'f'
],
'performance_schema'
,
keyDict
[
'c'
],
''
,
''
,
''
)
#print("============ ret code: ", retCode)
if
retCode
!=
"TAOS_OK"
:
tdLog
.
exit
(
"taos -f fail"
)
print
(
"========== check new db =========="
)
tdSql
.
query
(
"show databases"
)
for
i
in
range
(
tdSql
.
queryRows
):
#print ("dbseq: %d, dbname: %s"%(i, tdSql.getData(i, 0)))
if
tdSql
.
getData
(
i
,
0
)
==
newDbName
:
break
else
:
tdLog
.
exit
(
"create db fail after taos -f fail"
)
sqlString
=
"select * from "
+
newDbName
+
".ntbf"
tdSql
.
error
(
sqlString
)
shellCmd
=
"rm -f "
+
sqlFile
os
.
system
(
shellCmd
)
keyDict
[
'f'
]
=
pwd
+
"/0-others/noexistfile.txt"
retCode
,
retVal
=
taos_command
(
buildPath
,
"f"
,
keyDict
[
'f'
],
'failed to open file'
,
keyDict
[
'c'
],
''
,
''
,
''
)
#print("============ ret code: ", retCode)
if
retCode
!=
"TAOS_OK"
:
tdLog
.
exit
(
"taos -f fail"
)
tdSql
.
query
(
'drop database %s'
%
newDbName
)
tdLog
.
printNoPrefix
(
"================================ parameter: -a with error value"
)
#newDbName="dba"
errorPassword
=
'errorPassword'
sqlString
=
'create database '
+
newDbName
+
';'
retCode
,
retVal
=
taos_command
(
buildPath
,
"u"
,
keyDict
[
'u'
],
"taos>"
,
keyDict
[
'c'
],
sqlString
,
'a'
,
errorPassword
)
if
retCode
!=
"TAOS_FAIL"
:
tdLog
.
exit
(
"taos -u %s -a %s"
%
(
keyDict
[
'u'
],
errorPassword
))
tdLog
.
printNoPrefix
(
"================================ parameter: -p with error value"
)
#newDbName="dba"
keyDict
[
'p'
]
=
'errorPassword'
retCode
,
retVal
=
taos_command
(
buildPath
,
"u"
,
keyDict
[
'u'
],
"taos>"
,
keyDict
[
'c'
],
sqlString
,
'p'
,
keyDict
[
'p'
])
if
retCode
==
"TAOS_FAIL"
and
"Authentication failure"
in
retVal
:
tdLog
.
info
(
"taos -p %s test suceess"
%
keyDict
[
'p'
])
else
:
tdLog
.
exit
(
"taos -u %s -p %s"
%
(
keyDict
[
'u'
],
keyDict
[
'p'
]))
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
f
"
{
__file__
}
successfully executed"
)
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录