admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | ''' |
| 3 | Created on 22-Oct-2012 |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 4 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 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 |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 20 | |
| 21 | |
| 22 | |
| 23 | teston is the main module. |
| 24 | |
| 25 | ''' |
| 26 | |
| 27 | import sys |
| 28 | import getpass |
| 29 | import os |
| 30 | import re |
| 31 | import __builtin__ |
| 32 | import new |
| 33 | import xmldict |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 34 | import importlib |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 35 | module = new.module("test") |
| 36 | import openspeak |
| 37 | global path, drivers_path, core_path, tests_path,logs_path |
| 38 | path = re.sub("(core|bin)$", "", os.getcwd()) |
| 39 | drivers_path = path+"drivers/" |
| 40 | core_path = path+"core" |
| 41 | tests_path = path+"tests" |
| 42 | logs_path = path+"logs/" |
| 43 | config_path = path + "config/" |
| 44 | sys.path.append(path) |
| 45 | sys.path.append( drivers_path) |
| 46 | sys.path.append(core_path ) |
| 47 | sys.path.append(tests_path) |
| 48 | |
| 49 | from core.utilities import Utilities |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 50 | from core.Thread import Thread |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 51 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 52 | |
| 53 | class TestON: |
| 54 | ''' |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 55 | TestON will initiate the specified test. |
| 56 | The main tasks are : |
| 57 | * Initiate the required Component handles for the test. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 58 | * Create Log file Handles. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 59 | ''' |
| 60 | def __init__(self,options): |
| 61 | ''' |
| 62 | Initialise the component handles specified in the topology file of the specified test. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 63 | ''' |
| 64 | # Initialization of the variables. |
| 65 | __builtin__.main = self |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 66 | __builtin__.path = path |
| 67 | __builtin__.utilities = Utilities() |
| 68 | self.TRUE = 1 |
| 69 | self.FALSE = 0 |
| 70 | self.ERROR = -1 |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 71 | self.NORESULT = 2 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 72 | self.FAIL = False |
| 73 | self.PASS = True |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 74 | self.CASERESULT = self.ERROR |
| 75 | self.STEPRESULT = self.NORESULT |
| 76 | self.stepResults = [] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 77 | self.init_result = self.TRUE |
| 78 | self.testResult = "Summary" |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 79 | self.stepName = "" |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 80 | self.stepCache = "" |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 81 | # make this into two lists? one for step names, one for results? |
| 82 | # this way, the case result could be a true AND of these results |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 83 | self.EXPERIMENTAL_MODE = False |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 84 | self.test_target = None |
| 85 | self.lastcommand = None |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 86 | self.testDir = tests_path |
| 87 | self.configFile = config_path + "teston.cfg" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 88 | self.parsingClass = "xmlparser" |
| 89 | self.parserPath = core_path + "/xmlparser" |
| 90 | self.loggerPath = core_path + "/logger" |
| 91 | self.loggerClass = "Logger" |
| 92 | self.logs_path = logs_path |
| 93 | self.driver = '' |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 94 | self.Thread = Thread |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 95 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 96 | self.configparser() |
| 97 | verifyOptions(options) |
| 98 | load_logger() |
| 99 | self.componentDictionary = {} |
| 100 | self.componentDictionary = self.topology ['COMPONENT'] |
| 101 | self.driversList=[] |
| 102 | if type(self.componentDictionary) == str : |
| 103 | self.componentDictionary = dict(self.componentDictionary) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 104 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 105 | for component in self.componentDictionary : |
| 106 | self.driversList.append(self.componentDictionary[component]['type']) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 107 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 108 | self.driversList = list(set(self.driversList)) # Removing duplicates. |
| 109 | # Checking the test_target option set for the component or not |
| 110 | if type(self.componentDictionary) == dict: |
| 111 | for component in self.componentDictionary.keys(): |
| 112 | if 'test_target' in self.componentDictionary[component].keys(): |
| 113 | self.test_target = component |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 114 | |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 115 | # Checking for the openspeak file and test script |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 116 | self.logger.initlog(self) |
| 117 | |
| 118 | # Creating Drivers Handles |
| 119 | initString = "\n"+"*" * 30+"\n CASE INIT \n"+"*" * 30+"\n" |
| 120 | self.log.exact(initString) |
| 121 | self.driverObject = {} |
| 122 | self.random_order = 111 # Random order id to connect the components |
| 123 | components_connect_order = {} |
| 124 | #component_list.append() |
| 125 | if type(self.componentDictionary) == dict: |
| 126 | for component in self.componentDictionary.keys(): |
| 127 | self.componentDictionary[component]['connect_order'] = self.componentDictionary[component]['connect_order'] if ('connect_order' in self.componentDictionary[component].keys()) else str(self.get_random()) |
| 128 | components_connect_order[component] = eval(self.componentDictionary[component]['connect_order']) |
| 129 | #Ordering components based on the connect order. |
| 130 | ordered_component_list =sorted(components_connect_order, key=lambda key: components_connect_order[key]) |
| 131 | print ordered_component_list |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 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 |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 145 | except Exception: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 146 | print "There is no such file to parse " + self.configFile |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 147 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 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 Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 154 | driver_options = {} |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 155 | 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 |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 161 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 162 | classPath = self.getDriverPath(driverName.lower()) |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 163 | driverModule = importlib.import_module(classPath) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 164 | driverClass = getattr(driverModule, driverName) |
| 165 | driverObject = driverClass() |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 166 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 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 Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 174 | self.exit() |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 175 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 176 | vars(self)[component] = driverObject |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 177 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 178 | def run(self): |
| 179 | ''' |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 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, |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 183 | else will retun FALSE |
| 184 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 185 | self.testCaseResult = {} |
Jon Hall | a118598 | 2014-09-15 14:55:10 -0700 | [diff] [blame] | 186 | self.TOTAL_TC = 0 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 187 | self.TOTAL_TC_RUN = 0 |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 188 | self.TOTAL_TC_PLANNED = 0 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 189 | self.TOTAL_TC_NORESULT = 0 |
| 190 | self.TOTAL_TC_FAIL = 0 |
| 191 | self.TOTAL_TC_PASS = 0 |
Jon Hall | a118598 | 2014-09-15 14:55:10 -0700 | [diff] [blame] | 192 | self.TEST_ITERATION = 0 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 193 | self.stepCount = 0 |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 194 | self.CASERESULT = self.NORESULT |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 195 | |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 196 | import testparser |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 197 | 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 Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 201 | repeat= int(self.params['repeat']) if ('repeat' in self.params) else 1 |
| 202 | self.TOTAL_TC_PLANNED = len(self.testcases_list)*repeat |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 203 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 204 | result = self.TRUE |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 205 | while(repeat): |
Jon Hall | a118598 | 2014-09-15 14:55:10 -0700 | [diff] [blame] | 206 | for self.CurrentTestCaseNumber in self.testcases_list: |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 207 | result = self.runCase(self.CurrentTestCaseNumber) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 208 | repeat-=1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 209 | return result |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 210 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 211 | def runCase(self,testCaseNumber): |
| 212 | self.CurrentTestCaseNumber = testCaseNumber |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 213 | self.CurrentTestCase = "" |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 214 | self.stepResults = [] |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 215 | self.stepName = "" |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 216 | self.caseExplaination = "" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 217 | result = self.TRUE |
| 218 | self.stepCount = 0 |
| 219 | self.EXPERIMENTAL_MODE = self.FALSE |
| 220 | self.addCaseHeader() |
| 221 | self.testCaseNumber = str(testCaseNumber) |
| 222 | stopped = False |
| 223 | try : |
| 224 | self.stepList = self.code[self.testCaseNumber].keys() |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 225 | except KeyError: |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 226 | self.log.error("There is no Test-Case "+ self.testCaseNumber) |
| 227 | return self.FALSE |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 228 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 229 | self.stepCount = 0 |
| 230 | while self.stepCount < len(self.code[self.testCaseNumber].keys()): |
| 231 | result = self.runStep(self.stepList,self.code,self.testCaseNumber) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 232 | if result == self.FALSE: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 233 | break |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 234 | elif result == self.TRUE: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 235 | continue |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 236 | if not stopped : |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 237 | if all( self.TRUE == i for i in self.stepResults ): |
| 238 | # ALL PASSED |
| 239 | self.CASERESULT = self.TRUE |
| 240 | elif self.FALSE in self.stepResults: |
| 241 | # AT LEAST ONE FAILED |
| 242 | self.CASERESULT = self.FALSE |
| 243 | elif self.TRUE in self.stepResults: |
| 244 | # AT LEAST ONE PASSED |
| 245 | self.CASERESULT = self.TRUE |
| 246 | else: |
| 247 | self.CASERESULT = self.NORESULT |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 248 | self.testCaseResult[str(self.CurrentTestCaseNumber)] = self.CASERESULT |
| 249 | self.logger.updateCaseResults(self) |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 250 | self.log.wiki( "<p>" + self.caseExplaination + "</p>" ) |
| 251 | self.log.summary( self.caseExplaination ) |
| 252 | self.log.wiki( "<ul>" ) |
| 253 | for line in self.stepCache.splitlines(): |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 254 | if re.search( " - PASS$", line ): |
| 255 | self.log.wiki( "<li>" + line + " <ac:emoticon ac:name=\"tick\" /></li>\n" ) |
| 256 | elif re.search( " - FAIL$", line ): |
| 257 | self.log.wiki( "<li>" + line + " <ac:emoticon ac:name=\"cross\" /></li>\n" ) |
| 258 | elif re.search( " - No Result$", line ): |
| 259 | self.log.wiki( "<li>" + line + " <ac:emoticon ac:name=\"warning\" /></li>\n" ) |
| 260 | self.log.wiki( "</ul>" ) |
| 261 | self.log.summary( self.stepCache ) |
| 262 | self.stepCache = "" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 263 | return result |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 264 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 265 | def runStep(self,stepList,code,testCaseNumber): |
| 266 | if not cli.pause: |
| 267 | try : |
| 268 | step = stepList[self.stepCount] |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 269 | self.STEPRESULT = self.NORESULT |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 270 | exec code[testCaseNumber][step] in module.__dict__ |
| 271 | self.stepCount = self.stepCount + 1 |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 272 | if step > 0: |
| 273 | self.stepCache += "\t"+str(testCaseNumber)+"."+str(step)+" "+self.stepName+" - " |
| 274 | if self.STEPRESULT == self.TRUE: |
| 275 | self.stepCache += "PASS\n" |
| 276 | #self.stepCache += "PASS <ac:emoticon ac:name=\"tick\" /></li>\n" |
| 277 | elif self.STEPRESULT == self.FALSE: |
| 278 | self.stepCache += "FAIL\n" |
| 279 | #self.stepCache += "FAIL <ac:emoticon ac:name=\"cross\" /></li>\n" |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 280 | else: |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 281 | self.stepCache += "No Result\n" |
| 282 | #self.stepCache += "No Result <ac:emoticon ac:name=\"warning\" /></li>\n" |
| 283 | self.stepResults.append(self.STEPRESULT) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 284 | except TypeError,e: |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 285 | print "\nException in the following section of code: " +\ |
| 286 | str(testCaseNumber) + "." + str(step) + ": " +\ |
| 287 | self.stepName |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 288 | #print code[testCaseNumber][step] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 289 | self.stepCount = self.stepCount + 1 |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 290 | self.log.exception(e) |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 291 | self.logger.updateCaseResults(self) |
| 292 | #WIKI results |
| 293 | self.log.wiki( "<ul>" ) |
Jon Hall | 5015755 | 2015-05-04 16:20:03 -0700 | [diff] [blame] | 294 | for line in self.stepCache.splitlines(): |
Jon Hall | 79bec22 | 2015-04-30 16:23:30 -0700 | [diff] [blame] | 295 | if re.search( " - PASS$", line ): |
| 296 | self.log.wiki( "<li>" + line + " <ac:emoticon ac:name=\"tick\" /></li>\n" ) |
| 297 | elif re.search( " - FAIL$", line ): |
| 298 | self.log.wiki( "<li>" + line + " <ac:emoticon ac:name=\"cross\" /></li>\n" ) |
| 299 | elif re.search( " - No Result$", line ): |
| 300 | self.log.wiki( "<li>" + line + " <ac:emoticon ac:name=\"warning\" /></li>\n" ) |
| 301 | self.log.wiki( "</ul>" ) |
| 302 | #summary results |
| 303 | self.log.summary( self.stepCache ) |
| 304 | self.stepCache = "" |
shahshreya | 957feaa | 2015-03-23 16:08:29 -0700 | [diff] [blame] | 305 | self.cleanup() |
Jon Hall | 00539b1 | 2015-04-03 13:55:46 -0700 | [diff] [blame] | 306 | self.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 307 | return main.TRUE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 308 | if cli.stop: |
| 309 | cli.stop = False |
| 310 | stopped = True |
| 311 | self.TOTAL_TC_NORESULT = self.TOTAL_TC_NORESULT + 1 |
| 312 | self.testCaseResult[str(self.CurrentTestCaseNumber)] = "Stopped" |
| 313 | self.logger.updateCaseResults(self) |
| 314 | result = self.cleanup() |
| 315 | return main.FALSE |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 316 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 317 | def addCaseHeader(self): |
| 318 | caseHeader = "\n"+"*" * 30+"\n Result summary for Testcase"+str(self.CurrentTestCaseNumber)+"\n"+"*" * 30+"\n" |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 319 | self.log.exact(caseHeader) |
| 320 | caseHeader = "\n"+"*" * 40 +"\nStart of Test Case"+str(self.CurrentTestCaseNumber)+" : " |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 321 | for driver in self.componentDictionary.keys(): |
| 322 | vars(self)[driver+'log'].info(caseHeader) |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 323 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 324 | def addCaseFooter(self): |
| 325 | if self.stepCount-1 > 0 : |
| 326 | previousStep = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount-1)+": "+ str(self.stepName) + "" |
| 327 | stepHeader = "\n"+"*" * 40+"\nEnd of Step "+previousStep+"\n"+"*" * 40+"\n" |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 328 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 329 | caseFooter = "\n"+"*" * 40+"\nEnd of Test case "+str(self.CurrentTestCaseNumber)+"\n"+"*" * 40+"\n" |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 330 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 331 | for driver in self.driversList: |
| 332 | vars(self)[driver].write(stepHeader+"\n"+caseFooter) |
| 333 | |
| 334 | def cleanup(self): |
| 335 | ''' |
| 336 | Release all the component handles and the close opened file handles. |
| 337 | This will return TRUE if all the component handles and log handles closed properly, |
| 338 | else return FALSE |
| 339 | |
| 340 | ''' |
| 341 | result = self.TRUE |
| 342 | self.logger.testSummary(self) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 343 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 344 | #self.reportFile.close() |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 345 | |
admin | 2c7034f | 2013-08-02 15:09:17 -0700 | [diff] [blame] | 346 | #utilities.send_mail() |
Jon Hall | 00539b1 | 2015-04-03 13:55:46 -0700 | [diff] [blame] | 347 | for component in self.componentDictionary.keys(): |
| 348 | try : |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 349 | tempObject = vars(self)[component] |
Jon Hall | 1a77a1e | 2015-04-06 10:41:13 -0700 | [diff] [blame] | 350 | print "Disconnecting from " + str(tempObject.name) + ": " + \ |
| 351 | str(tempObject) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 352 | tempObject.disconnect() |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 353 | #tempObject.execute(cmd="exit",prompt="(.*)",timeout=120) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 354 | |
Jon Hall | 00539b1 | 2015-04-03 13:55:46 -0700 | [diff] [blame] | 355 | except (Exception): |
| 356 | self.log.exception( "Exception while disconnecting from " + |
| 357 | str( component ) ) |
| 358 | result = self.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 359 | # Closing all the driver's session files |
| 360 | for driver in self.componentDictionary.keys(): |
| 361 | vars(self)[driver].close_log_handles() |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 362 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 363 | return result |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 364 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 365 | def pause(self): |
| 366 | ''' |
| 367 | This function will pause the test's execution, and will continue after user provide 'resume' command. |
| 368 | ''' |
| 369 | __builtin__.testthread.pause() |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 370 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 371 | def onfail(self,*components): |
| 372 | ''' |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 373 | When test step failed, calling all the components onfail. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 374 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 375 | if not components: |
| 376 | try : |
| 377 | for component in self.componentDictionary.keys(): |
| 378 | tempObject = vars(self)[component] |
| 379 | result = tempObject.onfail() |
| 380 | except(Exception),e: |
| 381 | print str(e) |
| 382 | result = self.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 383 | else: |
| 384 | try : |
| 385 | for component in components: |
| 386 | tempObject = vars(self)[component] |
| 387 | result = tempObject.onfail() |
| 388 | except(Exception),e: |
| 389 | print str(e) |
| 390 | result = self.FALSE |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 391 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 392 | def getDriverPath(self,driverName): |
| 393 | ''' |
| 394 | Based on the component 'type' specified in the params , this method will find the absolute path , |
| 395 | by recursively searching the name of the component. |
| 396 | ''' |
| 397 | import commands |
| 398 | |
| 399 | cmd = "find "+drivers_path+" -name "+driverName+".py" |
| 400 | result = commands.getoutput(cmd) |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 401 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 402 | result_array = str(result).split('\n') |
| 403 | result_count = 0 |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 404 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 405 | for drivers_list in result_array: |
| 406 | result_count = result_count+1 |
| 407 | if result_count > 1 : |
| 408 | print "found "+driverName+" "+ str(result_count) + " times"+str(result_array) |
| 409 | self.exit() |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 410 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 411 | result = re.sub("(.*)drivers","",result) |
| 412 | result = re.sub("\.py","",result) |
| 413 | result = re.sub("\.pyc","",result) |
| 414 | result = re.sub("\/",".",result) |
| 415 | result = "drivers"+result |
| 416 | return result |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 417 | |
| 418 | def step(self,stepDesc): |
| 419 | ''' |
| 420 | The step information of the test-case will append to the logs. |
| 421 | ''' |
| 422 | previousStep = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount-1)+": "+ str(self.stepName) + "" |
| 423 | self.stepName = stepDesc |
| 424 | |
| 425 | stepName = " "+str(self.CurrentTestCaseNumber)+"."+str(self.stepCount)+": "+ str(stepDesc) + "" |
| 426 | try : |
| 427 | if self.stepCount == 0: |
| 428 | stepName = " INIT : Initializing the test case :"+self.CurrentTestCase |
| 429 | except AttributeError: |
| 430 | stepName = " INIT : Initializing the test case :"+str(self.CurrentTestCaseNumber) |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 431 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 432 | self.log.step(stepName) |
| 433 | stepHeader = "" |
| 434 | if self.stepCount > 1 : |
| 435 | stepHeader = "\n"+"-"*45+"\nEnd of Step "+previousStep+"\n"+"-"*45+"\n" |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 436 | |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 437 | stepHeader += "\n"+"-"*45+"\nStart of Step"+stepName+"\n"+"-"*45+"\n" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 438 | for driver in self.componentDictionary.keys(): |
| 439 | vars(self)[driver+'log'].info(stepHeader) |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 440 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 441 | def case(self,testCaseName): |
| 442 | ''' |
| 443 | Test's each test-case information will append to the logs. |
| 444 | ''' |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 445 | self.CurrentTestCase = testCaseName |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 446 | testCaseName = " " + str(testCaseName) + "" |
| 447 | self.log.case(testCaseName) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 448 | caseHeader = testCaseName+"\n"+"*" * 40+"\n" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 449 | for driver in self.componentDictionary.keys(): |
| 450 | vars(self)[driver+'log'].info(caseHeader) |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 451 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 452 | def testDesc(self,description): |
| 453 | ''' |
| 454 | Test description will append to the logs. |
| 455 | ''' |
| 456 | description = "Test Description : " + str (description) + "" |
| 457 | self.log.info(description) |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 458 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 459 | def _getTest(self): |
| 460 | ''' |
| 461 | This method will parse the test script to find required test information. |
| 462 | ''' |
| 463 | testFile = self.tests_path + "/"+self.TEST + "/"+self.TEST + ".py" |
| 464 | testFileHandler = open(testFile, 'r') |
| 465 | testFileList = testFileHandler.readlines() |
| 466 | testFileHandler.close() |
| 467 | #self.TOTAL_TC_PLANNED = 0 |
| 468 | counter = 0 |
| 469 | for index in range(len(testFileList)): |
| 470 | lineMatch = re.match('\s+def CASE(\d+)(.*):',testFileList[index],0) |
| 471 | if lineMatch: |
| 472 | counter = counter + 1 |
Jon Hall | a118598 | 2014-09-15 14:55:10 -0700 | [diff] [blame] | 473 | self.TC_PLANNED = len(self.testcases_list) |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 474 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 475 | def response_parser(self,response, return_format): |
| 476 | ''' It will load the default response parser ''' |
| 477 | response_dict = {} |
| 478 | response_dict = self.response_to_dict(response, return_format) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 479 | return_format_string = self.dict_to_return_format(response,return_format,response_dict) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 480 | return return_format_string |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 481 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 482 | def response_to_dict(self,response,return_format): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 483 | response_dict = {} |
| 484 | json_match = re.search('^\s*{', response) |
| 485 | xml_match = re.search('^\s*\<', response) |
| 486 | ini_match = re.search('^\s*\[', response) |
| 487 | if json_match : |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 488 | self.log.info(" Response is in 'JSON' format and Converting to '"+return_format+"' format") |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 489 | # Formatting the json string |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 490 | response = re.sub(r"{\s*'?(\w)", r'{"\1', response) |
| 491 | response = re.sub(r",\s*'?(\w)", r',"\1', response) |
| 492 | response = re.sub(r"(\w)'?\s*:", r'\1":', response) |
| 493 | response = re.sub(r":\s*'(\w)'\s*([,}])", r':"\1"\2', response) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 494 | try : |
| 495 | import json |
| 496 | response_dict = json.loads(response) |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 497 | except Exception, e: |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 498 | self.log.exception( e ) |
| 499 | self.log.error("Json Parser is unable to parse the string") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 500 | return response_dict |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 501 | elif ini_match : |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 502 | self.log.info(" Response is in 'INI' format and Converting to '"+return_format+"' format") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 503 | from configobj import ConfigObj |
| 504 | response_file = open("respnse_file.temp",'w') |
| 505 | response_file.write(response) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 506 | response_file.close() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 507 | response_dict = ConfigObj("respnse_file.temp") |
| 508 | return response_dict |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 509 | elif xml_match : |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 510 | self.log.info(" Response is in 'XML' format and Converting to '"+return_format+"' format") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 511 | try : |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 512 | response_dict = xmldict.xml_to_dict("<response> "+str(response)+" </response>") |
| 513 | except Exception, e: |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 514 | self.log.exception( e ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 515 | return response_dict |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 516 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 517 | def dict_to_return_format(self,response,return_format,response_dict): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 518 | if return_format =='table' : |
| 519 | ''' Will return in table format''' |
| 520 | to_do = "Call the table output formatter" |
| 521 | global response_table |
| 522 | response_table = '\n' |
| 523 | response_table = response_table +'\t'.join(response_dict)+"\n" |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 524 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 525 | def get_table(value_to_convert): |
| 526 | ''' This will parse the dictionary recusrsively and print as table format''' |
| 527 | table_data = "" |
| 528 | if type(value_to_convert) == dict : |
| 529 | table_data = table_data +'\t'.join(value_to_convert)+"\n" |
| 530 | for temp_val in value_to_convert.values() : |
| 531 | table_data = table_data + get_table(temp_val) |
| 532 | else : |
| 533 | table_data = table_data + str(value_to_convert) +"\t" |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 534 | return table_data |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 535 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 536 | for value in response_dict.values() : |
| 537 | response_table = response_table + get_table(value) |
Jon Hall | 88e498c | 2015-03-06 09:54:35 -0800 | [diff] [blame] | 538 | # response_table = response_table + '\t'.join(response_dict.values()) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 539 | return response_table |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 540 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 541 | elif return_format =='config': |
| 542 | ''' Will return in config format''' |
| 543 | to_do = 'Call dict to config coverter' |
| 544 | response_string = str(response_dict) |
| 545 | print response_string |
| 546 | response_config = re.sub(",", "\n\t", response_string) |
| 547 | response_config = re.sub("u\'", "\'", response_config) |
| 548 | response_config = re.sub("{", "", response_config) |
| 549 | response_config = re.sub("}", "\n", response_config) |
| 550 | response_config = re.sub(":", " =", response_config) |
| 551 | return "[response]\n\t "+response_config |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 552 | elif return_format == 'xml': |
| 553 | ''' Will return in xml format''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 554 | response_xml = xmldict.dict_to_xml(response_dict) |
| 555 | response_xml = re.sub(">\s*<", ">\n<", response_xml) |
| 556 | return "\n"+response_xml |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 557 | elif return_format == 'json': |
| 558 | ''' Will return in json format''' |
| 559 | to_do = 'Call dict to xml coverter' |
| 560 | import json |
| 561 | response_json = json.dumps(response_dict) |
| 562 | return response_json |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 563 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 564 | def get_random(self): |
| 565 | self.random_order = self.random_order + 1 |
| 566 | return self.random_order |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 567 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 568 | def exit(self): |
| 569 | __builtin__.testthread = None |
| 570 | sys.exit() |
| 571 | |
| 572 | def verifyOptions(options): |
| 573 | ''' |
| 574 | This will verify the command line options and set to default values, if any option not given in command line. |
| 575 | ''' |
| 576 | import pprint |
| 577 | pp = pprint.PrettyPrinter(indent=4) |
| 578 | |
Jon Hall | 88e498c | 2015-03-06 09:54:35 -0800 | [diff] [blame] | 579 | # pp.pprint(options) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 580 | verifyTest(options) |
| 581 | verifyExample(options) |
| 582 | verifyTestScript(options) |
| 583 | verifyParams() |
| 584 | verifyLogdir(options) |
| 585 | verifyMail(options) |
| 586 | verifyTestCases(options) |
| 587 | |
| 588 | def verifyTest(options): |
| 589 | if options.testname: |
| 590 | main.TEST = options.testname |
| 591 | main.classPath = "tests."+main.TEST+"."+main.TEST |
| 592 | main.tests_path = tests_path |
| 593 | elif options.example : |
| 594 | main.TEST = options.example |
| 595 | main.tests_path = path+"/examples/" |
| 596 | main.classPath = "examples."+main.TEST+"."+main.TEST |
| 597 | else : |
| 598 | print "Test or Example not specified please specify the --test <test name > or --example <example name>" |
| 599 | self.exit() |
| 600 | |
| 601 | def verifyExample(options): |
| 602 | if options.example: |
| 603 | main.testDir = path+'/examples/' |
| 604 | main.tests_path = path+"/examples/" |
| 605 | main.classPath = "examples."+main.TEST+"."+main.TEST |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 606 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 607 | def verifyLogdir(options): |
Jon Hall | 88e498c | 2015-03-06 09:54:35 -0800 | [diff] [blame] | 608 | # Verifying Log directory option |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 609 | if options.logdir: |
| 610 | main.logdir = options.logdir |
| 611 | else : |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 612 | main.logdir = main.FALSE |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 613 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 614 | def verifyMail(options): |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 615 | # Checking the mailing list |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 616 | if options.mail: |
| 617 | main.mail = options.mail |
| 618 | elif main.params.has_key('mail'): |
| 619 | main.mail = main.params['mail'] |
| 620 | else : |
| 621 | main.mail = 'paxweb@paxterrasolutions.com' |
| 622 | |
| 623 | def verifyTestCases(options): |
Jon Hall | 88e498c | 2015-03-06 09:54:35 -0800 | [diff] [blame] | 624 | # Getting Test cases list |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 625 | if options.testcases: |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 626 | testcases_list = options.testcases |
Jon Hall | 88e498c | 2015-03-06 09:54:35 -0800 | [diff] [blame] | 627 | # sys.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 628 | testcases_list = re.sub("(\[|\])", "", options.testcases) |
| 629 | main.testcases_list = eval(testcases_list+",") |
| 630 | else : |
| 631 | if 'testcases' in main.params.keys(): |
Jon Hall | a118598 | 2014-09-15 14:55:10 -0700 | [diff] [blame] | 632 | temp = eval(main.params['testcases']+",") |
| 633 | list1=[] |
| 634 | if type(temp[0])==list: |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 635 | for test in temp: |
| 636 | for testcase in test: |
| 637 | if type(testcase)==int: |
| 638 | testcase=[testcase] |
| 639 | list1.extend(testcase) |
| 640 | else : |
| 641 | temp=list(temp) |
| 642 | for testcase in temp: |
| 643 | if type(testcase)==int: |
| 644 | testcase=[testcase] |
| 645 | list1.extend(testcase) |
| 646 | main.testcases_list=list1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 647 | else : |
| 648 | print "testcases not specifed in params, please provide in params file or 'testcases' commandline argument" |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 649 | sys.exit() |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 650 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 651 | def verifyTestScript(options): |
| 652 | ''' |
| 653 | Verifyies test script. |
| 654 | ''' |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 655 | main.openspeak = openspeak.OpenSpeak() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 656 | openspeakfile = main.testDir+"/" + main.TEST + "/" + main.TEST + ".ospk" |
| 657 | testfile = main.testDir+"/" + main.TEST + "/" + main.TEST + ".py" |
| 658 | if os.path.exists(openspeakfile) : |
| 659 | main.openspeak.compiler(openspeakfile=openspeakfile,writetofile=1) |
| 660 | elif os.path.exists(testfile): |
| 661 | print '' |
| 662 | else: |
| 663 | print "\nThere is no :\""+main.TEST+"\" test, Please Provide OpenSpeak Script/ test script" |
| 664 | __builtin__.testthread = None |
| 665 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 666 | try : |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 667 | testModule = __import__(main.classPath, globals(), locals(), [main.TEST], -1) |
| 668 | except(ImportError): |
Jon Hall | f8ecf73 | 2014-12-02 21:14:16 -0500 | [diff] [blame] | 669 | print "There was an import error, it might mean that there is no test like "+main.TEST |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 670 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 671 | |
| 672 | testClass = getattr(testModule, main.TEST) |
| 673 | main.testObject = testClass() |
| 674 | load_parser() |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 675 | main.params = main.parser.parseParams(main.classPath) |
| 676 | main.topology = main.parser.parseTopology(main.classPath) |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 677 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 678 | def verifyParams(): |
| 679 | try : |
| 680 | main.params = main.params['PARAMS'] |
| 681 | except(KeyError): |
| 682 | print "Error with the params file: Either the file not specified or the format is not correct" |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 683 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 684 | try : |
| 685 | main.topology = main.topology['TOPOLOGY'] |
| 686 | except(KeyError): |
| 687 | print "Error with the Topology file: Either the file not specified or the format is not correct" |
| 688 | main.exit() |
Jon Hall | 81d3d39 | 2015-04-24 14:40:35 -0700 | [diff] [blame] | 689 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 690 | def load_parser() : |
| 691 | ''' |
| 692 | It facilitates the loading customised parser for topology and params file. |
| 693 | It loads parser mentioned in tab named parser of teston.cfg file. |
| 694 | It also loads default xmlparser if no parser have specified in teston.cfg file. |
| 695 | |
| 696 | ''' |
| 697 | confighash = main.configDict |
| 698 | if 'file' in confighash['config']['parser'] and 'class' in confighash['config']['parser']: |
| 699 | if confighash['config']['parser']['file'] != None or confighash['config']['parser']['class']!= None : |
| 700 | if os.path.exists(confighash['config']['parser']['file']) : |
| 701 | module = re.sub(r".py\s*$","",confighash['config']['parser']['file']) |
| 702 | moduleList = module.split("/") |
| 703 | newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]]) |
| 704 | try : |
| 705 | parsingClass = confighash['config']['parser']['class'] |
| 706 | parsingModule = __import__(newModule, globals(), locals(), [parsingClass], -1) |
| 707 | parsingClass = getattr(parsingModule, parsingClass) |
| 708 | main.parser = parsingClass() |
| 709 | #hashobj = main.parser.parseParams(main.classPath) |
| 710 | if hasattr(main.parser,"parseParams") and hasattr(main.parser,"parseTopology") and hasattr(main.parser,"parse") : |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 711 | pass |
| 712 | else: |
| 713 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 714 | except ImportError: |
| 715 | print sys.exc_info()[1] |
| 716 | main.exit() |
| 717 | else : |
| 718 | print "No Such File Exists !!"+ confighash['config']['parser']['file'] +"using default parser" |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 719 | load_defaultParser() |
| 720 | elif confighash['config']['parser']['file'] == None or confighash['config']['parser']['class'] == None : |
| 721 | load_defaultParser() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 722 | else: |
| 723 | load_defaultParser() |
| 724 | |
| 725 | def load_defaultParser(): |
| 726 | ''' |
| 727 | It will load the default parser which is xml parser to parse the params and topology file. |
| 728 | ''' |
| 729 | moduleList = main.parserPath.split("/") |
| 730 | newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]]) |
| 731 | try : |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 732 | parsingClass = main.parsingClass |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 733 | parsingModule = __import__(newModule, globals(), locals(), [parsingClass], -1) |
| 734 | parsingClass = getattr(parsingModule, parsingClass) |
| 735 | main.parser = parsingClass() |
| 736 | if hasattr(main.parser,"parseParams") and hasattr(main.parser,"parseTopology") and hasattr(main.parser,"parse") : |
| 737 | pass |
| 738 | else: |
| 739 | main.exit() |
| 740 | |
| 741 | except ImportError: |
| 742 | print sys.exc_info()[1] |
| 743 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 744 | def load_logger() : |
| 745 | ''' |
| 746 | It facilitates the loading customised parser for topology and params file. |
| 747 | It loads parser mentioned in tab named parser of teston.cfg file. |
| 748 | It also loads default xmlparser if no parser have specified in teston.cfg file. |
| 749 | |
| 750 | ''' |
| 751 | confighash = main.configDict |
| 752 | if 'file' in confighash['config']['logger'] and 'class' in confighash['config']['logger']: |
| 753 | if confighash['config']['logger']['file'] != None or confighash['config']['logger']['class']!= None : |
| 754 | if os.path.exists(confighash['config']['logger']['file']) : |
| 755 | module = re.sub(r".py\s*$","",confighash['config']['logger']['file']) |
| 756 | moduleList = module.split("/") |
| 757 | newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]]) |
| 758 | try : |
| 759 | loggerClass = confighash['config']['logger']['class'] |
| 760 | loggerModule = __import__(newModule, globals(), locals(), [loggerClass], -1) |
| 761 | loggerClass = getattr(loggerModule, loggerClass) |
| 762 | main.logger = loggerClass() |
| 763 | #hashobj = main.parser.parseParams(main.classPath) |
| 764 | |
| 765 | except ImportError: |
| 766 | print sys.exc_info()[1] |
| 767 | else : |
| 768 | print "No Such File Exists !!"+confighash['config']['logger']['file']+ "Using default logger" |
| 769 | load_defaultlogger() |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 770 | elif confighash['config']['parser']['file'] == None or confighash['config']['parser']['class'] == None : |
| 771 | load_defaultlogger() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 772 | else: |
| 773 | load_defaultlogger() |
| 774 | |
| 775 | def load_defaultlogger(): |
| 776 | ''' |
| 777 | It will load the default parser which is xml parser to parse the params and topology file. |
| 778 | ''' |
| 779 | moduleList = main.loggerPath.split("/") |
| 780 | newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]]) |
| 781 | try : |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 782 | loggerClass = main.loggerClass |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 783 | loggerModule = __import__(newModule, globals(), locals(), [loggerClass], -1) |
| 784 | loggerClass = getattr(loggerModule, loggerClass) |
| 785 | main.logger = loggerClass() |
| 786 | |
| 787 | except ImportError: |
| 788 | print sys.exc_info()[1] |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 789 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 790 | |
| 791 | def load_defaultlogger(): |
| 792 | ''' |
| 793 | It will load the default parser which is xml parser to parse the params and topology file. |
| 794 | ''' |
| 795 | moduleList = main.loggerPath.split("/") |
| 796 | newModule = ".".join([moduleList[len(moduleList) - 2],moduleList[len(moduleList) - 1]]) |
| 797 | try : |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 798 | loggerClass = main.loggerClass |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 799 | loggerModule = __import__(newModule, globals(), locals(), [loggerClass], -1) |
| 800 | loggerClass = getattr(loggerModule, loggerClass) |
| 801 | main.logger = loggerClass() |
| 802 | |
| 803 | except ImportError: |
| 804 | print sys.exc_info()[1] |
| 805 | main.exit() |
| 806 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 807 | def _echo(self): |
| 808 | print "THIS IS ECHO" |