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