add websocket connection

This commit is contained in:
Ping Xiao 2023-09-01 15:45:31 +08:00
parent 95ccfb6665
commit 9ddf1178b9
1 changed files with 62 additions and 34 deletions

View File

@ -35,6 +35,7 @@ from util.taosadapter import *
import taos import taos
import taosrest import taosrest
import taosws
def checkRunTimeError(): def checkRunTimeError():
import win32gui import win32gui
@ -105,12 +106,13 @@ if __name__ == "__main__":
queryPolicy = 1 queryPolicy = 1
createDnodeNums = 1 createDnodeNums = 1
restful = False restful = False
websocket = False
replicaVar = 1 replicaVar = 1
asan = False asan = False
independentMnode = True independentMnode = True
previousCluster = False previousCluster = False
opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:N:M:Q:C:RD:n:i:aP', [ opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:N:M:Q:C:RWD:n:i:aP', [
'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd','dnodeNums','mnodeNums','queryPolicy','createDnodeNums','restful','adaptercfgupdate','replicaVar','independentMnode','previous']) 'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd','dnodeNums','mnodeNums','queryPolicy','createDnodeNums','restful','websocket','adaptercfgupdate','replicaVar','independentMnode','previous'])
for key, value in opts: for key, value in opts:
if key in ['-h', '--help']: if key in ['-h', '--help']:
tdLog.printNoPrefix( tdLog.printNoPrefix(
@ -131,6 +133,7 @@ if __name__ == "__main__":
tdLog.printNoPrefix('-Q set queryPolicy in one dnode') tdLog.printNoPrefix('-Q set queryPolicy in one dnode')
tdLog.printNoPrefix('-C create Dnode Numbers in one cluster') tdLog.printNoPrefix('-C create Dnode Numbers in one cluster')
tdLog.printNoPrefix('-R restful realization form') tdLog.printNoPrefix('-R restful realization form')
tdLog.printNoPrefix('-W websocket connection')
tdLog.printNoPrefix('-D taosadapter update cfg dict ') tdLog.printNoPrefix('-D taosadapter update cfg dict ')
tdLog.printNoPrefix('-n the number of replicas') tdLog.printNoPrefix('-n the number of replicas')
tdLog.printNoPrefix('-i independentMnode Mnode') tdLog.printNoPrefix('-i independentMnode Mnode')
@ -203,6 +206,9 @@ if __name__ == "__main__":
if key in ['-R', '--restful']: if key in ['-R', '--restful']:
restful = True restful = True
if key in ['-W', '--websocket']:
websocket = True
if key in ['-a', '--asan']: if key in ['-a', '--asan']:
asan = True asan = True
@ -224,7 +230,7 @@ if __name__ == "__main__":
# do exeCmd command # do exeCmd command
# #
if not execCmd == "": if not execCmd == "":
if restful: if restful or websocket:
tAdapter.init(deployPath) tAdapter.init(deployPath)
else: else:
tdDnodes.init(deployPath) tdDnodes.init(deployPath)
@ -263,7 +269,7 @@ if __name__ == "__main__":
if valgrind: if valgrind:
time.sleep(2) time.sleep(2)
if restful: if restful or websocket:
toBeKilled = "taosadapter" toBeKilled = "taosadapter"
# 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
@ -358,7 +364,7 @@ if __name__ == "__main__":
tdDnodes.deploy(1,updateCfgDict) tdDnodes.deploy(1,updateCfgDict)
tdDnodes.start(1) tdDnodes.start(1)
tdCases.logSql(logSql) tdCases.logSql(logSql)
if restful: if restful or websocket:
tAdapter.deploy(adapter_cfg_dict) tAdapter.deploy(adapter_cfg_dict)
tAdapter.start() tAdapter.start()
@ -366,6 +372,8 @@ if __name__ == "__main__":
queryPolicy=int(queryPolicy) queryPolicy=int(queryPolicy)
if restful: if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc") conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else: else:
conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) conn = taos.connect(host,config=tdDnodes.getSimCfgPath())
@ -395,14 +403,16 @@ if __name__ == "__main__":
tdDnodes.starttaosd(dnode.index) tdDnodes.starttaosd(dnode.index)
tdCases.logSql(logSql) tdCases.logSql(logSql)
if restful: if restful or websocket:
tAdapter.deploy(adapter_cfg_dict) tAdapter.deploy(adapter_cfg_dict)
tAdapter.start() tAdapter.start()
if not restful: if restful:
conn = taos.connect(host,config=tdDnodes.getSimCfgPath())
else:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc") conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else:
conn = taos.connect(host,config=tdDnodes.getSimCfgPath())
# tdLog.info(tdDnodes.getSimCfgPath(),host) # tdLog.info(tdDnodes.getSimCfgPath(),host)
if createDnodeNums == 1: if createDnodeNums == 1:
createDnodeNums=dnodeNums createDnodeNums=dnodeNums
@ -419,6 +429,8 @@ if __name__ == "__main__":
queryPolicy=int(queryPolicy) queryPolicy=int(queryPolicy)
if restful: if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc") conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else: else:
conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) conn = taos.connect(host,config=tdDnodes.getSimCfgPath())
@ -438,10 +450,12 @@ if __name__ == "__main__":
if ucase is not None and hasattr(ucase, 'noConn') and ucase.noConn == True: if ucase is not None and hasattr(ucase, 'noConn') and ucase.noConn == True:
conn = None conn = None
else: else:
if not restful: if restful:
conn = taos.connect(host="%s"%(host), config=tdDnodes.sim.getCfgDir()) conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else: else:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc") conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
if testCluster: if testCluster:
tdLog.info("Procedures for testing cluster") tdLog.info("Procedures for testing cluster")
@ -451,10 +465,12 @@ if __name__ == "__main__":
tdCases.runOneCluster(fileName) tdCases.runOneCluster(fileName)
else: else:
tdLog.info("Procedures for testing self-deployment") tdLog.info("Procedures for testing self-deployment")
if not restful: if restful:
conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else: else:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc") conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
if fileName == "all": if fileName == "all":
tdCases.runAllWindows(conn) tdCases.runAllWindows(conn)
@ -470,10 +486,12 @@ if __name__ == "__main__":
tdDnodes.stopAll() tdDnodes.stopAll()
tdDnodes.start(1) tdDnodes.start(1)
time.sleep(1) time.sleep(1)
if not restful: if restful:
conn = taos.connect( host, config=tdDnodes.getSimCfgPath())
else:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc") conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else:
conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
tdLog.info("Procedures for tdengine deployed in %s" % (host)) tdLog.info("Procedures for tdengine deployed in %s" % (host))
tdLog.info("query test after taosd restart") tdLog.info("query test after taosd restart")
tdCases.runOneWindows(conn, sp[0] + "_" + "restart.py", replicaVar) tdCases.runOneWindows(conn, sp[0] + "_" + "restart.py", replicaVar)
@ -505,7 +523,7 @@ if __name__ == "__main__":
except: except:
pass pass
if restful: if restful or websocket:
tAdapter.init(deployPath, masterIp) tAdapter.init(deployPath, masterIp)
tAdapter.stop(force_kill=True) tAdapter.stop(force_kill=True)
@ -515,16 +533,18 @@ if __name__ == "__main__":
tdDnodes.start(1) tdDnodes.start(1)
tdCases.logSql(logSql) tdCases.logSql(logSql)
if restful: if restful or websocket:
tAdapter.deploy(adapter_cfg_dict) tAdapter.deploy(adapter_cfg_dict)
tAdapter.start() tAdapter.start()
if queryPolicy != 1: if queryPolicy != 1:
queryPolicy=int(queryPolicy) queryPolicy=int(queryPolicy)
if not restful: if restful:
conn = taos.connect(host,config=tdDnodes.getSimCfgPath())
else:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc") conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else:
conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
# tdSql.init(conn.cursor()) # tdSql.init(conn.cursor())
# tdSql.execute("create qnode on dnode 1") # tdSql.execute("create qnode on dnode 1")
# tdSql.execute('alter local "queryPolicy" "%d"'%queryPolicy) # tdSql.execute('alter local "queryPolicy" "%d"'%queryPolicy)
@ -566,15 +586,17 @@ if __name__ == "__main__":
tdDnodes.starttaosd(dnode.index) tdDnodes.starttaosd(dnode.index)
tdCases.logSql(logSql) tdCases.logSql(logSql)
if restful: if restful or websocket:
tAdapter.deploy(adapter_cfg_dict) tAdapter.deploy(adapter_cfg_dict)
tAdapter.start() tAdapter.start()
# create taos connect # create taos connect
if not restful: if restful:
conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else: else:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc") conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
print(tdDnodes.getSimCfgPath(),host) print(tdDnodes.getSimCfgPath(),host)
if createDnodeNums == 1: if createDnodeNums == 1:
createDnodeNums=dnodeNums createDnodeNums=dnodeNums
@ -594,8 +616,10 @@ if __name__ == "__main__":
queryPolicy=int(queryPolicy) queryPolicy=int(queryPolicy)
if restful: if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc") conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else: else:
conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute("create qnode on dnode 1") cursor.execute("create qnode on dnode 1")
@ -620,10 +644,12 @@ if __name__ == "__main__":
tdCases.runOneCluster(fileName) tdCases.runOneCluster(fileName)
else: else:
tdLog.info("Procedures for testing self-deployment") tdLog.info("Procedures for testing self-deployment")
if not restful: if restful:
conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else: else:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc") conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
if fileName == "all": if fileName == "all":
tdCases.runAllLinux(conn) tdCases.runAllLinux(conn)
@ -640,10 +666,12 @@ if __name__ == "__main__":
tdDnodes.stopAll() tdDnodes.stopAll()
tdDnodes.start(1) tdDnodes.start(1)
time.sleep(1) time.sleep(1)
if not restful: if restful:
conn = taos.connect( host, config=tdDnodes.getSimCfgPath())
else:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc") conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else:
conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
tdLog.info("Procedures for tdengine deployed in %s" % (host)) tdLog.info("Procedures for tdengine deployed in %s" % (host))
tdLog.info("query test after taosd restart") tdLog.info("query test after taosd restart")
tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py", replicaVar) tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py", replicaVar)