提交 06f72448 编写于 作者: wafwerar's avatar wafwerar

fix(os): case run remote taosd

上级 9175e4ce
...@@ -17,6 +17,10 @@ import os.path ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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,65 @@ class TDDnode: ...@@ -268,117 +295,65 @@ 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:
tdLog.debug(
"wait 10 seconds for the dnode:%d to start." %
(self.index))
time.sleep(10)
# time.sleep(5)
def startWin(self):
binPath = self.getPath("taosd.exe")
if (binPath == ""):
tdLog.exit("taosd.exe not found!")
else: else:
tdLog.info("taosd.exe found: %s" % binPath) if os.system(cmd) != 0:
tdLog.exit(cmd)
taosadapterBinPath = self.getPath("taosadapter.exe") self.running = 1
if (taosadapterBinPath == ""): print("dnode:%d is running with %s " % (self.index, cmd))
tdLog.info("taosAdapter.exe not found!") tdLog.debug("dnode:%d is running with %s " % (self.index, cmd))
else: if self.valgrind == 0:
tdLog.info("taosAdapter.exe found in %s" % taosadapterBuildPath) time.sleep(0.1)
key = 'from offline to online'
if self.deployed == 0: bkey = bytes(key, encoding="utf8")
tdLog.exit("dnode:%d is not deployed" % (self.index)) logFile = self.logDir + "/taosdlog.0"
i = 0
cmd = "mintty -h never -w hide %s -c %s" % ( while not os.path.exists(logFile):
binPath, self.cfgDir) sleep(0.1)
i += 1
if (taosadapterBinPath != ""): if i > 50:
taosadapterCmd = "mintty -h never -w hide %s --monitor.writeToTD=false " % ( break
taosadapterBinPath) popen = subprocess.Popen(
if os.system(taosadapterCmd) != 0: 'tail -n +0 -f ' + logFile,
tdLog.exit(taosadapterCmd) stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
if os.system(cmd) != 0: shell=True)
tdLog.exit(cmd) pid = popen.pid
# print('Popen.pid:' + str(pid))
self.running = 1 timeout = time.time() + 60 * 2
tdLog.debug("dnode:%d is running with %s " % (self.index, cmd)) while True:
if self.valgrind == 0: line = popen.stdout.readline().strip()
time.sleep(0.1) if bkey in line:
key = 'from offline to online' popen.kill()
bkey = bytes(key, encoding="utf8") break
logFile = self.logDir + "/taosdlog.0" if time.time() > timeout:
i = 0 tdLog.exit('wait too long for taosd start')
while not os.path.exists(logFile): tdLog.debug("the dnode:%d has been started." % (self.index))
sleep(0.1) else:
i += 1 tdLog.debug(
if i > 50: "wait 10 seconds for the dnode:%d to start." %
break (self.index))
popen = subprocess.Popen( time.sleep(10)
'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 +377,19 @@ class TDDnode: ...@@ -402,12 +377,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 +417,9 @@ class TDDnode: ...@@ -435,6 +417,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 +484,10 @@ class TDDnodes: ...@@ -499,8 +484,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 +507,9 @@ class TDDnodes: ...@@ -520,9 +507,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 +532,7 @@ class TDDnodes: ...@@ -545,7 +532,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 +559,7 @@ class TDDnodes: ...@@ -572,10 +559,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)
......
...@@ -44,8 +44,9 @@ if __name__ == "__main__": ...@@ -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__": ...@@ -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__": ...@@ -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__": ...@@ -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__": ...@@ -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__": ...@@ -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()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册