blob: 142505a01f35e6c461daba404572d6938924ea6d [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
49
adminbae64d82013-08-01 10:50:15 -070050
51class TestON:
52 '''
53
54 TestON will initiate the specified test.
55 The main tasks are :
56 * Initiate the required Component handles for the test.
57 * Create Log file Handles.
58
59 '''
60 def __init__(self,options):
61 '''
62 Initialise the component handles specified in the topology file of the specified test.
63
64 '''
65 # Initialization of the variables.
66 __builtin__.main = self
Jon Halla1185982014-09-15 14:55:10 -070067
adminbae64d82013-08-01 10:50:15 -070068 __builtin__.path = path
69 __builtin__.utilities = Utilities()
70 self.TRUE = 1
71 self.FALSE = 0
72 self.ERROR = -1
73 self.FAIL = False
74 self.PASS = True
75 self.CASERESULT = self.TRUE
76 self.init_result = self.TRUE
77 self.testResult = "Summary"
78 self.stepName =""
Jon Halld61331b2015-02-17 16:35:47 -080079 self.EXPERIMENTAL_MODE = False
adminbae64d82013-08-01 10:50:15 -070080 self.test_target = None
81 self.lastcommand = None
Jon Halld61331b2015-02-17 16:35:47 -080082 self.testDir = tests_path
83 self.configFile = config_path + "teston.cfg"
adminbae64d82013-08-01 10:50:15 -070084 self.parsingClass = "xmlparser"
85 self.parserPath = core_path + "/xmlparser"
86 self.loggerPath = core_path + "/logger"
87 self.loggerClass = "Logger"
88 self.logs_path = logs_path
89 self.driver = ''
Jon Halla1185982014-09-15 14:55:10 -070090
adminbae64d82013-08-01 10:50:15 -070091
92 self.configparser()
93 verifyOptions(options)
94 load_logger()
95 self.componentDictionary = {}
96 self.componentDictionary = self.topology ['COMPONENT']
97 self.driversList=[]
98 if type(self.componentDictionary) == str :
99 self.componentDictionary = dict(self.componentDictionary)
100
101 for component in self.componentDictionary :
102 self.driversList.append(self.componentDictionary[component]['type'])
103
104 self.driversList = list(set(self.driversList)) # Removing duplicates.
105 # Checking the test_target option set for the component or not
106 if type(self.componentDictionary) == dict:
107 for component in self.componentDictionary.keys():
108 if 'test_target' in self.componentDictionary[component].keys():
109 self.test_target = component
110
Jon Halld61331b2015-02-17 16:35:47 -0800111 # Checking for the openspeak file and test script
adminbae64d82013-08-01 10:50:15 -0700112 self.logger.initlog(self)
113
114 # Creating Drivers Handles
115 initString = "\n"+"*" * 30+"\n CASE INIT \n"+"*" * 30+"\n"
116 self.log.exact(initString)
117 self.driverObject = {}
118 self.random_order = 111 # Random order id to connect the components
119 components_connect_order = {}
120 #component_list.append()
121 if type(self.componentDictionary) == dict:
122 for component in self.componentDictionary.keys():
123 self.componentDictionary[component]['connect_order'] = self.componentDictionary[component]['connect_order'] if ('connect_order' in self.componentDictionary[component].keys()) else str(self.get_random())
124 components_connect_order[component] = eval(self.componentDictionary[component]['connect_order'])
125 #Ordering components based on the connect order.
126 ordered_component_list =sorted(components_connect_order, key=lambda key: components_connect_order[key])
127 print ordered_component_list
128
129 for component in ordered_component_list:
130 self.componentInit(component)
131
132 def configparser(self):
133 '''
134 It will parse the config file (teston.cfg) and return as dictionary
135 '''
136 matchFileName = re.match(r'(.*)\.cfg', self.configFile, re.M | re.I)
137 if matchFileName:
138 xml = open(self.configFile).read()
139 try :
140 self.configDict = xmldict.xml_to_dict(xml)
141 return self.configDict
Jon Hall63604932015-02-26 17:09:50 -0800142 except (Exception):
adminbae64d82013-08-01 10:50:15 -0700143 print "There is no such file to parse " + self.configFile
144
145 def componentInit(self,component):
146 '''
147 This method will initialize specified component
148 '''
Jon Halleb3a6842015-02-18 15:17:51 -0800149 import importlib
adminbae64d82013-08-01 10:50:15 -0700150 global driver_options
151 self.log.info("Creating component Handle: "+component)
Jon Halld61331b2015-02-17 16:35:47 -0800152 driver_options = {}
adminbae64d82013-08-01 10:50:15 -0700153 if 'COMPONENTS' in self.componentDictionary[component].keys():
154 driver_options =dict(self.componentDictionary[component]['COMPONENTS'])
155
156 driver_options['name']=component
157 driverName = self.componentDictionary[component]['type']
158 driver_options ['type'] = driverName
159
160 classPath = self.getDriverPath(driverName.lower())
Jon Halleb3a6842015-02-18 15:17:51 -0800161 driverModule = importlib.import_module(classPath)
adminbae64d82013-08-01 10:50:15 -0700162 driverClass = getattr(driverModule, driverName)
163 driverObject = driverClass()
164
165 connect_result = driverObject.connect(user_name = self.componentDictionary[component]['user'] if ('user' in self.componentDictionary[component].keys()) else getpass.getuser(),
166 ip_address= self.componentDictionary[component]['host'] if ('host' in self.componentDictionary[component].keys()) else 'localhost',
167 pwd = self.componentDictionary[component]['password'] if ('password' in self.componentDictionary[component].keys()) else 'changeme',
168 port = self.componentDictionary[component]['port'] if ('port' in self.componentDictionary[component].keys()) else None,
169 options = driver_options)
170 if not connect_result:
171 self.log.error("Exiting form the test execution because the connecting to the "+component+" component failed.")
Jon Halld61331b2015-02-17 16:35:47 -0800172 self.exit()
adminbae64d82013-08-01 10:50:15 -0700173
174 vars(self)[component] = driverObject
175
176 def run(self):
177 '''
178 The Execution of the test script's cases listed in the Test params file will be done here.
179 And Update each test case result.
180 This method will return TRUE if it executed all the test cases successfully,
181 else will retun FALSE
182 '''
183
184 self.testCaseResult = {}
Jon Halla1185982014-09-15 14:55:10 -0700185 self.TOTAL_TC = 0
adminbae64d82013-08-01 10:50:15 -0700186 self.TOTAL_TC_RUN = 0
Jon Halld61331b2015-02-17 16:35:47 -0800187 self.TOTAL_TC_PLANNED = 0
adminbae64d82013-08-01 10:50:15 -0700188 self.TOTAL_TC_NORESULT = 0
189 self.TOTAL_TC_FAIL = 0
190 self.TOTAL_TC_PASS = 0
Jon Halla1185982014-09-15 14:55:10 -0700191 self.TEST_ITERATION = 0
adminbae64d82013-08-01 10:50:15 -0700192 self.stepCount = 0
193 self.CASERESULT = self.TRUE
194
Jon Halld61331b2015-02-17 16:35:47 -0800195 import testparser
adminbae64d82013-08-01 10:50:15 -0700196 testFile = self.tests_path + "/"+self.TEST + "/"+self.TEST + ".py"
197 test = testparser.TestParser(testFile)
198 self.testscript = test.testscript
199 self.code = test.getStepCode()
Jon Halla1185982014-09-15 14:55:10 -0700200 repeat= int(self.params['repeat']) if ('repeat' in self.params) else 1
201 main.TOTAL_TC_PLANNED = len(self.testcases_list)*repeat
adminbae64d82013-08-01 10:50:15 -0700202
203 result = self.TRUE
Jon Halla1185982014-09-15 14:55:10 -0700204 while(repeat):
205 for self.CurrentTestCaseNumber in self.testcases_list:
Jon Halld61331b2015-02-17 16:35:47 -0800206 result = self.runCase(self.CurrentTestCaseNumber)
207 repeat-=1
adminbae64d82013-08-01 10:50:15 -0700208 return result
209
210 def runCase(self,testCaseNumber):
211 self.CurrentTestCaseNumber = testCaseNumber
212 result = self.TRUE
213 self.stepCount = 0
214 self.EXPERIMENTAL_MODE = self.FALSE
215 self.addCaseHeader()
216 self.testCaseNumber = str(testCaseNumber)
217 stopped = False
218 try :
219 self.stepList = self.code[self.testCaseNumber].keys()
Jon Halld61331b2015-02-17 16:35:47 -0800220 except KeyError:
adminbae64d82013-08-01 10:50:15 -0700221 main.log.error("There is no Test-Case "+ self.testCaseNumber)
222 return main.FALSE
223
224 self.stepCount = 0
225 while self.stepCount < len(self.code[self.testCaseNumber].keys()):
226 result = self.runStep(self.stepList,self.code,self.testCaseNumber)
227 if result == main.FALSE:
228 break
229 elif result == main.TRUE :
230 continue
231
232 if not stopped :
233 self.testCaseResult[str(self.CurrentTestCaseNumber)] = self.CASERESULT
234 self.logger.updateCaseResults(self)
235 return result
236
237 def runStep(self,stepList,code,testCaseNumber):
238 if not cli.pause:
239 try :
240 step = stepList[self.stepCount]
241 exec code[testCaseNumber][step] in module.__dict__
242 self.stepCount = self.stepCount + 1
243 except TypeError,e:
Jon Hall63604932015-02-26 17:09:50 -0800244 print "Exception in the following section of code: Test Step " +\
245 str(testCaseNumber) + "." + str(step) + " ):"
246 #print code[testCaseNumber][step]
adminbae64d82013-08-01 10:50:15 -0700247 self.stepCount = self.stepCount + 1
Jon Hall20ead012015-02-18 14:00:42 -0800248 self.log.exception(e)
adminbae64d82013-08-01 10:50:15 -0700249 return main.TRUE
250
251 if cli.stop:
252 cli.stop = False
253 stopped = True
254 self.TOTAL_TC_NORESULT = self.TOTAL_TC_NORESULT + 1
255 self.testCaseResult[str(self.CurrentTestCaseNumber)] = "Stopped"
256 self.logger.updateCaseResults(self)
257 result = self.cleanup()
258 return main.FALSE
259
260 def addCaseHeader(self):
261 caseHeader = "\n"+"*" * 30+"\n Result summary for Testcase"+str(self.CurrentTestCaseNumber)+"\n"+"*" * 30+"\n"
Jon Halld61331b2015-02-17 16:35:47 -0800262 self.log.exact(caseHeader)
263 caseHeader = "\n"+"*" * 40 +"\nStart of Test Case"+str(self.CurrentTestCaseNumber)+" : "
adminbae64d82013-08-01 10:50:15 -0700264 for driver in self.componentDictionary.keys():
265 vars(self)[driver+'log'].info(caseHeader)
266
267 def addCaseFooter(self):
268 if self.stepCount-1 > 0 :
269 previousStep = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount-1)+": "+ str(self.stepName) + ""
270 stepHeader = "\n"+"*" * 40+"\nEnd of Step "+previousStep+"\n"+"*" * 40+"\n"
271
272 caseFooter = "\n"+"*" * 40+"\nEnd of Test case "+str(self.CurrentTestCaseNumber)+"\n"+"*" * 40+"\n"
273
274 for driver in self.driversList:
275 vars(self)[driver].write(stepHeader+"\n"+caseFooter)
276
277 def cleanup(self):
278 '''
279 Release all the component handles and the close opened file handles.
280 This will return TRUE if all the component handles and log handles closed properly,
281 else return FALSE
282
283 '''
284 result = self.TRUE
285 self.logger.testSummary(self)
Jon Halld61331b2015-02-17 16:35:47 -0800286
adminbae64d82013-08-01 10:50:15 -0700287 #self.reportFile.close()
Jon Halld61331b2015-02-17 16:35:47 -0800288
adminbae64d82013-08-01 10:50:15 -0700289
admin2c7034f2013-08-02 15:09:17 -0700290 #utilities.send_mail()
adminbae64d82013-08-01 10:50:15 -0700291 try :
292 for component in self.componentDictionary.keys():
Jon Halld61331b2015-02-17 16:35:47 -0800293 tempObject = vars(self)[component]
294 print "Disconnecting " + str(tempObject)
adminbae64d82013-08-01 10:50:15 -0700295 tempObject.disconnect()
Jon Halld61331b2015-02-17 16:35:47 -0800296 #tempObject.execute(cmd="exit",prompt="(.*)",timeout=120)
adminbae64d82013-08-01 10:50:15 -0700297
298 except(Exception):
Jon Halld61331b2015-02-17 16:35:47 -0800299 self.log.exception( "Exception while disconnecting from " +
300 str( component ) )
Jon Halla1185982014-09-15 14:55:10 -0700301 #print " There is an error with closing hanldes"
adminbae64d82013-08-01 10:50:15 -0700302 result = self.FALSE
303 # Closing all the driver's session files
304 for driver in self.componentDictionary.keys():
305 vars(self)[driver].close_log_handles()
Jon Halld61331b2015-02-17 16:35:47 -0800306
adminbae64d82013-08-01 10:50:15 -0700307 return result
Jon Halld61331b2015-02-17 16:35:47 -0800308
adminbae64d82013-08-01 10:50:15 -0700309 def pause(self):
310 '''
311 This function will pause the test's execution, and will continue after user provide 'resume' command.
312 '''
313 __builtin__.testthread.pause()
314
315 def onfail(self,*components):
316 '''
317 When test step failed, calling all the components onfail.
318 '''
319
320 if not components:
321 try :
322 for component in self.componentDictionary.keys():
323 tempObject = vars(self)[component]
324 result = tempObject.onfail()
325 except(Exception),e:
326 print str(e)
327 result = self.FALSE
328
329 else:
330 try :
331 for component in components:
332 tempObject = vars(self)[component]
333 result = tempObject.onfail()
334 except(Exception),e:
335 print str(e)
336 result = self.FALSE
337
338
339 def getDriverPath(self,driverName):
340 '''
341 Based on the component 'type' specified in the params , this method will find the absolute path ,
342 by recursively searching the name of the component.
343 '''
344 import commands
345
346 cmd = "find "+drivers_path+" -name "+driverName+".py"
347 result = commands.getoutput(cmd)
348
349 result_array = str(result).split('\n')
350 result_count = 0
351
352 for drivers_list in result_array:
353 result_count = result_count+1
354 if result_count > 1 :
355 print "found "+driverName+" "+ str(result_count) + " times"+str(result_array)
356 self.exit()
357
358 result = re.sub("(.*)drivers","",result)
359 result = re.sub("\.py","",result)
360 result = re.sub("\.pyc","",result)
361 result = re.sub("\/",".",result)
362 result = "drivers"+result
363 return result
364
365
366 def step(self,stepDesc):
367 '''
368 The step information of the test-case will append to the logs.
369 '''
370 previousStep = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount-1)+": "+ str(self.stepName) + ""
371 self.stepName = stepDesc
372
373 stepName = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount)+": "+ str(stepDesc) + ""
374 try :
375 if self.stepCount == 0:
376 stepName = " INIT : Initializing the test case :"+self.CurrentTestCase
377 except AttributeError:
378 stepName = " INIT : Initializing the test case :"+str(self.CurrentTestCaseNumber)
379
380 self.log.step(stepName)
381 stepHeader = ""
382 if self.stepCount > 1 :
383 stepHeader = "\n"+"-"*45+"\nEnd of Step "+previousStep+"\n"+"-"*45+"\n"
384
Jon Halld61331b2015-02-17 16:35:47 -0800385 stepHeader += "\n"+"-"*45+"\nStart of Step"+stepName+"\n"+"-"*45+"\n"
adminbae64d82013-08-01 10:50:15 -0700386 for driver in self.componentDictionary.keys():
387 vars(self)[driver+'log'].info(stepHeader)
388
389 def case(self,testCaseName):
390 '''
391 Test's each test-case information will append to the logs.
392 '''
Jon Halld61331b2015-02-17 16:35:47 -0800393 self.CurrentTestCase = testCaseName
adminbae64d82013-08-01 10:50:15 -0700394 testCaseName = " " + str(testCaseName) + ""
395 self.log.case(testCaseName)
Jon Halld61331b2015-02-17 16:35:47 -0800396 caseHeader = testCaseName+"\n"+"*" * 40+"\n"
adminbae64d82013-08-01 10:50:15 -0700397 for driver in self.componentDictionary.keys():
398 vars(self)[driver+'log'].info(caseHeader)
399
400 def testDesc(self,description):
401 '''
402 Test description will append to the logs.
403 '''
404 description = "Test Description : " + str (description) + ""
405 self.log.info(description)
406
407 def _getTest(self):
408 '''
409 This method will parse the test script to find required test information.
410 '''
411 testFile = self.tests_path + "/"+self.TEST + "/"+self.TEST + ".py"
412 testFileHandler = open(testFile, 'r')
413 testFileList = testFileHandler.readlines()
414 testFileHandler.close()
415 #self.TOTAL_TC_PLANNED = 0
416 counter = 0
417 for index in range(len(testFileList)):
418 lineMatch = re.match('\s+def CASE(\d+)(.*):',testFileList[index],0)
419 if lineMatch:
420 counter = counter + 1
Jon Halla1185982014-09-15 14:55:10 -0700421 self.TC_PLANNED = len(self.testcases_list)
422
adminbae64d82013-08-01 10:50:15 -0700423
424 def response_parser(self,response, return_format):
425 ''' It will load the default response parser '''
426 response_dict = {}
427 response_dict = self.response_to_dict(response, return_format)
Jon Halld61331b2015-02-17 16:35:47 -0800428 return_format_string = self.dict_to_return_format(response,return_format,response_dict)
adminbae64d82013-08-01 10:50:15 -0700429 return return_format_string
430
431 def response_to_dict(self,response,return_format):
432
433 response_dict = {}
434 json_match = re.search('^\s*{', response)
435 xml_match = re.search('^\s*\<', response)
436 ini_match = re.search('^\s*\[', response)
437 if json_match :
438 main.log.info(" Response is in 'JSON' format and Converting to '"+return_format+"' format")
Jon Halld61331b2015-02-17 16:35:47 -0800439 # Formatting the json string
adminbae64d82013-08-01 10:50:15 -0700440
441 response = re.sub(r"{\s*'?(\w)", r'{"\1', response)
442 response = re.sub(r",\s*'?(\w)", r',"\1', response)
443 response = re.sub(r"(\w)'?\s*:", r'\1":', response)
444 response = re.sub(r":\s*'(\w)'\s*([,}])", r':"\1"\2', response)
445
446 try :
447 import json
448 response_dict = json.loads(response)
Jon Hall20ead012015-02-18 14:00:42 -0800449 except Exception, e:
450 main.log.exception(e)
adminbae64d82013-08-01 10:50:15 -0700451 main.log.error("Json Parser is unable to parse the string")
452 return response_dict
453
454 elif ini_match :
455 main.log.info(" Response is in 'INI' format and Converting to '"+return_format+"' format")
456 from configobj import ConfigObj
457 response_file = open("respnse_file.temp",'w')
458 response_file.write(response)
Jon Halld61331b2015-02-17 16:35:47 -0800459 response_file.close()
adminbae64d82013-08-01 10:50:15 -0700460 response_dict = ConfigObj("respnse_file.temp")
461 return response_dict
462
463 elif xml_match :
464 main.log.info(" Response is in 'XML' format and Converting to '"+return_format+"' format")
465 try :
adminbae64d82013-08-01 10:50:15 -0700466 response_dict = xmldict.xml_to_dict("<response> "+str(response)+" </response>")
467 except Exception, e:
Jon Hall20ead012015-02-18 14:00:42 -0800468 main.log.exception(e)
adminbae64d82013-08-01 10:50:15 -0700469 return response_dict
470
471 def dict_to_return_format(self,response,return_format,response_dict):
472
473 if return_format =='table' :
474 ''' Will return in table format'''
475 to_do = "Call the table output formatter"
476 global response_table
477 response_table = '\n'
478 response_table = response_table +'\t'.join(response_dict)+"\n"
479
480 def get_table(value_to_convert):
481 ''' This will parse the dictionary recusrsively and print as table format'''
482 table_data = ""
483 if type(value_to_convert) == dict :
484 table_data = table_data +'\t'.join(value_to_convert)+"\n"
485 for temp_val in value_to_convert.values() :
486 table_data = table_data + get_table(temp_val)
487 else :
488 table_data = table_data + str(value_to_convert) +"\t"
Jon Halld61331b2015-02-17 16:35:47 -0800489 return table_data
adminbae64d82013-08-01 10:50:15 -0700490
491 for value in response_dict.values() :
492 response_table = response_table + get_table(value)
493
494
495
496 #response_table = response_table + '\t'.join(response_dict.values())
497
498 return response_table
499
500 elif return_format =='config':
501 ''' Will return in config format'''
502 to_do = 'Call dict to config coverter'
503 response_string = str(response_dict)
504 print response_string
505 response_config = re.sub(",", "\n\t", response_string)
506 response_config = re.sub("u\'", "\'", response_config)
507 response_config = re.sub("{", "", response_config)
508 response_config = re.sub("}", "\n", response_config)
509 response_config = re.sub(":", " =", response_config)
510 return "[response]\n\t "+response_config
511
512 elif return_format == 'xml':
513 ''' Will return in xml format'''
adminbae64d82013-08-01 10:50:15 -0700514 response_xml = xmldict.dict_to_xml(response_dict)
515 response_xml = re.sub(">\s*<", ">\n<", response_xml)
516 return "\n"+response_xml
517
518 elif return_format == 'json':
519 ''' Will return in json format'''
520 to_do = 'Call dict to xml coverter'
521 import json
522 response_json = json.dumps(response_dict)
523 return response_json
524
525 def get_random(self):
526 self.random_order = self.random_order + 1
527 return self.random_order
528
529 def exit(self):
530 __builtin__.testthread = None
531 sys.exit()
532
533def verifyOptions(options):
534 '''
535 This will verify the command line options and set to default values, if any option not given in command line.
536 '''
537 import pprint
538 pp = pprint.PrettyPrinter(indent=4)
539
540 #pp.pprint(options)
541 verifyTest(options)
542 verifyExample(options)
543 verifyTestScript(options)
544 verifyParams()
545 verifyLogdir(options)
546 verifyMail(options)
547 verifyTestCases(options)
548
549def verifyTest(options):
550 if options.testname:
551 main.TEST = options.testname
552 main.classPath = "tests."+main.TEST+"."+main.TEST
553 main.tests_path = tests_path
554 elif options.example :
555 main.TEST = options.example
556 main.tests_path = path+"/examples/"
557 main.classPath = "examples."+main.TEST+"."+main.TEST
558 else :
559 print "Test or Example not specified please specify the --test <test name > or --example <example name>"
560 self.exit()
561
562def verifyExample(options):
563 if options.example:
564 main.testDir = path+'/examples/'
565 main.tests_path = path+"/examples/"
566 main.classPath = "examples."+main.TEST+"."+main.TEST
567
568def verifyLogdir(options):
Jon Halld61331b2015-02-17 16:35:47 -0800569 #Verifying Log directory option
adminbae64d82013-08-01 10:50:15 -0700570 if options.logdir:
571 main.logdir = options.logdir
572 else :
Jon Halld61331b2015-02-17 16:35:47 -0800573 main.logdir = main.FALSE
adminbae64d82013-08-01 10:50:15 -0700574
575def verifyMail(options):
Jon Halld61331b2015-02-17 16:35:47 -0800576 # Checking the mailing list
adminbae64d82013-08-01 10:50:15 -0700577 if options.mail:
578 main.mail = options.mail
579 elif main.params.has_key('mail'):
580 main.mail = main.params['mail']
581 else :
582 main.mail = 'paxweb@paxterrasolutions.com'
583
584def verifyTestCases(options):
Jon Halld61331b2015-02-17 16:35:47 -0800585 #Getting Test cases list
adminbae64d82013-08-01 10:50:15 -0700586 if options.testcases:
Jon Halld61331b2015-02-17 16:35:47 -0800587 testcases_list = options.testcases
588 #sys.exit()
adminbae64d82013-08-01 10:50:15 -0700589 testcases_list = re.sub("(\[|\])", "", options.testcases)
590 main.testcases_list = eval(testcases_list+",")
591 else :
592 if 'testcases' in main.params.keys():
Jon Halla1185982014-09-15 14:55:10 -0700593 temp = eval(main.params['testcases']+",")
594 list1=[]
595 if type(temp[0])==list:
596 for test in temp:
597 for testcase in test:
598 if type(testcase)==int:
599 testcase=[testcase]
600 list1.extend(testcase)
601 else :
602 temp=list(temp)
603 for testcase in temp:
604 if type(testcase)==int:
605 testcase=[testcase]
606 list1.extend(testcase)
Jon Halld61331b2015-02-17 16:35:47 -0800607 main.testcases_list=list1
adminbae64d82013-08-01 10:50:15 -0700608 else :
609 print "testcases not specifed in params, please provide in params file or 'testcases' commandline argument"
Jon Halld61331b2015-02-17 16:35:47 -0800610 sys.exit()
adminbae64d82013-08-01 10:50:15 -0700611
612def verifyTestScript(options):
613 '''
614 Verifyies test script.
615 '''
Jon Halld61331b2015-02-17 16:35:47 -0800616 main.openspeak = openspeak.OpenSpeak()
adminbae64d82013-08-01 10:50:15 -0700617 openspeakfile = main.testDir+"/" + main.TEST + "/" + main.TEST + ".ospk"
618 testfile = main.testDir+"/" + main.TEST + "/" + main.TEST + ".py"
619 if os.path.exists(openspeakfile) :
620 main.openspeak.compiler(openspeakfile=openspeakfile,writetofile=1)
621 elif os.path.exists(testfile):
622 print ''
623 else:
624 print "\nThere is no :\""+main.TEST+"\" test, Please Provide OpenSpeak Script/ test script"
625 __builtin__.testthread = None
626 main.exit()
627
628 try :
adminbae64d82013-08-01 10:50:15 -0700629 testModule = __import__(main.classPath, globals(), locals(), [main.TEST], -1)
630 except(ImportError):
Jon Hallf8ecf732014-12-02 21:14:16 -0500631 print "There was an import error, it might mean that there is no test like "+main.TEST
Jon Halld61331b2015-02-17 16:35:47 -0800632 main.exit()
adminbae64d82013-08-01 10:50:15 -0700633
634 testClass = getattr(testModule, main.TEST)
635 main.testObject = testClass()
636 load_parser()
Jon Halld61331b2015-02-17 16:35:47 -0800637 main.params = main.parser.parseParams(main.classPath)
638 main.topology = main.parser.parseTopology(main.classPath)
adminbae64d82013-08-01 10:50:15 -0700639
640def verifyParams():
641 try :
642 main.params = main.params['PARAMS']
643 except(KeyError):
644 print "Error with the params file: Either the file not specified or the format is not correct"
Jon Halld61331b2015-02-17 16:35:47 -0800645 main.exit()
adminbae64d82013-08-01 10:50:15 -0700646
647 try :
648 main.topology = main.topology['TOPOLOGY']
649 except(KeyError):
650 print "Error with the Topology file: Either the file not specified or the format is not correct"
651 main.exit()
652
653def load_parser() :
654 '''
655 It facilitates the loading customised parser for topology and params file.
656 It loads parser mentioned in tab named parser of teston.cfg file.
657 It also loads default xmlparser if no parser have specified in teston.cfg file.
658
659 '''
660 confighash = main.configDict
661 if 'file' in confighash['config']['parser'] and 'class' in confighash['config']['parser']:
662 if confighash['config']['parser']['file'] != None or confighash['config']['parser']['class']!= None :
663 if os.path.exists(confighash['config']['parser']['file']) :
664 module = re.sub(r".py\s*$","",confighash['config']['parser']['file'])
665 moduleList = module.split("/")
666 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
667 try :
668 parsingClass = confighash['config']['parser']['class']
669 parsingModule = __import__(newModule, globals(), locals(), [parsingClass], -1)
670 parsingClass = getattr(parsingModule, parsingClass)
671 main.parser = parsingClass()
672 #hashobj = main.parser.parseParams(main.classPath)
673 if hasattr(main.parser,"parseParams") and hasattr(main.parser,"parseTopology") and hasattr(main.parser,"parse") :
674
675 pass
676 else:
677 main.exit()
678
679 except ImportError:
680 print sys.exc_info()[1]
681 main.exit()
682 else :
683 print "No Such File Exists !!"+ confighash['config']['parser']['file'] +"using default parser"
Jon Halld61331b2015-02-17 16:35:47 -0800684 load_defaultParser()
685 elif confighash['config']['parser']['file'] == None or confighash['config']['parser']['class'] == None :
686 load_defaultParser()
adminbae64d82013-08-01 10:50:15 -0700687 else:
688 load_defaultParser()
689
690def load_defaultParser():
691 '''
692 It will load the default parser which is xml parser to parse the params and topology file.
693 '''
694 moduleList = main.parserPath.split("/")
695 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
696 try :
Jon Halld61331b2015-02-17 16:35:47 -0800697 parsingClass = main.parsingClass
adminbae64d82013-08-01 10:50:15 -0700698 parsingModule = __import__(newModule, globals(), locals(), [parsingClass], -1)
699 parsingClass = getattr(parsingModule, parsingClass)
700 main.parser = parsingClass()
701 if hasattr(main.parser,"parseParams") and hasattr(main.parser,"parseTopology") and hasattr(main.parser,"parse") :
702 pass
703 else:
704 main.exit()
705
706 except ImportError:
707 print sys.exc_info()[1]
708
709
710def load_logger() :
711 '''
712 It facilitates the loading customised parser for topology and params file.
713 It loads parser mentioned in tab named parser of teston.cfg file.
714 It also loads default xmlparser if no parser have specified in teston.cfg file.
715
716 '''
717 confighash = main.configDict
718 if 'file' in confighash['config']['logger'] and 'class' in confighash['config']['logger']:
719 if confighash['config']['logger']['file'] != None or confighash['config']['logger']['class']!= None :
720 if os.path.exists(confighash['config']['logger']['file']) :
721 module = re.sub(r".py\s*$","",confighash['config']['logger']['file'])
722 moduleList = module.split("/")
723 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
724 try :
725 loggerClass = confighash['config']['logger']['class']
726 loggerModule = __import__(newModule, globals(), locals(), [loggerClass], -1)
727 loggerClass = getattr(loggerModule, loggerClass)
728 main.logger = loggerClass()
729 #hashobj = main.parser.parseParams(main.classPath)
730
731 except ImportError:
732 print sys.exc_info()[1]
733 else :
734 print "No Such File Exists !!"+confighash['config']['logger']['file']+ "Using default logger"
735 load_defaultlogger()
Jon Halld61331b2015-02-17 16:35:47 -0800736 elif confighash['config']['parser']['file'] == None or confighash['config']['parser']['class'] == None :
737 load_defaultlogger()
adminbae64d82013-08-01 10:50:15 -0700738 else:
739 load_defaultlogger()
740
741def load_defaultlogger():
742 '''
743 It will load the default parser which is xml parser to parse the params and topology file.
744 '''
745 moduleList = main.loggerPath.split("/")
746 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
747 try :
Jon Halld61331b2015-02-17 16:35:47 -0800748 loggerClass = main.loggerClass
adminbae64d82013-08-01 10:50:15 -0700749 loggerModule = __import__(newModule, globals(), locals(), [loggerClass], -1)
750 loggerClass = getattr(loggerModule, loggerClass)
751 main.logger = loggerClass()
752
753 except ImportError:
754 print sys.exc_info()[1]
Jon Halld61331b2015-02-17 16:35:47 -0800755 main.exit()
adminbae64d82013-08-01 10:50:15 -0700756
757def load_defaultlogger():
758 '''
759 It will load the default parser which is xml parser to parse the params and topology file.
760 '''
761 moduleList = main.loggerPath.split("/")
762 newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]])
763 try :
Jon Halld61331b2015-02-17 16:35:47 -0800764 loggerClass = main.loggerClass
adminbae64d82013-08-01 10:50:15 -0700765 loggerModule = __import__(newModule, globals(), locals(), [loggerClass], -1)
766 loggerClass = getattr(loggerModule, loggerClass)
767 main.logger = loggerClass()
768
769 except ImportError:
770 print sys.exc_info()[1]
771 main.exit()
772
773
774
775
776def _echo(self):
777 print "THIS IS ECHO"