Skip to content

Commit 4ee3fdb

Browse files
Santhosh EdukullaGirish Shilamkar
authored andcommitted
CLOUDSTACK-5423: Fixed 5423
1 parent 395c624 commit 4ee3fdb

3 files changed

Lines changed: 137 additions & 102 deletions

File tree

‎tools/marvin/marvin/configGenerator.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ def __init__(self, typ, labeldict=None):
9393
if 'vmware' in labeldict.keys() else None
9494
self.simulator = labeldict['simulator']\
9595
if 'simulator' in labeldict.keys() else None
96-
#{
97-
# 'xen' : 'cloud-xen',
98-
# 'kvm' : 'cloud-kvm',
99-
# 'vmware' : 'cloud-vmware'
100-
#}
10196

10297

10398
class pod(object):

‎tools/marvin/marvin/deployAndRun.py‎

Lines changed: 131 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,82 +15,153 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import deployDataCenter
19-
import TestCaseExecuteEngine
18+
from tcExecuteEngine import TestCaseExecuteEngine
2019
import sys
20+
import os
21+
import traceback
22+
import time
2123
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+
2344

45+
def parseAndCheck():
46+
'''
47+
Parses,reads the options and verifies for the config file
48+
'''
49+
global parser
2450
parser = ArgumentParser()
2551

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")
3454
parser.add_argument("-c", "--config", action="store",
3555
default="./datacenterCfg", dest="config",
3656
help="the path where the json config file generated,\
37-
by default is ./datacenterCfg")
57+
by default is ./datacenterCfg")
3858
parser.add_argument("-l", "--load", dest="load", action="store_true",
3959
help="only load config, do not deploy,\
40-
it will only run testcase")
60+
it will only run testcase")
4161
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")
4363

4464
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)
4569

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}
4979

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}
6296
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)
71101
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"])
72116
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()
85130
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"

tools/marvin/marvin/TestCaseExecuteEngine.py renamed to tools/marvin/marvin/tcExecuteEngine.py

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,20 @@
2222
from functools import partial
2323

2424

25-
def testCaseLogger(message, logger=None):
26-
if logger is not None:
27-
logger.debug(message)
28-
29-
3025
class TestCaseExecuteEngine(object):
31-
def __init__(self, testclient, config, testcaseLogFile=None,
32-
testResultLogFile=None):
26+
def __init__(self, testclient, config, tc_logger=None, debug_stream=None):
3327
"""
3428
Initialize the testcase execution engine, just the basics here
3529
@var testcaseLogFile: client log file
3630
@var testResultLogFile: summary report file
3731
"""
3832
self.testclient = testclient
3933
self.config = config
40-
self.logformat =\
41-
logging.Formatter(
42-
"%(asctime)s - %(levelname)s - %(name)s - %(message)s")
34+
self.tcRunLogger = tc_logger
35+
self.debugStream = debug_stream
4336
self.loader = unittest.loader.TestLoader()
4437
self.suite = None
4538

46-
if testcaseLogFile is not None:
47-
self.logfile = testcaseLogFile
48-
self.logger = logging.getLogger("TestCaseExecuteEngine")
49-
fh = logging.FileHandler(self.logfile)
50-
fh.setFormatter(self.logformat)
51-
self.logger.addHandler(fh)
52-
self.logger.setLevel(logging.DEBUG)
53-
if testResultLogFile is not None:
54-
ch = logging.StreamHandler()
55-
ch.setLevel(logging.ERROR)
56-
ch.setFormatter(self.logformat)
57-
self.logger.addHandler(ch)
58-
fp = open(testResultLogFile, "w")
59-
self.testResultLogFile = fp
60-
else:
61-
self.testResultLogFile = sys.stdout
62-
6339
def loadTestsFromDir(self, testDirectory):
6440
""" Load the test suites from a package with multiple test files """
6541
self.suite = self.loader.discover(testDirectory)
@@ -77,18 +53,11 @@ def injectTestCase(self, testSuites):
7753
if isinstance(test, unittest.BaseTestSuite):
7854
self.injectTestCase(test)
7955
else:
80-
#logger bears the name of the test class
81-
testcaselogger = logging.getLogger("%s" % (test))
82-
fh = logging.FileHandler(self.logfile)
83-
fh.setFormatter(self.logformat)
84-
testcaselogger.addHandler(fh)
85-
testcaselogger.setLevel(logging.DEBUG)
86-
8756
#inject testclient and logger into each unittest
57+
self.tcRunLogger.name = test.__str__()
8858
setattr(test, "testClient", self.testclient)
8959
setattr(test, "config", self.config)
90-
setattr(test, "debug", partial(testCaseLogger,
91-
logger=testcaselogger))
60+
setattr(test, "debug", self.tcRunLogger.debug)
9261
setattr(test.__class__, "clstestclient", self.testclient)
9362
if hasattr(test, "user"):
9463
# attribute when test is entirely executed as user
@@ -98,5 +67,5 @@ def injectTestCase(self, testSuites):
9867

9968
def run(self):
10069
if self.suite:
101-
unittest.TextTestRunner(stream=self.testResultLogFile,
70+
unittest.TextTestRunner(stream=self.debugStream,
10271
verbosity=2).run(self.suite)

0 commit comments

Comments
 (0)