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