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