dnodes.py 22.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
###################################################################
#           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
#
###################################################################

# -*- coding: utf-8 -*-

import sys
import os
import os.path
17
import platform
L
liuyq-617 已提交
18 19
import pathlib
import shutil
20
import subprocess
21
from time import sleep
22 23 24 25
from util.log import *


class TDSimClient:
Z
zhaoyanggh 已提交
26
    def __init__(self, path):
27
        self.testCluster = False
Z
zhaoyanggh 已提交
28
        self.path = path
S
Shuduo Sang 已提交
29 30 31 32 33 34
        self.cfgDict = {
            "numOfLogLines": "100000000",
            "numOfThreadsPerCore": "2.0",
            "locale": "en_US.UTF-8",
            "charset": "UTF-8",
            "asyncLog": "0",
35 36 37
            "minTablesPerVnode": "4",
            "maxTablesPerVnode": "1000",
            "tableIncStepPerVnode": "10000",
38 39
            "maxVgroupsPerDb": "1000",
            "sdbDebugFlag": "143",
S
Shuduo Sang 已提交
40 41 42 43 44 45
            "rpcDebugFlag": "135",
            "tmrDebugFlag": "131",
            "cDebugFlag": "135",
            "udebugFlag": "135",
            "jnidebugFlag": "135",
            "qdebugFlag": "135",
46
            "telemetryReporting": "0",
47
            "enableCoreFile": "1",
Z
zhaoyanggh 已提交
48
        }
49

S
Shuduo Sang 已提交
50 51 52 53
    def getLogDir(self):
        self.logDir = "%s/sim/psim/log" % (self.path)
        return self.logDir

54
    def getCfgDir(self):
S
Shuduo Sang 已提交
55
        self.cfgDir = "%s/sim/psim/cfg" % (self.path)
56 57
        return self.cfgDir

58 59 60
    def setTestCluster(self, value):
        self.testCluster = value

S
Shuduo Sang 已提交
61 62 63
    def addExtraCfg(self, option, value):
        self.cfgDict.update({option: value})

64
    def cfg(self, option, value):
65
        cmd = "echo %s %s >> %s" % (option, value, self.cfgPath)
66 67
        if os.system(cmd) != 0:
            tdLog.exit(cmd)
L
liuyq-617 已提交
68 69 70
    def os_string(self,path):
        os_path = path.replace("/",os.sep)
        return os_path
71
    def deploy(self):
L
liuyq-617 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
        self.logDir = self.os_string("%s/sim/psim/log" % (self.path))
        self.cfgDir = self.os_string("%s/sim/psim/cfg" % (self.path))
        self.cfgPath = self.os_string("%s/sim/psim/cfg/taos.cfg" % (self.path))

        # cmd = "rm -rf " + self.logDir
        # if os.system(cmd) != 0:
        #     tdLog.exit(cmd)
        if os.path.exists(self.logDir): 
            try:
                shutil.rmtree(self.logDir)
            except:
                tdLog.exit("del %s failed"%self.logDir)
        # cmd = "mkdir -p " + self.logDir
        # if os.system(cmd) != 0:
        #     tdLog.exit(cmd)
        os.makedirs(self.logDir)
        # cmd = "rm -rf " + self.cfgDir
        # if os.system(cmd) != 0:
        #     tdLog.exit(cmd)
        if os.path.exists(self.cfgDir): 
            try:
                shutil.rmtree(self.cfgDir)
            except:
                tdLog.exit("del %s failed"%self.cfgDir)
        # cmd = "mkdir -p " + self.cfgDir
        # if os.system(cmd) != 0:
        #     tdLog.exit(cmd)
        os.makedirs(self.cfgDir)
        # cmd = "touch " + self.cfgPath
        # if os.system(cmd) != 0:
        #     tdLog.exit(cmd)
        try:
            pathlib.Path(self.cfgPath).touch()
        except:
             tdLog.exit("create %s failed"%self.cfgPath)
107 108 109
        if self.testCluster:
            self.cfg("masterIp", "192.168.0.1")
            self.cfg("secondIp", "192.168.0.2")
110
        self.cfg("logDir", self.logDir)
S
Shuduo Sang 已提交
111 112 113 114

        for key, value in self.cfgDict.items():
            self.cfg(key, value)

115 116 117 118 119 120 121 122
        tdLog.debug("psim is deployed and configured by %s" % (self.cfgPath))


class TDDnode:
    def __init__(self, index):
        self.index = index
        self.running = 0
        self.deployed = 0
