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 |
Jon Hall | 5b58673 | 2015-06-11 11:39:39 -0700 | [diff] [blame] | 35 | import threading |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 36 | module = new.module( "test" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 37 | import openspeak |
Hari Krishna | be4b97b | 2015-07-15 12:19:43 -0700 | [diff] [blame] | 38 | import subprocess |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 39 | global path, drivers_path, core_path, tests_path, logs_path |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 40 | location = os.path.abspath( os.path.dirname( __file__ ) ) |
| 41 | path = re.sub( "(core|bin)$", "", location ) |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 42 | drivers_path = path + "drivers" |
| 43 | core_path = path + "core" |
| 44 | tests_path = path + "tests" |
| 45 | logs_path = path + "logs/" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 46 | config_path = path + "config/" |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 47 | sys.path.append( path ) |
| 48 | sys.path.append( drivers_path ) |
| 49 | sys.path.append( core_path ) |
| 50 | sys.path.append( tests_path ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 51 | |
| 52 | from core.utilities import Utilities |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 53 | from core.Thread import Thread |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 54 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 55 | |
| 56 | class TestON: |
| 57 | ''' |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 58 | TestON will initiate the specified test. |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 59 | The main tasks are: |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 60 | * Initiate the required Component handles for the test. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 61 | * Create Log file Handles. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 62 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 63 | def __init__( self, options ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 64 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 65 | Initialise the component handles specified in the topology file of |
| 66 | the specified test. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 67 | ''' |
| 68 | # Initialization of the variables. |
| 69 | __builtin__.main = self |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 70 | __builtin__.path = path |
| 71 | __builtin__.utilities = Utilities() |
| 72 | self.TRUE = 1 |
| 73 | self.FALSE = 0 |
| 74 | self.ERROR = -1 |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 75 | self.NORESULT = 2 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 76 | self.FAIL = False |
| 77 | self.PASS = True |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 78 | self.CASERESULT = self.ERROR |
| 79 | self.STEPRESULT = self.NORESULT |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 80 | self.init_result = self.TRUE |
| 81 | self.testResult = "Summary" |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 82 | self.stepName = "" |
| 83 | self.stepCache = "" |
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 | 5b58673 | 2015-06-11 11:39:39 -0700 | [diff] [blame] | 96 | self.cleanupFlag = False |
| 97 | self.cleanupLock = threading.Lock() |
Jon Hall | 0fc0d45 | 2015-07-14 09:49:58 -0700 | [diff] [blame] | 98 | self.initiated = False |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 99 | |
Jon Hall | 2507978 | 2015-10-13 13:54:39 -0700 | [diff] [blame] | 100 | self.config = self.configparser() |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 101 | verifyOptions( options ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 102 | load_logger() |
| 103 | self.componentDictionary = {} |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 104 | self.componentDictionary = self.topology['COMPONENT'] |
| 105 | self.driversList = [] |
| 106 | if isinstance( self.componentDictionary, str): |
| 107 | self.componentDictionary = dict( self.componentDictionary ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 108 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 109 | for component in self.componentDictionary: |
| 110 | self.driversList.append( self.componentDictionary[component]['type'] ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 111 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 112 | self.driversList = list( set( self.driversList ) ) # Removing duplicates. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 113 | # Checking the test_target option set for the component or not |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 114 | if isinstance( self.componentDictionary, dict ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 115 | for component in self.componentDictionary.keys(): |
| 116 | if 'test_target' in self.componentDictionary[component].keys(): |
| 117 | self.test_target = component |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 118 | |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 119 | # Checking for the openspeak file and test script |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 120 | self.logger.initlog( self ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 121 | |
| 122 | # Creating Drivers Handles |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 123 | initString = "\n" + "*" * 30 + "\n CASE INIT \n" + "*" * 30 + "\n" |
| 124 | self.log.exact( initString ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 125 | self.driverObject = {} |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 126 | self.random_order = 111 # Random order id to connect the components |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 127 | components_connect_order = {} |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 128 | if isinstance( self.componentDictionary, dict ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 129 | for component in self.componentDictionary.keys(): |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 130 | if 'connect_order' not in self.componentDictionary[component].keys(): |
| 131 | self.componentDictionary[component]['connect_order'] = str( self.get_random() ) |
| 132 | components_connect_order[component] = eval( self.componentDictionary[component]['connect_order'] ) |
| 133 | # Ordering components based on the connect order. |
| 134 | ordered_component_list = sorted( components_connect_order, |
| 135 | key=lambda key: components_connect_order[key] ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 136 | print ordered_component_list |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 137 | for component in ordered_component_list: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 138 | self.componentInit( component ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 139 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 140 | def configparser( self ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 141 | ''' |
| 142 | It will parse the config file (teston.cfg) and return as dictionary |
| 143 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 144 | matchFileName = re.match( r'(.*)\.cfg', self.configFile, re.M | re.I ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 145 | if matchFileName: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 146 | xml = open( self.configFile ).read() |
| 147 | try: |
| 148 | self.configDict = xmldict.xml_to_dict( xml ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 149 | return self.configDict |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 150 | except IOError: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 151 | print "There is no such file to parse " + self.configFile |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 152 | else: |
| 153 | print "There is no such file to parse " + self.configFile |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 154 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 155 | def componentInit( self, component ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 156 | ''' |
| 157 | This method will initialize specified component |
| 158 | ''' |
| 159 | global driver_options |
Jon Hall | 0fc0d45 | 2015-07-14 09:49:58 -0700 | [diff] [blame] | 160 | self.initiated = False |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 161 | self.log.info( "Creating component Handle: " + component ) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 162 | driver_options = {} |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 163 | if 'COMPONENTS' in self.componentDictionary[component].keys(): |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 164 | driver_options = dict( self.componentDictionary[component]['COMPONENTS'] ) |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 165 | driver_options['name'] = component |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 166 | driverName = self.componentDictionary[component]['type'] |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 167 | driver_options['type'] = driverName |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 168 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 169 | classPath = self.getDriverPath( driverName.lower() ) |
| 170 | driverModule = importlib.import_module( classPath ) |
| 171 | driverClass = getattr( driverModule, driverName ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 172 | driverObject = driverClass() |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 173 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 174 | if "OCN" in self.componentDictionary[component]['host'] and\ |
| 175 | main.onoscell: |
Hari Krishna | be4b97b | 2015-07-15 12:19:43 -0700 | [diff] [blame] | 176 | self.componentDictionary[component]['host'] = main.mnIP |
| 177 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 178 | user_name = self.componentDictionary[component].get( 'user', |
| 179 | getpass.getuser() ) |
| 180 | ip_address = self.componentDictionary[component].get( 'host', |
| 181 | 'localhost' ) |
| 182 | pwd = self.componentDictionary[component].get( 'password', |
| 183 | 'changeme' ) |
| 184 | port = self.componentDictionary[component].get( 'port' ) |
| 185 | connect_result = driverObject.connect( user_name=user_name, |
| 186 | ip_address=ip_address, |
| 187 | pwd=pwd, |
| 188 | port=port, |
| 189 | options=driver_options) |
cameron@onlab.us | 5cc6a37 | 2015-05-11 17:18:07 -0700 | [diff] [blame] | 190 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 191 | if not connect_result: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 192 | self.log.error( "Exiting from the test execution because connecting to the " + |
| 193 | component + " component failed." ) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 194 | self.exit() |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 195 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 196 | vars( self )[component] = driverObject |
Jon Hall | 0fc0d45 | 2015-07-14 09:49:58 -0700 | [diff] [blame] | 197 | self.initiated = True |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 198 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 199 | def run( self ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 200 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 201 | The Execution of the test script's cases listed in the Test params |
| 202 | file will be done here then update each test case result. |
| 203 | This method will return main.TRUE if it executed all the test cases |
| 204 | successfully, else will retun main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 205 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 206 | self.testCaseResult = {} |
Jon Hall | a118598 | 2014-09-15 14:55:10 -0700 | [diff] [blame] | 207 | self.TOTAL_TC = 0 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 208 | self.TOTAL_TC_RUN = 0 |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 209 | self.TOTAL_TC_PLANNED = 0 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 210 | self.TOTAL_TC_NORESULT = 0 |
| 211 | self.TOTAL_TC_FAIL = 0 |
| 212 | self.TOTAL_TC_PASS = 0 |
Jon Hall | a118598 | 2014-09-15 14:55:10 -0700 | [diff] [blame] | 213 | self.TEST_ITERATION = 0 |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 214 | |
| 215 | # NOTE: number of main.step statements in the |
| 216 | # outer most level of the test case. used to |
| 217 | # execute code in smaller steps |
| 218 | self.stepCount = 0 |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 219 | self.CASERESULT = self.NORESULT |
| 220 | |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 221 | import testparser |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 222 | test = testparser.TestParser( main.testFile ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 223 | self.testscript = test.testscript |
| 224 | self.code = test.getStepCode() |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 225 | repeat = int( self.params.get( 'repeat', 1 ) ) |
| 226 | self.TOTAL_TC_PLANNED = len( self.testcases_list ) * repeat |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 227 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 228 | result = self.TRUE |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 229 | while repeat: |
Jon Hall | a118598 | 2014-09-15 14:55:10 -0700 | [diff] [blame] | 230 | for self.CurrentTestCaseNumber in self.testcases_list: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 231 | result = self.runCase( self.CurrentTestCaseNumber ) |
| 232 | repeat -= 1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 233 | return result |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 234 | |
Jon Hall | e234cc4 | 2015-08-31 15:26:47 -0700 | [diff] [blame] | 235 | def runCase( self, testCaseNumber ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 236 | self.CurrentTestCaseNumber = testCaseNumber |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 237 | self.CurrentTestCase = "" |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 238 | |
| 239 | # List of step results in a case. ANDed together to get the result |
| 240 | self.stepResultsList = [] |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 241 | self.stepName = "" |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 242 | self.caseExplanation = "" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 243 | result = self.TRUE |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 244 | |
| 245 | # NOTE: number of main.step statements in the |
| 246 | # outer most level of the test case. used to |
| 247 | # execute code in smaller steps |
| 248 | self.stepCount = 0 |
| 249 | |
| 250 | # NOTE: This is the current number of main.step()'s executed |
| 251 | # in a case. Used for logging. |
| 252 | self.stepNumber = 0 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 253 | self.EXPERIMENTAL_MODE = self.FALSE |
| 254 | self.addCaseHeader() |
Jon Hall | e234cc4 | 2015-08-31 15:26:47 -0700 | [diff] [blame] | 255 | self.testCaseNumber = str( testCaseNumber ) |
| 256 | self.CASERESULT = self.NORESULT |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 257 | stopped = False |
Jon Hall | 5a72b71 | 2015-09-28 12:20:59 -0700 | [diff] [blame] | 258 | try: |
| 259 | self.code[self.testCaseNumber] |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 260 | except KeyError: |
Jon Hall | e234cc4 | 2015-08-31 15:26:47 -0700 | [diff] [blame] | 261 | self.log.error( "There is no Test-Case " + self.testCaseNumber ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 262 | return self.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 263 | self.stepCount = 0 |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 264 | while self.stepCount < len( self.code[self.testCaseNumber].keys() ): |
| 265 | result = self.runStep( self.code, self.testCaseNumber ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 266 | if result == self.FALSE: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 267 | break |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 268 | elif result == self.TRUE: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 269 | continue |
Jon Hall | 5a72b71 | 2015-09-28 12:20:59 -0700 | [diff] [blame] | 270 | # stepResults format: ( stepNo[], stepName[], stepResult[], onFail[] ) |
| 271 | stepResults = self.stepResultsList |
Jon Hall | e234cc4 | 2015-08-31 15:26:47 -0700 | [diff] [blame] | 272 | if not stopped: |
| 273 | if self.CASERESULT == self.TRUE or self.CASERESULT == self.FALSE: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 274 | # Result was already explitily set somewhere else like |
| 275 | # in skipCase() |
Jon Hall | e234cc4 | 2015-08-31 15:26:47 -0700 | [diff] [blame] | 276 | pass |
Jon Hall | 5a72b71 | 2015-09-28 12:20:59 -0700 | [diff] [blame] | 277 | elif all( self.TRUE == i for i in stepResults ): |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 278 | # ALL PASSED |
| 279 | self.CASERESULT = self.TRUE |
Jon Hall | 5a72b71 | 2015-09-28 12:20:59 -0700 | [diff] [blame] | 280 | elif self.FALSE in stepResults: |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 281 | # AT LEAST ONE FAILED |
| 282 | self.CASERESULT = self.FALSE |
Jon Hall | 5a72b71 | 2015-09-28 12:20:59 -0700 | [diff] [blame] | 283 | elif self.TRUE in stepResults: |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 284 | # AT LEAST ONE PASSED |
| 285 | self.CASERESULT = self.TRUE |
| 286 | else: |
| 287 | self.CASERESULT = self.NORESULT |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 288 | self.testCaseResult[str( self.CurrentTestCaseNumber )] = self.CASERESULT |
| 289 | self.logger.updateCaseResults( self ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 290 | self.log.wiki( "<p>" + self.caseExplanation + "</p>" ) |
| 291 | self.log.summary( self.caseExplanation ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 292 | self.log.wiki( "<ul>" ) |
acsmars | e2d1ed1 | 2015-10-05 13:51:17 -0700 | [diff] [blame] | 293 | subcaseMessage = False |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 294 | for line in self.stepCache.splitlines(): |
acsmars | e2d1ed1 | 2015-10-05 13:51:17 -0700 | [diff] [blame] | 295 | if re.search( "[0-9]\.[0-9]", line ): # Step |
| 296 | if subcaseMessage: # End of Failure Message Printout |
| 297 | self.log.wiki( "</ul>\n" ) |
| 298 | subcaseMessage = False |
| 299 | if re.search( " - PASS$", line ): |
| 300 | self.log.wiki( "<li>" + line + " <ac:emoticon ac:name=\"tick\" /></li>\n" ) |
| 301 | elif re.search( " - FAIL$", line ): |
| 302 | self.log.wiki( "<li>" + line + " <ac:emoticon ac:name=\"cross\" /></li>\n" ) |
| 303 | elif re.search( " - No Result$", line ): |
| 304 | self.log.wiki( "<li>" + line + " <ac:emoticon ac:name=\"warning\" /></li>\n" ) |
| 305 | else: # Substep |
| 306 | if not subcaseMessage: # Open Failure Message Printout |
| 307 | self.log.wiki( "<ul><li>" + line + "</li>\n" ) |
| 308 | subcaseMessage = True |
| 309 | else: # Add to Failure Message Printout |
| 310 | self.log.wiki( "<li>" + line + "</li>\n" ) |
acsmars | 27e62dd | 2015-10-06 11:35:47 -0700 | [diff] [blame] | 311 | if subcaseMessage: # End of Failure Message Printout for last item |
| 312 | self.log.wiki( "</ul>\n" ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 313 | self.log.wiki( "</ul>" ) |
| 314 | self.log.summary( self.stepCache ) |
| 315 | self.stepCache = "" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 316 | return result |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 317 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 318 | def runStep( self, code, testCaseNumber ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 319 | if not cli.pause: |
Jon Hall | 5a72b71 | 2015-09-28 12:20:59 -0700 | [diff] [blame] | 320 | try: |
| 321 | step = self.stepCount |
| 322 | # stepResults format: ( stepNo, stepName, stepResult, onFail ) |
| 323 | # NOTE: This is needed to catch results of main.step()'s |
| 324 | # called inside functions or loops |
| 325 | self.stepResults = ( [], [], [], [] ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 326 | exec code[testCaseNumber][step] in module.__dict__ |
| 327 | self.stepCount = self.stepCount + 1 |
Jon Hall | 96b816f | 2015-11-03 12:00:56 -0800 | [diff] [blame] | 328 | self.parseStepResults( testCaseNumber ) |
Jon Hall | e234cc4 | 2015-08-31 15:26:47 -0700 | [diff] [blame] | 329 | except StopIteration: # Raised in self.skipCase() |
| 330 | self.log.warn( "Skipping the rest of CASE" + |
| 331 | str( testCaseNumber ) ) |
Jon Hall | 96b816f | 2015-11-03 12:00:56 -0800 | [diff] [blame] | 332 | self.parseStepResults( testCaseNumber ) |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 333 | self.stepResultsList.append( self.STEPRESULT ) |
Jon Hall | e234cc4 | 2015-08-31 15:26:47 -0700 | [diff] [blame] | 334 | self.stepCache += "\t\t" + self.onFailMsg + "\n" |
| 335 | self.stepCount = self.stepCount + 1 |
| 336 | return self.FALSE |
Jon Hall | c160635 | 2015-10-06 14:51:36 -0700 | [diff] [blame] | 337 | except StandardError as e: |
| 338 | try: |
| 339 | stepNo = self.stepResults[0][ self.stepNumber - 1 ] |
| 340 | except IndexError: |
| 341 | stepNo = "<IndexError>" |
| 342 | main.log.warn( "Error trying to get step number. " + |
| 343 | "It is likely between step " + |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 344 | str( self.stepNumber ) + " and step " + |
Jon Hall | c160635 | 2015-10-06 14:51:36 -0700 | [diff] [blame] | 345 | str( self.stepNumber + 1 ) ) |
| 346 | try: |
| 347 | stepName = self.stepResults[1][ self.stepNumber - 1 ] |
| 348 | except IndexError: |
| 349 | stepName = "<IndexError>" |
| 350 | self.log.error( "\nException in the following section of" + |
| 351 | " code: " + str( testCaseNumber ) + "." + |
| 352 | str( stepNo ) + ": " + stepName ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 353 | self.log.error( str( e.__class__ ) + str( e.message ) ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 354 | self.stepCount = self.stepCount + 1 |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 355 | self.logger.updateCaseResults( self ) |
| 356 | # WIKI results |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 357 | self.log.wiki( "<ul>" ) |
| 358 | for line in self.stepCache.splitlines(): |
| 359 | if re.search( " - PASS$", line ): |
| 360 | self.log.wiki( "<li>" + line + " <ac:emoticon ac:name=\"tick\" /></li>\n" ) |
| 361 | elif re.search( " - FAIL$", line ): |
| 362 | self.log.wiki( "<li>" + line + " <ac:emoticon ac:name=\"cross\" /></li>\n" ) |
| 363 | elif re.search( " - No Result$", line ): |
| 364 | self.log.wiki( "<li>" + line + " <ac:emoticon ac:name=\"warning\" /></li>\n" ) |
Jon Hall | 9062761 | 2015-06-09 14:57:02 -0700 | [diff] [blame] | 365 | else: # Should only be on fail message |
| 366 | self.log.wiki( "<ul><li>" + line + "</li></ul>\n" ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 367 | self.log.wiki( "</ul>" ) |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 368 | # summary results |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 369 | self.log.summary( self.stepCache ) |
| 370 | self.stepCache = "" |
shahshreya | 957feaa | 2015-03-23 16:08:29 -0700 | [diff] [blame] | 371 | self.cleanup() |
Jon Hall | 00539b1 | 2015-04-03 13:55:46 -0700 | [diff] [blame] | 372 | self.exit() |
Jon Hall | e234cc4 | 2015-08-31 15:26:47 -0700 | [diff] [blame] | 373 | return self.TRUE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 374 | if cli.stop: |
| 375 | cli.stop = False |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 376 | self.TOTAL_TC_NORESULT = self.TOTAL_TC_NORESULT + 1 |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 377 | self.testCaseResult[str( self.CurrentTestCaseNumber )] = "Stopped" |
| 378 | self.logger.updateCaseResults( self ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 379 | result = self.cleanup() |
Jon Hall | e234cc4 | 2015-08-31 15:26:47 -0700 | [diff] [blame] | 380 | return self.FALSE |
| 381 | |
Jon Hall | 96b816f | 2015-11-03 12:00:56 -0800 | [diff] [blame] | 382 | def parseStepResults( self, testCaseNumber ): |
| 383 | """ |
| 384 | Parse throught the step results for the wiki |
| 385 | """ |
| 386 | try: |
| 387 | # Iterate through each of the steps and print them |
| 388 | for index in range( len( self.stepResults[0] ) ): |
| 389 | # stepResults = ( stepNo, stepName, stepResult, onFail ) |
| 390 | stepNo = self.stepResults[0][ index ] |
| 391 | stepName = self.stepResults[1][ index ] |
| 392 | stepResult = self.stepResults[2][ index ] |
| 393 | onFail = self.stepResults[3][ index ] |
| 394 | self.stepCache += "\t" + str( testCaseNumber ) + "." |
| 395 | self.stepCache += str( stepNo ) + " " |
| 396 | self.stepCache += stepName + " - " |
| 397 | if stepResult == self.TRUE: |
| 398 | self.stepCache += "PASS\n" |
| 399 | elif stepResult == self.FALSE: |
| 400 | self.stepCache += "FAIL\n" |
| 401 | self.stepCache += "\t\t" + onFail + "\n" |
| 402 | else: |
| 403 | self.stepCache += "No Result\n" |
| 404 | self.stepResultsList.append( stepResult ) |
| 405 | except Exception: |
| 406 | self.log.exception( "Error parsing step results" ) |
| 407 | |
Jon Hall | e234cc4 | 2015-08-31 15:26:47 -0700 | [diff] [blame] | 408 | def skipCase( self, result="DEFAULT", msg=None ): |
| 409 | """ |
| 410 | Will skip the rest of the code in a test case. The case results will be |
| 411 | determined as normal based on completed assertions unless the result |
| 412 | argument is given. |
| 413 | |
| 414 | Optional Arguments: |
| 415 | result: Case insensite string. Can be 'PASS' or 'FAIL' and will set |
| 416 | the case result accordingly. |
| 417 | msg: Message to be printed when the case is skipped in the reports. |
| 418 | """ |
| 419 | result = result.upper().strip() |
| 420 | if result == "PASS": |
| 421 | self.CASERESULT = self.TRUE |
| 422 | elif result == "FAIL": |
| 423 | self.CASERESULT = self.FALSE |
| 424 | self.onFailMsg = "Skipping the rest of this case. " |
| 425 | if msg: |
| 426 | self.onFailMsg += str( msg ) |
| 427 | raise StopIteration |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 428 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 429 | def addCaseHeader( self ): |
| 430 | caseHeader = "\n" + "*" * 30 + "\n Result summary for Testcase" +\ |
| 431 | str( self.CurrentTestCaseNumber ) + "\n" + "*" * 30 + "\n" |
| 432 | self.log.exact( caseHeader ) |
| 433 | caseHeader = "\n" + "*" * 40 + "\nStart of Test Case" +\ |
| 434 | str( self.CurrentTestCaseNumber ) + " : " |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 435 | for driver in self.componentDictionary.keys(): |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 436 | vars( self )[driver + 'log'].info( caseHeader ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 437 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 438 | def addCaseFooter( self ): |
Jon Hall | 5a72b71 | 2015-09-28 12:20:59 -0700 | [diff] [blame] | 439 | stepNo = self.stepResults[0][-2] |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 440 | if stepNo > 0: |
| 441 | previousStep = " " + str( self.CurrentTestCaseNumber ) + "." +\ |
| 442 | str( stepNo ) + ": " + str( self.stepName ) |
| 443 | stepHeader = "\n" + "*" * 40 + "\nEnd of Step " + previousStep +\ |
| 444 | "\n" + "*" * 40 + "\n" |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 445 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 446 | caseFooter = "\n" + "*" * 40 + "\nEnd of Test case " +\ |
| 447 | str( self.CurrentTestCaseNumber ) + "\n" + "*" * 40 + "\n" |
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 | for driver in self.driversList: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 450 | vars( self )[driver].write( stepHeader + "\n" + caseFooter ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 451 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 452 | def cleanup( self ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 453 | ''' |
Jon Hall | 5b58673 | 2015-06-11 11:39:39 -0700 | [diff] [blame] | 454 | Print a summary of the current test's results then attempt to release |
| 455 | all the component handles and the close opened file handles. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 456 | |
Jon Hall | 5b58673 | 2015-06-11 11:39:39 -0700 | [diff] [blame] | 457 | This function shouldbe threadsafe such that cleanup will only be |
| 458 | executed once per test. |
| 459 | |
| 460 | This will return TRUE if all the component handles and log handles |
| 461 | closed properly, else return FALSE. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 462 | ''' |
| 463 | result = self.TRUE |
Jon Hall | 5b58673 | 2015-06-11 11:39:39 -0700 | [diff] [blame] | 464 | lock = self.cleanupLock |
| 465 | if lock.acquire( False ): |
| 466 | try: |
| 467 | if self.cleanupFlag is False: # First thread to run this |
| 468 | self.cleanupFlag = True |
Jon Hall | 0fc0d45 | 2015-07-14 09:49:58 -0700 | [diff] [blame] | 469 | if self.initiated: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 470 | self.logger.testSummary( self ) |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 471 | components = self.componentDictionary |
| 472 | for component in sorted( components, |
| 473 | key=lambda item: components[item]['connect_order'], |
| 474 | reverse=True ): |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 475 | try: |
| 476 | tempObject = vars( self )[component] |
| 477 | print "Disconnecting from " + str( tempObject.name ) +\ |
| 478 | ": " + str( tempObject.__class__) |
Jon Hall | 5b58673 | 2015-06-11 11:39:39 -0700 | [diff] [blame] | 479 | tempObject.disconnect() |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 480 | except KeyboardInterrupt: |
| 481 | pass |
| 482 | except KeyError: |
| 483 | # Component not created yet |
| 484 | self.log.warn( "Could not find the component " + |
| 485 | str( component ) ) |
| 486 | except StandardError: |
Jon Hall | 5b58673 | 2015-06-11 11:39:39 -0700 | [diff] [blame] | 487 | self.log.exception( "Exception while disconnecting from " + |
| 488 | str( component ) ) |
| 489 | result = self.FALSE |
| 490 | # Closing all the driver's session files |
| 491 | for driver in self.componentDictionary.keys(): |
| 492 | try: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 493 | vars( self )[driver].close_log_handles() |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 494 | except KeyboardInterrupt: |
| 495 | pass |
| 496 | except KeyError: |
| 497 | # Component not created yet |
| 498 | self.log.warn( "Could not find the component " + |
| 499 | str( driver ) + " while trying to" + |
| 500 | " close log file" ) |
| 501 | except StandardError: |
Jon Hall | 5b58673 | 2015-06-11 11:39:39 -0700 | [diff] [blame] | 502 | self.log.exception( "Exception while closing log files for " + |
| 503 | str( driver ) ) |
| 504 | result = self.FALSE |
| 505 | else: |
| 506 | pass # Someone else already ran through this function |
| 507 | finally: |
| 508 | lock.release() |
| 509 | else: # Someone already has a lock |
| 510 | # NOTE: This could cause problems if we don't release the lock |
| 511 | # correctly |
| 512 | lock.acquire() # Wait for the other thread to finish |
| 513 | # NOTE: If we don't wait, exit could be called while the thread |
| 514 | # with the lock is still cleaning up |
| 515 | lock.release() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 516 | return result |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 517 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 518 | def pause( self ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 519 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 520 | This function will pause the test's execution, and will continue after |
| 521 | user provide 'resume' command. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 522 | ''' |
| 523 | __builtin__.testthread.pause() |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 524 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 525 | def onfail( self, *components ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 526 | ''' |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 527 | When test step failed, calling all the components onfail. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 528 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 529 | if not components: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 530 | try: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 531 | for component in self.componentDictionary.keys(): |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 532 | tempObject = vars( self )[component] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 533 | result = tempObject.onfail() |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 534 | except StandardError as e: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 535 | print str( e ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 536 | result = self.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 537 | else: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 538 | try: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 539 | for component in components: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 540 | tempObject = vars( self )[component] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 541 | result = tempObject.onfail() |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 542 | except StandardError as e: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 543 | print str( e ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 544 | result = self.FALSE |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 545 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 546 | def getDriverPath( self, driverName ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 547 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 548 | Based on the component 'type' specified in the params , this method |
| 549 | will find the absolute path, by recursively searching the name of |
| 550 | the component. |
| 551 | |
| 552 | NOTE: This function requires the linux 'find' command. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 553 | ''' |
| 554 | import commands |
| 555 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 556 | cmd = "find " + drivers_path + " -name " + driverName + ".py" |
| 557 | result = commands.getoutput( cmd ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 558 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 559 | result_array = str( result ).split( '\n' ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 560 | result_count = 0 |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 561 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 562 | for drivers_list in result_array: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 563 | result_count = result_count + 1 |
| 564 | if result_count > 1: |
| 565 | print "Found " + driverName + " " + str( result_count ) + " times:" |
| 566 | print str( result_array ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 567 | self.exit() |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 568 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 569 | result = re.sub( "(.*)drivers", "", result ) |
| 570 | result = re.sub( "\/\/", "/", result ) |
| 571 | result = re.sub( "\.py", "", result ) |
| 572 | result = re.sub( "\.pyc", "", result ) |
| 573 | result = re.sub( "\/", ".", result ) |
| 574 | result = "drivers" + result |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 575 | return result |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 576 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 577 | def step( self, stepDesc ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 578 | ''' |
| 579 | The step information of the test-case will append to the logs. |
| 580 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 581 | previousStep = " " + str( self.CurrentTestCaseNumber ) + "." +\ |
| 582 | str( self.stepNumber ) + ": " + str( self.stepName ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 583 | self.stepName = stepDesc |
Jon Hall | 5a72b71 | 2015-09-28 12:20:59 -0700 | [diff] [blame] | 584 | self.stepNumber += 1 |
| 585 | self.stepResults[0].append( self.stepNumber ) |
| 586 | self.stepResults[1].append( stepDesc ) |
| 587 | self.stepResults[2].append( self.NORESULT ) |
| 588 | self.stepResults[3].append( "No on fail message given" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 589 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 590 | stepName = " " + str( self.CurrentTestCaseNumber ) + "." +\ |
| 591 | str( self.stepNumber ) + ": " + str( stepDesc ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 592 | self.log.step(stepName) |
| 593 | stepHeader = "" |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 594 | line = "\n" + "-" * 45 + "\n" |
| 595 | if self.stepNumber > 1: |
| 596 | stepHeader = line + "End of Step " + previousStep + line |
| 597 | stepHeader += line + "Start of Step" + stepName + line |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 598 | for driver in self.componentDictionary.keys(): |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 599 | vars( self )[driver + 'log'].info( stepHeader ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 600 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 601 | def case( self, testCaseName ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 602 | ''' |
| 603 | Test's each test-case information will append to the logs. |
| 604 | ''' |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 605 | self.CurrentTestCase = testCaseName |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 606 | testCaseName = " " + str( testCaseName ) |
| 607 | self.log.case( testCaseName ) |
| 608 | caseHeader = testCaseName + "\n" + "*" * 40 + "\n" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 609 | for driver in self.componentDictionary.keys(): |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 610 | vars( self )[driver + 'log'].info( caseHeader ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 611 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 612 | def testDesc( self, description ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 613 | ''' |
| 614 | Test description will append to the logs. |
| 615 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 616 | description = "Test Description : " + str( description ) |
| 617 | self.log.info( description ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 618 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 619 | def _getTest( self ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 620 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 621 | This method will parse the test script to find required test |
| 622 | information. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 623 | ''' |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 624 | testFileHandler = open( main.testFile, 'r' ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 625 | testFileList = testFileHandler.readlines() |
| 626 | testFileHandler.close() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 627 | counter = 0 |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 628 | for index in range( len( testFileList ) ): |
| 629 | lineMatch = re.match( '\s+def CASE(\d+)(.*):', |
| 630 | testFileList[index], |
| 631 | 0 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 632 | if lineMatch: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 633 | counter = counter + 1 |
| 634 | self.TC_PLANNED = len( self.testcases_list ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 635 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 636 | def response_parser( self, response, return_format ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 637 | ''' It will load the default response parser ''' |
| 638 | response_dict = {} |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 639 | response_dict = self.response_to_dict( response, return_format ) |
| 640 | return_format_string = self.dict_to_return_format( response, |
| 641 | return_format, |
| 642 | response_dict ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 643 | return return_format_string |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 644 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 645 | def response_to_dict( self, response, return_format ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 646 | response_dict = {} |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 647 | json_match = re.search( '^\s*{', response ) |
| 648 | xml_match = re.search( '^\s*\<', response ) |
| 649 | ini_match = re.search( '^\s*\[', response ) |
| 650 | if json_match: |
| 651 | self.log.info( "Response is in 'JSON' format, converting to '" + |
| 652 | return_format + "' format" ) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 653 | # Formatting the json string |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 654 | response = re.sub( r"{\s*'?(\w)", r'{"\1', response ) |
| 655 | response = re.sub( r",\s*'?(\w)", r',"\1', response ) |
| 656 | response = re.sub( r"(\w)'?\s*:", r'\1":', response ) |
| 657 | response = re.sub( r":\s*'(\w)'\s*([,}])", r':"\1"\2', response ) |
| 658 | try: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 659 | import json |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 660 | response_dict = json.loads( response ) |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 661 | except StandardError: |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 662 | self.log.exception( "Json Parser is unable to parse the string" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 663 | return response_dict |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 664 | elif ini_match: |
| 665 | self.log.info( "Response is in 'INI' format, converting to '" + |
| 666 | return_format + "' format" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 667 | from configobj import ConfigObj |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 668 | response_file = open( "respnse_file.temp", 'w' ) |
| 669 | response_file.write( response ) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 670 | response_file.close() |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 671 | response_dict = ConfigObj( "respnse_file.temp" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 672 | return response_dict |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 673 | elif xml_match: |
| 674 | self.log.info( "Response is in 'XML' format, converting to '" + |
| 675 | return_format + "' format" ) |
| 676 | try: |
| 677 | response_dict = xmldict.xml_to_dict( "<response> " + |
| 678 | str( response ) + |
| 679 | " </response>" ) |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 680 | except StandardError: |
| 681 | self.log.exception() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 682 | return response_dict |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 683 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 684 | def dict_to_return_format( self, response, return_format, response_dict ): |
| 685 | if return_format == 'table': |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 686 | ''' Will return in table format''' |
| 687 | to_do = "Call the table output formatter" |
| 688 | global response_table |
| 689 | response_table = '\n' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 690 | response_table = response_table + '\t'.join( response_dict ) + "\n" |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 691 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 692 | def get_table( value_to_convert ): |
| 693 | ''' This will parse the dictionary recusrsively and print as |
| 694 | table format''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 695 | table_data = "" |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 696 | if isinstance( value_to_convert, dict ): |
| 697 | table_data = table_data + '\t'.join( value_to_convert ) +\ |
| 698 | "\n" |
| 699 | for temp_val in value_to_convert.values(): |
| 700 | table_data = table_data + get_table( temp_val ) |
| 701 | else: |
| 702 | table_data = table_data + str( value_to_convert ) + "\t" |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 703 | return table_data |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 704 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 705 | for value in response_dict.values(): |
| 706 | response_table = response_table + get_table( value ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 707 | return response_table |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 708 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 709 | elif return_format == 'config': |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 710 | ''' Will return in config format''' |
| 711 | to_do = 'Call dict to config coverter' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 712 | response_string = str( response_dict ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 713 | print response_string |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 714 | response_config = re.sub( ",", "\n\t", response_string ) |
| 715 | response_config = re.sub( "u\'", "\'", response_config ) |
| 716 | response_config = re.sub( "{", "", response_config ) |
| 717 | response_config = re.sub( "}", "\n", response_config ) |
| 718 | response_config = re.sub( ":", " =", response_config ) |
| 719 | return "[response]\n\t " + response_config |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 720 | elif return_format == 'xml': |
| 721 | ''' Will return in xml format''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 722 | response_xml = xmldict.dict_to_xml( response_dict ) |
| 723 | response_xml = re.sub( ">\s*<", ">\n<", response_xml ) |
| 724 | return "\n" + response_xml |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 725 | elif return_format == 'json': |
| 726 | ''' Will return in json format''' |
| 727 | to_do = 'Call dict to xml coverter' |
| 728 | import json |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 729 | response_json = json.dumps( response_dict ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 730 | return response_json |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 731 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 732 | def get_random( self ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 733 | self.random_order = self.random_order + 1 |
| 734 | return self.random_order |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 735 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 736 | def exit( self ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 737 | __builtin__.testthread = None |
Jon Hall | 5b58673 | 2015-06-11 11:39:39 -0700 | [diff] [blame] | 738 | for thread in threading.enumerate(): |
| 739 | if thread.isAlive(): |
| 740 | try: |
| 741 | thread._Thread__stop() |
| 742 | except: |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 743 | # NOTE: We should catch any exceptions while trying to |
| 744 | # close the thread so that we can try to close the other |
| 745 | # threads as well |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 746 | print str( thread.getName() ) +\ |
| 747 | ' could not be terminated' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 748 | sys.exit() |
| 749 | |
Jon Hall | cd3d2a3 | 2015-10-01 11:07:28 -0700 | [diff] [blame] | 750 | def stop( self, email=False ): |
| 751 | """ |
| 752 | Stop the test until Ctrl-D is entered. |
| 753 | Ctrl-C will kill the test |
Jon Hall | 2507978 | 2015-10-13 13:54:39 -0700 | [diff] [blame] | 754 | |
| 755 | Optional arguments: |
| 756 | email can either be a bool, or you can specify the email address |
| 757 | to send the email to |
Jon Hall | cd3d2a3 | 2015-10-01 11:07:28 -0700 | [diff] [blame] | 758 | """ |
| 759 | try: |
| 760 | if email: |
Jon Hall | 2507978 | 2015-10-13 13:54:39 -0700 | [diff] [blame] | 761 | if '@' in email: |
| 762 | main.mail = email |
| 763 | utilities.send_warning_email() |
Jon Hall | cd3d2a3 | 2015-10-01 11:07:28 -0700 | [diff] [blame] | 764 | self.log.error( "Test execution suspended. Press Ctrl-D to " |
| 765 | "resume or Ctrl-C to exit the test" ) |
| 766 | # NOTE: Ctrl-D needs to be entered on a new line |
| 767 | while True: |
| 768 | # TODO: we could give the user an interactive prompt where |
| 769 | # they could call functions |
| 770 | raw_input() |
| 771 | except EOFError: |
| 772 | return |
| 773 | # Pass all other exceptions up to caller |
| 774 | |
| 775 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 776 | def verifyOptions( options ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 777 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 778 | This will verify the command line options and set to default values, |
| 779 | if any option not given in command line. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 780 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 781 | verifyTest( options ) |
| 782 | verifyExample( options ) |
| 783 | verifyTestScript( options ) |
YPZhang | 1c89e76 | 2016-06-29 10:43:58 -0700 | [diff] [blame] | 784 | verifyParams( options ) |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 785 | verifyLogdir( options ) |
| 786 | verifyMail( options ) |
| 787 | verifyTestCases( options ) |
| 788 | verifyOnosCell( options ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 789 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 790 | def verifyTest( options ): |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 791 | try: |
| 792 | if options.testname: |
| 793 | main.TEST = options.testname |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 794 | main.classPath = "tests." + main.TEST + "." + main.TEST |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 795 | main.tests_path = tests_path |
| 796 | elif options.example: |
| 797 | main.TEST = options.example |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 798 | main.tests_path = path + "/examples/" |
| 799 | main.classPath = "examples." + main.TEST + "." + main.TEST |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 800 | except AttributeError: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 801 | print "Test or Example not specified please specify the --test <test name > or --example <example name>" |
Jon Hall | 5b58673 | 2015-06-11 11:39:39 -0700 | [diff] [blame] | 802 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 803 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 804 | def verifyExample( options ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 805 | if options.example: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 806 | main.testDir = path + '/examples/' |
| 807 | main.tests_path = path + "/examples/" |
| 808 | main.classPath = "examples." + main.TEST + "." + main.TEST |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 809 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 810 | def verifyLogdir( options ): |
Jon Hall | 88e498c | 2015-03-06 09:54:35 -0800 | [diff] [blame] | 811 | # Verifying Log directory option |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 812 | if options.logdir: |
| 813 | main.logdir = options.logdir |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 814 | else: |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 815 | main.logdir = main.FALSE |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 816 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 817 | def verifyMail( options ): |
Jon Hall | 2507978 | 2015-10-13 13:54:39 -0700 | [diff] [blame] | 818 | # Mail-To: field |
| 819 | if options.mail: # Test run specific |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 820 | main.mail = options.mail |
Jon Hall | 2507978 | 2015-10-13 13:54:39 -0700 | [diff] [blame] | 821 | elif main.params.get('mail'): # Test suite specific |
| 822 | main.mail = main.params.get( 'mail' ) |
| 823 | else: # TestON specific |
| 824 | main.mail = main.config['config'].get( 'mail_to' ) |
| 825 | # Mail-From: field |
| 826 | main.sender = main.config['config'].get( 'mail_from' ) |
| 827 | # Mail smtp server |
| 828 | main.smtp = main.config['config'].get( 'mail_server' ) |
| 829 | # Mail-From account password |
| 830 | main.senderPwd = main.config['config'].get( 'mail_pass' ) |
| 831 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 832 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 833 | def verifyTestCases( options ): |
Jon Hall | 88e498c | 2015-03-06 09:54:35 -0800 | [diff] [blame] | 834 | # Getting Test cases list |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 835 | if options.testcases: |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 836 | testcases_list = options.testcases |
Jon Hall | 88e498c | 2015-03-06 09:54:35 -0800 | [diff] [blame] | 837 | # sys.exit() |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 838 | testcases_list = re.sub( "(\[|\])", "", options.testcases ) |
| 839 | main.testcases_list = eval( testcases_list + "," ) |
| 840 | else: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 841 | if 'testcases' in main.params.keys(): |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 842 | temp = eval( main.params['testcases'] + "," ) |
| 843 | list1 = [] |
| 844 | if isinstance( temp[0], list ): |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 845 | for test in temp: |
| 846 | for testcase in test: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 847 | if isinstance( testcase, int ): |
| 848 | testcase = [testcase] |
| 849 | list1.extend( testcase ) |
| 850 | else: |
| 851 | temp = list( temp ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 852 | for testcase in temp: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 853 | if isinstance( testcase, int ): |
| 854 | testcase = [testcase] |
| 855 | list1.extend( testcase ) |
| 856 | main.testcases_list = list1 |
| 857 | else: |
| 858 | print "Testcases not specifed in params, please provide in " +\ |
| 859 | "params file or 'testcases' commandline argument" |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 860 | sys.exit() |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 861 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 862 | def verifyOnosCell( options ): |
Hari Krishna | be4b97b | 2015-07-15 12:19:43 -0700 | [diff] [blame] | 863 | # Verifying onoscell option |
Hari Krishna | 03f530e | 2015-07-10 17:28:27 -0700 | [diff] [blame] | 864 | if options.onoscell: |
| 865 | main.onoscell = options.onoscell |
Hari Krishna | be4b97b | 2015-07-15 12:19:43 -0700 | [diff] [blame] | 866 | main.onosIPs = [] |
| 867 | main.mnIP = "" |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 868 | cellCMD = ". ~/.profile; cell " + main.onoscell |
| 869 | output = subprocess.check_output( ["bash", '-c', cellCMD] ) |
Hari Krishna | be4b97b | 2015-07-15 12:19:43 -0700 | [diff] [blame] | 870 | splitOutput = output.splitlines() |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 871 | for i in range( len( splitOutput ) ): |
| 872 | if re.match( "OCN", splitOutput[i] ): |
| 873 | mnNode = splitOutput[i].split( "=" ) |
Hari Krishna | be4b97b | 2015-07-15 12:19:43 -0700 | [diff] [blame] | 874 | main.mnIP = mnNode[1] |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 875 | # cell already sorts OC variables in bash, so no need to |
| 876 | # sort in TestON |
| 877 | if re.match( "OC[1-9]", splitOutput[i] ): |
| 878 | onosNodes = splitOutput[i].split( "=" ) |
Hari Krishna | be4b97b | 2015-07-15 12:19:43 -0700 | [diff] [blame] | 879 | main.onosIPs.append( onosNodes[1] ) |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 880 | else: |
Hari Krishna | 03f530e | 2015-07-10 17:28:27 -0700 | [diff] [blame] | 881 | main.onoscell = main.FALSE |
| 882 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 883 | def verifyTestScript( options ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 884 | ''' |
| 885 | Verifyies test script. |
| 886 | ''' |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 887 | main.openspeak = openspeak.OpenSpeak() |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 888 | directory = main.testDir + "/" + main.TEST |
| 889 | if os.path.exists( directory ): |
| 890 | pass |
| 891 | else: |
| 892 | directory = "" |
| 893 | for root, dirs, files in os.walk( main.testDir, topdown=True): |
| 894 | if not directory: |
| 895 | for name in dirs: |
| 896 | if name == main.TEST: |
| 897 | directory = ( os.path.join( root, name ) ) |
| 898 | index = directory.find( "/tests/" ) + 1 |
| 899 | main.classPath = directory[index:].replace( '/', '.' ) + "." + main.TEST |
| 900 | break |
| 901 | openspeakfile = directory + "/" + main.TEST + ".ospk" |
| 902 | main.testFile = directory + "/" + main.TEST + ".py" |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 903 | if os.path.exists( openspeakfile ): |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 904 | # Openspeak file found, compiling to python |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 905 | main.openspeak.compiler( openspeakfile=openspeakfile, writetofile=1 ) |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 906 | elif os.path.exists( main.testFile ): |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 907 | # No openspeak found, using python file instead |
| 908 | pass |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 909 | else: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 910 | print "\nThere is no \"" + main.TEST + "\" test script.\nPlease provide a " +\ |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 911 | "Python or OpenSpeak test script in the tests folder: " +\ |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 912 | main.testDir + "/" + main.TEST + "/" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 913 | __builtin__.testthread = None |
| 914 | main.exit() |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 915 | try: |
| 916 | testModule = __import__( main.classPath, |
| 917 | globals(), |
| 918 | locals(), |
| 919 | [main.TEST], |
| 920 | -1 ) |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 921 | except ImportError: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 922 | print "There was an import error, it might mean that there is " +\ |
| 923 | "no test named " + main.TEST |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 924 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 925 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 926 | testClass = getattr( testModule, main.TEST ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 927 | main.testObject = testClass() |
| 928 | load_parser() |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 929 | main.params = main.parser.parseParams( main.classPath ) |
| 930 | main.topology = main.parser.parseTopology( main.classPath ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 931 | |
YPZhang | 1c89e76 | 2016-06-29 10:43:58 -0700 | [diff] [blame] | 932 | def verifyParams( options ): |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 933 | try: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 934 | main.params = main.params['PARAMS'] |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 935 | except KeyError: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 936 | print "Error with the params file: Either the file not specified " +\ |
| 937 | "or the format is not correct" |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 938 | main.exit() |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 939 | try: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 940 | main.topology = main.topology['TOPOLOGY'] |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 941 | except KeyError: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 942 | print "Error with the Topology file: Either the file not specified " +\ |
| 943 | "or the format is not correct" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 944 | main.exit() |
YPZhang | 1c89e76 | 2016-06-29 10:43:58 -0700 | [diff] [blame] | 945 | # Overwrite existing params variables if they are specified from command line |
| 946 | if len(options.params) > 0: |
| 947 | # Some params variables are specified from command line |
| 948 | for param in options.params: |
| 949 | if not re.search( ".=.", param ): |
| 950 | print( "Error when parsing params: params should follow key=value format" ) |
| 951 | continue |
| 952 | # Split the param string to netest keys and value |
| 953 | [ keys, value ] = param.split( "=" ) |
| 954 | # Split the nested keys according to its hierarchy |
| 955 | keyList = keys.split( "/" ) |
| 956 | # Get the outermost dictionary |
| 957 | paramDict = main.params |
| 958 | # Get the innermost dictionary |
| 959 | try: |
| 960 | while len( keyList ) > 1: |
| 961 | key = keyList.pop(0) |
| 962 | assert isinstance( paramDict[ key ], dict ) |
| 963 | paramDict = paramDict[ key ] |
| 964 | except KeyError: |
| 965 | print( "Error when parsing params: key \"" + key + "\" not found in main.params" ) |
| 966 | main.exit() |
| 967 | except AssertionError: |
| 968 | print( "Error when parsing params: \"" + key + "\" is already the innermost level in main.params" ) |
| 969 | main.exit() |
| 970 | # Change the value |
| 971 | if not paramDict.has_key( keyList[0] ): |
| 972 | print( "Error when parsing params: key \"" + keyList[0] + "\" not found in main.params" ) |
| 973 | main.exit() |
| 974 | elif isinstance( paramDict[ keyList[0] ], dict ): |
| 975 | print( "Error when parsing params: more levels under key \"" + keyList[0] + "\" in main.params" ) |
| 976 | main.exit() |
| 977 | else: |
| 978 | paramDict[ keyList[0] ] = value |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 979 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 980 | def load_parser(): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 981 | ''' |
| 982 | It facilitates the loading customised parser for topology and params file. |
| 983 | It loads parser mentioned in tab named parser of teston.cfg file. |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 984 | It also loads default xmlparser if no parser have specified in teston.cfg |
| 985 | file. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 986 | |
| 987 | ''' |
| 988 | confighash = main.configDict |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 989 | if 'file' in confighash['config']['parser'] and\ |
| 990 | 'class' in confighash['config']['parser']: |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 991 | path = confighash['config']['parser']['file'] |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 992 | if path is not None or\ |
| 993 | confighash['config']['parser']['class'] is not None: |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 994 | try: |
| 995 | module = re.sub( r".py\s*$", "", path ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 996 | moduleList = module.split("/") |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 997 | newModule = ".".join( moduleList[-2:] ) |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 998 | parsingClass = confighash['config']['parser']['class'] |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 999 | parsingModule = __import__( newModule, |
| 1000 | globals(), |
| 1001 | locals(), |
| 1002 | [parsingClass], |
| 1003 | -1 ) |
| 1004 | parsingClass = getattr( parsingModule, parsingClass ) |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 1005 | main.parser = parsingClass() |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1006 | if hasattr( main.parser, "parseParams" ) and\ |
| 1007 | hasattr( main.parser, "parseTopology" ) and\ |
| 1008 | hasattr( main.parser, "parse" ): |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 1009 | pass |
| 1010 | else: |
| 1011 | print "Invalid parser format" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1012 | main.exit() |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 1013 | except ImportError: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1014 | print "Could not find the file " + path +\ |
| 1015 | " using default parser." |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 1016 | load_defaultParser() |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1017 | elif confighash['config']['parser']['file'] is None or\ |
| 1018 | confighash['config']['parser']['class'] is None: |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 1019 | load_defaultParser() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1020 | else: |
| 1021 | load_defaultParser() |
| 1022 | |
| 1023 | def load_defaultParser(): |
| 1024 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1025 | It will load the default parser which is xml parser to parse the params and |
| 1026 | topology file. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1027 | ''' |
| 1028 | moduleList = main.parserPath.split("/") |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1029 | newModule = ".".join( moduleList[-2:] ) |
| 1030 | try: |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 1031 | parsingClass = main.parsingClass |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1032 | parsingModule = __import__( newModule, |
| 1033 | globals(), |
| 1034 | locals(), |
| 1035 | [parsingClass], |
| 1036 | -1 ) |
| 1037 | parsingClass = getattr( parsingModule, parsingClass ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1038 | main.parser = parsingClass() |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1039 | if hasattr( main.parser, "parseParams" ) and\ |
| 1040 | hasattr( main.parser, "parseTopology" ) and\ |
| 1041 | hasattr( main.parser, "parse" ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1042 | pass |
| 1043 | else: |
| 1044 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1045 | except ImportError: |
| 1046 | print sys.exc_info()[1] |
| 1047 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1048 | def load_logger(): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1049 | ''' |
| 1050 | It facilitates the loading customised parser for topology and params file. |
| 1051 | It loads parser mentioned in tab named parser of teston.cfg file. |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1052 | It also loads default xmlparser if no parser have specified in teston.cfg |
| 1053 | file. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1054 | ''' |
| 1055 | confighash = main.configDict |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1056 | if 'file' in confighash['config']['logger'] and\ |
| 1057 | 'class' in confighash['config']['logger']: |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 1058 | path = confighash['config']['logger']['file'] |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1059 | if path is not None or\ |
| 1060 | confighash['config']['logger']['class'] is not None: |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 1061 | try: |
| 1062 | module = re.sub( r".py\s*$", "", path ) |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1063 | moduleList = module.split( "/" ) |
| 1064 | newModule = ".".join( moduleList[-2:] ) |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 1065 | loggerClass = confighash['config']['logger']['class'] |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1066 | loggerModule = __import__( newModule, |
| 1067 | globals(), |
| 1068 | locals(), |
| 1069 | [loggerClass], |
| 1070 | -1 ) |
| 1071 | loggerClass = getattr( loggerModule, loggerClass ) |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 1072 | main.logger = loggerClass() |
Jon Hall | 4450624 | 2015-07-29 17:40:26 -0700 | [diff] [blame] | 1073 | except ImportError: |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1074 | print "Could not find the file " + path +\ |
| 1075 | " using default logger." |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1076 | load_defaultlogger() |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1077 | elif confighash['config']['parser']['file'] is None or\ |
| 1078 | confighash['config']['parser']['class'] is None: |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 1079 | load_defaultlogger() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1080 | else: |
| 1081 | load_defaultlogger() |
| 1082 | |
| 1083 | def load_defaultlogger(): |
| 1084 | ''' |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1085 | It will load the default parser which is xml parser to parse the params and |
| 1086 | topology file. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1087 | ''' |
| 1088 | moduleList = main.loggerPath.split("/") |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1089 | newModule = ".".join( moduleList[-2:] ) |
| 1090 | try: |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 1091 | loggerClass = main.loggerClass |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1092 | loggerModule = __import__( newModule, |
| 1093 | globals(), |
| 1094 | locals(), |
| 1095 | [loggerClass], |
| 1096 | -1 ) |
| 1097 | loggerClass = getattr( loggerModule, loggerClass ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1098 | main.logger = loggerClass() |
| 1099 | |
| 1100 | except ImportError: |
| 1101 | print sys.exc_info()[1] |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 1102 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1103 | |
Jon Hall | 714eeba | 2015-09-29 17:53:10 -0700 | [diff] [blame] | 1104 | def _echo( self ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1105 | print "THIS IS ECHO" |