test.py 3.4 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 34 35
    valgrind = 0
    stop = 0
    opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:scgh', [
36
        'file=', 'path=', 'master', 'stop', 'cluster', 'valgrind', 'help'])
37 38 39 40 41 42 43 44 45 46
    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('-c Test Cluster Flag')
            tdLog.printNoPrefix('-s stop All dnodes')
            sys.exit(0)
47

48 49
        if key in ['-f', '--file']:
            fileName = value
50

51 52
        if key in ['-p', '--path']:
            deployPath = value
53

54 55
        if key in ['-m', '--master']:
            masterIp = value
56

57 58
        if key in ['-c', '--cluster']:
            testCluster = True
59 60 61 62

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

63
        if key in ['-s', '--stop']:
64 65 66 67 68 69 70 71 72 73 74 75 76
            stop = 1

    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 -HUP " % toBeKilled

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

77
        while(processID):
78 79 80 81
            os.system(killCmd)
            time.sleep(1)
            processID = subprocess.check_output(psCmd, shell=True)

82 83 84
        fuserCmd = "fuser -k -n tcp 6030"
        subprocess.check_output(fuserCmd, shell=True)

S
Shuduo Sang 已提交
85 86
        tdLog.info('stop All dnodes')
        sys.exit(0)
87

88 89 90 91 92 93 94 95
    tdDnodes.init(deployPath)
    tdDnodes.setTestCluster(testCluster)
    tdDnodes.setValgrind(valgrind)

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

96
    if masterIp == "":
97
        host = '127.0.0.1'
98
    else:
99
        host = masterIp
100

101
    tdLog.info("Procedures for tdengine deployed in %s" % (host))
102 103

    if testCluster:
104
        tdLog.info("Procedures for testing cluster")
105 106
        if fileName == "all":
            tdCases.runAllCluster()
107
        else:
108
            tdCases.runOneCluster(fileName)
109
    else:
110
        tdLog.info("Procedures for testing self-deployment")
111
        conn = taos.connect(
112 113
            host,
            config=tdDnodes.getSimCfgPath())
114
        if fileName == "all":
115
            tdCases.runAllLinux(conn)
116
        else:
117 118 119
            tdCases.runOneLinux(conn, fileName)

    conn.close()