123
        self.testCluster = False
124
        self.valgrind = 0
L
liuyq-617 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
        self.cfgDict = {
            "numOfLogLines":"100000000",
            "mnodeEqualVnodeNum":"0",
            "walLevel":"2",
            "fsync":"1000",
            "statusInterval":"1",
            "numOfMnodes":"3",
            "numOfThreadsPerCore":"2.0",
            "monitor":"0",
            "maxVnodeConnections":"30000",
            "maxMgmtConnections":"30000",
            "maxMeterConnections":"30000",
            "maxShellConns":"30000",
            "locale":"en_US.UTF-8",
            "charset":"UTF-8",
            "asyncLog":"0",
            "anyIp":"0",
P
Ping Xiao 已提交
142
            "telemetryReporting":"0",
L
liuyq-617 已提交
143
            "dDebugFlag":"135",
L
liuyq-617 已提交
144
            "tsdbDebugFlag":"135",
L
liuyq-617 已提交
145 146 147 148 149 150 151 152 153
            "mDebugFlag":"135",
            "sdbDebugFlag":"135",
            "rpcDebugFlag":"135",
            "tmrDebugFlag":"131",
            "cDebugFlag":"135",
            "httpDebugFlag":"135",
            "monitorDebugFlag":"135",
            "udebugFlag":"135",
            "jnidebugFlag":"135",
154
            "qdebugFlag":"135",
155 156
            "maxSQLLength":"1048576",
            "enableCoreFile": "1",
L
liuyq-617 已提交
157
        }
158 159 160 161

    def init(self, path):
        self.path = path

162 163 164
    def setTestCluster(self, value):
        self.testCluster = value

165 166 167
    def setValgrind(self, value):
        self.valgrind = value

168 169 170 171 172 173 174 175 176 177 178 179 180
    def getDataSize(self):
        totalSize = 0

        if (self.deployed == 1):
            for dirpath, dirnames, filenames in os.walk(self.dataDir):
                for f in filenames:
                    fp = os.path.join(dirpath, f)

                    if not os.path.islink(fp):
                        totalSize = totalSize + os.path.getsize(fp)

        return totalSize

L
liuyq-617 已提交
181 182 183 184
    def addExtraCfg(self, option, value):
        self.cfgDict.update({option: value})

    def deploy(self, *updatecfgDict):
185 186 187 188
        self.logDir = "%s/sim/dnode%d/log" % (self.path, self.index)
        self.dataDir = "%s/sim/dnode%d/data" % (self.path, self.index)
        self.cfgDir = "%s/sim/dnode%d/cfg" % (self.path, self.index)
        self.cfgPath = "%s/sim/dnode%d/cfg/taos.cfg" % (
S
Shuduo Sang 已提交
189
            self.path, self.index)
190 191 192 193 194 195 196 197 198 199 200 201 202

        cmd = "rm -rf " + self.dataDir
        if os.system(cmd) != 0:
            tdLog.exit(cmd)

        cmd = "rm -rf " + self.logDir
        if os.system(cmd) != 0:
            tdLog.exit(cmd)

        cmd = "rm -rf " + self.cfgDir
        if os.system(cmd) != 0:
            tdLog.exit(cmd)

203
        os.makedirs(self.dataDir, exist_ok=True) # like "mkdir -p"
204

205
        os.makedirs(self.logDir, exist_ok=True) # like "mkdir -p"
206

207
        os.makedirs(self.cfgDir, exist_ok=True) # like "mkdir -p"
208 209 210 211 212

        cmd = "touch " + self.cfgPath
        if os.system(cmd) != 0:
            tdLog.exit(cmd)

213 214 215
        if self.testCluster:
            self.startIP()

216 217 218 219 220 221
        if self.testCluster:
            self.cfg("masterIp", "192.168.0.1")
            self.cfg("secondIp", "192.168.0.2")
            self.cfg("publicIp", "192.168.0.%d" % (self.index))
            self.cfg("internalIp", "192.168.0.%d" % (self.index))
            self.cfg("privateIp", "192.168.0.%d" % (self.index))
L
liuyq-617 已提交
222 223 224 225
        self.cfgDict["dataDir"] = self.dataDir
        self.cfgDict["logDir"] = self.logDir
        # self.cfg("dataDir",self.dataDir)
        # self.cfg("logDir",self.logDir)
L
liuyq-617 已提交
226
        # print(updatecfgDict)
L
liuyq-617 已提交
227
        isFirstDir = 1
