TDengine/tests/system-test/test.py

693 lines
26 KiB
Python
Raw Normal View History

2022-04-18 08:09:03 +00:00
#!/usr/bin/python
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# install pip
# pip install src/connector/python/
# -*- coding: utf-8 -*-
import os
2022-04-18 08:09:03 +00:00
import sys
import getopt
import subprocess
import time
2022-05-27 11:00:48 +00:00
import base64
import json
2022-05-27 14:53:29 +00:00
import platform
2022-06-09 03:48:41 +00:00
import socket
2022-06-14 11:31:45 +00:00
import threading
import importlib
2022-07-19 08:39:50 +00:00
import toml
2022-04-18 08:09:03 +00:00
sys.path.append("../pytest")
from util.log import *
from util.dnodes import *
from util.cases import *
2022-06-22 04:07:42 +00:00
from util.cluster import *
2022-07-19 08:39:50 +00:00
from util.taosadapter import *
2022-04-18 08:09:03 +00:00
import taos
2022-07-13 08:55:35 +00:00
import taosrest
2023-09-01 07:45:31 +00:00
import taosws
2022-04-18 08:09:03 +00:00
2022-06-14 11:31:45 +00:00
def checkRunTimeError():
import win32gui
2022-06-16 11:53:39 +00:00
timeCount = 0
2022-06-14 11:31:45 +00:00
while 1:
time.sleep(1)
2022-06-16 11:53:39 +00:00
timeCount = timeCount + 1
2022-06-24 05:56:35 +00:00
print("checkRunTimeError",timeCount)
2022-07-14 05:58:23 +00:00
if (timeCount>600):
2022-06-24 05:56:35 +00:00
print("stop the test.")
2022-06-16 11:53:39 +00:00
os.system("TASKKILL /F /IM taosd.exe")
os.system("TASKKILL /F /IM taos.exe")
os.system("TASKKILL /F /IM tmq_sim.exe")
2022-06-16 11:58:24 +00:00
os.system("TASKKILL /F /IM mintty.exe")
2022-07-14 05:58:23 +00:00
os.system("TASKKILL /F /IM python.exe")
2022-06-16 11:53:39 +00:00
quit(0)
2022-06-14 11:31:45 +00:00
hwnd = win32gui.FindWindow(None, "Microsoft Visual C++ Runtime Library")
if hwnd:
os.system("TASKKILL /F /IM taosd.exe")
2022-04-18 08:09:03 +00:00
#
# run case on previous cluster
#
def runOnPreviousCluster(host, config, fileName):
print("enter run on previeous")
# load case module
sep = "/"
if platform.system().lower() == 'windows':
sep = os.sep
moduleName = fileName.replace(".py", "").replace(sep, ".")
uModule = importlib.import_module(moduleName)
case = uModule.TDTestCase()
# create conn
conn = taos.connect(host, config)
# run case
2023-04-08 11:22:21 +00:00
case.init(conn, False)
try:
case.run()
except Exception as e:
tdLog.notice(repr(e))
tdLog.exit("%s failed" % (fileName))
# stop
case.stop()
2022-04-18 08:09:03 +00:00
if __name__ == "__main__":
2022-07-13 01:52:03 +00:00
#
# analysis paramaters
#
2022-04-18 08:09:03 +00:00
fileName = "all"
deployPath = ""
masterIp = ""
testCluster = False
valgrind = 0
killValgrind = 1
2022-04-18 08:09:03 +00:00
logSql = True
stop = 0
restart = False
dnodeNums = 1
2022-06-23 10:01:49 +00:00
mnodeNums = 0
2022-05-27 11:00:48 +00:00
updateCfgDict = {}
2022-07-19 08:39:50 +00:00
adapter_cfg_dict = {}
2022-05-28 07:30:14 +00:00
execCmd = ""
2022-07-02 07:28:45 +00:00
queryPolicy = 1
2022-07-10 08:12:09 +00:00
createDnodeNums = 1
2022-07-13 08:55:35 +00:00
restful = False
2023-09-01 07:45:31 +00:00
websocket = False
replicaVar = 1
2022-11-19 02:54:38 +00:00
asan = False
independentMnode = False
previousCluster = False
2023-09-01 07:45:31 +00:00
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','websocket','adaptercfgupdate','replicaVar','independentMnode','previous'])
2022-04-18 08:09:03 +00:00
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')
2022-05-27 11:00:48 +00:00
tdLog.printNoPrefix('-d update cfg dict, base64 json str')
tdLog.printNoPrefix('-k not kill valgrind processer')
2022-05-28 07:30:14 +00:00
tdLog.printNoPrefix('-e eval str to run')
2022-07-10 08:12:09 +00:00
tdLog.printNoPrefix('-N start dnodes numbers in clusters')
2022-06-23 10:01:49 +00:00
tdLog.printNoPrefix('-M create mnode numbers in clusters')
2022-07-02 07:28:45 +00:00
tdLog.printNoPrefix('-Q set queryPolicy in one dnode')
2022-07-10 08:12:09 +00:00
tdLog.printNoPrefix('-C create Dnode Numbers in one cluster')
2022-07-13 08:55:35 +00:00
tdLog.printNoPrefix('-R restful realization form')
2023-09-01 07:45:31 +00:00
tdLog.printNoPrefix('-W websocket connection')
2022-07-19 08:39:50 +00:00
tdLog.printNoPrefix('-D taosadapter update cfg dict ')
tdLog.printNoPrefix('-n the number of replicas')
tdLog.printNoPrefix('-i independentMnode Mnode')
2022-11-19 02:54:38 +00:00
tdLog.printNoPrefix('-a address sanitizer mode')
tdLog.printNoPrefix('-P run case with [P]revious cluster, do not create new cluster to run case.')
2022-04-18 08:09:03 +00:00
sys.exit(0)
2022-07-13 01:52:03 +00:00
if key in ['-r', '--restart']:
2022-04-18 08:09:03 +00:00
restart = True
if key in ['-f', '--file']:
fileName = value
if key in ['-p', '--path']:
deployPath = value
if key in ['-m', '--master']:
masterIp = value
if key in ['-l', '--logSql']:
if (value.upper() == "TRUE"):
logSql = True
elif (value.upper() == "FALSE"):
logSql = False
else:
tdLog.printNoPrefix("logSql value %s is invalid" % logSql)
sys.exit(0)
if key in ['-c', '--cluster']:
testCluster = True
if key in ['-g', '--valgrind']:
valgrind = 1
if key in ['-s', '--stop']:
stop = 1
2022-05-27 11:00:48 +00:00
if key in ['-d', '--updateCfgDict']:
try:
updateCfgDict = eval(base64.b64decode(value.encode()).decode())
except:
print('updateCfgDict convert fail.')
sys.exit(0)
2022-05-28 07:30:14 +00:00
if key in ['-k', '--killValgrind']:
2023-09-06 09:15:04 +00:00
killValgrind = 1
2022-05-28 07:30:14 +00:00
if key in ['-e', '--execCmd']:
try:
execCmd = base64.b64decode(value.encode()).decode()
except:
2022-07-19 08:39:50 +00:00
print('execCmd run fail.')
2022-05-28 07:30:14 +00:00
sys.exit(0)
2022-06-22 04:07:42 +00:00
if key in ['-N', '--dnodeNums']:
dnodeNums = value
2022-06-23 10:01:49 +00:00
if key in ['-M', '--mnodeNums']:
mnodeNums = value
2022-07-02 07:28:45 +00:00
if key in ['-Q', '--queryPolicy']:
queryPolicy = value
2022-07-10 08:12:09 +00:00
if key in ['-C', '--createDnodeNums']:
createDnodeNums = value
if key in ['-i', '--independentMnode']:
independentMnode = value
2022-07-13 08:55:35 +00:00
if key in ['-R', '--restful']:
restful = True
2023-09-01 07:45:31 +00:00
if key in ['-W', '--websocket']:
websocket = True
2022-07-13 08:55:35 +00:00
2022-11-19 02:54:38 +00:00
if key in ['-a', '--asan']:
asan = True
2022-07-19 08:39:50 +00:00
if key in ['-D', '--adaptercfgupdate']:
try:
adaptercfgupdate = eval(base64.b64decode(value.encode()).decode())
except:
print('adapter cfg update convert fail.')
sys.exit(0)
if key in ['-n', '--replicaVar']:
replicaVar = value
if key in ['-P', '--previous']:
previousCluster = True
#
# do exeCmd command
#
2022-05-28 07:30:14 +00:00
if not execCmd == "":
2023-09-01 07:45:31 +00:00
if restful or websocket:
2022-07-19 08:39:50 +00:00
tAdapter.init(deployPath)
else:
tdDnodes.init(deployPath)
2022-06-06 16:23:23 +00:00
print(execCmd)
2022-05-28 07:30:14 +00:00
exec(execCmd)
quit()
#
# do stop option
#
2022-04-18 08:09:03 +00:00
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
psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled
processID = subprocess.check_output(psCmd, shell=True)
while(processID):
os.system(killCmd)
time.sleep(1)
processID = subprocess.check_output(psCmd, shell=True)
for port in range(6030, 6041):
2022-08-12 10:00:11 +00:00
usePortPID = "lsof -i tcp:%d | grep LISTEN | awk '{print $2}'" % port
2022-04-18 08:09:03 +00:00
processID = subprocess.check_output(usePortPID, shell=True)
if processID:
killCmd = "kill -TERM %s" % processID
os.system(killCmd)
fuserCmd = "fuser -k -n tcp %d" % port
os.system(fuserCmd)
if valgrind:
time.sleep(2)
2023-09-01 07:45:31 +00:00
if restful or websocket:
2022-11-09 06:39:13 +00:00
toBeKilled = "taosadapter"
2022-07-19 08:39:50 +00:00
2022-08-12 10:00:11 +00:00
# killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" % toBeKilled
killCmd = f"pkill {toBeKilled}"
2022-07-19 08:39:50 +00:00
psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled
2022-08-12 10:00:11 +00:00
# psCmd = f"pgrep {toBeKilled}"
2022-07-19 08:39:50 +00:00
processID = subprocess.check_output(psCmd, shell=True)
while(processID):
os.system(killCmd)
time.sleep(1)
processID = subprocess.check_output(psCmd, shell=True)
2022-08-12 10:00:11 +00:00
port = 6041
usePortPID = f"lsof -i tcp:{port} | grep LISTEN | awk '{{print $2}}'"
processID = subprocess.check_output(usePortPID, shell=True)
2022-07-19 08:39:50 +00:00
2022-08-12 10:00:11 +00:00
if processID:
killCmd = f"kill -TERM {processID}"
os.system(killCmd)
fuserCmd = f"fuser -k -n tcp {port}"
os.system(fuserCmd)
2022-07-19 08:39:50 +00:00
tdLog.info('stop taosadapter')
2022-04-18 08:09:03 +00:00
tdLog.info('stop All dnodes')
2022-07-13 01:52:03 +00:00
#
# get hostname
#
2022-04-18 08:09:03 +00:00
if masterIp == "":
2022-06-09 03:48:41 +00:00
host = socket.gethostname()
2022-04-18 08:09:03 +00:00
else:
2022-05-30 02:38:29 +00:00
try:
config = eval(masterIp)
host = config["host"]
except Exception as r:
host = masterIp
2022-04-18 08:09:03 +00:00
tdLog.info("Procedures for tdengine deployed in %s" % (host))
#
# do previousCluster option
#
if previousCluster:
tdDnodes.init(deployPath, masterIp)
runOnPreviousCluster(host, tdDnodes.getSimCfgPath(), fileName)
tdLog.info("run on previous cluster end.")
quit()
#
# windows run
#
2022-06-14 11:31:45 +00:00
if platform.system().lower() == 'windows':
2022-06-25 08:14:54 +00:00
fileName = fileName.replace("/", os.sep)
2022-06-28 11:08:48 +00:00
if (masterIp == "" and not fileName == "0-others\\udf_create.py"):
2022-06-14 11:31:45 +00:00
threading.Thread(target=checkRunTimeError,daemon=True).start()
2022-04-18 08:09:03 +00:00
tdLog.info("Procedures for testing self-deployment")
2022-05-28 07:30:14 +00:00
tdDnodes.init(deployPath, masterIp)
2022-05-27 11:00:48 +00:00
tdDnodes.setTestCluster(testCluster)
tdDnodes.setValgrind(valgrind)
tdDnodes.stopAll()
key_word = 'tdCases.addWindows'
is_test_framework = 0
try:
2022-06-07 01:49:09 +00:00
if key_word in open(fileName, encoding='UTF-8').read():
2022-05-27 11:00:48 +00:00
is_test_framework = 1
2022-06-09 03:48:41 +00:00
except Exception as r:
print(r)
2022-05-27 11:00:48 +00:00
updateCfgDictStr = ''
2022-07-19 08:39:50 +00:00
# adapter_cfg_dict_str = ''
2022-05-27 11:00:48 +00:00
if is_test_framework:
moduleName = fileName.replace(".py", "").replace(os.sep, ".")
uModule = importlib.import_module(moduleName)
try:
ucase = uModule.TDTestCase()
2022-06-25 08:14:54 +00:00
if ((json.dumps(updateCfgDict) == '{}') and hasattr(ucase, 'updatecfgDict')):
2022-05-27 11:00:48 +00:00
updateCfgDict = ucase.updatecfgDict
updateCfgDictStr = "-d %s"%base64.b64encode(json.dumps(updateCfgDict).encode()).decode()
2022-07-19 08:39:50 +00:00
if ((json.dumps(adapter_cfg_dict) == '{}') and hasattr(ucase, 'taosadapter_cfg_dict')):
adapter_cfg_dict = ucase.taosadapter_cfg_dict
# adapter_cfg_dict_str = f"-D {base64.b64encode(toml.dumps(adapter_cfg_dict).encode()).decode()}"
2022-06-09 03:48:41 +00:00
except Exception as r:
print(r)
2022-05-27 11:00:48 +00:00
else:
pass
# if restful:
tAdapter.init(deployPath, masterIp)
tAdapter.stop(force_kill=True)
2022-07-19 08:39:50 +00:00
2022-06-25 08:14:54 +00:00
if dnodeNums == 1 :
tdDnodes.deploy(1,updateCfgDict)
tdDnodes.start(1)
tdCases.logSql(logSql)
2023-09-01 07:45:31 +00:00
if restful or websocket:
2022-07-19 08:39:50 +00:00
tAdapter.deploy(adapter_cfg_dict)
tAdapter.start()
2022-07-14 05:58:23 +00:00
if queryPolicy != 1:
queryPolicy=int(queryPolicy)
2022-07-19 08:39:50 +00:00
if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
2023-09-01 07:45:31 +00:00
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
2022-07-19 08:39:50 +00:00
else:
conn = taos.connect(host,config=tdDnodes.getSimCfgPath())
cursor = conn.cursor()
cursor.execute("create qnode on dnode 1")
cursor.execute(f'alter local "queryPolicy" "{queryPolicy}"')
cursor.execute("show local variables")
res = cursor.fetchall()
for i in range(cursor.rowcount):
if res[i][0] == "queryPolicy" :
if int(res[i][1]) == int(queryPolicy):
2023-02-27 09:54:31 +00:00
tdLog.info(f'alter queryPolicy to {queryPolicy} successfully')
2024-04-16 03:29:19 +00:00
cursor.close()
2022-07-19 08:39:50 +00:00
else:
tdLog.debug(res)
tdLog.exit(f"alter queryPolicy to {queryPolicy} failed")
2022-06-25 08:14:54 +00:00
else :
tdLog.debug("create an cluster with %s nodes and make %s dnode as independent mnode"%(dnodeNums,mnodeNums))
dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums, mnodeNums=mnodeNums, independentMnode=independentMnode)
2022-06-25 08:14:54 +00:00
tdDnodes = ClusterDnodes(dnodeslist)
tdDnodes.init(deployPath, masterIp)
tdDnodes.setTestCluster(testCluster)
tdDnodes.setValgrind(valgrind)
tdDnodes.stopAll()
for dnode in tdDnodes.dnodes:
tdDnodes.deploy(dnode.index, updateCfgDict)
2022-06-25 08:14:54 +00:00
for dnode in tdDnodes.dnodes:
tdDnodes.starttaosd(dnode.index)
tdCases.logSql(logSql)
2023-09-01 07:45:31 +00:00
if restful or websocket:
2022-07-19 08:39:50 +00:00
tAdapter.deploy(adapter_cfg_dict)
tAdapter.start()
2023-09-01 07:45:31 +00:00
if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
2023-09-01 07:45:31 +00:00
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else:
conn = taos.connect(host,config=tdDnodes.getSimCfgPath())
# tdLog.info(tdDnodes.getSimCfgPath(),host)
2022-07-10 08:12:09 +00:00
if createDnodeNums == 1:
createDnodeNums=dnodeNums
else:
createDnodeNums=createDnodeNums
cluster.create_dnode(conn,createDnodeNums)
cluster.create_mnode(conn,mnodeNums)
2022-06-25 08:14:54 +00:00
try:
if cluster.check_dnode(conn) :
print("check dnode ready")
except Exception as r:
print(r)
if queryPolicy != 1:
queryPolicy=int(queryPolicy)
if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
2023-09-01 07:45:31 +00:00
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else:
conn = taos.connect(host,config=tdDnodes.getSimCfgPath())
cursor = conn.cursor()
cursor.execute("create qnode on dnode 1")
cursor.execute(f'alter local "queryPolicy" "{queryPolicy}"')
cursor.execute("show local variables")
res = cursor.fetchall()
for i in range(cursor.rowcount):
if res[i][0] == "queryPolicy" :
if int(res[i][1]) == int(queryPolicy):
2023-02-27 09:54:31 +00:00
tdLog.info(f'alter queryPolicy to {queryPolicy} successfully')
2024-04-16 03:29:19 +00:00
cursor.close()
else:
tdLog.debug(res)
tdLog.exit(f"alter queryPolicy to {queryPolicy} failed")
2022-06-25 08:14:54 +00:00
if ucase is not None and hasattr(ucase, 'noConn') and ucase.noConn == True:
conn = None
else:
2023-09-01 07:45:31 +00:00
if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
2022-07-13 08:55:35 +00:00
else:
2023-09-01 07:45:31 +00:00
conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
if testCluster:
tdLog.info("Procedures for testing cluster")
if fileName == "all":
tdCases.runAllCluster()
else:
tdCases.runOneCluster(fileName)
2022-05-27 11:00:48 +00:00
else:
tdLog.info("Procedures for testing self-deployment")
2023-09-01 07:45:31 +00:00
if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else:
2023-09-01 07:45:31 +00:00
conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
if fileName == "all":
tdCases.runAllWindows(conn)
else:
tdCases.runOneWindows(conn, fileName, replicaVar)
if restart:
if fileName == "all":
tdLog.info("not need to query ")
else:
sp = fileName.rsplit(".", 1)
if len(sp) == 2 and sp[1] == "py":
tdDnodes.stopAll()
tdDnodes.start(1)
time.sleep(1)
2023-09-01 07:45:31 +00:00
if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
2023-09-01 07:45:31 +00:00
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("query test after taosd restart")
tdCases.runOneWindows(conn, sp[0] + "_" + "restart.py", replicaVar)
else:
tdLog.info("not need to query")
2022-04-18 08:09:03 +00:00
else:
tdDnodes.setKillValgrind(killValgrind)
2022-05-28 07:30:14 +00:00
tdDnodes.init(deployPath, masterIp)
2022-04-18 08:09:03 +00:00
tdDnodes.setTestCluster(testCluster)
tdDnodes.setValgrind(valgrind)
2022-11-19 02:54:38 +00:00
tdDnodes.setAsan(asan)
2022-04-18 08:09:03 +00:00
tdDnodes.stopAll()
is_test_framework = 0
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()
2022-05-27 11:00:48 +00:00
if (json.dumps(updateCfgDict) == '{}'):
updateCfgDict = ucase.updatecfgDict
2022-07-19 08:39:50 +00:00
if (json.dumps(adapter_cfg_dict) == '{}'):
adapter_cfg_dict = ucase.taosadapter_cfg_dict
2022-05-27 11:00:48 +00:00
except:
pass
2022-07-19 08:39:50 +00:00
2023-09-01 07:45:31 +00:00
if restful or websocket:
2022-07-19 08:39:50 +00:00
tAdapter.init(deployPath, masterIp)
tAdapter.stop(force_kill=True)
2022-06-22 04:07:42 +00:00
if dnodeNums == 1 :
# dnode is one
2022-06-22 04:07:42 +00:00
tdDnodes.deploy(1,updateCfgDict)
tdDnodes.start(1)
tdCases.logSql(logSql)
2022-07-19 08:39:50 +00:00
2023-09-01 07:45:31 +00:00
if restful or websocket:
2022-07-19 08:39:50 +00:00
tAdapter.deploy(adapter_cfg_dict)
tAdapter.start()
2022-07-02 07:28:45 +00:00
if queryPolicy != 1:
queryPolicy=int(queryPolicy)
2023-09-01 07:45:31 +00:00
if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
2023-09-01 07:45:31 +00:00
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else:
conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
2022-07-13 08:55:35 +00:00
# tdSql.init(conn.cursor())
# tdSql.execute("create qnode on dnode 1")
# tdSql.execute('alter local "queryPolicy" "%d"'%queryPolicy)
# tdSql.query("show local variables;")
# for i in range(tdSql.queryRows):
# if tdSql.queryResult[i][0] == "queryPolicy" :
# if int(tdSql.queryResult[i][1]) == int(queryPolicy):
2023-02-27 09:54:31 +00:00
# tdLog.info('alter queryPolicy to %d successfully'%queryPolicy)
2022-07-13 08:55:35 +00:00
# else :
# tdLog.debug(tdSql.queryResult)
# tdLog.exit("alter queryPolicy to %d failed"%queryPolicy)
cursor = conn.cursor()
cursor.execute("create qnode on dnode 1")
cursor.execute(f'alter local "queryPolicy" "{queryPolicy}"')
cursor.execute("show local variables")
res = cursor.fetchall()
for i in range(cursor.rowcount):
if res[i][0] == "queryPolicy" :
if int(res[i][1]) == int(queryPolicy):
2023-02-27 09:54:31 +00:00
tdLog.info(f'alter queryPolicy to {queryPolicy} successfully')
2024-04-15 03:09:24 +00:00
cursor.close()
2022-07-13 08:55:35 +00:00
else:
tdLog.debug(res)
tdLog.exit(f"alter queryPolicy to {queryPolicy} failed")
2022-06-22 04:07:42 +00:00
else :
# dnode > 1 cluster
2022-06-23 10:01:49 +00:00
tdLog.debug("create an cluster with %s nodes and make %s dnode as independent mnode"%(dnodeNums,mnodeNums))
2023-09-01 05:24:47 +00:00
print(independentMnode,"independentMnode valuse")
dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums, mnodeNums=mnodeNums, independentMnode=independentMnode)
2022-06-22 04:07:42 +00:00
tdDnodes = ClusterDnodes(dnodeslist)
tdDnodes.init(deployPath, masterIp)
tdDnodes.setTestCluster(testCluster)
tdDnodes.setValgrind(valgrind)
2022-11-24 05:52:09 +00:00
tdDnodes.setAsan(asan)
2022-06-22 04:07:42 +00:00
tdDnodes.stopAll()
for dnode in tdDnodes.dnodes:
2023-11-16 13:19:58 +00:00
tdDnodes.deploy(dnode.index,updateCfgDict)
2022-06-22 04:07:42 +00:00
for dnode in tdDnodes.dnodes:
tdDnodes.starttaosd(dnode.index)
tdCases.logSql(logSql)
2022-07-19 08:39:50 +00:00
2023-09-01 07:45:31 +00:00
if restful or websocket:
2022-07-19 08:39:50 +00:00
tAdapter.deploy(adapter_cfg_dict)
tAdapter.start()
# create taos connect
2023-09-01 07:45:31 +00:00
if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
2022-07-13 08:55:35 +00:00
else:
2023-09-01 07:45:31 +00:00
conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
2022-06-22 04:07:42 +00:00
print(tdDnodes.getSimCfgPath(),host)
2022-07-10 08:12:09 +00:00
if createDnodeNums == 1:
createDnodeNums=dnodeNums
else:
createDnodeNums=createDnodeNums
cluster.create_dnode(conn,createDnodeNums)
cluster.create_mnode(conn,mnodeNums)
2022-06-22 04:07:42 +00:00
try:
if cluster.check_dnode(conn) :
print("check dnode ready")
except Exception as r:
print(r)
2022-07-13 01:52:03 +00:00
# do queryPolicy option
if queryPolicy != 1:
queryPolicy=int(queryPolicy)
if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
2023-09-01 07:45:31 +00:00
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else:
2023-09-01 07:45:31 +00:00
conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
cursor = conn.cursor()
cursor.execute("create qnode on dnode 1")
cursor.execute(f'alter local "queryPolicy" "{queryPolicy}"')
cursor.execute("show local variables")
res = cursor.fetchall()
for i in range(cursor.rowcount):
if res[i][0] == "queryPolicy" :
if int(res[i][1]) == int(queryPolicy):
2023-02-27 09:54:31 +00:00
tdLog.info(f'alter queryPolicy to {queryPolicy} successfully')
2024-04-16 03:29:19 +00:00
cursor.close()
else:
tdLog.debug(res)
tdLog.exit(f"alter queryPolicy to {queryPolicy} failed")
2022-07-13 01:52:03 +00:00
# run case
2022-04-18 08:09:03 +00:00
if testCluster:
tdLog.info("Procedures for testing cluster")
if fileName == "all":
tdCases.runAllCluster()
else:
tdCases.runOneCluster(fileName)
else:
tdLog.info("Procedures for testing self-deployment")
2023-09-01 07:45:31 +00:00
if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
2022-07-13 08:55:35 +00:00
else:
2023-09-01 07:45:31 +00:00
conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
2022-07-13 01:52:03 +00:00
2022-04-18 08:09:03 +00:00
if fileName == "all":
tdCases.runAllLinux(conn)
else:
tdCases.runOneLinux(conn, fileName, replicaVar)
2022-07-13 01:52:03 +00:00
# do restart option
2022-04-18 08:09:03 +00:00
if restart:
if fileName == "all":
tdLog.info("not need to query ")
2022-07-13 01:52:03 +00:00
else:
2022-04-18 08:09:03 +00:00
sp = fileName.rsplit(".", 1)
if len(sp) == 2 and sp[1] == "py":
tdDnodes.stopAll()
tdDnodes.start(1)
2022-07-13 01:52:03 +00:00
time.sleep(1)
2023-09-01 07:45:31 +00:00
if restful:
conn = taosrest.connect(url=f"http://{host}:6041",timezone="utc")
2023-09-01 07:45:31 +00:00
elif websocket:
conn = taosws.connect(f"taosws://root:taosdata@{host}:6041")
else:
conn = taos.connect(host=f"{host}", config=tdDnodes.getSimCfgPath())
2022-04-18 08:09:03 +00:00
tdLog.info("Procedures for tdengine deployed in %s" % (host))
tdLog.info("query test after taosd restart")
tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py", replicaVar)
2022-04-18 08:09:03 +00:00
else:
tdLog.info("not need to query")
2022-07-13 08:55:35 +00:00
# close for end
2022-06-25 08:14:54 +00:00
if conn is not None:
conn.close()
2022-11-19 02:54:38 +00:00
if asan:
2024-02-05 09:11:39 +00:00
# tdDnodes.StopAllSigint()
2022-11-20 09:29:16 +00:00
tdLog.info("Address sanitizer mode finished")
2022-07-13 09:29:59 +00:00
sys.exit(0)