blob: f48d3dd59d2ea553a2746eb6ce9cc3b0cb1568cf [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
Jon Hall30b82fa2015-03-04 17:15:43 -080034import importlib
adminbae64d82013-08-01 10:50:15 -070035module = new.module("test")
36import openspeak
37global path, drivers_path, core_path, tests_path,logs_path
38path = re.sub("(core|bin)$", "", os.getcwd())
39drivers_path = path+"drivers/"
40core_path = path+"core"
41tests_path = path+"tests"
42logs_path = path+"logs/"
43config_path = path + "config/"
44sys.path.append(path)
45sys.path.append( drivers_path)
46sys.path.append(core_path )
47sys.path.append(tests_path)
48
49from core.utilities import Utilities
kelvin-onlabfb521662015-02-27 09:52:40 -080050from core.Thread import Thread
adminbae64d82013-08-01 10:50:15 -070051
adminbae64d82013-08-01 10:50:15 -070052
53class TestON:
54 '''
55
56 TestON will initiate the specified test.
57 The main tasks are :
58 * Initiate the required Component handles for the test.
59 * Create Log file Handles.
60
61 '''
62 def __init__(self,options):
63 '''
64 Initialise the component handles specified in the topology file of the specified test.
65
66 '''
67 # Initialization of the variables.
68 __builtin__.main = self
Jon Halla1185982014-09-15 14:55:10 -070069
adminbae64d82013-08-01 10:50:15 -070070 __builtin__.path = path
71 __builtin__.utilities = Utilities()
72 self.TRUE = 1
73 self.FALSE = 0
74 self.ERROR = -1
75 self.FAIL = False
76 self.PASS = True
77 self.CASERESULT = self.TRUE
78 self.init_result = self.TRUE
79 self.testResult = "Summary"
80 self.stepName =""
Jon Halld61331b2015-02-17 16:35:47 -080081 self.EXPERIMENTAL_MODE = False
adminbae64d82013-08-01 10:50:15 -070082 self.test_target = None
83 self.lastcommand = None
Jon Halld61331b2015-02-17 16:35:47 -080084 self.testDir = tests_path
85 self.configFile = config_path + "teston.cfg"
adminbae64d82013-08-01 10:50:15 -070086 self.parsingClass = "xmlparser"
87 self.parserPath = core_path + "/xmlparser"
88 self.loggerPath = core_path + "/logger"
89 self.loggerClass = "Logger"
90 self.logs_path = logs_path
91 self.driver = ''
kelvin-onlabfb521662015-02-27 09:52:40 -080092 self.Thread = Thread
Jon Halla1185982014-09-15 14:55:10 -070093
adminbae64d82013-08-01 10:50:15 -070094
95 self.configparser()
96 verifyOptions(options)
97 load_logger()
98 self.componentDictionary = {}
99 self.componentDictionary = self.topology ['COMPONENT']
100 self.driversList=[]
101 if type(self.componentDictionary) == str :
102 self.componentDictionary = dict(self.componentDictionary)
103
104 for component in self.componentDictionary :
105 self.driversList.append(self.componentDictionary[component]['type'])
106
107 self.driversList = list(set(self.driversList)) # Removing duplicates.
108 # Checking the test_target option set for the component or not
109 if type(self.componentDictionary) == dict:
110 for component in self.componentDictionary.keys():
111 if 'test_target' in self.componentDictionary[component].keys():
112 self.test_target = component
113
Jon Halld61331b2015-02-17 16:35:47 -0800114 # Checking for the openspeak file and test script
adminbae64d82013-08-01 10:50:15 -0700115 self.logger.initlog(self)
116
117 # Creating Drivers Handles
118 initString = "\n"+"*" * 30+"\n CASE INIT \n"+"*" * 30+"\n"
119 self.log.exact(initString)
120 self.driverObject = {}
121 self.random_order = 111 # Random order id to connect the components
122 components_connect_order = {}
123 #component_list.append()
124 if type(self.componentDictionary) == dict:
125 for component in self.componentDictionary.keys():
126 self.componentDictionary[component]['connect_order'] = self.componentDictionary[component]['connect_order'] if ('connect_order' in self.componentDictionary[component].keys()) else str(self.get_random())
127 components_connect_order[component] = eval(self.componentDictionary[component]['connect_order'])
128 #Ordering components based on the connect order.
129 ordered_component_list =sorted(components_connect_order, key=lambda key: components_connect_order[key])
130 print ordered_component_list
131
132 for component in ordered_component_list:
133 self.componentInit(component)
134
135 def configparser(self):
136 '''
137 It will parse the config file (teston.cfg) and return as dictionary
138 '''
139 matchFileName = re.match(r'(.*)\.cfg', self.configFile, re.M | re.I)
140 if matchFileName:
141 xml = open(self.configFile).read()
142 try :
143 self.configDict = xmldict.xml_to_dict(xml)
144 return self.configDict
145 except :
146 print "There is no such file to parse " + self.configFile
147
148 def componentInit(self,component):
149 '''
150 This method will initialize specified component
151 '''
152 global driver_options
153 self.log.info("Creating component Handle: "+component)
Jon Halld61331b2015-02-17 16:35:47 -0800154 driver_options = {}
adminbae64d82013-08-01 10:50:15 -0700155 if 'COMPONENTS' in self.componentDictionary[component].keys():
156 driver_options =dict(self.componentDictionary[component]['COMPONENTS'])
157
158 driver_options['name']=component
159 driverName = self.componentDictionary[component]['type']
160 driver_options ['type'] = driverName
161
162 classPath = self.getDriverPath(driverName.lower())
Jon Hall30b82fa2015-03-04 17:15:43 -0800163 driverModule = importlib.import_module(classPath)
adminbae64d82013-08-01 10:50:15 -0700164 driverClass = getattr(driverModule, driverName)
165 driverObject = driverClass()
166
167 connect_result = driverObject.connect(user_name = self.componentDictionary[component]['user'] if ('user' in self.componentDictionary[component].keys()) else getpass.getuser(),
168 ip_address= self.componentDictionary[component]['host'] if ('host' in self.componentDictionary[component].keys()) else 'localhost',
169 pwd = self.componentDictionary[component]['password'] if ('password' in self.componentDictionary[component].keys()) else 'changeme',
170 port = self.componentDictionary[component]['port'] if ('port' in self.componentDictionary[component].keys()) else None,
171 options = driver_options)
172 if not connect_result:
173 self.log.error("Exiting form the test execution because the connecting to the "+component+" component failed.")
Jon Halld61331b2015-02-17 16:35:47 -0800174 self.exit()
adminbae64d82013-08-01 10:50:15 -0700175
176 vars(self)[component] = driverObject
177
178 def run(self):
179 '''
180 The Execution of the test script's cases listed in the Test params file will be done here.
181 And Update each test case result.
182 This method will return TRUE if it executed all the test cases successfully,
183 else will retun FALSE
184 '''
185
186 self.testCaseResult = {}
Jon Halla1185982014-09-15 14:55:10 -0700187 self.TOTAL_TC = 0
adminbae64d82013-08-01 10:50:15 -0700188 self.TOTAL_TC_RUN = 0
Jon Halld61331b2015-02-17 16:35:47 -0800189 self.TOTAL_TC_PLANNED = 0
adminbae64d82013-08-01 10:50:15 -0700190 self.TOTAL_TC_NORESULT = 0
191 self.TOTAL_TC_FAIL = 0
192 self.TOTAL_TC_PASS = 0
Jon Halla1185982014-09-15 14:55:10 -0700193 self.TEST_ITERATION = 0
adminbae64d82013-08-01 10:50:15 -0700194 self.stepCount = 0
195 self.CASERESULT = self.TRUE
196
Jon Halld61331b2015-02-17 16:35:47 -0800197 import testparser
adminbae64d82013-08-01 10:50:15 -0700198 testFile = self.tests_path + "/"+self.TEST + "/"+self.TEST + ".py"
199 test = testparser.TestParser(testFile)
200 self.testscript = test.testscript
201 self.code = test.getStepCode()
Jon Halla1185982014-09-15 14:55:10 -0700202 repeat= int(self.params['repeat']) if ('repeat' in self.params) else 1
203 main.TOTAL_TC_PLANNED = len(self.testcases_list)*repeat
adminbae64d82013-08-01 10:50:15 -0700204
205 result = self.TRUE
Jon Halla1185982014-09-15 14:55:10 -0700206 while(repeat):
207 for self.CurrentTestCaseNumber in self.testcases_list:
Jon Halld61331b2015-02-17 16:35:47 -0800208 result = self.runCase(self.CurrentTestCaseNumber)
209 repeat-=1
adminbae64d82013-08-01 10:50:15 -0700210 return result
211
212 def runCase(self,testCaseNumber):
213 self.CurrentTestCaseNumber = testCaseNumber
214 result = self.TRUE
215 self.stepCount = 0
216 self.EXPERIMENTAL_MODE = self.FALSE
217 self.addCaseHeader()
218 self.testCaseNumber = str(testCaseNumber)
219 stopped = False
220 try :
221 self.stepList = self.code[self.testCaseNumber].keys()
Jon Halld61331b2015-02-17 16:35:47 -0800222 except KeyError:
adminbae64d82013-08-01 10:50:15 -0700223 main.log.error("There is no Test-Case "+ self.testCaseNumber)
224 return main.FALSE
225
226 self.stepCount = 0
227 while self.stepCount < len(self.code[self.testCaseNumber].keys()):
228 result = self.runStep(self.stepList,self.code,self.testCaseNumber)
229 if result == main.FALSE:
230 break
231 elif result == main.TRUE :
232 continue
233
234 if not stopped :
235 self.testCaseResult[str(self.CurrentTestCaseNumber)] = self.CASERESULT
236 self.logger.updateCaseResults(self)
237 return result
238
239 def runStep(self,stepList,code,testCaseNumber):
240 if not cli.pause:
241 try :
242 step = stepList[self.stepCount]
243 exec code[testCaseNumber][step] in module.__dict__
244 self.stepCount = self.stepCount + 1
245 except TypeError,e:
Jon Hall30b82fa2015-03-04 17:15:43 -0800246 print "Exception in the following section of code:"
247 print code[testCaseNumber][step]
adminbae64d82013-08-01 10:50:15 -0700248 self.stepCount = self.stepCount + 1
Jon Hall30b82fa2015-03-04 17:15:43 -0800249 self.log.exception(e)
adminbae64d82013-08-01 10:50:15 -0700250 return main.TRUE
251
252 if cli.stop:
253 cli.stop = False
254 stopped = True
255 self.TOTAL_TC_NORESULT = self.TOTAL_TC_NORESULT + 1
256 self.testCaseResult[str(self.CurrentTestCaseNumber)] = "Stopped"
257 self.logger.updateCaseResults(self)
258 result = self.cleanup()
259 return main.FALSE
260
261 def addCaseHeader(self):
262 caseHeader = "\n"+"*" * 30+"\n Result summary for Testcase"+str(self.CurrentTestCaseNumber)+"\n"+"*" * 30+"\n"
Jon Halld61331b2015-02-17 16:35:47 -0800263 self.log.exact(caseHeader)
264 caseHeader = "\n"+"*" * 40 +"\nStart of Test Case"+str(self.CurrentTestCaseNumber)+" : "
adminbae64d82013-08-01 10:50:15 -0700265 for driver in self.componentDictionary.keys():
266 vars(self)[driver+'log'].info(caseHeader)
267
268 def addCaseFooter(self):
269 if self.stepCount-1 > 0 :
270 previousStep = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount-1)+": "+ str(self.stepName) + ""
271 stepHeader = "\n"+"*" * 40+"\nEnd of Step "+previousStep+"\n"+"*" * 40+"\n"
272
273 caseFooter = "\n"+"*" * 40+"\nEnd of Test case "+str(self.CurrentTestCaseNumber)+"\n"+"*" * 40+"\n"
274
275 for driver in self.driversList:
276 vars(self)[driver].write(stepHeader+"\n"+caseFooter)
277
278 def cleanup(self):
279 '''
280 Release all the component handles and the close opened file handles.
281 This will return TRUE if all the component handles and log handles closed properly,
282 else return FALSE
283
284 '''
285 result = self.TRUE
286 self.logger.testSummary(self)
Jon Halld61331b2015-02-17 16:35:47 -0800287
adminbae64d82013-08-01 10:50:15 -0700288 #self.reportFile.close()
Jon Halld61331b2015-02-17 16:35:47 -0800289
adminbae64d82013-08-01 10:50:15 -0700290
admin2c7034f2013-08-02 15:09:17 -0700291 #utilities.send_mail()
adminbae64d82013-08-01 10:50:15 -0700292 try :
293 for component in self.componentDictionary.keys():
Jon Halld61331b2015-02-17 16:35:47 -0800294 tempObject = vars(self)[component]
295 print "Disconnecting " + str(tempObject)
adminbae64d82013-08-01 10:50:15 -0700296 tempObject.disconnect()
Jon Halld61331b2015-02-17 16:35:47 -0800297 #tempObject.execute(cmd="exit",prompt="(.*)",timeout=120)
adminbae64d82013-08-01 10:50:15 -0700298
299 except(Exception):
Jon Halld61331b2015-02-17 16:35:47 -0800300 self.log.exception( "Exception while disconnecting from " +
301 str( component ) )
Jon Halla1185982014-09-15 14:55:10 -0700302 #print " There is an error with closing hanldes"
adminbae64d82013-08-01 10:50:15 -0700303 result = self.FALSE
304 # Closing all the driver's session files
305 for driver in self.componentDictionary.keys():
306 vars(self)[driver].close_log_handles()
Jon Halld61331b2015-02-17 16:35:47 -0800307
adminbae64d82013-08-01 10:50:15 -0700308 return result
Jon Halld61331b2015-02-17 16:35:47 -0800309
adminbae64d82013-08-01 10:50:15 -0700310 def pause(self):
311 '''
312 This function will pause the test's execution, and will continue after user provide 'resume' command.
313 '''
314 __builtin__.testthread.pause()
315
316 def onfail(self,*components):
317 '''
318 When test step failed, calling all the components onfail.
319 '''
320
321 if not components:
322 try :
323 for component in self.componentDictionary.keys():
324 tempObject = vars(self)[component]
325 result = tempObject.onfail()
326 except(Exception),e:
327 print str(e)
328 result = self.FALSE
329
330 else:
331 try :
332 for component in components:
333 tempObject = vars(self)[component]
334 result = tempObject.onfail()
335 except(Exception),e:
336 print str(e)
337 result = self.FALSE
338
339
340 def getDriverPath(self,driverName):
341 '''
342 Based on the component 'type' specified in the params , this method will find the absolute path ,
343 by recursively searching the name of the component.
344 '''
345 import commands
346
347 cmd = "find "+drivers_path+" -name "+driverName+".py"
348 result = commands.getoutput(cmd)
349
350 result_array = str(result).split('\n')
351 result_count = 0
352
353 for drivers_list in result_array:
354 result_count = result_count+1
355 if result_count > 1 :
356 print "found "+driverName+" "+ str(result_count) + " times"+str(result_array)
357 self.exit()
358
359 result = re.sub("(.*)drivers","",result)
360 result = re.sub("\.py","",result)
361 result = re.sub("\.pyc","",result)
362 result = re.sub("\/",".",result)
363 result = "drivers"+result
364 return result
365
366
367 def step(self,stepDesc):
368 '''
369 The step information of the test-case will append to the logs.
370 '''
371 previousStep = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount-1)+": "+ str(self.stepName) + ""
372 self.stepName = stepDesc
373
374 stepName = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount)+": "+ str(stepDesc) + ""
375 try :
376 if self.stepCount == 0:
377 stepName = " INIT : Initializing the test case :"+self.CurrentTestCase
378 except AttributeError:
379 stepName = " INIT : Initializing the test case :"+str(self.CurrentTestCaseNumber)
380
381 self.log.step(stepName)
382 stepHeader = ""
383 if self.stepCount > 1 :
384 stepHeader = "\n"+"-"*45+"\nEnd of Step "+previousStep+"\n"+"-"*45+"\n"
385
Jon Halld61331b2015-02-17 16:35:47 -0800386 stepHeader += "\n"+"-"*45+"\nStart of Step"+stepName+"\n"+"-"*45+"\n"
adminbae64d82013-08-01 10:50:15 -0700387 for driver in self.componentDictionary.keys():
388 vars(self)[driver+'log'].info(stepHeader)
389
390 def case(self,testCaseName):
391 '''
392 Test's each test-case information will append to the logs.
393 '''
Jon Halld61331b2015-02-17 16:35:47 -0800394 self.CurrentTestCase = testCaseName
adminbae64d82013-08-01 10:50:15 -0700395 testCaseName = " " + str(testCaseName) + ""
396 self.log.case(testCaseName)
Jon Halld61331b2015-02-17 16:35:47 -0800397 caseHeader = testCaseName+"\n"+"*" * 40+"\n"
adminbae64d82013-08-01 10:50:15 -0700398 for driver in self.componentDictionary.keys():
399 vars(self)[driver+'log'].info(caseHeader)
400
401 def testDesc(self,description):
402 '''
403 Test description will append to the logs.
404 '''
405 description = "Test Description : " + str (description) + ""
406 self.log.info(description)
407
408 def _getTest(self):
409 '''
410 This method will parse the test script to find required test information.
411 '''
412 testFile = self.tests_path + "/"+self.TEST + "/"+self.TEST + ".py"
413 testFileHandler = open(testFile, 'r')
414 testFileList = testFileHandler.readlines()
415 testFileHandler.close()
416 #self.TOTAL_TC_PLANNED = 0
417 counter = 0
418 for index in range(len(testFileList)):
419 lineMatch = re.match('\s+def CASE(\d+)(.*):',testFileList[index],0)
420 if lineMatch:
421 counter = counter + 1
Jon Halla1185982014-09-15 14:55:10 -0700422 self.TC_PLANNED = len(self.testcases_list)
423
adminbae64d82013-08-01 10:50:15 -0700424
425 def response_parser(self,response, return_format):
426 ''' It will load the default response parser '''
427 response_dict = {}
428 response_dict = self.response_to_dict(response, return_format)
Jon Halld61331b2015-02-17 16:35:47 -0800429 return_format_string = self.dict_to_return_format(response,return_format,response_dict)
adminbae64d82013-08-01 10:50:15 -0700430 return return_format_string
431
432 def response_to_dict(self,response,return_format):
433
434 response_dict = {}
435 json_match = re.search('^\s*{', response)
436 xml_match = re.search('^\s*\<', response)
437 ini_match = re.search('^\s*\[', response)
438 if json_match :
439 main.log.info(" Response is in 'JSON' format and Converting to '"+return_format+"' format")
Jon Halld61331b2015-02-17 16:35:47 -0800440 # Formatting the json string
adminbae64d82013-08-01 10:50:15 -0700441
442 response = re.sub(r"{\s*'?(\w)", r'{"\1', response)
443 response = re.sub(r",\s*'?(\w)", r',"\1', response)
444 response = re.sub(r"(\w)'?\s*:", r'\1":', response)
445 response = re.sub(r":\s*'(\w)'\s*([,}])", r':"\1"\2', response)
446
447 try :
448 import json
449 response_dict = json.loads(response)
Jon Hall30b82fa2015-03-04 17:15:43 -0800450 except Exception, e:
451 main.log.exception( e )
adminbae64d82013-08-01 10:50:15 -0700452 main.log.error("Json Parser is unable to parse the string")
453 return response_dict
454
455 elif ini_match :
456 main.log.info(" Response is in 'INI' format and Converting to '"+return_format+"' format")
457 from configobj import ConfigObj
458 response_file = open("respnse_file.temp",'w')
459 response_file.write(response)
Jon Halld61331b2015-02-17 16:35:47 -0800460 response_file.close()
adminbae64d82013-08-01 10:50:15 -0700461 response_dict = ConfigObj("respnse_file.temp")
462 return response_dict
463
464 elif xml_match :
465 main.log.info(" Response is in 'XML' format and Converting to '"+return_format+"' format")
466 try :
adminbae64d82013-08-01 10:50:15 -0700467 response_dict = xmldict.xml_to_dict("<response> "+str(response)+" </response>")
468 except Exception, e:
Jon Hall30b82fa2015-03-04 17:15:43 -0800469 main.log.exception( e )
adminbae64d82013-08-01 10:50:15 -0700470 return response_dict
471
472 def dict_to_return_format(self,response,return_format,response_dict):
473
474 if return_format =='table' :
475 ''' Will return in table format'''
476 to_do = "Call the table output formatter"
477 global response_table
478 response_table = '\n'
479 response_table = response_table +'\t'.join(response_dict)+"\n"
480
481 def get_table(value_to_convert):
482 ''' This will parse the dictionary recusrsively and print as table format'''
483 table_data = ""
484 if type(value_to_convert) == dict :
485 table_data = table_data +'\t'.join(value_to_convert)+"\n"
486 for temp_val in value_to_convert.values() :
487 table_data = table_data + get_table(temp_val)
488 else :
489 table_data = table_data + str(value_to_convert) +"\t"
Jon Halld61331b2015-02-17 16:35:47 -0800490 return table_data
adminbae64d82013-08-01 10:50:15 -0700491
492 for value in response_dict.values() :
493 response_table = response_table + get_table(value)
494
495
496
497 #response_table = response_table + '\t'.join(response_dict.values())
498
499 return response_table
500
501 elif return_format =='config':
502 ''' Will return in config format'''
503 to_do = 'Call dict to config coverter'
504 response_string = str(response_dict)
505 print response_string
506 response_config = re.sub(",", "\n\t", response_string)
507 response_config = re.sub("u\'", "\'", response_config)
508 response_config = re.sub("{", "", response_config)
509 response_config = re.sub("}", "\n", response_config)
510 response_config = re.sub(":", " =", response_config)
511 return "[response]\n\t "+response_config
512
513 elif return_format == 'xml':
514 ''' Will return in xml format'''
adminbae64d82013-08-01 10:50:15 -0700515 response_xml = xmldict.dict_to_xml(response_dict)
516 response_xml = re.sub(">\s*<", ">\n<", response_xml)
517 return "\n"+response_xml
518
519 elif return_format == 'json':
520 ''' Will return in json format'''
521 to_do = 'Call dict to xml coverter'
522 import json
523 response_json = json.dumps(response_dict)
524 return response_json
525
526 def get_random(self):
527 self.random_order = self.random_order + 1
528 return self.random_order
529
530 def exit(self):
531 __builtin__.testthread = None
532 sys.exit()
533
534def verifyOptions(options):
535 '''
536 This will verify the command line options and set to default values, if any option not given in command line.
537 '''
538 import pprint
539 pp = pprint.PrettyPrinter(indent=4)
540
541 #pp.pprint(options)
542 verifyTest(options)
543 verifyExample(options)
544 verifyTestScript(options)
545 verifyParams()
546 verifyLogdir(options)
547 verifyMail(options)
548 verifyTestCases(options)
549
550def verifyTest(options):
551 if options.testname:
552 main.TEST = options.testname
553 main.classPath = "tests."+main.TEST+"."+main.TEST
554 main.tests_path = tests_path
555 elif options.example :
556 main.TEST = options.example
557 main.tests_path = path+"/examples/"
558 main.classPath = "examples."+main.TEST+"."+main.TEST
559 else :
560 print "Test or Example not specified please specify the --test <test name > or --example <example name>"
561 self.exit()
562
563def verifyExample(options):
564 if options.example:
565 main.testDir = path+'/examples/'
566 main.tests_path = path+"/examples/"
567 main.classPath = "examples."+main.TEST+"."+main.TEST
568
569def verifyLogdir(options):
Jon Halld61331b2015-02-17 16:35:47 -0800570 #Verifying Log directory option
adminbae64d82013-08-01 10:50:15 -0700571 if options.logdir:
572 main.logdir = options.logdir
573 else :
Jon Halld61331b2015-02-17 16:35:47 -0800574 main.logdir = main.FALSE
adminbae64d82013-08-01 10:50:15 -0700575
576def verifyMail(options):
Jon Halld61331b2015-02-17 16:35:47 -0800577 # Checking the mailing list
adminbae64d82013-08-01 10:50:15 -0700578 if options.mail:
579 main.mail = options.mail
580 elif main.params.has_key('mail'):
581 main.mail = main.params['mail']
582 else :
583 main.mail = 'paxweb@paxterrasolutions.com'
584
585def verifyTestCases(options):
Jon Halld61331b2015-02-17 16:35:47 -0800586 #Getting Test cases list
adminbae64d82013-08-01 10:50:15 -0700587 if options.testcases:
Jon Halld61331b2015-02-17 16:35:47 -0800588 testcases_list = options.testcases
589 #sys.exit()
adminbae64d82013-08-01 10:50:15 -0700590 testcases_list = re.sub("(\[|\])", "", options.testcases)
591 main.testcases_list = eval(testcases_list+",")
592 else :
593 if 'testcases' in main.params.keys():
Jon Halla1185982014-09-15 14:55:10 -0700594 temp = eval(main.params['testcases']+",")
595 list1=[]
596 if type(temp[0])==list:
597 for test in temp:
598 for testcase in test:
599 if type(testcase)==int:
600 testcase=[testcase]
601 list1.extend(testcase)
602 else :
603 temp=list(temp)
604 for testcase in temp:
605 if type(testcase)==int:
606 testcase=[testcase]
607 list1.extend(testcase)
Jon Halld61331b2015-02-17 16:35:47 -0800608 main.testcases_list=list1
adminbae64d82013-08-01 10:50:15 -0700609 else :
610 print "testcases not specifed in params, please provide in params file or 'testcases' commandline argument"
Jon Halld61331b2015-02-17 16:35:47 -0800611 sys.exit()
adminbae64d82013-08-01 10:50:15 -0700612
613def verifyTestScript(options):
614 '''
615 Verifyies test script.
616 '''
Jon Halld61331b2015-02-17 16:35:47 -0800617 main.openspeak = openspeak.OpenSpeak()
adminbae64d82013-08-01 10:50:15 -0700618 openspeakfile = main.testDir+"/" + main.TEST + "/" + main.TEST + ".ospk"
619 testfile = main.testDir+"/" + main.TEST + "/" + main.TEST + ".py"
620 if os.path.exists(openspeakfile) :
621 main.openspeak.compiler(openspeakfile=openspeakfile,writetofile=1)
622 elif os.path.exists(testfile):
623 print ''
624 else:
625 print "\nThere is no :\""+main.TEST+"\" test, Please Provide OpenSpeak Script/ test script"
626 __builtin__.testthread = None
627 main.exit()
628
629 try :
adminbae64d82013-08-01 10:50:15 -0700630 testModule = __import__(main.classPath, globals(), locals(), [main.TEST], -1)
631 except(ImportError):
Jon Hallf8ecf732014-12-02 21:14:16 -0500632 print "There was an import error, it might mean that there is no test like "+main.TEST
Jon Halld61331b2015-02-17 16:35:47 -0800633 main.exit()
adminbae64d82013-08-01 10:50:15 -0700634
635 testClass = getattr(testModule, main.TEST)
636 main.testObject = testClass()
637 load_parser()
Jon Halld61331b2015-02-17 16:35:47 -0800638 main.params = main.parser.parseParams(main.classPath)
639 main.topology = main.parser.parseTopology(main.classPath)
adminbae64d82013-08-01 10:50:15 -0700640
641def verifyParams():
642 try :
643 main.params = main.params['PARAMS']
644 except(KeyError):
645 print "Error with the params file: Either the file not specified or the format is not correct"
Jon Halld61331b2015-02-17 16:35:47 -0800646 main.exit()
adminbae64d82013-08-01 10:50:15 -0700647
648 try :
649 main.topology = main.topology['TOPOLOGY']
650 except(KeyError):
651 print "Error with the Topology file: Either the file not specified or the format is not correct"
652 main.exit()
653
654def load_parser() :
655 '''
656 It facilitates the loading customised parser for topology and params file.
657 It loads parser mentioned in tab named parser of teston.cfg file.
658 It also loads default xmlparser if no parser have specified in teston.cfg file.
659
660 '''
661 confighash = main.configDict
662 if 'file' in confighash['config']['parser'] and 'class' in confighash['config']['parser']:
663 if confighash['config']['parser']['file'] != None or confighash['config']['parser']['class']!= None :
664 if os.path.exists(confighash['config']['parser']['file']) :
665 module = re.sub(r".py\s*$","",confighash['config']['parser']['file'])
666 moduleList = module.split("/")
667 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
668 try :
669 parsingClass = confighash['config']['parser']['class']
670 parsingModule = __import__(newModule, globals(), locals(), [parsingClass], -1)
671 parsingClass = getattr(parsingModule, parsingClass)
672 main.parser = parsingClass()
673 #hashobj = main.parser.parseParams(main.classPath)
674 if hasattr(main.parser,"parseParams") and hasattr(main.parser,"parseTopology") and hasattr(main.parser,"parse") :
675
676 pass
677 else:
678 main.exit()
679
680 except ImportError:
681 print sys.exc_info()[1]
682 main.exit()
683 else :
684 print "No Such File Exists !!"+ confighash['config']['parser']['file'] +"using default parser"
Jon Halld61331b2015-02-17 16:35:47 -0800685 load_defaultParser()
686 elif confighash['config']['parser']['file'] == None or confighash['config']['parser']['class'] == None :
687 load_defaultParser()
adminbae64d82013-08-01 10:50:15 -0700688 else:
689 load_defaultParser()
690
691def load_defaultParser():
692 '''
693 It will load the default parser which is xml parser to parse the params and topology file.
694 '''
695 moduleList = main.parserPath.split("/")
696 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
697 try :
Jon Halld61331b2015-02-17 16:35:47 -0800698 parsingClass = main.parsingClass
adminbae64d82013-08-01 10:50:15 -0700699 parsingModule = __import__(newModule, globals(), locals(), [parsingClass], -1)
700 parsingClass = getattr(parsingModule, parsingClass)
701 main.parser = parsingClass()
702 if hasattr(main.parser,"parseParams") and hasattr(main.parser,"parseTopology") and hasattr(main.parser,"parse") :
703 pass
704 else:
705 main.exit()
706
707 except ImportError:
708 print sys.exc_info()[1]
709
710
711def load_logger() :
712 '''
713 It facilitates the loading customised parser for topology and params file.
714 It loads parser mentioned in tab named parser of teston.cfg file.
715 It also loads default xmlparser if no parser have specified in teston.cfg file.
716
717 '''
718 confighash = main.configDict
719 if 'file' in confighash['config']['logger'] and 'class' in confighash['config']['logger']:
720 if confighash['config']['logger']['file'] != None or confighash['config']['logger']['class']!= None :
721 if os.path.exists(confighash['config']['logger']['file']) :
722 module = re.sub(r".py\s*$","",confighash['config']['logger']['file'])
723 moduleList = module.split("/")
724 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
725 try :
726 loggerClass = confighash['config']['logger']['class']
727 loggerModule = __import__(newModule, globals(), locals(), [loggerClass], -1)
728 loggerClass = getattr(loggerModule, loggerClass)
729 main.logger = loggerClass()
730 #hashobj = main.parser.parseParams(main.classPath)
731
732 except ImportError:
733 print sys.exc_info()[1]
734 else :
735 print "No Such File Exists !!"+confighash['config']['logger']['file']+ "Using default logger"
736 load_defaultlogger()
Jon Halld61331b2015-02-17 16:35:47 -0800737 elif confighash['config']['parser']['file'] == None or confighash['config']['parser']['class'] == None :
738 load_defaultlogger()
adminbae64d82013-08-01 10:50:15 -0700739 else:
740 load_defaultlogger()
741
742def load_defaultlogger():
743 '''
744 It will load the default parser which is xml parser to parse the params and topology file.
745 '''
746 moduleList = main.loggerPath.split("/")
747 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
748 try :
Jon Halld61331b2015-02-17 16:35:47 -0800749 loggerClass = main.loggerClass
adminbae64d82013-08-01 10:50:15 -0700750 loggerModule = __import__(newModule, globals(), locals(), [loggerClass], -1)
751 loggerClass = getattr(loggerModule, loggerClass)
752 main.logger = loggerClass()
753
754 except ImportError:
755 print sys.exc_info()[1]
Jon Halld61331b2015-02-17 16:35:47 -0800756 main.exit()
adminbae64d82013-08-01 10:50:15 -0700757
758def load_defaultlogger():
759 '''
760 It will load the default parser which is xml parser to parse the params and topology file.
761 '''
762 moduleList = main.loggerPath.split("/")
763 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
764 try :
Jon Halld61331b2015-02-17 16:35:47 -0800765 loggerClass = main.loggerClass
adminbae64d82013-08-01 10:50:15 -0700766 loggerModule = __import__(newModule, globals(), locals(), [loggerClass], -1)
767 loggerClass = getattr(loggerModule, loggerClass)
768 main.logger = loggerClass()
769
770 except ImportError:
771 print sys.exc_info()[1]
772 main.exit()
773
774
775
776
777def _echo(self):
778 print "THIS IS ECHO"