diff --git a/tools/marvin/marvin/configGenerator.py b/tools/marvin/marvin/configGenerator.py index 3f98aca9ff1..6d5b70d3108 100644 --- a/tools/marvin/marvin/configGenerator.py +++ b/tools/marvin/marvin/configGenerator.py @@ -93,11 +93,6 @@ class trafficType(object): if 'vmware' in labeldict.keys() else None self.simulator = labeldict['simulator']\ if 'simulator' in labeldict.keys() else None - #{ - # 'xen' : 'cloud-xen', - # 'kvm' : 'cloud-kvm', - # 'vmware' : 'cloud-vmware' - #} class pod(object): diff --git a/tools/marvin/marvin/deployAndRun.py b/tools/marvin/marvin/deployAndRun.py index d162fb39685..56747a7cb2d 100644 --- a/tools/marvin/marvin/deployAndRun.py +++ b/tools/marvin/marvin/deployAndRun.py @@ -15,78 +15,153 @@ # specific language governing permissions and limitations # under the License. -import deployDataCenter -import TestCaseExecuteEngine +from tcExecuteEngine import TestCaseExecuteEngine import sys +import os +import traceback +import time from argparse import ArgumentParser -if __name__ == "__main__": +from marvinInit import MarvinInit +from marvin.codes import (SUCCESS, + FAILED, + EXCEPTION, + UNKNOWN_ERROR + ) + +parser = None + + +def printAndExit(): + ''' + Prints pretty message for parser and exit + ''' + global parser + if parser is not None: + parser.print_usage() + exit(1) + + +def parseAndCheck(): + ''' + Parses,reads the options and verifies for the config file + ''' + global parser parser = ArgumentParser() - parser.add_argument("-d", "--directory", dest="testCaseFolder", - help="the test case directory") - parser.add_argument("-f", "--file", dest="module", - help="run tests in the given file") - parser.add_argument("-r", "--result", dest="result", - help="test result log file", default='/tmp/t.log') - parser.add_argument("-t", "--client", dest="testcaselog", - help="test case log file", default='/tmp/r.log') + parser.add_argument("-d", "--tcpath", dest="tcpath", + help="the test case directory or file path") parser.add_argument("-c", "--config", action="store", default="./datacenterCfg", dest="config", help="the path where the json config file generated,\ - by default is ./datacenterCfg") + by default is ./datacenterCfg") parser.add_argument("-l", "--load", dest="load", action="store_true", help="only load config, do not deploy,\ - it will only run testcase") + it will only run testcase") parser.add_argument("-n", "--num", dest="number", - help="how many times you want run the test case") + help="how many times you want to run the tests") options = parser.parse_args() + cfg_file = options.config + tc_path = options.tcpath + load_flag = options.load + num_iter = 1 if options.number is None else int(options.number) - testResultLogFile = None - if options.result is not None: - testResultLogFile = options.result + ''' + Check if the config file is None or not and exit accordingly + ''' + if cfg_file is None: + printAndExit() + return {"cfg_file": cfg_file, + "load_flag": load_flag, + "tc_path": tc_path, + "num_iter": num_iter} - testCaseLogFile = None - if options.testcaselog is not None: - testCaseLogFile = options.testcaselog - deploy = deployDataCenter.deployDataCenters(options.config) - if options.load: - deploy.loadCfg() - else: - deploy.deploy() - iterates = 1 - if options.number is not None: - if options.number == "loop": - iterates = sys.maxint + +def startMarvin(cfg_file, load_flag): + ''' + Initialize the Marvin + ''' + try: + obj_marvininit = MarvinInit(cfg_file, load_flag) + if obj_marvininit.init() == SUCCESS: + testClient = obj_marvininit.getTestClient() + tcRunLogger = obj_marvininit.getLogger() + parsedConfig = obj_marvininit.getParsedConfig() + debugStream = obj_marvininit.getDebugFile() + return {"tc_client": testClient, + "tc_runlogger": tcRunLogger, + "tc_parsedcfg": parsedConfig, + "tc_debugstream": debugStream} else: - try: - iterates = int(options.number) - except: - iterates = 1 - - if options.testCaseFolder is None: - if options.module is None: - parser.print_usage() + print "\nMarvin Initialization Failed" exit(1) + except Exception, e: + print "\n Exception occurred while starting Marvin %s" % str(e) + exit(1) + + +def runTCs(num_iter, inp1, inp2): + ''' + Run Test Cases based upon number of iterations + ''' + n = 0 + while(n < num_iter): + engine = TestCaseExecuteEngine(inp2["tc_client"], + inp2["tc_parsedcfg"], + inp2["tc_runlogger"], + inp2["tc_debugstream"]) + if inp1["tc_file"] is not None: + engine.loadTestsFromFile(inp1["tc_file"]) else: - n = 0 - while(n < iterates): - engine = \ - TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, - deploy.getCfg(), - testCaseLogFile, - testResultLogFile) - engine.loadTestsFromFile(options.module) - engine.run() - n = n + 1 + engine.loadTestsFromDir(inp1["tc_dir"]) + engine.run() + n = n + 1 + + +def checkTCPath(tc_path): + ''' + Verifies if the tc_path is a folder or file and its existence + ''' + ret = {"tc_file": None, "tc_dir": None} + check = True + if tc_path is None: + printAndExit() else: - n = 0 - while(n