L
liuyq-617 已提交
228 229 230
        if updatecfgDict[0] and updatecfgDict[0][0]:
            print(updatecfgDict[0][0])
            for key,value in updatecfgDict[0][0].items():
L
liuyq-617 已提交
231 232 233 234 235 236 237 238 239
                if value == 'dataDir' :
                    if isFirstDir:
                        self.cfgDict.pop('dataDir')
                        self.cfg(value,key)
                        isFirstDir = 0
                    else:
                        self.cfg(value,key)
                else:
                    self.addExtraCfg(key,value)
L
liuyq-617 已提交
240 241 242
        for key, value in self.cfgDict.items():
            self.cfg(key, value)

243 244 245 246 247
        self.deployed = 1
        tdLog.debug(
            "dnode:%d is deployed and configured by %s" %
            (self.index, self.cfgPath))

P
Ping Xiao 已提交
248
    def getBuildPath(self, tool="taosd"):
249
        buildPath = ""
250 251
        selfPath = os.path.dirname(os.path.realpath(__file__))

252
        if ("community" in selfPath):
253
            projPath = selfPath[:selfPath.find("community")]
254
        else:
255 256 257
            projPath = selfPath[:selfPath.find("tests")]

        for root, dirs, files in os.walk(projPath):
P
Ping Xiao 已提交
258
            if ((tool) in files):
259 260
                rootRealPath = os.path.dirname(os.path.realpath(root))
                if ("packaging" not in rootRealPath):
S
Shuduo Sang 已提交
261
                    buildPath = root[:len(root)-len("/build/bin")]
262 263 264 265 266 267 268
                    break
        return buildPath

    def start(self):
        buildPath = self.getBuildPath()

        if (buildPath == ""):
269
            tdLog.exit("taosd not found!")
270
        else:
271 272 273
            tdLog.info("taosd found in %s" % buildPath)

        binPath = buildPath + "/build/bin/taosd"
274
        taosadapterBinPath = buildPath + "/build/bin/taosadapter"
275 276 277

        if self.deployed == 0:
            tdLog.exit("dnode:%d is not deployed" % (self.index))
278 279

        if self.valgrind == 0:
280
            cmd = "nohup %s -c %s > /dev/null 2>&1 & " % (
281 282 283 284
                binPath, self.cfgDir)
        else:
            valgrindCmdline = "valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes"

285
            cmd = "nohup %s %s -c %s 2>&1 & " % (
286 287 288 289
                valgrindCmdline, binPath, self.cfgDir)

            print(cmd)

290 291 292 293
        taosadapterCmd = "nohup %s > /dev/null 2>&1 & " % (
                taosadapterBinPath)
        if os.system(taosadapterCmd) != 0:
            tdLog.exit(taosadapterCmd)
294

295 296
        if os.system(cmd) != 0:
            tdLog.exit(cmd)
297

298 299
        self.running = 1
        tdLog.debug("dnode:%d is running with %s " % (self.index, cmd))
L
liuyq-617 已提交
300 301 302 303 304
        if self.valgrind == 0:
            time.sleep(0.1)
            key = 'from offline to online'
            bkey = bytes(key,encoding="utf8")
            logFile = self.logDir + "/taosdlog.0"
L
liuyq-617 已提交
305 306 307 308 309 310
            i = 0
            while not os.path.exists(logFile):
                sleep(0.1)
                i += 1
                if i>50:
                    break
L
liuyq-617 已提交
311 312
            popen = subprocess.Popen('tail -f ' + logFile, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
            pid = popen.pid
L
liuyq-617 已提交
313 314
            # print('Popen.pid:' + str(pid))
            timeout = time.time() + 60*2
L
liuyq-617 已提交
315 316 317 318 319
            while True:
                line = popen.stdout.readline().strip()
                if bkey in line:
                    popen.kill()
                    break
L
liuyq-617 已提交
320 321
                if time.time() > timeout:
                    tdLog.exit('wait too long for taosd start')
L
liuyq-617 已提交
322 323
            tdLog.debug("the dnode:%d has been started." % (self.index))
        else:
L
liuyq-617 已提交
324 325
            tdLog.debug("wait 10 seconds for the dnode:%d to start." % (self.index))
            time.sleep(10)
L
liuyq-617 已提交
326

L
liuyq-617 已提交
327 328
        
        # time.sleep(5)
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
    def startWin(self):
        buildPath = self.getBuildPath("taosd.exe")

        if (buildPath == ""):
            tdLog.exit("taosd.exe not found!")
        else:
            tdLog.info("taosd.exe found in %s" % buildPath)

        binPath = buildPath + "/build/bin/taosd.exe"
        taosadapterBinPath = buildPath + "/build/bin/taosadapter.exe"

        if self.deployed == 0:
            tdLog.exit("dnode:%d is not deployed" % (self.index))

        cmd = "mintty -h never -w hide %s -c %s" % (
                binPath, self.cfgDir)

        taosadapterCmd = "mintty -h never -w hide %s " % (
                taosadapterBinPath)
        if os.system(taosadapterCmd) != 0:
            tdLog.exit(taosadapterCmd)

        if os.system(cmd) != 0:
            tdLog.exit(cmd)

        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 -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)
