kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2015 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 21 | """ |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 22 | Wrapper function for FuncTopo |
| 23 | Includes onosclidriver and mininetclidriver functions |
| 24 | """ |
| 25 | import time |
| 26 | import json |
| 27 | import re |
| 28 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 29 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 30 | def __init__( self ): |
| 31 | self.default = '' |
| 32 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 33 | |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 34 | def getTimestampFromString( main, targetString ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 35 | # Get time string from the target string |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 36 | try: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 37 | assert isinstance( targetString, str ) |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 38 | timeString = targetString.split( ' | ' ) |
| 39 | timeString = timeString[ 0 ] |
| 40 | from datetime import datetime |
| 41 | # convert time string to timestamp |
| 42 | t = datetime.strptime( timeString, "%Y-%m-%d %H:%M:%S,%f" ) |
| 43 | import time |
| 44 | timestamp = time.mktime( t.timetuple() ) |
| 45 | timestamp += int( t.microsecond / 1000 ) / 1000.0 |
| 46 | return timestamp |
| 47 | except AssertionError: |
| 48 | main.log.error( "Got nothing firom log" ) |
| 49 | return -1 |
| 50 | except IndexError: |
| 51 | main.log.error( "Time string index error" ) |
| 52 | return -1 |
| 53 | except ValueError: |
| 54 | main.log.error( "Got wrong string from log" ) |
| 55 | return -1 |
| 56 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 57 | |
Chiyu Cheng | 899621b | 2016-11-14 11:14:48 -0800 | [diff] [blame] | 58 | def getRoleRequestTimeFromTshark( main ): |
| 59 | try: |
| 60 | main.log.info( "Get role request time" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 61 | with open( main.tsharkResultPath, "r" ) as resultFile: |
Chiyu Cheng | 899621b | 2016-11-14 11:14:48 -0800 | [diff] [blame] | 62 | resultText = resultFile.readlines() |
| 63 | # select the last role request string |
| 64 | roleRequestString = resultText[ len( resultText ) - 1 ] |
| 65 | main.log.info( roleRequestString ) |
| 66 | # get timestamp from role request string |
| 67 | roleRequestTime = roleRequestString.split( " " ) |
| 68 | resultFile.close() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 69 | return float( roleRequestTime[ 1 ] ) |
Chiyu Cheng | 899621b | 2016-11-14 11:14:48 -0800 | [diff] [blame] | 70 | except IndexError: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 71 | main.log.error( "Got wrong role request string from Tshark file" ) |
Chiyu Cheng | 899621b | 2016-11-14 11:14:48 -0800 | [diff] [blame] | 72 | return -1 |
Devin Lim | a7cfdbd | 2017-09-29 15:02:22 -0700 | [diff] [blame] | 73 | except ValueError: |
| 74 | main.log.error( "Got wrong string from log" ) |
| 75 | return -1 |
Chiyu Cheng | 899621b | 2016-11-14 11:14:48 -0800 | [diff] [blame] | 76 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 77 | |
| 78 | def compareTimeDiffWithRoleRequest( main, term, Mode, index=0 ): |
| 79 | """ |
Chiyu Cheng | 899621b | 2016-11-14 11:14:48 -0800 | [diff] [blame] | 80 | Description: |
| 81 | Compare the time difference between the time of target term and the time of role request |
| 82 | Inclides onosclidriver functions |
| 83 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 84 | """ |
Chiyu Cheng | 899621b | 2016-11-14 11:14:48 -0800 | [diff] [blame] | 85 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 86 | termInfo = main.Cluster.active( index ).CLI.logSearch( mode=Mode, searchTerm=term ) |
Chiyu Cheng | 899621b | 2016-11-14 11:14:48 -0800 | [diff] [blame] | 87 | termTime = getTimestampFromString( main, termInfo[ 0 ] ) |
| 88 | roleRequestTime = getRoleRequestTimeFromTshark( main ) |
| 89 | if termTime == -1 or roleRequestTime == -1: |
| 90 | main.writeData = -1 |
| 91 | main.log.error( "Can't compare the difference with role request time" ) |
| 92 | return -1 |
Jon Hall | 465d56c | 2016-12-05 10:03:02 -0800 | [diff] [blame] | 93 | # Only concern about the absolute value of difference. |
Chiyu Cheng | 899621b | 2016-11-14 11:14:48 -0800 | [diff] [blame] | 94 | return abs( roleRequestTime - termTime ) |
| 95 | except IndexError: |
| 96 | main.log.error( "Catch the wrong information of search term " ) |
| 97 | main.writeData = -1 |
| 98 | return -1 |
Devin Lim | a7cfdbd | 2017-09-29 15:02:22 -0700 | [diff] [blame] | 99 | except ValueError: |
| 100 | main.log.error( "Got wrong string from log" ) |
| 101 | return -1 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 102 | |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 103 | def getInfoFromLog( main, term1, mode1, term2, mode2, index=0, funcMode='TD' ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 104 | """ |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 105 | Description: |
| 106 | Get needed informations of the search term from karaf.log |
| 107 | Includes onosclidriver functions |
| 108 | Function mode: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 109 | TD ( time difference ): |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 110 | Get time difference between start and end |
| 111 | Term1: startTerm |
| 112 | Term2: endTerm |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 113 | DR ( disconnect rate ): |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 114 | Get switch disconnect rate |
| 115 | Term1: disconnectTerm |
| 116 | Term2: connectTerm |
| 117 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 118 | """ |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 119 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 120 | termInfo1 = main.Cluster.active( index ).CLI.logSearch( mode=mode1, searchTerm=term1 ) |
| 121 | termInfo2 = main.Cluster.active( index ).CLI.logSearch( mode=mode2, searchTerm=term2 ) |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 122 | if funcMode == 'TD': |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 123 | startTime = getTimestampFromString( main, termInfo1[ 0 ] ) |
| 124 | endTime = getTimestampFromString( main, termInfo2[ 0 ] ) |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 125 | if startTime == -1 or endTime == -1: |
| 126 | main.log.error( "Wrong Time!" ) |
| 127 | main.writeData = -1 |
| 128 | return -1 |
| 129 | return endTime - startTime |
| 130 | if funcMode == 'DR': |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 131 | # In this mode, termInfo1 means the total number of switch disconnection and |
| 132 | # termInfo2 means the total number of new switch connection |
| 133 | # termInfo2 - termInfo1 means the actual real number of switch connection. |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 134 | disconnection = int( termInfo1 ) * 1.0 |
| 135 | expectConnection = int( main.currScale ) ** 2 |
| 136 | realConnection = int( termInfo2 ) - int( termInfo1 ) |
| 137 | if expectConnection != realConnection: |
| 138 | main.log.error( "The number of real switch connection doesn't match the number of expected connection" ) |
| 139 | main.writeData = -1 |
| 140 | return -1 |
| 141 | rate = disconnection / expectConnection |
| 142 | return rate |
| 143 | except IndexError: |
| 144 | main.log.error( "Catch the wrong information of search term" ) |
| 145 | main.writeData = -1 |
| 146 | return -1 |
Devin Lim | a7cfdbd | 2017-09-29 15:02:22 -0700 | [diff] [blame] | 147 | except ValueError: |
| 148 | main.log.error( "Got wrong string from log" ) |
| 149 | return -1 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 150 | |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 151 | def testTopology( main, topoFile='', args='', mnCmd='', timeout=300, clean=True ): |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 152 | """ |
| 153 | Description: |
| 154 | This function combines different wrapper functions in this module |
| 155 | to simulate a topology test |
| 156 | Test Steps: |
| 157 | - Load topology |
| 158 | - Discover topology |
| 159 | - Compare topology |
| 160 | - pingall |
| 161 | - Bring links down |
| 162 | - Compare topology |
| 163 | - pingall |
| 164 | - Bring links up |
| 165 | - Compare topology |
| 166 | - pingall |
| 167 | Options: |
| 168 | clean: Does sudo mn -c to clean mininet residue |
| 169 | Please read mininetclidriver.py >> startNet( .. ) function for details |
| 170 | Returns: |
| 171 | Returns main.TRUE if the test is successful, main.FALSE otherwise |
| 172 | """ |
| 173 | testTopoResult = main.TRUE |
| 174 | compareTopoResult = main.TRUE |
| 175 | topoObjectResult = main.TRUE |
| 176 | stopResult = main.TRUE |
| 177 | |
| 178 | if clean: |
| 179 | # Cleans minient |
| 180 | stopResult = stopMininet( main ) |
| 181 | |
| 182 | # Restart ONOS to clear hosts test new mininet topology |
| 183 | reinstallOnosResult = reinstallOnos( main ) |
| 184 | |
| 185 | # Starts topology |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 186 | startResult = startNewTopology( main, topoFile, args, mnCmd, timeout=timeout ) |
GlennRC | 1c5df3c | 2015-08-27 16:12:09 -0700 | [diff] [blame] | 187 | # onos needs time to see the links |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 188 | time.sleep( 15 ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 189 | |
| 190 | # Gets list of switches in mininet |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 191 | # assignSwitch( main ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 192 | |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 193 | testTopoResult = startResult and topoObjectResult |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 194 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 195 | return testTopoResult |
| 196 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 197 | |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 198 | def startNewTopology( main, topoFile='', args='', mnCmd='', timeout=900 ): |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 199 | """ |
| 200 | Description: |
| 201 | This wrapper function starts new topology |
| 202 | Options: |
| 203 | Please read mininetclidriver.py >> startNet( .. ) function for details |
| 204 | Return: |
| 205 | Returns main.TRUE if topology is successfully created by mininet, |
| 206 | main.FALSE otherwise |
| 207 | NOTE: |
| 208 | Assumes Mininet1 is the name of the handler |
| 209 | """ |
| 210 | assert main, "There is no main variable" |
| 211 | assert main.Mininet1, "Mininet 1 is not created" |
| 212 | result = main.TRUE |
| 213 | |
| 214 | main.log.info( main.topoName + ": Starting new Mininet topology" ) |
| 215 | |
| 216 | # log which method is being used |
| 217 | if topoFile: |
| 218 | main.log.info( main.topoName + ": Starting topology with " + |
| 219 | topoFile + "topology file" ) |
| 220 | elif not topoFile and not mnCmd: |
| 221 | main.log.info( main.topoName + ": Starting topology using" + |
| 222 | " the topo file" ) |
| 223 | elif topoFile and mnCmd: |
| 224 | main.log.error( main.topoName + ": You can only use one " + |
| 225 | "method to start a topology" ) |
| 226 | elif mnCmd: |
| 227 | main.log.info( main.topoName + ": Starting topology with '" + |
| 228 | mnCmd + "' Mininet command" ) |
| 229 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 230 | result = main.Mininet1.startNet( topoFile=topoFile, |
| 231 | args=args, |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 232 | mnCmd=mnCmd, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 233 | timeout=timeout ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 234 | |
| 235 | return result |
| 236 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 237 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 238 | def stopMininet( main ): |
| 239 | """ |
| 240 | Stops current topology and execute mn -c basically triggers |
| 241 | stopNet in mininetclidrivers |
| 242 | |
| 243 | NOTE: Mininet should be running when issuing this command other wise |
| 244 | the this function will cause the test to stop |
| 245 | """ |
| 246 | stopResult = main.TRUE |
| 247 | stopResult = main.Mininet1.stopNet() |
| 248 | time.sleep( 30 ) |
| 249 | if not stopResult: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 250 | main.log.info( main.topoName + ": Did not stop Mininet topology" ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 251 | return stopResult |
| 252 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 253 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 254 | def compareTopo( main ): |
| 255 | """ |
| 256 | Compare topology( devices, links, ports, hosts ) between ONOS and |
| 257 | mininet using sts |
| 258 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 259 | try: |
| 260 | from tests.dependencies.topology import Topology |
| 261 | except ImportError: |
| 262 | main.log.error( "Topology not found exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 263 | main.cleanAndExit() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 264 | try: |
| 265 | main.topoRelated |
| 266 | except ( NameError, AttributeError ): |
| 267 | main.topoRelated = Topology() |
| 268 | return main.topoRelated.compareTopos( main.Mininet1 ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 269 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 270 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 271 | def assignSwitch( main ): |
| 272 | """ |
| 273 | Returns switch list using getSwitch in Mininet driver |
| 274 | """ |
| 275 | switchList = [] |
| 276 | assignResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 277 | switchList = main.Mininet1.getSwitch() |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 278 | assignResult = main.Mininet1.assignSwController( sw=switchList, |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 279 | ip=main.Cluster.active( 0 ).ipAddress, |
GlennRC | 632e289 | 2015-10-19 18:58:41 -0700 | [diff] [blame] | 280 | port=6633 ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 281 | |
| 282 | for sw in switchList: |
| 283 | response = main.Mininet1.getSwController( sw ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 284 | if re.search( "tcp:" + main.Cluster.active( 0 ).ipAddress, response ): |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 285 | assignResult = assignResult and main.TRUE |
| 286 | else: |
| 287 | assignResult = main.FALSE |
| 288 | |
| 289 | return switchList |
| 290 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 291 | |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 292 | def connectivity( main, timeout=900, shortCircuit=True, acceptableFailed=20 ): |
| 293 | """ |
| 294 | Use fwd app and pingall to discover all the hosts |
| 295 | """ |
| 296 | activateResult = main.TRUE |
| 297 | appCheck = main.TRUE |
| 298 | getDataResult = main.TRUE |
| 299 | main.log.info( main.topoName + ": Activating reactive forwarding app " ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 300 | activateResult = main.Cluster.active( 0 ).activateApp( "org.onosproject.fwd" ) |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 301 | |
| 302 | if main.hostsData: |
| 303 | main.hostsData = {} |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 304 | for ctrl in main.Cluster.active(): |
| 305 | appCheck = appCheck and ctrl.CLI.appToIDCheck() |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 306 | if appCheck != main.TRUE: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 307 | main.log.warn( ctrl.CLI.apps() ) |
| 308 | main.log.warn( ctrl.CLI.appIDs() ) |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 309 | |
| 310 | time.sleep( main.fwdSleep ) |
| 311 | |
| 312 | # Discover hosts using pingall |
| 313 | pingResult = main.Mininet1.pingall( timeout=timeout, |
| 314 | shortCircuit=shortCircuit, |
| 315 | acceptableFailed=acceptableFailed ) |
| 316 | |
| 317 | main.log.info( main.topoName + ": Deactivate reactive forwarding app " ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 318 | activateResult = main.Cluster.active( 0 ).deactivateApp( "org.onosproject.fwd" ) |
| 319 | for ctrl in main.Cluster.active(): |
| 320 | appCheck = appCheck and ctrl.CLI.appToIDCheck() |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 321 | if appCheck != main.TRUE: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 322 | main.log.warn( ctrl.CLI.apps() ) |
| 323 | main.log.warn( ctrl.CLI.appIDs() ) |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 324 | |
| 325 | return pingResult |
| 326 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 327 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 328 | def getHostsData( main ): |
| 329 | """ |
| 330 | Use fwd app and pingall to discover all the hosts |
| 331 | """ |
| 332 | activateResult = main.TRUE |
| 333 | appCheck = main.TRUE |
| 334 | getDataResult = main.TRUE |
| 335 | main.log.info( main.topoName + ": Activating reactive forwarding app " ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 336 | activateResult = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.fwd" ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 337 | |
| 338 | if main.hostsData: |
| 339 | main.hostsData = {} |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 340 | for ctrl in main.Cluster.active(): |
| 341 | appCheck = appCheck and ctrl.CLI.appToIDCheck() |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 342 | if appCheck != main.TRUE: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 343 | main.log.warn( ctrl.CLI.apps() ) |
| 344 | main.log.warn( ctrl.CLI.appIDs() ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 345 | |
| 346 | time.sleep( main.fwdSleep ) |
| 347 | # Discover hosts using pingall |
| 348 | pingResult = main.Mininet1.pingall( timeout=900 ) |
| 349 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 350 | hostsJson = json.loads( main.Cluster.active( 0 ).CLI.hosts() ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 351 | hosts = main.Mininet1.getHosts().keys() |
| 352 | |
| 353 | for host in hosts: |
| 354 | main.hostsData[ host ] = {} |
| 355 | main.hostsData[ host ][ 'mac' ] = \ |
| 356 | main.Mininet1.getMacAddress( host ).upper() |
| 357 | for hostj in hostsJson: |
| 358 | if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]: |
| 359 | main.hostsData[ host ][ 'id' ] = hostj[ 'id' ] |
| 360 | main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ] |
| 361 | main.hostsData[ host ][ 'location' ] = \ |
Jeremy Ronquillo | 0e538bc | 2017-06-13 15:16:09 -0700 | [diff] [blame] | 362 | hostj[ 'locations' ][ 0 ][ 'elementId' ] + '/' + \ |
| 363 | hostj[ 'locations' ][ 0 ][ 'port' ] |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 364 | main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ] |
| 365 | |
| 366 | if activateResult and main.hostsData: |
| 367 | main.log.info( main.topoName + ": Successfully used fwd app" + |
| 368 | " to discover hosts " ) |
| 369 | getDataResult = main.TRUE |
| 370 | else: |
| 371 | main.log.info( main.topoName + ": Failed to use fwd app" + |
| 372 | " to discover hosts " ) |
| 373 | getDataResult = main.FALSE |
| 374 | |
| 375 | main.log.info( main.topoName + ": Deactivate reactive forwarding app " ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 376 | activateResult = main.Cluster.active( 0 ).CLI.deactivateApp( "org.onosproject.fwd" ) |
| 377 | for ctrl in main.Cluster.active(): |
| 378 | appCheck = appCheck and ctrl.CLI.appToIDCheck() |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 379 | if appCheck != main.TRUE: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 380 | main.log.warn( ctrl.CLI.apps() ) |
| 381 | main.log.warn( ctrl.CLI.appIDs() ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 382 | |
| 383 | # This data can be use later for intents |
| 384 | print main.hostsData |
| 385 | |
| 386 | return getDataResult |
| 387 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 388 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 389 | def reinstallOnos( main ): |
| 390 | """ |
| 391 | Description: |
| 392 | Stop and start ONOS that clears hosts,devices etc. in order to test |
| 393 | new mininet topology |
| 394 | Return: |
| 395 | Retruns main.TRUE for a successful restart, main.FALSE otherwise. |
| 396 | """ |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 397 | stopResult = [] |
| 398 | startResult = [] |
| 399 | onosIsUpResult = [] |
| 400 | restartResult = main.TRUE |
| 401 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 402 | uninstallResult = main.testSetUp.uninstallOnos( main.Cluster, False ) |
| 403 | if uninstallResult != main.TRUE: |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 404 | restartResult = main.FALSE |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 405 | installResult = main.testSetUp.installOnos( main.Cluster, False ) |
| 406 | if installResult != main.TRUE: |
You Wang | f5de25b | 2017-01-06 15:13:01 -0800 | [diff] [blame] | 407 | restartResult = main.FALSE |
| 408 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 409 | secureSshResult = main.testSetUp.setupSsh( main.Cluster ) |
| 410 | if secureSshResult != main.TRUE: |
| 411 | restartResult = main.FALSE |
| 412 | |
| 413 | for ctrl in main.Cluster.runningNodes: |
| 414 | onosIsUpResult.append( main.ONOSbench.isup( ctrl.ipAddress ) ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 415 | |
| 416 | if all( result == main.TRUE for result in onosIsUpResult ): |
| 417 | main.log.report( "ONOS instance is up and ready" ) |
| 418 | else: |
| 419 | main.log.report( "ONOS instance may not be up, stop and " + |
| 420 | "start ONOS again " ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 421 | for ctrl in main.Cluster.runningNodes: |
| 422 | stopResult.append( main.ONOSbench.onosStop( ctrl.ipAddress ) ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 423 | |
| 424 | if all( result == main.TRUE for result in stopResult ): |
| 425 | main.log.info( main.topoName + ": Successfully stop ONOS cluster" ) |
| 426 | else: |
| 427 | main.log.error( main.topoName + ": Failed to stop ONOS cluster" ) |
| 428 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 429 | for ctrl in main.Cluster.runningNodes: |
| 430 | startResult.append( main.ONOSbench.onosStart( ctrl.ipAddress ) ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 431 | |
| 432 | if all( result == main.TRUE for result in startResult ): |
| 433 | main.log.info( main.topoName + ": Successfully start ONOS cluster" ) |
| 434 | else: |
| 435 | main.log.error( main.topoName + ": Failed to start ONOS cluster" ) |
| 436 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 437 | main.log.info( main.topoName + ": Starting ONOS CLI" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 438 | cliResult = main.testSetUp.startOnosClis( main.Cluster ) |
| 439 | if cliResult != main.TRUE: |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 440 | restartResult = main.FALSE |
| 441 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 442 | return restartResult |
Devin Lim | 4a87b2a | 2017-10-11 18:23:12 -0700 | [diff] [blame] | 443 | |
| 444 | def checkingONOSStablility( main ): |
| 445 | compareRetry = 0 |
| 446 | while compareRetry < 3 and main.postResult: |
| 447 | for controller in main.Cluster.active(): |
| 448 | if controller.CLI.summary() is None: |
| 449 | main.info.error( "Something happened to ONOS. Skip the rest of the steps" ) |
| 450 | main.postResult = False |
| 451 | break |
| 452 | time.sleep( 5 ) |
| 453 | compareRetry += 1 |
| 454 | time.sleep( 10 ) |