|
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | 17 |
|
18 | | -import deployDataCenter |
19 | | -import TestCaseExecuteEngine |
| 18 | +from tcExecuteEngine import TestCaseExecuteEngine |
20 | 19 | import sys |
| 20 | +import os |
| 21 | +import traceback |
| 22 | +import time |
21 | 23 | from argparse import ArgumentParser |
22 | | -if __name__ == "__main__": |
| 24 | +from marvinInit import MarvinInit |
| 25 | +from marvin.codes import (SUCCESS, |
| 26 | + FAILED, |
| 27 | + EXCEPTION, |
| 28 | + UNKNOWN_ERROR |
| 29 | + ) |
| 30 | + |
| 31 | + |
| 32 | +parser = None |
| 33 | + |
| 34 | + |
| 35 | +def printAndExit(): |
| 36 | + ''' |
| 37 | + Prints pretty message for parser and exit |
| 38 | + ''' |
| 39 | + global parser |
| 40 | + if parser is not None: |
| 41 | + parser.print_usage() |
| 42 | + exit(1) |
| 43 | + |
23 | 44 |
|
| 45 | +def parseAndCheck(): |
| 46 | + ''' |
| 47 | + Parses,reads the options and verifies for the config file |
| 48 | + ''' |
| 49 | + global parser |
24 | 50 | parser = ArgumentParser() |
25 | 51 |
|
26 | | - parser.add_argument("-d", "--directory", dest="testCaseFolder", |
27 | | - help="the test case directory") |
28 | | - parser.add_argument("-f", "--file", dest="module", |
29 | | - help="run tests in the given file") |
30 | | - parser.add_argument("-r", "--result", dest="result", |
31 | | - help="test result log file", default='/tmp/t.log') |
32 | | - parser.add_argument("-t", "--client", dest="testcaselog", |
33 | | - help="test case log file", default='/tmp/r.log') |
| 52 | + parser.add_argument("-d", "--tcpath", dest="tcpath", |
| 53 | + help="the test case directory or file path") |
34 | 54 | parser.add_argument("-c", "--config", action="store", |
35 | 55 | default="./datacenterCfg", dest="config", |
36 | 56 | help="the path where the json config file generated,\ |
37 | | - by default is ./datacenterCfg") |
| 57 | + by default is ./datacenterCfg") |
38 | 58 | parser.add_argument("-l", "--load", dest="load", action="store_true", |
39 | 59 | help="only load config, do not deploy,\ |
40 | | - it will only run testcase") |
| 60 | + it will only run testcase") |
41 | 61 | parser.add_argument("-n", "--num", dest="number", |
42 | | - help="how many times you want run the test case") |
| 62 | + help="how many times you want to run the tests") |
43 | 63 |
|
44 | 64 | options = parser.parse_args() |
| 65 | + cfg_file = options.config |
| 66 | + tc_path = options.tcpath |
| 67 | + load_flag = options.load |
| 68 | + num_iter = 1 if options.number is None else int(options.number) |
45 | 69 |
|
46 | | - testResultLogFile = None |
47 | | - if options.result is not None: |
48 | | - testResultLogFile = options.result |
| 70 | + ''' |
| 71 | + Check if the config file is None or not and exit accordingly |
| 72 | + ''' |
| 73 | + if cfg_file is None: |
| 74 | + printAndExit() |
| 75 | + return {"cfg_file": cfg_file, |
| 76 | + "load_flag": load_flag, |
| 77 | + "tc_path": tc_path, |
| 78 | + "num_iter": num_iter} |
49 | 79 |
|
50 | | - testCaseLogFile = None |
51 | | - if options.testcaselog is not None: |
52 | | - testCaseLogFile = options.testcaselog |
53 | | - deploy = deployDataCenter.deployDataCenters(options.config) |
54 | | - if options.load: |
55 | | - deploy.loadCfg() |
56 | | - else: |
57 | | - deploy.deploy() |
58 | | - iterates = 1 |
59 | | - if options.number is not None: |
60 | | - if options.number == "loop": |
61 | | - iterates = sys.maxint |
| 80 | + |
| 81 | +def startMarvin(cfg_file, load_flag): |
| 82 | + ''' |
| 83 | + Initialize the Marvin |
| 84 | + ''' |
| 85 | + try: |
| 86 | + obj_marvininit = MarvinInit(cfg_file, load_flag) |
| 87 | + if obj_marvininit.init() == SUCCESS: |
| 88 | + testClient = obj_marvininit.getTestClient() |
| 89 | + tcRunLogger = obj_marvininit.getLogger() |
| 90 | + parsedConfig = obj_marvininit.getParsedConfig() |
| 91 | + debugStream = obj_marvininit.getDebugFile() |
| 92 | + return {"tc_client": testClient, |
| 93 | + "tc_runlogger": tcRunLogger, |
| 94 | + "tc_parsedcfg": parsedConfig, |
| 95 | + "tc_debugstream": debugStream} |
62 | 96 | else: |
63 | | - try: |
64 | | - iterates = int(options.number) |
65 | | - except: |
66 | | - iterates = 1 |
67 | | - |
68 | | - if options.testCaseFolder is None: |
69 | | - if options.module is None: |
70 | | - parser.print_usage() |
| 97 | + print "\nMarvin Initialization Failed" |
| 98 | + exit(1) |
| 99 | + except Exception, e: |
| 100 | + print "\n Exception occurred while starting Marvin %s" % str(e) |
71 | 101 | exit(1) |
| 102 | + |
| 103 | + |
| 104 | +def runTCs(num_iter, inp1, inp2): |
| 105 | + ''' |
| 106 | + Run Test Cases based upon number of iterations |
| 107 | + ''' |
| 108 | + n = 0 |
| 109 | + while(n < num_iter): |
| 110 | + engine = TestCaseExecuteEngine(inp2["tc_client"], |
| 111 | + inp2["tc_parsedcfg"], |
| 112 | + inp2["tc_runlogger"], |
| 113 | + inp2["tc_debugstream"]) |
| 114 | + if inp1["tc_file"] is not None: |
| 115 | + engine.loadTestsFromFile(inp1["tc_file"]) |
72 | 116 | else: |
73 | | - n = 0 |
74 | | - while(n < iterates): |
75 | | - engine = \ |
76 | | - TestCaseExecuteEngine.TestCaseExecuteEngine( |
77 | | - deploy.testClient, |
78 | | - deploy.getCfg( |
79 | | - ), |
80 | | - testCaseLogFile, |
81 | | - testResultLogFile) |
82 | | - engine.loadTestsFromFile(options.module) |
83 | | - engine.run() |
84 | | - n = n + 1 |
| 117 | + engine.loadTestsFromDir(inp1["tc_dir"]) |
| 118 | + engine.run() |
| 119 | + n = n + 1 |
| 120 | + |
| 121 | + |
| 122 | +def checkTCPath(tc_path): |
| 123 | + ''' |
| 124 | + Verifies if the tc_path is a folder or file and its existence |
| 125 | + ''' |
| 126 | + ret = {"tc_file": None, "tc_dir": None} |
| 127 | + check = True |
| 128 | + if tc_path is None: |
| 129 | + printAndExit() |
85 | 130 | else: |
86 | | - n = 0 |
87 | | - while(n < iterates): |
88 | | - engine = TestCaseExecuteEngine.TestCaseExecuteEngine( |
89 | | - deploy.testClient, |
90 | | - deploy.getCfg( |
91 | | - ), |
92 | | - testCaseLogFile, |
93 | | - testResultLogFile) |
94 | | - engine.loadTestsFromDir(options.testCaseFolder) |
95 | | - engine.run() |
96 | | - n = n + 1 |
| 131 | + if os.path.isfile(tc_path): |
| 132 | + ret["tc_file"] = tc_path |
| 133 | + elif os.path.isdir(tc_path): |
| 134 | + ret["tc_dir"] = tc_path |
| 135 | + else: |
| 136 | + check = False |
| 137 | + if check is False: |
| 138 | + print"\nTC Path is Invalid.So Exiting" |
| 139 | + exit(1) |
| 140 | + |
| 141 | + return ret |
| 142 | + |
| 143 | +if __name__ == "__main__": |
| 144 | + |
| 145 | + ''' |
| 146 | + 1. Parse and Check |
| 147 | + ''' |
| 148 | + out1 = parseAndCheck() |
| 149 | + print "\nStep1 :Parsing Options And Check Went Fine" |
| 150 | + |
| 151 | + ''' |
| 152 | + 2. Start Marvin |
| 153 | + ''' |
| 154 | + out2 = startMarvin(out1["cfg_file"], out1["load_flag"]) |
| 155 | + print "\nStep2: Marvin Initialization Went Fine" |
| 156 | + |
| 157 | + ''' |
| 158 | + 3. Check TC folder or Module and Path existence |
| 159 | + ''' |
| 160 | + out3 = checkTCPath(out1["tc_path"]) |
| 161 | + print "\nStep3: TC Path Check Went Fine" |
| 162 | + |
| 163 | + ''' |
| 164 | + 4. Run TCs |
| 165 | + ''' |
| 166 | + runTCs(out1["num_iter"], out3, out2) |
| 167 | + print "\nStep4: TC Running Finished" |
0 commit comments