382 383 384 385 386 387 388 389 390 391
    
    def startWithoutSleep(self):
        buildPath = self.getBuildPath()

        if (buildPath == ""):
            tdLog.exit("taosd not found!")
        else:
            tdLog.info("taosd found in %s" % buildPath)

        binPath = buildPath + "/build/bin/taosd"
392
        taosadapterBinPath = buildPath + "/build/bin/taosadapter"
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407

        if self.deployed == 0:
            tdLog.exit("dnode:%d is not deployed" % (self.index))

        if self.valgrind == 0:
            cmd = "nohup %s -c %s > /dev/null 2>&1 & " % (
                binPath, self.cfgDir)
        else:
            valgrindCmdline = "valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes"

            cmd = "nohup %s %s -c %s 2>&1 & " % (
                valgrindCmdline, binPath, self.cfgDir)

            print(cmd)

408 409 410
        taosadapterCmd = "%s > /dev/null 2>&1 & " % (taosadapterBinPath)
        if os.system(taosadapterCmd) != 0:
            tdLog.exit(taosadapterCmd)
411

412 413 414 415
        if os.system(cmd) != 0:
            tdLog.exit(cmd)
        self.running = 1
        tdLog.debug("dnode:%d is running with %s " % (self.index, cmd))
416 417

    def stop(self):
418
        taosadapterToBeKilled = "taosadapter"
419

420 421 422
        taosadapterPsCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % taosadapterToBeKilled
        taosadapterProcessID = subprocess.check_output(
                    taosadapterPsCmd, shell=True).decode("utf-8")
423

424 425 426
        while(taosadapterProcessID):
            taosadapterKillCmd = "kill -INT %s > /dev/null 2>&1" % taosadapterProcessID
            os.system(taosadapterKillCmd)
427
            time.sleep(1)
428 429
            taosadapterProcessID = subprocess.check_output(
                    taosadapterPsCmd, shell=True).decode("utf-8")
430

431 432 433 434 435
        if self.valgrind == 0:
            toBeKilled = "taosd"
        else:
            toBeKilled = "valgrind.bin"

436
        if self.running != 0:
437
            psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled
S
Shuduo Sang 已提交
438 439
            processID = subprocess.check_output(
                psCmd, shell=True).decode("utf-8")
440 441

            while(processID):
442
                killCmd = "kill -INT %s > /dev/null 2>&1" % processID
443 444
                os.system(killCmd)
                time.sleep(1)
S
Shuduo Sang 已提交
445 446
                processID = subprocess.check_output(
                    psCmd, shell=True).decode("utf-8")
447 448 449 450 451
            for port in range(6030, 6041):
                fuserCmd = "fuser -k -n tcp %d" % port
                os.system(fuserCmd)
            if self.valgrind:
                time.sleep(2)
452

S
Shuduo Sang 已提交
453
            self.running = 0
454
            tdLog.debug("dnode:%d is stopped by kill -INT" % (self.index))
455 456

    def forcestop(self):
457 458 459 460 461
        if self.valgrind == 0:
            toBeKilled = "taosd"
        else:
            toBeKilled = "valgrind.bin"

462
        if self.running != 0:
463
            psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled
S
Shuduo Sang 已提交
464 465
            processID = subprocess.check_output(
                psCmd, shell=True).decode("utf-8")
466 467

            while(processID):
468
                killCmd = "kill -KILL %s > /dev/null 2>&1" % processID
469 470
                os.system(killCmd)
                time.sleep(1)
S
Shuduo Sang 已提交
471 472
                processID = subprocess.check_output(
                    psCmd, shell=True).decode("utf-8")
