blob: 27ddea7571b07f997f663e24dd83968a2cd757a9 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
2'''
3Created on 22-Oct-2012
4
5@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
6
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21
22
23teston is the main module.
24
25'''
26
27import sys
28import getpass
29import os
30import re
31import __builtin__
32import new
33import xmldict
34module = new.module("test")
35import openspeak
36global path, drivers_path, core_path, tests_path,logs_path
37path = re.sub("(core|bin)$", "", os.getcwd())
38drivers_path = path+"drivers/"
39core_path = path+"core"
40tests_path = path+"tests"
41logs_path = path+"logs/"
42config_path = path + "config/"
43sys.path.append(path)
44sys.path.append( drivers_path)
45sys.path.append(core_path )
46sys.path.append(tests_path)
47
48from core.utilities import Utilities
kelvin-onlabfb521662015-02-27 09:52:40 -080049from core.Thread import Thread
adminbae64d82013-08-01 10:50:15 -070050
adminbae64d82013-08-01 10:50:15 -070051
52class TestON:
53 '''
54
55 TestON will initiate the specified test.
56 The main tasks are :
57 * Initiate the required Component handles for the test.
58 * Create Log file Handles.
59
60 '''
61 def __init__(self,options):
62 '''
63 Initialise the component handles specified in the topology file of the specified test.
64
65 '''
66 # Initialization of the variables.
67 __builtin__.main = self
Jon Halla1185982014-09-15 14:55:10 -070068
adminbae64d82013-08-01 10:50:15 -070069 __builtin__.path = path
70 __builtin__.utilities = Utilities()
71 self.TRUE = 1
72 self.FALSE = 0
73 self.ERROR = -1
74 self.FAIL = False
75 self.PASS = True
76 self.CASERESULT = self.TRUE
77 self.init_result = self.TRUE
78 self.testResult = "Summary"
79 self.stepName =""
Jon Halld61331b2015-02-17 16:35:47 -080080 self.EXPERIMENTAL_MODE = False
adminbae64d82013-08-01 10:50:15 -070081 self.test_target = None
82 self.lastcommand = None
Jon Halld61331b2015-02-17 16:35:47 -080083 self.testDir = tests_path
84 self.configFile = config_path + "teston.cfg"
adminbae64d82013-08-01 10:50:15 -070085 self.parsingClass = "xmlparser"
86 self.parserPath = core_path + "/xmlparser"
87 self.loggerPath = core_path + "/logger"
88 self.loggerClass = "Logger"
89 self.logs_path = logs_path
90 self.driver = ''
kelvin-onlabfb521662015-02-27 09:52:40 -080091 self.Thread = Thread
Jon Halla1185982014-09-15 14:55:10 -070092
adminbae64d82013-08-01 10:50:15 -070093
94 self.configparser()
95 verifyOptions(options)
96 load_logger()
97 self.componentDictionary = {}
98 self.componentDictionary = self.topology ['COMPONENT']
99 self.driversList=[]
100 if type(self.componentDictionary) == str :
101 self.componentDictionary = dict(self.componentDictionary)
102
103 for component in self.componentDictionary :
104 self.driversList.append(self.componentDictionary[component]['type'])
105
106 self.driversList = list(set(self.driversList)) # Removing duplicates.
107 # Checking the test_target option set for the component or not
108 if type(self.componentDictionary) == dict:
109 for component in self.componentDictionary.keys():
110 if 'test_target' in self.componentDictionary[component].keys():
111 self.test_target = component
112
Jon Halld61331b2015-02-17 16:35:47 -0800113 # Checking for the openspeak file and test script
adminbae64d82013-08-01 10:50:15 -0700114 self.logger.initlog(self)
115
116 # Creating Drivers Handles
117 initString = "\n"+"*" * 30+"\n CASE INIT \n"+"*" * 30+"\n"
118 self.log.exact(initString)
119 self.driverObject = {}
120 self.random_order = 111 # Random order id to connect the components
121 components_connect_order = {}
122 #component_list.append()
123 if type(self.componentDictionary) == dict:
124 for component in self.componentDictionary.keys():
125 self.componentDictionary[component]['connect_order'] = self.componentDictionary[component]['connect_order'] if ('connect_order' in self.componentDictionary[component].keys()) else str(self.get_random())
126 components_connect_order[component] = eval(self.componentDictionary[component]['connect_order'])
127 #Ordering components based on the connect order.
128 ordered_component_list =sorted(components_connect_order, key=lambda key: components_connect_order[key])
129 print ordered_component_list
130
131 for component in ordered_component_list:
132 self.componentInit(component)
133
134 def configparser(self):
135 '''
136 It will parse the config file (teston.cfg) and return as dictionary
137 '''
138 matchFileName = re.match(r'(.*)\.cfg', self.configFile, re.M | re.I)
139 if matchFileName:
140 xml = open(self.configFile).read()
141 try :
142 self.configDict = xmldict.xml_to_dict(xml)
143 return self.configDict
144 except :
145 print "There is no such file to parse " + self.configFile
146
147 def componentInit(self,component):
148 '''
149 This method will initialize specified component
150 '''
151 global driver_options
152 self.log.info("Creating component Handle: "+component)
Jon Halld61331b2015-02-17 16:35:47 -0800153 driver_options = {}
adminbae64d82013-08-01 10:50:15 -0700154 if 'COMPONENTS' in self.componentDictionary[component].keys():
155 driver_options =dict(self.componentDictionary[component]['COMPONENTS'])
156
157 driver_options['name']=component
158 driverName = self.componentDictionary[component]['type']
159 driver_options ['type'] = driverName
160
161 classPath = self.getDriverPath(driverName.lower())
kelvin-onlabfb521662015-02-27 09:52:40 -0800162 driverModule = __import__(classPath, globals(), locals(), [driverName.lower()], -1)
adminbae64d82013-08-01 10:50:15 -0700163 driverClass = getattr(driverModule, driverName)
164 driverObject = driverClass()
165
166 connect_result = driverObject.connect(user_name = self.componentDictionary[component]['user'] if ('user' in self.componentDictionary[component].keys()) else getpass.getuser(),
167 ip_address= self.componentDictionary[component]['host'] if ('host' in self.componentDictionary[component].keys()) else 'localhost',
168 pwd = self.componentDictionary[component]['password'] if ('password' in self.componentDictionary[component].keys()) else 'changeme',
169 port = self.componentDictionary[component]['port'] if ('port' in self.componentDictionary[component].keys()) else None,
170 options = driver_options)
171 if not connect_result:
172 self.log.error("Exiting form the test execution because the connecting to the "+component+" component failed.")
Jon Halld61331b2015-02-17 16:35:47 -0800173 self.exit()
adminbae64d82013-08-01 10:50:15 -0700174
175 vars(self)[component] = driverObject
176
177 def run(self):
178 '''
179 The Execution of the test script's cases listed in the Test params file will be done here.
180 And Update each test case result.
181 This method will return TRUE if it executed all the test cases successfully,
182 else will retun FALSE
183 '''
184
185 self.testCaseResult = {}
Jon Halla1185982014-09-15 14:55:10 -0700186 self.TOTAL_TC = 0
adminbae64d82013-08-01 10:50:15 -0700187 self.TOTAL_TC_RUN = 0
Jon Halld61331b2015-02-17 16:35:47 -0800188 self.TOTAL_TC_PLANNED = 0
adminbae64d82013-08-01 10:50:15 -0700189 self.TOTAL_TC_NORESULT = 0
190 self.TOTAL_TC_FAIL = 0
191 self.TOTAL_TC_PASS = 0
Jon Halla1185982014-09-15 14:55:10 -0700192 self.TEST_ITERATION = 0
adminbae64d82013-08-01 10:50:15 -0700193 self.stepCount = 0
194 self.CASERESULT = self.TRUE
195
Jon Halld61331b2015-02-17 16:35:47 -0800196 import testparser
adminbae64d82013-08-01 10:50:15 -0700197 testFile = self.tests_path + "/"+self.TEST + "/"+self.TEST + ".py"
198 test = testparser.TestParser(testFile)
199 self.testscript = test.testscript
200 self.code = test.getStepCode()
Jon Halla1185982014-09-15 14:55:10 -0700201 repeat= int(self.params['repeat']) if ('repeat' in self.params) else 1
202 main.TOTAL_TC_PLANNED = len(self.testcases_list)*repeat
adminbae64d82013-08-01 10:50:15 -0700203
204 result = self.TRUE
Jon Halla1185982014-09-15 14:55:10 -0700205 while(repeat):
206 for self.CurrentTestCaseNumber in self.testcases_list:
Jon Halld61331b2015-02-17 16:35:47 -0800207 result = self.runCase(self.CurrentTestCaseNumber)
208 repeat-=1
adminbae64d82013-08-01 10:50:15 -0700209 return result
210
211 def runCase(self,testCaseNumber):
212 self.CurrentTestCaseNumber = testCaseNumber
213 result = self.TRUE
214 self.stepCount = 0
215 self.EXPERIMENTAL_MODE = self.FALSE
216 self.addCaseHeader()
217 self.testCaseNumber = str(testCaseNumber)
218 stopped = False
219 try :
220 self.stepList = self.code[self.testCaseNumber].keys()
Jon Halld61331b2015-02-17 16:35:47 -0800221 except KeyError:
adminbae64d82013-08-01 10:50:15 -0700222 main.log.error("There is no Test-Case "+ self.testCaseNumber)
223 return main.FALSE
224
225 self.stepCount = 0
226 while self.stepCount < len(self.code[self.testCaseNumber].keys()):
227 result = self.runStep(self.stepList,self.code,self.testCaseNumber)
228 if result == main.FALSE:
229 break
230 elif result == main.TRUE :
231 continue
232
233 if not stopped :
234 self.testCaseResult[str(self.CurrentTestCaseNumber)] = self.CASERESULT
235 self.logger.updateCaseResults(self)
236 return result
237
238 def runStep(self,stepList,code,testCaseNumber):
239 if not cli.pause:
240 try :
241 step = stepList[self.stepCount]
242 exec code[testCaseNumber][step] in module.__dict__
243 self.stepCount = self.stepCount + 1
244 except TypeError,e:
245 self.stepCount = self.stepCount + 1
kelvin-onlabfb521662015-02-27 09:52:40 -0800246 self.log.error(e)
adminbae64d82013-08-01 10:50:15 -0700247 return main.TRUE
248
249 if cli.stop:
250 cli.stop = False
251 stopped = True
252 self.TOTAL_TC_NORESULT = self.TOTAL_TC_NORESULT + 1
253 self.testCaseResult[str(self.CurrentTestCaseNumber)] = "Stopped"
254 self.logger.updateCaseResults(self)
255 result = self.cleanup()
256 return main.FALSE
257
258 def addCaseHeader(self):
259 caseHeader = "\n"+"*" * 30+"\n Result summary for Testcase"+str(self.CurrentTestCaseNumber)+"\n"+"*" * 30+"\n"
Jon Halld61331b2015-02-17 16:35:47 -0800260 self.log.exact(caseHeader)
261 caseHeader = "\n"+"*" * 40 +"\nStart of Test Case"+str(self.CurrentTestCaseNumber)+" : "
adminbae64d82013-08-01 10:50:15 -0700262 for driver in self.componentDictionary.keys():
263 vars(self)[driver+'log'].info(caseHeader)
264
265 def addCaseFooter(self):
266 if self.stepCount-1 > 0 :
267 previousStep = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount-1)+": "+ str(self.stepName) + ""
268 stepHeader = "\n"+"*" * 40+"\nEnd of Step "+previousStep+"\n"+"*" * 40+"\n"
269
270 caseFooter = "\n"+"*" * 40+"\nEnd of Test case "+str(self.CurrentTestCaseNumber)+"\n"+"*" * 40+"\n"
271
272 for driver in self.driversList:
273 vars(self)[driver].write(stepHeader+"\n"+caseFooter)
274
275 def cleanup(self):
276 '''
277 Release all the component handles and the close opened file handles.
278 This will return TRUE if all the component handles and log handles closed properly,
279 else return FALSE
280
281 '''
282 result = self.TRUE
283 self.logger.testSummary(self)
Jon Halld61331b2015-02-17 16:35:47 -0800284
adminbae64d82013-08-01 10:50:15 -0700285 #self.reportFile.close()
Jon Halld61331b2015-02-17 16:35:47 -0800286
adminbae64d82013-08-01 10:50:15 -0700287
admin2c7034f2013-08-02 15:09:17 -0700288 #utilities.send_mail()
adminbae64d82013-08-01 10:50:15 -0700289 try :
290 for component in self.componentDictionary.keys():
Jon Halld61331b2015-02-17 16:35:47 -0800291 tempObject = vars(self)[component]
292 print "Disconnecting " + str(tempObject)
adminbae64d82013-08-01 10:50:15 -0700293 tempObject.disconnect()
Jon Halld61331b2015-02-17 16:35:47 -0800294 #tempObject.execute(cmd="exit",prompt="(.*)",timeout=120)
adminbae64d82013-08-01 10:50:15 -0700295
296 except(Exception):
Jon Halld61331b2015-02-17 16:35:47 -0800297 self.log.exception( "Exception while disconnecting from " +
298 str( component ) )
Jon Halla1185982014-09-15 14:55:10 -0700299 #print " There is an error with closing hanldes"
adminbae64d82013-08-01 10:50:15 -0700300 result = self.FALSE
301 # Closing all the driver's session files
302 for driver in self.componentDictionary.keys():
303 vars(self)[driver].close_log_handles()
Jon Halld61331b2015-02-17 16:35:47 -0800304
adminbae64d82013-08-01 10:50:15 -0700305 return result
Jon Halld61331b2015-02-17 16:35:47 -0800306
adminbae64d82013-08-01 10:50:15 -0700307 def pause(self):
308 '''
309 This function will pause the test's execution, and will continue after user provide 'resume' command.
310 '''
311 __builtin__.testthread.pause()
312
313 def onfail(self,*components):
314 '''
315 When test step failed, calling all the components onfail.
316 '''
317
318 if not components:
319 try :
320 for component in self.componentDictionary.keys():
321 tempObject = vars(self)[component]
322 result = tempObject.onfail()
323 except(Exception),e:
324 print str(e)
325 result = self.FALSE
326
327 else:
328 try :
329 for component in components:
330 tempObject = vars(self)[component]
331 result = tempObject.onfail()
332 except(Exception),e:
333 print str(e)
334 result = self.FALSE
335
336
337 def getDriverPath(self,driverName):
338 '''
339 Based on the component 'type' specified in the params , this method will find the absolute path ,
340 by recursively searching the name of the component.
341 '''
342 import commands
343
344 cmd = "find "+drivers_path+" -name "+driverName+".py"
345 result = commands.getoutput(cmd)
346
347 result_array = str(result).split('\n')
348 result_count = 0
349
350 for drivers_list in result_array:
351 result_count = result_count+1
352 if result_count > 1 :
353 print "found "+driverName+" "+ str(result_count) + " times"+str(result_array)
354 self.exit()
355
356 result = re.sub("(.*)drivers","",result)
357 result = re.sub("\.py","",result)
358 result = re.sub("\.pyc","",result)
359 result = re.sub("\/",".",result)
360 result = "drivers"+result
361 return result
362
363
364 def step(self,stepDesc):
365 '''
366 The step information of the test-case will append to the logs.
367 '''
368 previousStep = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount-1)+": "+ str(self.stepName) + ""
369 self.stepName = stepDesc
370
371 stepName = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount)+": "+ str(stepDesc) + ""
372 try :
373 if self.stepCount == 0:
374 stepName = " INIT : Initializing the test case :"+self.CurrentTestCase
375 except AttributeError:
376 stepName = " INIT : Initializing the test case :"+str(self.CurrentTestCaseNumber)
377
378 self.log.step(stepName)
379 stepHeader = ""
380 if self.stepCount > 1 :
381 stepHeader = "\n"+"-"*45+"\nEnd of Step "+previousStep+"\n"+"-"*45+"\n"
382
Jon Halld61331b2015-02-17 16:35:47 -0800383 stepHeader += "\n"+"-"*45+"\nStart of Step"+stepName+"\n"+"-"*45+"\n"
adminbae64d82013-08-01 10:50:15 -0700384 for driver in self.componentDictionary.keys():
385 vars(self)[driver+'log'].info(stepHeader)
386
387 def case(self,testCaseName):
388 '''
389 Test's each test-case information will append to the logs.
390 '''
Jon Halld61331b2015-02-17 16:35:47 -0800391 self.CurrentTestCase = testCaseName
adminbae64d82013-08-01 10:50:15 -0700392 testCaseName = " " + str(testCaseName) + ""
393 self.log.case(testCaseName)
Jon Halld61331b2015-02-17 16:35:47 -0800394 caseHeader = testCaseName+"\n"+"*" * 40+"\n"
adminbae64d82013-08-01 10:50:15 -0700395 for driver in self.componentDictionary.keys():
396 vars(self)[driver+'log'].info(caseHeader)
397
398 def testDesc(self,description):
399 '''
400 Test description will append to the logs.
401 '''
402 description = "Test Description : " + str (description) + ""
403 self.log.info(description)
404
405 def _getTest(self):
406 '''
407 This method will parse the test script to find required test information.
408 '''
409 testFile = self.tests_path + "/"+self.TEST + "/"+self.TEST + ".py"
410 testFileHandler = open(testFile, 'r')
411 testFileList = testFileHandler.readlines()
412 testFileHandler.close()
413 #self.TOTAL_TC_PLANNED = 0
414 counter = 0
415 for index in range(len(testFileList)):
416 lineMatch = re.match('\s+def CASE(\d+)(.*):',testFileList[index],0)
417 if lineMatch:
418 counter = counter + 1
Jon Halla1185982014-09-15 14:55:10 -0700419 self.TC_PLANNED = len(self.testcases_list)
420
adminbae64d82013-08-01 10:50:15 -0700421
422 def response_parser(self,response, return_format):
423 ''' It will load the default response parser '''
424 response_dict = {}
425 response_dict = self.response_to_dict(response, return_format)
Jon Halld61331b2015-02-17 16:35:47 -0800426 return_format_string = self.dict_to_return_format(response,return_format,response_dict)
adminbae64d82013-08-01 10:50:15 -0700427 return return_format_string
428
429 def response_to_dict(self,response,return_format):
430
431 response_dict = {}
432 json_match = re.search('^\s*{', response)
433 xml_match = re.search('^\s*\<', response)
434 ini_match = re.search('^\s*\[', response)
435 if json_match :
436 main.log.info(" Response is in 'JSON' format and Converting to '"+return_format+"' format")
Jon Halld61331b2015-02-17 16:35:47 -0800437 # Formatting the json string
adminbae64d82013-08-01 10:50:15 -0700438
439 response = re.sub(r"{\s*'?(\w)", r'{"\1', response)
440 response = re.sub(r",\s*'?(\w)", r',"\1', response)
441 response = re.sub(r"(\w)'?\s*:", r'\1":', response)
442 response = re.sub(r":\s*'(\w)'\s*([,}])", r':"\1"\2', response)
443
444 try :
445 import json
446 response_dict = json.loads(response)
kelvin-onlabfb521662015-02-27 09:52:40 -0800447 except Exception , e :
448 print e
adminbae64d82013-08-01 10:50:15 -0700449 main.log.error("Json Parser is unable to parse the string")
450 return response_dict
451
452 elif ini_match :
453 main.log.info(" Response is in 'INI' format and Converting to '"+return_format+"' format")
454 from configobj import ConfigObj
455 response_file = open("respnse_file.temp",'w')
456 response_file.write(response)
Jon Halld61331b2015-02-17 16:35:47 -0800457 response_file.close()
adminbae64d82013-08-01 10:50:15 -0700458 response_dict = ConfigObj("respnse_file.temp")
459 return response_dict
460
461 elif xml_match :
462 main.log.info(" Response is in 'XML' format and Converting to '"+return_format+"' format")
463 try :
adminbae64d82013-08-01 10:50:15 -0700464 response_dict = xmldict.xml_to_dict("<response> "+str(response)+" </response>")
465 except Exception, e:
kelvin-onlabfb521662015-02-27 09:52:40 -0800466 main.log.error(e)
adminbae64d82013-08-01 10:50:15 -0700467 return response_dict
468
469 def dict_to_return_format(self,response,return_format,response_dict):
470
471 if return_format =='table' :
472 ''' Will return in table format'''
473 to_do = "Call the table output formatter"
474 global response_table
475 response_table = '\n'
476 response_table = response_table +'\t'.join(response_dict)+"\n"
477
478 def get_table(value_to_convert):
479 ''' This will parse the dictionary recusrsively and print as table format'''
480 table_data = ""
481 if type(value_to_convert) == dict :
482 table_data = table_data +'\t'.join(value_to_convert)+"\n"
483 for temp_val in value_to_convert.values() :
484 table_data = table_data + get_table(temp_val)
485 else :
486 table_data = table_data + str(value_to_convert) +"\t"
Jon Halld61331b2015-02-17 16:35:47 -0800487 return table_data
adminbae64d82013-08-01 10:50:15 -0700488
489 for value in response_dict.values() :
490 response_table = response_table + get_table(value)
491
492
493
494 #response_table = response_table + '\t'.join(response_dict.values())
495
496 return response_table
497
498 elif return_format =='config':
499 ''' Will return in config format'''
500 to_do = 'Call dict to config coverter'
501 response_string = str(response_dict)
502 print response_string
503 response_config = re.sub(",", "\n\t", response_string)
504 response_config = re.sub("u\'", "\'", response_config)
505 response_config = re.sub("{", "", response_config)
506 response_config = re.sub("}", "\n", response_config)
507 response_config = re.sub(":", " =", response_config)
508 return "[response]\n\t "+response_config
509
510 elif return_format == 'xml':
511 ''' Will return in xml format'''
adminbae64d82013-08-01 10:50:15 -0700512 response_xml = xmldict.dict_to_xml(response_dict)
513 response_xml = re.sub(">\s*<", ">\n<", response_xml)
514 return "\n"+response_xml
515
516 elif return_format == 'json':
517 ''' Will return in json format'''
518 to_do = 'Call dict to xml coverter'
519 import json
520 response_json = json.dumps(response_dict)
521 return response_json
522
523 def get_random(self):
524 self.random_order = self.random_order + 1
525 return self.random_order
526
527 def exit(self):
528 __builtin__.testthread = None
529 sys.exit()
530
531def verifyOptions(options):
532 '''
533 This will verify the command line options and set to default values, if any option not given in command line.
534 '''
535 import pprint
536 pp = pprint.PrettyPrinter(indent=4)
537
538 #pp.pprint(options)
539 verifyTest(options)
540 verifyExample(options)
541 verifyTestScript(options)
542 verifyParams()
543 verifyLogdir(options)
544 verifyMail(options)
545 verifyTestCases(options)
546
547def verifyTest(options):
548 if options.testname:
549 main.TEST = options.testname
550 main.classPath = "tests."+main.TEST+"."+main.TEST
551 main.tests_path = tests_path
552 elif options.example :
553 main.TEST = options.example
554 main.tests_path = path+"/examples/"
555 main.classPath = "examples."+main.TEST+"."+main.TEST
556 else :
557 print "Test or Example not specified please specify the --test <test name > or --example <example name>"
558 self.exit()
559
560def verifyExample(options):
561 if options.example:
562 main.testDir = path+'/examples/'
563 main.tests_path = path+"/examples/"
564 main.classPath = "examples."+main.TEST+"."+main.TEST
565
566def verifyLogdir(options):
Jon Halld61331b2015-02-17 16:35:47 -0800567 #Verifying Log directory option
adminbae64d82013-08-01 10:50:15 -0700568 if options.logdir:
569 main.logdir = options.logdir
570 else :
Jon Halld61331b2015-02-17 16:35:47 -0800571 main.logdir = main.FALSE
adminbae64d82013-08-01 10:50:15 -0700572
573def verifyMail(options):
Jon Halld61331b2015-02-17 16:35:47 -0800574 # Checking the mailing list
adminbae64d82013-08-01 10:50:15 -0700575 if options.mail:
576 main.mail = options.mail
577 elif main.params.has_key('mail'):
578 main.mail = main.params['mail']
579 else :
580 main.mail = 'paxweb@paxterrasolutions.com'
581
582def verifyTestCases(options):
Jon Halld61331b2015-02-17 16:35:47 -0800583 #Getting Test cases list
adminbae64d82013-08-01 10:50:15 -0700584 if options.testcases:
Jon Halld61331b2015-02-17 16:35:47 -0800585 testcases_list = options.testcases
586 #sys.exit()
adminbae64d82013-08-01 10:50:15 -0700587 testcases_list = re.sub("(\[|\])", "", options.testcases)
588 main.testcases_list = eval(testcases_list+",")
589 else :
590 if 'testcases' in main.params.keys():
Jon Halla1185982014-09-15 14:55:10 -0700591 temp = eval(main.params['testcases']+",")
592 list1=[]
593 if type(temp[0])==list:
594 for test in temp:
595 for testcase in test:
596 if type(testcase)==int:
597 testcase=[testcase]
598 list1.extend(testcase)
599 else :
600 temp=list(temp)
601 for testcase in temp:
602 if type(testcase)==int:
603 testcase=[testcase]
604 list1.extend(testcase)
Jon Halld61331b2015-02-17 16:35:47 -0800605 main.testcases_list=list1
adminbae64d82013-08-01 10:50:15 -0700606 else :
607 print "testcases not specifed in params, please provide in params file or 'testcases' commandline argument"
Jon Halld61331b2015-02-17 16:35:47 -0800608 sys.exit()
adminbae64d82013-08-01 10:50:15 -0700609
610def verifyTestScript(options):
611 '''
612 Verifyies test script.
613 '''
Jon Halld61331b2015-02-17 16:35:47 -0800614 main.openspeak = openspeak.OpenSpeak()
adminbae64d82013-08-01 10:50:15 -0700615 openspeakfile = main.testDir+"/" + main.TEST + "/" + main.TEST + ".ospk"
616 testfile = main.testDir+"/" + main.TEST + "/" + main.TEST + ".py"
617 if os.path.exists(openspeakfile) :
618 main.openspeak.compiler(openspeakfile=openspeakfile,writetofile=1)
619 elif os.path.exists(testfile):
620 print ''
621 else:
622 print "\nThere is no :\""+main.TEST+"\" test, Please Provide OpenSpeak Script/ test script"
623 __builtin__.testthread = None
624 main.exit()
625
626 try :
adminbae64d82013-08-01 10:50:15 -0700627 testModule = __import__(main.classPath, globals(), locals(), [main.TEST], -1)
628 except(ImportError):
Jon Hallf8ecf732014-12-02 21:14:16 -0500629 print "There was an import error, it might mean that there is no test like "+main.TEST
Jon Halld61331b2015-02-17 16:35:47 -0800630 main.exit()
adminbae64d82013-08-01 10:50:15 -0700631
632 testClass = getattr(testModule, main.TEST)
633 main.testObject = testClass()
634 load_parser()
Jon Halld61331b2015-02-17 16:35:47 -0800635 main.params = main.parser.parseParams(main.classPath)
636 main.topology = main.parser.parseTopology(main.classPath)
adminbae64d82013-08-01 10:50:15 -0700637
638def verifyParams():
639 try :
640 main.params = main.params['PARAMS']
641 except(KeyError):
642 print "Error with the params file: Either the file not specified or the format is not correct"
Jon Halld61331b2015-02-17 16:35:47 -0800643 main.exit()
adminbae64d82013-08-01 10:50:15 -0700644
645 try :
646 main.topology = main.topology['TOPOLOGY']
647 except(KeyError):
648 print "Error with the Topology file: Either the file not specified or the format is not correct"
649 main.exit()
650
651def load_parser() :
652 '''
653 It facilitates the loading customised parser for topology and params file.
654 It loads parser mentioned in tab named parser of teston.cfg file.
655 It also loads default xmlparser if no parser have specified in teston.cfg file.
656
657 '''
658 confighash = main.configDict
659 if 'file' in confighash['config']['parser'] and 'class' in confighash['config']['parser']:
660 if confighash['config']['parser']['file'] != None or confighash['config']['parser']['class']!= None :
661 if os.path.exists(confighash['config']['parser']['file']) :
662 module = re.sub(r".py\s*$","",confighash['config']['parser']['file'])
663 moduleList = module.split("/")
664 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
665 try :
666 parsingClass = confighash['config']['parser']['class']
667 parsingModule = __import__(newModule, globals(), locals(), [parsingClass], -1)
668 parsingClass = getattr(parsingModule, parsingClass)
669 main.parser = parsingClass()
670 #hashobj = main.parser.parseParams(main.classPath)
671 if hasattr(main.parser,"parseParams") and hasattr(main.parser,"parseTopology") and hasattr(main.parser,"parse") :
672
673 pass
674 else:
675 main.exit()
676
677 except ImportError:
678 print sys.exc_info()[1]
679 main.exit()
680 else :
681 print "No Such File Exists !!"+ confighash['config']['parser']['file'] +"using default parser"
Jon Halld61331b2015-02-17 16:35:47 -0800682 load_defaultParser()
683 elif confighash['config']['parser']['file'] == None or confighash['config']['parser']['class'] == None :
684 load_defaultParser()
adminbae64d82013-08-01 10:50:15 -0700685 else:
686 load_defaultParser()
687
688def load_defaultParser():
689 '''
690 It will load the default parser which is xml parser to parse the params and topology file.
691 '''
692 moduleList = main.parserPath.split("/")
693 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
694 try :
Jon Halld61331b2015-02-17 16:35:47 -0800695 parsingClass = main.parsingClass
adminbae64d82013-08-01 10:50:15 -0700696 parsingModule = __import__(newModule, globals(), locals(), [parsingClass], -1)
697 parsingClass = getattr(parsingModule, parsingClass)
698 main.parser = parsingClass()
699 if hasattr(main.parser,"parseParams") and hasattr(main.parser,"parseTopology") and hasattr(main.parser,"parse") :
700 pass
701 else:
702 main.exit()
703
704 except ImportError:
705 print sys.exc_info()[1]
706
707
708def load_logger() :
709 '''
710 It facilitates the loading customised parser for topology and params file.
711 It loads parser mentioned in tab named parser of teston.cfg file.
712 It also loads default xmlparser if no parser have specified in teston.cfg file.
713
714 '''
715 confighash = main.configDict
716 if 'file' in confighash['config']['logger'] and 'class' in confighash['config']['logger']:
717 if confighash['config']['logger']['file'] != None or confighash['config']['logger']['class']!= None :
718 if os.path.exists(confighash['config']['logger']['file']) :
719 module = re.sub(r".py\s*$","",confighash['config']['logger']['file'])
720 moduleList = module.split("/")
721 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
722 try :
723 loggerClass = confighash['config']['logger']['class']
724 loggerModule = __import__(newModule, globals(), locals(), [loggerClass], -1)
725 loggerClass = getattr(loggerModule, loggerClass)
726 main.logger = loggerClass()
727 #hashobj = main.parser.parseParams(main.classPath)
728
729 except ImportError:
730 print sys.exc_info()[1]
731 else :
732 print "No Such File Exists !!"+confighash['config']['logger']['file']+ "Using default logger"
733 load_defaultlogger()
Jon Halld61331b2015-02-17 16:35:47 -0800734 elif confighash['config']['parser']['file'] == None or confighash['config']['parser']['class'] == None :
735 load_defaultlogger()
adminbae64d82013-08-01 10:50:15 -0700736 else:
737 load_defaultlogger()
738
739def load_defaultlogger():
740 '''
741 It will load the default parser which is xml parser to parse the params and topology file.
742 '''
743 moduleList = main.loggerPath.split("/")
744 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
745 try :
Jon Halld61331b2015-02-17 16:35:47 -0800746 loggerClass = main.loggerClass
adminbae64d82013-08-01 10:50:15 -0700747 loggerModule = __import__(newModule, globals(), locals(), [loggerClass], -1)
748 loggerClass = getattr(loggerModule, loggerClass)
749 main.logger = loggerClass()
750
751 except ImportError:
752 print sys.exc_info()[1]
Jon Halld61331b2015-02-17 16:35:47 -0800753 main.exit()
adminbae64d82013-08-01 10:50:15 -0700754
755def load_defaultlogger():
756 '''
757 It will load the default parser which is xml parser to parse the params and topology file.
758 '''
759 moduleList = main.loggerPath.split("/")
760 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
761 try :
Jon Halld61331b2015-02-17 16:35:47 -0800762 loggerClass = main.loggerClass
adminbae64d82013-08-01 10:50:15 -0700763 loggerModule = __import__(newModule, globals(), locals(), [loggerClass], -1)
764 loggerClass = getattr(loggerModule, loggerClass)
765 main.logger = loggerClass()
766
767 except ImportError:
768 print sys.exc_info()[1]
769 main.exit()
770
771
772
773
774def _echo(self):
775 print "THIS IS ECHO"