Jon Hall | 85794ff | 2015-07-08 14:12:30 -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 | """ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 22 | Description: This test is to determine if a single |
| 23 | instance ONOS 'cluster' can handle a restart |
| 24 | |
| 25 | List of test cases: |
| 26 | CASE1: Compile ONOS and push it to the test machines |
| 27 | CASE2: Assign devices to controllers |
| 28 | CASE21: Assign mastership to controllers |
| 29 | CASE3: Assign intents |
| 30 | CASE4: Ping across added host intents |
| 31 | CASE5: Reading state of ONOS |
| 32 | CASE6: The Failure case. |
| 33 | CASE7: Check state after control plane failure |
| 34 | CASE8: Compare topo |
| 35 | CASE9: Link s3-s28 down |
| 36 | CASE10: Link s3-s28 up |
| 37 | CASE11: Switch down |
| 38 | CASE12: Switch up |
| 39 | CASE13: Clean up |
| 40 | CASE14: start election app on all onos nodes |
| 41 | CASE15: Check that Leadership Election is still functional |
| 42 | CASE16: Install Distributed Primitives app |
| 43 | CASE17: Check for basic functionality with distributed primitives |
| 44 | """ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 45 | class HAsingleInstanceRestart: |
| 46 | |
| 47 | def __init__( self ): |
| 48 | self.default = '' |
| 49 | |
| 50 | def CASE1( self, main ): |
| 51 | """ |
| 52 | CASE1 is to compile ONOS and push it to the test machines |
| 53 | |
| 54 | Startup sequence: |
| 55 | cell <name> |
| 56 | onos-verify-cell |
| 57 | NOTE: temporary - onos-remove-raft-logs |
| 58 | onos-uninstall |
| 59 | start mininet |
| 60 | git pull |
| 61 | mvn clean install |
| 62 | onos-package |
| 63 | onos-install -f |
| 64 | onos-wait-for-start |
| 65 | start cli sessions |
| 66 | start tcpdump |
| 67 | """ |
| 68 | main.log.info( "ONOS Single node cluster restart " + |
| 69 | "HA test - initialization" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 70 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 71 | # set global variables |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 72 | # These are for csv plotting in jenkins |
| 73 | main.HAlabels = [] |
| 74 | main.HAdata = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 75 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 76 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 77 | main.testSetUp = ONOSSetup() |
| 78 | except ImportError: |
| 79 | main.log.error( "ONOSSetup not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 80 | main.cleanAndExit() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 81 | main.testSetUp.envSetupDescription() |
| 82 | try: |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 83 | from tests.HA.dependencies.HA import HA |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 84 | main.HA = HA() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 85 | # load some variables from the params file |
| 86 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 87 | main.apps = main.params[ 'ENV' ][ 'appString' ] |
| 88 | main.numCtrls = int( main.params[ 'num_controllers' ] ) |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 89 | stepResult = main.testSetUp.envSetup( includeCaseDesc=False ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 90 | except Exception as e: |
| 91 | main.testSetUp.envSetupException( e ) |
| 92 | main.testSetUp.evnSetupConclusion( stepResult ) |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 93 | |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 94 | cellApps = str( main.params["ENV"]["appString"] ) |
Jon Hall | 5a5c843 | 2018-11-28 11:39:57 -0800 | [diff] [blame] | 95 | cellName = str( main.params["ENV"]["appString"] ) |
| 96 | applyFuncs = [ main.HA.removeKarafConsoleLogging, main.testSetUp.createApplyCell ] |
| 97 | applyArgs = [ None, [ main.Cluster, True, cellName , cellApps, "", True, main.Cluster.runningNodes[ 0 ].ipAddress ] ] |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 98 | try: |
| 99 | if main.params[ 'topology' ][ 'topoFile' ]: |
| 100 | main.log.info( 'Skipping start of Mininet in this case, make sure you start it elsewhere' ) |
| 101 | else: |
| 102 | applyFuncs.append( main.HA.startingMininet ) |
| 103 | applyArgs.append( None ) |
| 104 | except (KeyError, IndexError): |
| 105 | applyFuncs.append( main.HA.startingMininet ) |
| 106 | applyArgs.append( None ) |
| 107 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 108 | main.Cluster.setRunningNode( int( main.params[ 'num_controllers' ] ) ) |
| 109 | ip = main.Cluster.getIps( allNode=True ) |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 110 | main.testSetUp.ONOSSetUp( main.Cluster, cellName="SingleHA", |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 111 | extraApply=applyFuncs, |
| 112 | applyArgs=applyArgs, |
| 113 | includeCaseDesc=False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 114 | main.HA.initialSetUp() |
Jon Hall | 9d2dcad | 2016-04-08 10:15:20 -0700 | [diff] [blame] | 115 | |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 116 | main.step( 'Set logging levels' ) |
| 117 | logging = True |
| 118 | try: |
| 119 | logs = main.params.get( 'ONOS_Logging', False ) |
| 120 | if logs: |
| 121 | for namespace, level in logs.items(): |
| 122 | for ctrl in main.Cluster.active(): |
| 123 | ctrl.CLI.logSet( level, namespace ) |
| 124 | except AttributeError: |
| 125 | logging = False |
| 126 | utilities.assert_equals( expect=True, actual=logging, |
| 127 | onpass="Set log levels", |
| 128 | onfail="Failed to set log levels" ) |
| 129 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 130 | def CASE2( self, main ): |
| 131 | """ |
| 132 | Assign devices to controllers |
| 133 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 134 | main.HA.assignDevices( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 135 | |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 136 | def CASE102( self, main ): |
| 137 | """ |
| 138 | Set up Spine-Leaf fabric topology in Mininet |
| 139 | """ |
| 140 | main.HA.startTopology( main ) |
| 141 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 142 | def CASE21( self, main ): |
| 143 | """ |
| 144 | Assign mastership to controllers |
| 145 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 146 | main.HA.assignMastership( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 147 | |
| 148 | def CASE3( self, main ): |
| 149 | """ |
| 150 | Assign intents |
| 151 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 152 | main.HA.assignIntents( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 153 | |
| 154 | def CASE4( self, main ): |
| 155 | """ |
| 156 | Ping across added host intents |
| 157 | """ |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 158 | main.HA.pingAcrossHostIntent( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 159 | |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 160 | def CASE104( self, main ): |
| 161 | """ |
| 162 | Ping Hosts |
| 163 | """ |
| 164 | main.case( "Check connectivity" ) |
| 165 | main.step( "Ping between all hosts" ) |
| 166 | pingResult = main.Mininet1.pingall() |
| 167 | utilities.assert_equals( expect=main.TRUE, actual=pingResult, |
| 168 | onpass="All Pings Passed", |
| 169 | onfail="Failed to ping between all hosts" ) |
| 170 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 171 | def CASE5( self, main ): |
| 172 | """ |
| 173 | Reading state of ONOS |
| 174 | """ |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 175 | main.HA.readingState( main ) |
Jon Hall | 8bafdc0 | 2017-09-05 11:36:26 -0700 | [diff] [blame] | 176 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 177 | def CASE6( self, main ): |
| 178 | """ |
| 179 | The Failure case. |
| 180 | """ |
| 181 | import time |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 182 | assert main, "main not defined" |
| 183 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 184 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 185 | main.case( "Restart ONOS node" ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 186 | main.caseExplanation = "Killing ONOS process and restart cli " +\ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 187 | "sessions once onos is up." |
Jon Hall | 96091e6 | 2015-09-21 17:34:17 -0700 | [diff] [blame] | 188 | |
| 189 | main.step( "Checking ONOS Logs for errors" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 190 | for ctrl in main.Cluster.active(): |
| 191 | main.log.debug( "Checking logs for errors on " + ctrl.name + ":" ) |
| 192 | main.log.warn( main.ONOSbench.checkLogs( ctrl.ip_address ) ) |
| 193 | ctrl = main.Cluster.runningNodes[ 0 ] |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 194 | main.step( "Killing ONOS processes" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 195 | killResult = main.ONOSbench.onosKill( ctrl.ipAddress ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 196 | start = time.time() |
| 197 | utilities.assert_equals( expect=main.TRUE, actual=killResult, |
| 198 | onpass="ONOS Killed", |
| 199 | onfail="Error killing ONOS" ) |
| 200 | |
| 201 | main.step( "Checking if ONOS is up yet" ) |
| 202 | count = 0 |
| 203 | while count < 10: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 204 | onos1Isup = main.ONOSbench.isup( ctrl.ipAddress ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 205 | if onos1Isup == main.TRUE: |
| 206 | elapsed = time.time() - start |
| 207 | break |
| 208 | else: |
| 209 | count = count + 1 |
| 210 | utilities.assert_equals( expect=main.TRUE, actual=onos1Isup, |
| 211 | onpass="ONOS is back up", |
| 212 | onfail="ONOS failed to start" ) |
| 213 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 214 | main.step( "Starting ONOS CLI sessions" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 215 | cliResults = ctrl.CLI.startOnosCli( ctrl.ipAddress ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 216 | utilities.assert_equals( expect=main.TRUE, actual=cliResults, |
| 217 | onpass="ONOS cli startup successful", |
| 218 | onfail="ONOS cli startup failed" ) |
| 219 | |
| 220 | if elapsed: |
| 221 | main.log.info( "ESTIMATE: ONOS took %s seconds to restart" % |
| 222 | str( elapsed ) ) |
| 223 | main.restartTime = elapsed |
| 224 | else: |
| 225 | main.restartTime = -1 |
| 226 | time.sleep( 5 ) |
| 227 | # rerun on election apps |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 228 | ctrl.CLI.electionTestRun() |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 229 | |
| 230 | def CASE7( self, main ): |
| 231 | """ |
| 232 | Check state after ONOS failure |
| 233 | """ |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 234 | main.HA.checkStateAfterEvent( main, afterWhich=0, compareSwitch=True, isRestart=True ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 235 | |
| 236 | def CASE8( self, main ): |
| 237 | """ |
| 238 | Compare topo |
| 239 | """ |
| 240 | import json |
| 241 | import time |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 242 | assert main, "main not defined" |
| 243 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 244 | |
| 245 | main.case( "Compare ONOS Topology view to Mininet topology" ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 246 | main.caseExplanation = "Compare topology objects between Mininet" +\ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 247 | " and ONOS" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 248 | topoResult = main.FALSE |
| 249 | elapsed = 0 |
| 250 | count = 0 |
Jon Hall | e9b1fa3 | 2015-12-08 15:32:21 -0800 | [diff] [blame] | 251 | main.step( "Comparing ONOS topology to MN topology" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 252 | startTime = time.time() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 253 | ctrl = main.Cluster.active( 0 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 254 | # Give time for Gossip to work |
Jon Hall | e9b1fa3 | 2015-12-08 15:32:21 -0800 | [diff] [blame] | 255 | while topoResult == main.FALSE and ( elapsed < 60 or count < 3 ): |
Jon Hall | 96091e6 | 2015-09-21 17:34:17 -0700 | [diff] [blame] | 256 | devicesResults = main.TRUE |
| 257 | linksResults = main.TRUE |
| 258 | hostsResults = main.TRUE |
| 259 | hostAttachmentResults = True |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 260 | count += 1 |
| 261 | cliStart = time.time() |
| 262 | devices = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 263 | devices.append( ctrl.CLI.devices() ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 264 | hosts = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 265 | hosts.append( json.loads( ctrl.CLI.hosts() ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 266 | ipResult = main.TRUE |
| 267 | for controller in range( 0, len( hosts ) ): |
| 268 | controllerStr = str( controller + 1 ) |
| 269 | for host in hosts[ controller ]: |
| 270 | if host is None or host.get( 'ipAddresses', [] ) == []: |
| 271 | main.log.error( |
| 272 | "DEBUG:Error with host ips on controller" + |
| 273 | controllerStr + ": " + str( host ) ) |
| 274 | ipResult = main.FALSE |
| 275 | ports = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 276 | ports.append( ctrl.CLI.ports() ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 277 | links = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 278 | links.append( ctrl.CLI.links() ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 279 | clusters = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 280 | clusters.append( ctrl.CLI.clusters() ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 281 | |
| 282 | elapsed = time.time() - startTime |
| 283 | cliTime = time.time() - cliStart |
| 284 | print "CLI time: " + str( cliTime ) |
| 285 | |
| 286 | mnSwitches = main.Mininet1.getSwitches() |
| 287 | mnLinks = main.Mininet1.getLinks() |
| 288 | mnHosts = main.Mininet1.getHosts() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 289 | for controller in main.Cluster.getRunningPos(): |
| 290 | controllerStr = str( controller ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 291 | if devices[ controller ] and ports[ controller ] and\ |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 292 | "Error" not in devices[ controller ] and\ |
| 293 | "Error" not in ports[ controller ]: |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 294 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 295 | try: |
| 296 | currentDevicesResult = main.Mininet1.compareSwitches( |
| 297 | mnSwitches, |
| 298 | json.loads( devices[ controller ] ), |
| 299 | json.loads( ports[ controller ] ) ) |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 300 | except ( TypeError, ValueError ): |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 301 | main.log.exception( "Object not as expected; devices={!r}\nports={!r}".format( |
| 302 | devices[ controller ], ports[ controller ] ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 303 | else: |
| 304 | currentDevicesResult = main.FALSE |
| 305 | utilities.assert_equals( expect=main.TRUE, |
| 306 | actual=currentDevicesResult, |
| 307 | onpass="ONOS" + controllerStr + |
| 308 | " Switches view is correct", |
| 309 | onfail="ONOS" + controllerStr + |
| 310 | " Switches view is incorrect" ) |
| 311 | |
| 312 | if links[ controller ] and "Error" not in links[ controller ]: |
| 313 | currentLinksResult = main.Mininet1.compareLinks( |
| 314 | mnSwitches, mnLinks, |
| 315 | json.loads( links[ controller ] ) ) |
| 316 | else: |
| 317 | currentLinksResult = main.FALSE |
| 318 | utilities.assert_equals( expect=main.TRUE, |
| 319 | actual=currentLinksResult, |
| 320 | onpass="ONOS" + controllerStr + |
| 321 | " links view is correct", |
| 322 | onfail="ONOS" + controllerStr + |
| 323 | " links view is incorrect" ) |
| 324 | |
| 325 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 326 | currentHostsResult = main.Mininet1.compareHosts( |
| 327 | mnHosts, |
| 328 | hosts[ controller ] ) |
| 329 | else: |
| 330 | currentHostsResult = main.FALSE |
| 331 | utilities.assert_equals( expect=main.TRUE, |
| 332 | actual=currentHostsResult, |
| 333 | onpass="ONOS" + controllerStr + |
| 334 | " hosts exist in Mininet", |
| 335 | onfail="ONOS" + controllerStr + |
| 336 | " hosts don't match Mininet" ) |
| 337 | # CHECKING HOST ATTACHMENT POINTS |
| 338 | hostAttachment = True |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 339 | if main.topoMappings: |
| 340 | zeroHosts = False |
| 341 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 342 | if hosts[ controller ] == []: |
| 343 | main.log.warn( "There are no hosts discovered" ) |
| 344 | zeroHosts = True |
| 345 | else: |
| 346 | for host in hosts[ controller ]: |
| 347 | mac = None |
| 348 | location = None |
| 349 | device = None |
| 350 | port = None |
| 351 | try: |
| 352 | mac = host.get( 'mac' ) |
| 353 | assert mac, "mac field could not be found for this host object" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 354 | |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 355 | location = host.get( 'locations' )[ 0 ] |
| 356 | assert location, "location field could not be found for this host object" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 357 | |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 358 | # Trim the protocol identifier off deviceId |
| 359 | device = str( location.get( 'elementId' ) ).split( ':' )[ 1 ] |
| 360 | assert device, "elementId field could not be found for this host location object" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 361 | |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 362 | port = location.get( 'port' ) |
| 363 | assert port, "port field could not be found for this host location object" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 364 | |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 365 | # Now check if this matches where they should be |
| 366 | if mac and device and port: |
| 367 | if str( port ) != "1": |
| 368 | main.log.error( "The attachment port is incorrect for " + |
| 369 | "host " + str( mac ) + |
| 370 | ". Expected: 1 Actual: " + str( port ) ) |
| 371 | hostAttachment = False |
| 372 | if device != main.topoMappings[ str( mac ) ]: |
| 373 | main.log.error( "The attachment device is incorrect for " + |
| 374 | "host " + str( mac ) + |
| 375 | ". Expected: " + main.topoMappings[ str( mac ) ] + |
| 376 | " Actual: " + device ) |
| 377 | hostAttachment = False |
| 378 | else: |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 379 | hostAttachment = False |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 380 | except AssertionError: |
| 381 | main.log.exception( "Json object not as expected" ) |
| 382 | main.log.error( repr( host ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 383 | hostAttachment = False |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 384 | else: |
| 385 | main.log.error( "No hosts json output or \"Error\"" + |
| 386 | " in output. hosts = " + |
| 387 | repr( hosts[ controller ] ) ) |
| 388 | if zeroHosts is False: |
| 389 | hostAttachment = True |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 390 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 391 | devicesResults = devicesResults and currentDevicesResult |
| 392 | linksResults = linksResults and currentLinksResult |
| 393 | hostsResults = hostsResults and currentHostsResult |
| 394 | hostAttachmentResults = hostAttachmentResults and\ |
| 395 | hostAttachment |
| 396 | |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 397 | # "consistent" results don't make sense for single instance |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 398 | # there should always only be one cluster |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 399 | clusterResults = main.FALSE |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 400 | try: |
| 401 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
| 402 | except ( ValueError, TypeError ): |
| 403 | main.log.exception( "Error parsing clusters[0]: " + |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 404 | repr( clusters[ 0 ] ) ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 405 | numClusters = "ERROR" |
| 406 | clusterResults = main.FALSE |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 407 | if numClusters == 1: |
| 408 | clusterResults = main.TRUE |
| 409 | utilities.assert_equals( |
| 410 | expect=1, |
| 411 | actual=numClusters, |
| 412 | onpass="ONOS shows 1 SCC", |
| 413 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
| 414 | |
| 415 | topoResult = ( devicesResults and linksResults |
| 416 | and hostsResults and ipResult and clusterResults and |
| 417 | hostAttachmentResults ) |
| 418 | |
| 419 | topoResult = topoResult and int( count <= 2 ) |
| 420 | note = "note it takes about " + str( int( cliTime ) ) + \ |
| 421 | " seconds for the test to make all the cli calls to fetch " +\ |
| 422 | "the topology from each ONOS instance" |
| 423 | main.log.info( |
| 424 | "Very crass estimate for topology discovery/convergence( " + |
| 425 | str( note ) + " ): " + str( elapsed ) + " seconds, " + |
| 426 | str( count ) + " tries" ) |
| 427 | utilities.assert_equals( expect=main.TRUE, actual=topoResult, |
| 428 | onpass="Topology Check Test successful", |
| 429 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 430 | main.step( "Checking ONOS nodes" ) |
Devin Lim | 3ebd5e7 | 2017-11-14 10:38:00 -0800 | [diff] [blame] | 431 | nodeResults = utilities.retry( main.Cluster.nodesCheck, |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 432 | False, |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 433 | attempts=5 ) |
| 434 | |
| 435 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 436 | onpass="Nodes check successful", |
| 437 | onfail="Nodes check NOT successful" ) |
| 438 | if not nodeResults: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 439 | for ctrl in main.Cluster.active(): |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 440 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 441 | ctrl.name, |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 442 | ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 443 | |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 444 | if not topoResult: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 445 | main.cleanAndExit() |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 446 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 447 | def CASE9( self, main ): |
| 448 | """ |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 449 | Link down |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 450 | """ |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 451 | src = main.params['kill']['linkSrc'] |
| 452 | dst = main.params['kill']['linkDst'] |
| 453 | main.HA.linkDown( main, src, dst ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 454 | |
| 455 | def CASE10( self, main ): |
| 456 | """ |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 457 | Link up |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 458 | """ |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 459 | src = main.params['kill']['linkSrc'] |
| 460 | dst = main.params['kill']['linkDst'] |
| 461 | main.HA.linkUp( main, src, dst ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 462 | |
| 463 | def CASE11( self, main ): |
| 464 | """ |
| 465 | Switch Down |
| 466 | """ |
| 467 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 468 | main.HA.switchDown( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 469 | |
| 470 | def CASE12( self, main ): |
| 471 | """ |
| 472 | Switch Up |
| 473 | """ |
| 474 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 475 | main.HA.switchUp( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 476 | |
| 477 | def CASE13( self, main ): |
| 478 | """ |
| 479 | Clean up |
| 480 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 481 | main.HAlabels.append( "Restart" ) |
| 482 | main.HAdata.append( str( main.restartTime ) ) |
| 483 | main.HA.cleanUp( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 484 | |
| 485 | def CASE14( self, main ): |
| 486 | """ |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 487 | Start election app on all onos nodes |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 488 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 489 | main.HA.startElectionApp( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 490 | |
| 491 | def CASE15( self, main ): |
| 492 | """ |
| 493 | Check that Leadership Election is still functional |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 494 | 15.1 Run election on each node |
| 495 | 15.2 Check that each node has the same leaders and candidates |
| 496 | 15.3 Find current leader and withdraw |
| 497 | 15.4 Check that a new node was elected leader |
| 498 | 15.5 Check that that new leader was the candidate of old leader |
| 499 | 15.6 Run for election on old leader |
| 500 | 15.7 Check that oldLeader is a candidate, and leader if only 1 node |
| 501 | 15.8 Make sure that the old leader was added to the candidate list |
| 502 | |
| 503 | old and new variable prefixes refer to data from before vs after |
| 504 | withdrawl and later before withdrawl vs after re-election |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 505 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 506 | main.HA.isElectionFunctional( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 507 | |
| 508 | def CASE16( self, main ): |
| 509 | """ |
| 510 | Install Distributed Primitives app |
| 511 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 512 | main.HA.installDistributedPrimitiveApp( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 513 | |
| 514 | def CASE17( self, main ): |
| 515 | """ |
| 516 | Check for basic functionality with distributed primitives |
| 517 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 518 | main.HA.checkDistPrimitivesFunc( main ) |