473 474 475 476 477
            for port in range(6030, 6041):
                fuserCmd = "fuser -k -n tcp %d" % port
                os.system(fuserCmd)
            if self.valgrind:
                time.sleep(2)
478

S
Shuduo Sang 已提交
479
            self.running = 0
480
            tdLog.debug("dnode:%d is stopped by kill -KILL" % (self.index))
481 482 483 484 485 486 487 488 489 490 491 492 493

    def startIP(self):
        cmd = "sudo ifconfig lo:%d 192.168.0.%d up" % (self.index, self.index)
        if os.system(cmd) != 0:
            tdLog.exit(cmd)

    def stopIP(self):
        cmd = "sudo ifconfig lo:%d 192.168.0.%d down" % (
            self.index, self.index)
        if os.system(cmd) != 0:
            tdLog.exit(cmd)

    def cfg(self, option, value):
494
        cmd = "echo %s %s >> %s" % (option, value, self.cfgPath)
495 496 497 498
        if os.system(cmd) != 0:
            tdLog.exit(cmd)

    def getDnodeRootDir(self, index):
499
        dnodeRootDir = "%s/sim/psim/dnode%d" % (self.path, index)
500 501 502
        return dnodeRootDir

    def getDnodesRootDir(self):
503
        dnodesRootDir = "%s/sim/psim" % (self.path)
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
        return dnodesRootDir


class TDDnodes:
    def __init__(self):
        self.dnodes = []
        self.dnodes.append(TDDnode(1))
        self.dnodes.append(TDDnode(2))
        self.dnodes.append(TDDnode(3))
        self.dnodes.append(TDDnode(4))
        self.dnodes.append(TDDnode(5))
        self.dnodes.append(TDDnode(6))
        self.dnodes.append(TDDnode(7))
        self.dnodes.append(TDDnode(8))
        self.dnodes.append(TDDnode(9))
        self.dnodes.append(TDDnode(10))
520
        self.simDeployed = False
521 522

    def init(self, path):
T
tickduan 已提交
523
        psCmd = "ps -ef|grep -w taosd| grep -v grep| grep -v defunct | awk '{print $2}'"
S
Shuduo Sang 已提交
524
        processID = subprocess.check_output(psCmd, shell=True).decode("utf-8")
525
        while(processID):
L
test  
liuyq-617 已提交
526
            killCmd = "kill -9 %s > /dev/null 2>&1" % processID
527 528
            os.system(killCmd)
            time.sleep(1)
S
Shuduo Sang 已提交
529 530
            processID = subprocess.check_output(
                psCmd, shell=True).decode("utf-8")
531 532

        psCmd = "ps -ef|grep -w valgrind.bin| grep -v grep | awk '{print $2}'"
S
Shuduo Sang 已提交
533
        processID = subprocess.check_output(psCmd, shell=True).decode("utf-8")
534
        while(processID):
L
test  
liuyq-617 已提交
535
            killCmd = "kill -9 %s > /dev/null 2>&1" % processID
536 537
            os.system(killCmd)
            time.sleep(1)
S
Shuduo Sang 已提交
538 539
            processID = subprocess.check_output(
                psCmd, shell=True).decode("utf-8")
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569

        binPath = os.path.dirname(os.path.realpath(__file__))
        binPath = binPath + "/../../../debug/"
        tdLog.debug("binPath %s" % (binPath))
        binPath = os.path.realpath(binPath)
        tdLog.debug("binPath real path %s" % (binPath))

        # cmd = "sudo cp %s/build/lib/libtaos.so /usr/local/lib/taos/" % (binPath)
        # tdLog.debug(cmd)
        # os.system(cmd)

        # cmd = "sudo cp %s/build/bin/taos /usr/local/bin/taos/" % (binPath)
        # if os.system(cmd) != 0 :
        #  tdLog.exit(cmd)
        # tdLog.debug("execute %s" % (cmd))

        # cmd = "sudo cp %s/build/bin/taosd /usr/local/bin/taos/" % (binPath)
        # if os.system(cmd) != 0 :
        # tdLog.exit(cmd)
        # tdLog.debug("execute %s" % (cmd))

        if path == "":
            # self.path = os.path.expanduser('~')
            self.path = os.path.abspath(binPath + "../../")
        else:
            self.path = os.path.realpath(path)

        for i in range(len(self.dnodes)):
            self.dnodes[i].init(self.path)

Z
zhaoyanggh 已提交
570
        self.sim = TDSimClient(self.path)
S
Shuduo Sang 已提交
571

