Merge pull request #13157 from taosdata/fix/ZhiqiangWang/TD-15849-case-run-remote-taosd

fix(os): case run remote taosd
This commit is contained in:
Zhiqiang Wang 2022-05-28 17:35:12 +08:00 committed by GitHub
commit dc719f3c2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 124 additions and 130 deletions

View File

@ -17,6 +17,10 @@ import os.path
import platform import platform
import subprocess import subprocess
from time import sleep from time import sleep
import base64
import json
import copy
from fabric2 import Connection
from util.log import * from util.log import *
@ -111,6 +115,7 @@ class TDDnode:
self.deployed = 0 self.deployed = 0
self.testCluster = False self.testCluster = False
self.valgrind = 0 self.valgrind = 0
self.remoteIP = ""
self.cfgDict = { self.cfgDict = {
"walLevel": "2", "walLevel": "2",
"fsync": "1000", "fsync": "1000",
@ -137,8 +142,9 @@ class TDDnode:
"telemetryReporting": "0" "telemetryReporting": "0"
} }
def init(self, path): def init(self, path, remoteIP = ""):
self.path = path self.path = path
self.remoteIP = remoteIP
def setTestCluster(self, value): def setTestCluster(self, value):
self.testCluster = value self.testCluster = value
@ -162,6 +168,24 @@ class TDDnode:
def addExtraCfg(self, option, value): def addExtraCfg(self, option, value):
self.cfgDict.update({option: value}) self.cfgDict.update({option: value})
def remoteExec(self, updateCfgDict, execCmd):
remote_conn = Connection(self.remoteIP, port=22, user='root', connect_kwargs={'password':'123456'})
remote_top_dir = '~/test'
valgrindStr = ''
if (self.valgrind==1):
valgrindStr = '-g'
remoteCfgDict = copy.deepcopy(updateCfgDict)
if ("logDir" in remoteCfgDict):
del remoteCfgDict["logDir"]
if ("dataDir" in remoteCfgDict):
del remoteCfgDict["dataDir"]
if ("cfgDir" in remoteCfgDict):
del remoteCfgDict["cfgDir"]
remoteCfgDictStr = base64.b64encode(json.dumps(remoteCfgDict).encode()).decode()
execCmdStr = base64.b64encode(execCmd.encode()).decode()
with remote_conn.cd((remote_top_dir+sys.path[0].replace(self.path, '')).replace('\\','/')):
remote_conn.run("python3 ./test.py %s -d %s -e %s"%(valgrindStr,remoteCfgDictStr,execCmdStr))
def deploy(self, *updatecfgDict): def deploy(self, *updatecfgDict):
self.logDir = "%s/sim/dnode%d/log" % (self.path, self.index) self.logDir = "%s/sim/dnode%d/log" % (self.path, self.index)
self.dataDir = "%s/sim/dnode%d/data" % (self.path, self.index) self.dataDir = "%s/sim/dnode%d/data" % (self.path, self.index)
@ -229,8 +253,11 @@ class TDDnode:
self.cfg(value, key) self.cfg(value, key)
else: else:
self.addExtraCfg(key, value) self.addExtraCfg(key, value)
for key, value in self.cfgDict.items(): if (self.remoteIP == ""):
self.cfg(key, value) for key, value in self.cfgDict.items():
self.cfg(key, value)
else:
self.remoteExec(self.cfgDict, "tdDnodes.deploy(%d,updateCfgDict)"%self.index)
self.deployed = 1 self.deployed = 1
tdLog.debug( tdLog.debug(
@ -268,117 +295,68 @@ class TDDnode:
tdLog.exit("dnode:%d is not deployed" % (self.index)) tdLog.exit("dnode:%d is not deployed" % (self.index))
if self.valgrind == 0: if self.valgrind == 0:
cmd = "nohup %s -c %s > /dev/null 2>&1 & " % ( if platform.system().lower() == 'windows':
binPath, self.cfgDir) cmd = "mintty -h never -w hide %s -c %s" % (
binPath, self.cfgDir)
else:
cmd = "nohup %s -c %s > /dev/null 2>&1 & " % (
binPath, self.cfgDir)
else: else:
valgrindCmdline = "valgrind --log-file=\"%s/../log/valgrind.log\" --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes"%self.cfgDir valgrindCmdline = "valgrind --log-file=\"%s/../log/valgrind.log\" --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes"%self.cfgDir
cmd = "nohup %s %s -c %s 2>&1 & " % ( if platform.system().lower() == 'windows':
valgrindCmdline, binPath, self.cfgDir) cmd = "mintty -h never -w hide %s %s -c %s" % (
valgrindCmdline, binPath, self.cfgDir)
else:
cmd = "nohup %s %s -c %s 2>&1 & " % (
valgrindCmdline, binPath, self.cfgDir)
print(cmd) print(cmd)
if os.system(cmd) != 0: if (not self.remoteIP == ""):
tdLog.exit(cmd) self.remoteExec(self.cfgDict, "tdDnodes.deploy(%d,updateCfgDict)\ntdDnodes.start(%d)"%(self.index, self.index))
self.running = 1 self.running = 1
tdLog.debug("dnode:%d is running with %s " % (self.index, cmd))
if self.valgrind == 0:
time.sleep(0.1)
key = 'from offline to online'
bkey = bytes(key, encoding="utf8")
logFile = self.logDir + "/taosdlog.0"
i = 0
while not os.path.exists(logFile):
sleep(0.1)
i += 1
if i > 50:
break
popen = subprocess.Popen(
'tail -f ' + logFile,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
pid = popen.pid
# print('Popen.pid:' + str(pid))
timeout = time.time() + 60 * 2
while True:
line = popen.stdout.readline().strip()
if bkey in line:
popen.kill()
break
if time.time() > timeout:
tdLog.exit('wait too long for taosd start')
tdLog.debug("the dnode:%d has been started." % (self.index))
else: else:
tdLog.debug( if os.system(cmd) != 0:
"wait 10 seconds for the dnode:%d to start." % tdLog.exit(cmd)
(self.index)) self.running = 1
time.sleep(10) print("dnode:%d is running with %s " % (self.index, cmd))
tdLog.debug("dnode:%d is running with %s " % (self.index, cmd))
# time.sleep(5) if self.valgrind == 0:
def startWin(self): time.sleep(0.1)
binPath = self.getPath("taosd.exe") key = 'from offline to online'
bkey = bytes(key, encoding="utf8")
if (binPath == ""): logFile = self.logDir + "/taosdlog.0"
tdLog.exit("taosd.exe not found!") i = 0
else: while not os.path.exists(logFile):
tdLog.info("taosd.exe found: %s" % binPath) sleep(0.1)
i += 1
taosadapterBinPath = self.getPath("taosadapter.exe") if i > 50:
if (taosadapterBinPath == ""): break
tdLog.info("taosAdapter.exe not found!") tailCmdStr = 'tail -f '
else: if platform.system().lower() == 'windows':
tdLog.info("taosAdapter.exe found in %s" % taosadapterBuildPath) tailCmdStr = 'tail -n +0 -f '
popen = subprocess.Popen(
if self.deployed == 0: tailCmdStr + logFile,
tdLog.exit("dnode:%d is not deployed" % (self.index)) stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cmd = "mintty -h never -w hide %s -c %s" % ( shell=True)
binPath, self.cfgDir) pid = popen.pid
# print('Popen.pid:' + str(pid))
if (taosadapterBinPath != ""): timeout = time.time() + 60 * 2
taosadapterCmd = "mintty -h never -w hide %s --monitor.writeToTD=false " % ( while True:
taosadapterBinPath) line = popen.stdout.readline().strip()
if os.system(taosadapterCmd) != 0: if bkey in line:
tdLog.exit(taosadapterCmd) popen.kill()
break
if os.system(cmd) != 0: if time.time() > timeout:
tdLog.exit(cmd) tdLog.exit('wait too long for taosd start')
tdLog.debug("the dnode:%d has been started." % (self.index))
self.running = 1 else:
tdLog.debug("dnode:%d is running with %s " % (self.index, cmd)) tdLog.debug(
if self.valgrind == 0: "wait 10 seconds for the dnode:%d to start." %
time.sleep(0.1) (self.index))
key = 'from offline to online' time.sleep(10)
bkey = bytes(key, encoding="utf8")
logFile = self.logDir + "/taosdlog.0"
i = 0
while not os.path.exists(logFile):
sleep(0.1)
i += 1
if i > 50:
break
popen = subprocess.Popen(
'tail -n +0 -f ' + logFile,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
pid = popen.pid
# print('Popen.pid:' + str(pid))
timeout = time.time() + 60 * 2
while True:
line = popen.stdout.readline().strip()
if bkey in line:
popen.kill()
break
if time.time() > timeout:
tdLog.exit('wait too long for taosd start')
tdLog.debug("the dnode:%d has been started." % (self.index))
else:
tdLog.debug(
"wait 10 seconds for the dnode:%d to start." %
(self.index))
time.sleep(10)
def startWithoutSleep(self): def startWithoutSleep(self):
binPath = self.getPath() binPath = self.getPath()
@ -402,12 +380,19 @@ class TDDnode:
print(cmd) print(cmd)
if os.system(cmd) != 0: if (self.remoteIP == ""):
tdLog.exit(cmd) if os.system(cmd) != 0:
tdLog.exit(cmd)
else:
self.remoteExec(self.cfgDict, "tdDnodes.deploy(%d,updateCfgDict)\ntdDnodes.startWithoutSleep(%d)"%(self.index, self.index))
self.running = 1 self.running = 1
tdLog.debug("dnode:%d is running with %s " % (self.index, cmd)) tdLog.debug("dnode:%d is running with %s " % (self.index, cmd))
def stop(self): def stop(self):
if (not self.remoteIP == ""):
self.remoteExec(self.cfgDict, "tdDnodes.stop(%d)"%self.index)
return
if self.valgrind == 0: if self.valgrind == 0:
toBeKilled = "taosd" toBeKilled = "taosd"
else: else:
@ -435,6 +420,9 @@ class TDDnode:
tdLog.debug("dnode:%d is stopped by kill -INT" % (self.index)) tdLog.debug("dnode:%d is stopped by kill -INT" % (self.index))
def forcestop(self): def forcestop(self):
if (not self.remoteIP == ""):
self.remoteExec(self.cfgDict, "tdDnodes.forcestop(%d)"%self.index)
return
if self.valgrind == 0: if self.valgrind == 0:
toBeKilled = "taosd" toBeKilled = "taosd"
else: else:
@ -499,8 +487,10 @@ class TDDnodes:
self.dnodes.append(TDDnode(9)) self.dnodes.append(TDDnode(9))
self.dnodes.append(TDDnode(10)) self.dnodes.append(TDDnode(10))
self.simDeployed = False self.simDeployed = False
self.testCluster = False
self.valgrind = 0
def init(self, path): def init(self, path, remoteIP = ""):
psCmd = "ps -ef|grep -w taosd| grep -v grep| grep -v defunct | awk '{print $2}'" psCmd = "ps -ef|grep -w taosd| grep -v grep| grep -v defunct | awk '{print $2}'"
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8") processID = subprocess.check_output(psCmd, shell=True).decode("utf-8")
while(processID): while(processID):
@ -520,9 +510,9 @@ class TDDnodes:
psCmd, shell=True).decode("utf-8") psCmd, shell=True).decode("utf-8")
binPath = self.dnodes[0].getPath() + "/../../../" binPath = self.dnodes[0].getPath() + "/../../../"
tdLog.debug("binPath %s" % (binPath)) # tdLog.debug("binPath %s" % (binPath))
binPath = os.path.realpath(binPath) binPath = os.path.realpath(binPath)
tdLog.debug("binPath real path %s" % (binPath)) # tdLog.debug("binPath real path %s" % (binPath))
# cmd = "sudo cp %s/build/lib/libtaos.so /usr/local/lib/taos/" % (binPath) # cmd = "sudo cp %s/build/lib/libtaos.so /usr/local/lib/taos/" % (binPath)
# tdLog.debug(cmd) # tdLog.debug(cmd)
@ -545,7 +535,7 @@ class TDDnodes:
self.path = os.path.realpath(path) self.path = os.path.realpath(path)
for i in range(len(self.dnodes)): for i in range(len(self.dnodes)):
self.dnodes[i].init(self.path) self.dnodes[i].init(self.path, remoteIP)
self.sim = TDSimClient(self.path) self.sim = TDSimClient(self.path)
def setTestCluster(self, value): def setTestCluster(self, value):
@ -572,10 +562,7 @@ class TDDnodes:
def start(self, index): def start(self, index):
self.check(index) self.check(index)
if platform.system().lower() == 'windows': self.dnodes[index - 1].start()
self.dnodes[index - 1].startWin()
else:
self.dnodes[index - 1].start()
def startWithoutSleep(self, index): def startWithoutSleep(self, index):
self.check(index) self.check(index)

View File

@ -44,8 +44,9 @@ if __name__ == "__main__":
if platform.system().lower() == 'windows': if platform.system().lower() == 'windows':
windows = 1 windows = 1
updateCfgDict = {} updateCfgDict = {}
opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:', [ execCmd = ""
'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict']) opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:e:', [
'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'execCmd'])
for key, value in opts: for key, value in opts:
if key in ['-h', '--help']: if key in ['-h', '--help']:
tdLog.printNoPrefix( tdLog.printNoPrefix(
@ -59,6 +60,7 @@ if __name__ == "__main__":
tdLog.printNoPrefix('-g valgrind Test Flag') tdLog.printNoPrefix('-g valgrind Test Flag')
tdLog.printNoPrefix('-r taosd restart test') tdLog.printNoPrefix('-r taosd restart test')
tdLog.printNoPrefix('-d update cfg dict, base64 json str') tdLog.printNoPrefix('-d update cfg dict, base64 json str')
tdLog.printNoPrefix('-e eval str to run')
sys.exit(0) sys.exit(0)
if key in ['-r', '--restart']: if key in ['-r', '--restart']:
@ -97,6 +99,19 @@ if __name__ == "__main__":
except: except:
print('updateCfgDict convert fail.') print('updateCfgDict convert fail.')
sys.exit(0) sys.exit(0)
if key in ['-e', '--execCmd']:
try:
execCmd = base64.b64decode(value.encode()).decode()
except:
print('updateCfgDict convert fail.')
sys.exit(0)
if not execCmd == "":
tdDnodes.init(deployPath)
exec(execCmd)
quit()
if (stop != 0): if (stop != 0):
if (valgrind == 0): if (valgrind == 0):
toBeKilled = "taosd" toBeKilled = "taosd"
@ -136,7 +151,7 @@ if __name__ == "__main__":
if windows: if windows:
tdCases.logSql(logSql) tdCases.logSql(logSql)
tdLog.info("Procedures for testing self-deployment") tdLog.info("Procedures for testing self-deployment")
tdDnodes.init(deployPath) tdDnodes.init(deployPath, masterIp)
tdDnodes.setTestCluster(testCluster) tdDnodes.setTestCluster(testCluster)
tdDnodes.setValgrind(valgrind) tdDnodes.setValgrind(valgrind)
tdDnodes.stopAll() tdDnodes.stopAll()
@ -161,15 +176,7 @@ if __name__ == "__main__":
else: else:
pass pass
tdDnodes.deploy(1,updateCfgDict) tdDnodes.deploy(1,updateCfgDict)
if masterIp == "" or masterIp == "localhost": tdDnodes.start(1)
tdDnodes.start(1)
else:
remote_conn = Connection("root@%s"%host)
with remote_conn.cd('/var/lib/jenkins/workspace/TDinternal/community/tests/pytest'):
remote_conn.run("python3 ./test.py %s"%updateCfgDictStr)
# print("docker exec -d cross_platform bash -c \"cd ~/test/community/tests/system-test && python3 ./test.py %s\""%updateCfgDictStr)
# os.system("docker exec -d cross_platform bash -c \"cd ~/test/community/tests/system-test && (ps -aux | grep taosd | head -n 1 | awk '{print $2}' | xargs kill -9) && rm -rf /root/test/sim/dnode1/data/ && python3 ./test.py %s\""%updateCfgDictStr)
# time.sleep(2)
conn = taos.connect( conn = taos.connect(
host="%s"%(host), host="%s"%(host),
config=tdDnodes.sim.getCfgDir()) config=tdDnodes.sim.getCfgDir())
@ -178,7 +185,7 @@ if __name__ == "__main__":
else: else:
tdCases.runAllWindows(conn) tdCases.runAllWindows(conn)
else: else:
tdDnodes.init(deployPath) tdDnodes.init(deployPath, masterIp)
tdDnodes.setTestCluster(testCluster) tdDnodes.setTestCluster(testCluster)
tdDnodes.setValgrind(valgrind) tdDnodes.setValgrind(valgrind)
tdDnodes.stopAll() tdDnodes.stopAll()