test.py 4.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/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/linux/python2/

# -*- coding: utf-8 -*-
import sys
import getopt
18 19 20
import subprocess
from distutils.log import warn as printf

21 22 23 24 25 26 27 28 29 30 31 32
from util.log import *
from util.dnodes import *
from util.cases import *

import taos


if __name__ == "__main__":
    fileName = "all"
    deployPath = ""
    masterIp = ""
    testCluster = False
33
    valgrind = 0
S
Shuduo Sang 已提交
34
    logSql = True
35
    stop = 0
S
Shuduo Sang 已提交
36 37
    opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scgh', [
        'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help'])
38 39 40 41 42 43 44
    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')
S
Shuduo Sang 已提交
45
            tdLog.printNoPrefix('-l <True:False> logSql Flag')
46
            tdLog.printNoPrefix('-s stop All dnodes')
S
Shuduo Sang 已提交
47 48
            tdLog.printNoPrefix('-c Test Cluster Flag')
            tdLog.printNoPrefix('-g valgrind Test Flag')
49
            sys.exit(0)
50

51 52
        if key in ['-f', '--file']:
            fileName = value
53

54 55
        if key in ['-p', '--path']:
            deployPath = value
56

57 58
        if key in ['-m', '--master']:
            masterIp = value
59

S
Shuduo Sang 已提交
60 61 62 63 64 65 66 67 68
        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)

69 70
        if key in ['-c', '--cluster']:
            testCluster = True
71 72 73 74

        if key in ['-g', '--valgrind']:
            valgrind = 1

75
        if key in ['-s', '--stop']:
76 77 78 79 80 81 82 83
            stop = 1

    if (stop != 0):
        if (valgrind == 0):
            toBeKilled = "taosd"
        else:
            toBeKilled = "valgrind.bin"

84
        killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -HUP > /dev/null 2>&1" % toBeKilled
85 86 87 88

        psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled
        processID = subprocess.check_output(psCmd, shell=True)

89
        while(processID):
90 91 92 93
            os.system(killCmd)
            time.sleep(1)
            processID = subprocess.check_output(psCmd, shell=True)

94 95 96 97 98
        for port in range(6030, 6041):
            usePortPID = "lsof -i tcp:%d | grep LISTEn | awk '{print $2}'" % port
            processID = subprocess.check_output(usePortPID, shell=True)

            if processID:
99
                killCmd = "kill -TERM %s" % processID
100 101 102 103 104
                os.system(killCmd)
            fuserCmd = "fuser -k -n tcp %d" % port
            os.system(fuserCmd)
        if valgrind:
            time.sleep(2)
105

S
Shuduo Sang 已提交
106 107
        tdLog.info('stop All dnodes')
        sys.exit(0)
108

109 110 111 112 113 114 115 116
    tdDnodes.init(deployPath)
    tdDnodes.setTestCluster(testCluster)
    tdDnodes.setValgrind(valgrind)

    tdDnodes.stopAll()
    tdDnodes.deploy(1)
    tdDnodes.start(1)

117
    if masterIp == "":
118
        host = '127.0.0.1'
119
    else:
120
        host = masterIp
121

122
    tdLog.info("Procedures for tdengine deployed in %s" % (host))
123

S
Shuduo Sang 已提交
124 125
    tdCases.logSql(logSql)

126
    if testCluster:
127
        tdLog.info("Procedures for testing cluster")
128 129
        if fileName == "all":
            tdCases.runAllCluster()
130
        else:
131
            tdCases.runOneCluster(fileName)
132
    else:
133
        tdLog.info("Procedures for testing self-deployment")
134
        conn = taos.connect(
135 136
            host,
            config=tdDnodes.getSimCfgPath())
137
        if fileName == "all":
138
            tdCases.runAllLinux(conn)
139
        else:
140 141 142
            tdCases.runOneLinux(conn, fileName)

    conn.close()