572 573 574
    def setTestCluster(self, value):
        self.testCluster = value

575 576 577
    def setValgrind(self, value):
        self.valgrind = value

L
liuyq-617 已提交
578
    def deploy(self, index, *updatecfgDict):
579
        self.sim.setTestCluster(self.testCluster)
580 581 582 583

        if (self.simDeployed == False):
            self.sim.deploy()
            self.simDeployed = True
584

585
        self.check(index)
586
        self.dnodes[index - 1].setTestCluster(self.testCluster)
587
        self.dnodes[index - 1].setValgrind(self.valgrind)
L
liuyq-617 已提交
588
        self.dnodes[index - 1].deploy(updatecfgDict)
589 590 591 592 593 594 595 596

    def cfg(self, index, option, value):
        self.check(index)
        self.dnodes[index - 1].cfg(option, value)

    def start(self, index):
        self.check(index)
        self.dnodes[index - 1].start()
597 598 599 600

    def startWin(self, index):
        self.check(index)
        self.dnodes[index - 1].startWin()
601 602 603 604
    
    def startWithoutSleep(self, index):
        self.check(index)
        self.dnodes[index - 1].startWithoutSleep()
605 606 607 608 609

    def stop(self, index):
        self.check(index)
        self.dnodes[index - 1].stop()

610 611 612 613
    def getDataSize(self, index):
        self.check(index)
        return self.dnodes[index - 1].getDataSize()

614 615 616 617 618 619
    def forcestop(self, index):
        self.check(index)
        self.dnodes[index - 1].forcestop()

    def startIP(self, index):
        self.check(index)
620 621 622

        if self.testCluster:
            self.dnodes[index - 1].startIP()
623 624 625

    def stopIP(self, index):
        self.check(index)
626 627 628

        if self.dnodes[index - 1].testCluster:
            self.dnodes[index - 1].stopIP()
629 630 631 632 633 634

    def check(self, index):
        if index < 1 or index > 10:
            tdLog.exit("index:%d should on a scale of [1, 10]" % (index))

    def stopAll(self):
S
Shuduo Sang 已提交
635
        tdLog.info("stop all dnodes")
636 637 638
        for i in range(len(self.dnodes)):
            self.dnodes[i].stop()

T
tickduan 已提交
639
        psCmd = "ps -ef | grep -w taosd | grep 'root' | grep -v grep| grep -v defunct | awk '{print $2}'"
S
Shuduo Sang 已提交
640
        processID = subprocess.check_output(psCmd, shell=True).decode("utf-8")
641 642 643
        if processID:
            cmd = "sudo systemctl stop taosd"
            os.system(cmd)
644 645
        # if os.system(cmd) != 0 :
        # tdLog.exit(cmd)
T
tickduan 已提交
646
        psCmd = "ps -ef|grep -w taosd| grep -v grep| grep -v defunct | awk '{print $2}'"
S
Shuduo Sang 已提交
647
        processID = subprocess.check_output(psCmd, shell=True).decode("utf-8")
648
        while(processID):
L
liuyq-617 已提交
649
            killCmd = "kill -9 %s > /dev/null 2>&1" % processID
650 651
            os.system(killCmd)
            time.sleep(1)
S
Shuduo Sang 已提交
652 653
            processID = subprocess.check_output(
                psCmd, shell=True).decode("utf-8")
654 655

        psCmd = "ps -ef|grep -w valgrind.bin| grep -v grep | awk '{print $2}'"
S
Shuduo Sang 已提交
656
        processID = subprocess.check_output(psCmd, shell=True).decode("utf-8")
657
        while(processID):
658
            killCmd = "kill -TERM %s > /dev/null 2>&1" % processID
659 660
            os.system(killCmd)
            time.sleep(1)
S
Shuduo Sang 已提交
661 662
            processID = subprocess.check_output(
                psCmd, shell=True).decode("utf-8")
663

664 665 666 667
        # if os.system(cmd) != 0 :
        # tdLog.exit(cmd)

    def getDnodesRootDir(self):
668
        dnodesRootDir = "%s/sim" % (self.path)
669 670 671 672 673
        return dnodesRootDir

    def getSimCfgPath(self):
        return self.sim.getCfgDir()

S
Shuduo Sang 已提交
674 675 676 677 678 679
    def getSimLogPath(self):
        return self.sim.getLogDir()

    def addSimExtraCfg(self, option, value):
        self.sim.addExtraCfg(option, value)

680 681

tdDnodes = TDDnodes()