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