Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 2 | Copyright 2015 Open Networking Foundation (ONF) |
| 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 |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
| 21 | |
| 22 | """ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 23 | Description: This test is to determine if a single |
| 24 | instance ONOS 'cluster' can handle a restart |
| 25 | |
| 26 | List of test cases: |
| 27 | CASE1: Compile ONOS and push it to the test machines |
| 28 | CASE2: Assign devices to controllers |
| 29 | CASE21: Assign mastership to controllers |
| 30 | CASE3: Assign intents |
| 31 | CASE4: Ping across added host intents |
| 32 | CASE5: Reading state of ONOS |
| 33 | CASE6: The Failure case. |
| 34 | CASE7: Check state after control plane failure |
| 35 | CASE8: Compare topo |
| 36 | CASE9: Link s3-s28 down |
| 37 | CASE10: Link s3-s28 up |
| 38 | CASE11: Switch down |
| 39 | CASE12: Switch up |
| 40 | CASE13: Clean up |
| 41 | CASE14: start election app on all onos nodes |
| 42 | CASE15: Check that Leadership Election is still functional |
| 43 | CASE16: Install Distributed Primitives app |
| 44 | CASE17: Check for basic functionality with distributed primitives |
| 45 | """ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 46 | class HAsingleInstanceRestart: |
| 47 | |
| 48 | def __init__( self ): |
| 49 | self.default = '' |
| 50 | |
| 51 | def CASE1( self, main ): |
| 52 | """ |
| 53 | CASE1 is to compile ONOS and push it to the test machines |
| 54 | |
| 55 | Startup sequence: |
| 56 | cell <name> |
| 57 | onos-verify-cell |
| 58 | NOTE: temporary - onos-remove-raft-logs |
| 59 | onos-uninstall |
| 60 | start mininet |
| 61 | git pull |
| 62 | mvn clean install |
| 63 | onos-package |
| 64 | onos-install -f |
| 65 | onos-wait-for-start |
| 66 | start cli sessions |
| 67 | start tcpdump |
| 68 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 69 | import imp |
Jon Hall | f3d16e7 | 2015-12-16 17:45:08 -0800 | [diff] [blame] | 70 | import time |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 71 | import json |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 72 | main.log.info( "ONOS Single node cluster restart " + |
| 73 | "HA test - initialization" ) |
| 74 | main.case( "Setting up test environment" ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 75 | main.caseExplanation = "Setup the test environment including " +\ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 76 | "installing ONOS, starting Mininet and ONOS" +\ |
| 77 | "cli sessions." |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 78 | |
| 79 | # load some variables from the params file |
| 80 | PULLCODE = False |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 81 | if main.params[ 'GIT' ][ 'pull' ] == 'True': |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 82 | PULLCODE = True |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 83 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 84 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 85 | |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 86 | main.numCtrls = int( main.params[ 'num_controllers' ] ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 87 | if main.ONOSbench.maxNodes: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 88 | if main.ONOSbench.maxNodes < main.numCtrls: |
| 89 | main.numCtrls = int( main.ONOSbench.maxNodes ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 90 | # These are for csv plotting in jenkins |
| 91 | main.HAlabels = [] |
| 92 | main.HAdata = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 93 | try: |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 94 | from tests.HA.dependencies.HA import HA |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 95 | main.HA = HA() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 96 | except ImportError as e: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 97 | main.log.exception( e ) |
| 98 | main.cleanup() |
| 99 | main.exit() |
| 100 | |
| 101 | main.CLIs = [] |
| 102 | main.nodes = [] |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 103 | ipList = [] |
| 104 | for i in range( 1, int( main.ONOSbench.maxNodes ) + 1 ): |
| 105 | try: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 106 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 107 | main.nodes.append( getattr( main, 'ONOS' + str( i ) ) ) |
| 108 | ipList.append( main.nodes[ -1 ].ip_address ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 109 | except AttributeError: |
| 110 | break |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 111 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 112 | main.step( "Create cell file" ) |
| 113 | cellAppString = main.params[ 'ENV' ][ 'appString' ] |
| 114 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName, |
| 115 | main.Mininet1.ip_address, |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 116 | cellAppString, ipList, main.ONOScli1.karafUser ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 117 | main.step( "Applying cell variable to environment" ) |
| 118 | cellResult = main.ONOSbench.setCell( cellName ) |
| 119 | verifyResult = main.ONOSbench.verifyCell() |
| 120 | |
| 121 | # FIXME:this is short term fix |
| 122 | main.log.info( "Removing raft logs" ) |
| 123 | main.ONOSbench.onosRemoveRaftLogs() |
| 124 | |
| 125 | main.log.info( "Uninstalling ONOS" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 126 | for node in main.nodes: |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 127 | main.ONOSbench.onosUninstall( node.ip_address ) |
| 128 | |
| 129 | # Make sure ONOS is DEAD |
| 130 | main.log.info( "Killing any ONOS processes" ) |
| 131 | killResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 132 | for node in main.nodes: |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 133 | killed = main.ONOSbench.onosKill( node.ip_address ) |
| 134 | killResults = killResults and killed |
| 135 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 136 | gitPullResult = main.TRUE |
| 137 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 138 | main.HA.startingMininet() |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 139 | |
| 140 | main.step( "Git checkout and pull " + gitBranch ) |
| 141 | if PULLCODE: |
| 142 | main.ONOSbench.gitCheckout( gitBranch ) |
| 143 | gitPullResult = main.ONOSbench.gitPull() |
| 144 | # values of 1 or 3 are good |
| 145 | utilities.assert_lesser( expect=0, actual=gitPullResult, |
| 146 | onpass="Git pull successful", |
| 147 | onfail="Git pull failed" ) |
| 148 | main.ONOSbench.getVersion( report=True ) |
| 149 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 150 | main.HA.generateGraph( "HAsingleInstanceRestart" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 151 | |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 152 | main.CLIs = [] |
| 153 | main.nodes = [] |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 154 | ipList = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 155 | for i in range( 1, main.numCtrls + 1 ): |
| 156 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 157 | main.nodes.append( getattr( main, 'ONOS' + str( i ) ) ) |
| 158 | ipList.append( main.nodes[ -1 ].ip_address ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 159 | |
| 160 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "SingleHA", |
| 161 | main.Mininet1.ip_address, |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 162 | cellAppString, ipList[ 0 ], main.ONOScli1.karafUser ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 163 | cellResult = main.ONOSbench.setCell( "SingleHA" ) |
| 164 | verifyResult = main.ONOSbench.verifyCell() |
| 165 | main.step( "Creating ONOS package" ) |
Jon Hall | bd60ea0 | 2016-08-23 10:03:59 -0700 | [diff] [blame] | 166 | packageResult = main.ONOSbench.buckBuild() |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 167 | utilities.assert_equals( expect=main.TRUE, actual=packageResult, |
| 168 | onpass="ONOS package successful", |
| 169 | onfail="ONOS package failed" ) |
| 170 | |
| 171 | main.step( "Installing ONOS package" ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 172 | onosInstallResult = main.TRUE |
| 173 | for node in main.nodes: |
| 174 | tmpResult = main.ONOSbench.onosInstall( options="-f", |
| 175 | node=node.ip_address ) |
| 176 | onosInstallResult = onosInstallResult and tmpResult |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 177 | utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult, |
| 178 | onpass="ONOS install successful", |
| 179 | onfail="ONOS install failed" ) |
| 180 | |
You Wang | f5de25b | 2017-01-06 15:13:01 -0800 | [diff] [blame] | 181 | main.step( "Set up ONOS secure SSH" ) |
| 182 | secureSshResult = main.TRUE |
| 183 | for node in main.nodes: |
| 184 | secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=node.ip_address ) |
| 185 | utilities.assert_equals( expect=main.TRUE, actual=secureSshResult, |
| 186 | onpass="Test step PASS", |
| 187 | onfail="Test step FAIL" ) |
| 188 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 189 | main.step( "Checking if ONOS is up yet" ) |
| 190 | for i in range( 2 ): |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 191 | onosIsupResult = main.TRUE |
| 192 | for node in main.nodes: |
| 193 | started = main.ONOSbench.isup( node.ip_address ) |
| 194 | if not started: |
| 195 | main.log.error( node.name + " hasn't started" ) |
| 196 | onosIsupResult = onosIsupResult and started |
| 197 | if onosIsupResult == main.TRUE: |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 198 | break |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 199 | utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 200 | onpass="ONOS startup successful", |
| 201 | onfail="ONOS startup failed" ) |
| 202 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 203 | main.step( "Starting ONOS CLI sessions" ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 204 | cliResults = main.TRUE |
| 205 | threads = [] |
| 206 | for i in range( main.numCtrls ): |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 207 | t = main.Thread( target=main.CLIs[ i ].startOnosCli, |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 208 | name="startOnosCli-" + str( i ), |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 209 | args=[ main.nodes[ i ].ip_address ] ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 210 | threads.append( t ) |
| 211 | t.start() |
| 212 | |
| 213 | for t in threads: |
| 214 | t.join() |
| 215 | cliResults = cliResults and t.result |
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 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 220 | main.HA.initialSetUp() |
Jon Hall | 9d2dcad | 2016-04-08 10:15:20 -0700 | [diff] [blame] | 221 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 222 | def CASE2( self, main ): |
| 223 | """ |
| 224 | Assign devices to controllers |
| 225 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 226 | main.HA.assignDevices( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 227 | |
| 228 | def CASE21( self, main ): |
| 229 | """ |
| 230 | Assign mastership to controllers |
| 231 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 232 | main.HA.assignMastership( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 233 | |
| 234 | def CASE3( self, main ): |
| 235 | """ |
| 236 | Assign intents |
| 237 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 238 | main.HA.assignIntents( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 239 | |
| 240 | def CASE4( self, main ): |
| 241 | """ |
| 242 | Ping across added host intents |
| 243 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 244 | main.HA.pingAcrossHostIntent( main, False, True ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 245 | |
| 246 | def CASE5( self, main ): |
| 247 | """ |
| 248 | Reading state of ONOS |
| 249 | """ |
| 250 | import json |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 251 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 252 | assert main, "main not defined" |
| 253 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 254 | |
| 255 | main.case( "Setting up and gathering data for current state" ) |
| 256 | # The general idea for this test case is to pull the state of |
| 257 | # ( intents,flows, topology,... ) from each ONOS node |
| 258 | # We can then compare them with each other and also with past states |
| 259 | |
| 260 | main.step( "Check that each switch has a master" ) |
| 261 | global mastershipState |
| 262 | mastershipState = '[]' |
| 263 | |
| 264 | # Assert that each device has a master |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 265 | rolesNotNull = main.TRUE |
| 266 | threads = [] |
| 267 | for i in main.activeNodes: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 268 | t = main.Thread( target=main.CLIs[ i ].rolesNotNull, |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 269 | name="rolesNotNull-" + str( i ), |
| 270 | args=[] ) |
| 271 | threads.append( t ) |
| 272 | t.start() |
| 273 | |
| 274 | for t in threads: |
| 275 | t.join() |
| 276 | rolesNotNull = rolesNotNull and t.result |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 277 | utilities.assert_equals( |
| 278 | expect=main.TRUE, |
| 279 | actual=rolesNotNull, |
| 280 | onpass="Each device has a master", |
| 281 | onfail="Some devices don't have a master assigned" ) |
| 282 | |
| 283 | main.step( "Get the Mastership of each switch" ) |
| 284 | ONOS1Mastership = main.ONOScli1.roles() |
| 285 | # TODO: Make this a meaningful check |
| 286 | if "Error" in ONOS1Mastership or not ONOS1Mastership: |
| 287 | main.log.error( "Error in getting ONOS roles" ) |
| 288 | main.log.warn( |
| 289 | "ONOS1 mastership response: " + |
| 290 | repr( ONOS1Mastership ) ) |
| 291 | consistentMastership = main.FALSE |
| 292 | else: |
| 293 | mastershipState = ONOS1Mastership |
| 294 | consistentMastership = main.TRUE |
| 295 | |
| 296 | main.step( "Get the intents from each controller" ) |
| 297 | global intentState |
| 298 | intentState = [] |
| 299 | ONOS1Intents = main.ONOScli1.intents( jsonFormat=True ) |
| 300 | intentCheck = main.FALSE |
| 301 | if "Error" in ONOS1Intents or not ONOS1Intents: |
| 302 | main.log.error( "Error in getting ONOS intents" ) |
| 303 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) ) |
| 304 | else: |
| 305 | intentCheck = main.TRUE |
| 306 | |
| 307 | main.step( "Get the flows from each controller" ) |
| 308 | global flowState |
| 309 | flowState = [] |
| 310 | flowCheck = main.FALSE |
| 311 | ONOS1Flows = main.ONOScli1.flows( jsonFormat=True ) |
| 312 | if "Error" in ONOS1Flows or not ONOS1Flows: |
| 313 | main.log.error( "Error in getting ONOS flows" ) |
| 314 | main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows ) |
| 315 | else: |
| 316 | # TODO: Do a better check, maybe compare flows on switches? |
| 317 | flowState = ONOS1Flows |
| 318 | flowCheck = main.TRUE |
| 319 | |
| 320 | main.step( "Get the OF Table entries" ) |
| 321 | global flows |
| 322 | flows = [] |
| 323 | for i in range( 1, 29 ): |
GlennRC | 68467eb | 2015-11-16 18:01:01 -0800 | [diff] [blame] | 324 | flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3", debug=False ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 325 | if flowCheck == main.FALSE: |
| 326 | for table in flows: |
| 327 | main.log.warn( table ) |
| 328 | # TODO: Compare switch flow tables with ONOS flow tables |
| 329 | |
| 330 | main.step( "Collecting topology information from ONOS" ) |
| 331 | devices = [] |
| 332 | devices.append( main.ONOScli1.devices() ) |
| 333 | hosts = [] |
| 334 | hosts.append( json.loads( main.ONOScli1.hosts() ) ) |
| 335 | ports = [] |
| 336 | ports.append( main.ONOScli1.ports() ) |
| 337 | links = [] |
| 338 | links.append( main.ONOScli1.links() ) |
| 339 | clusters = [] |
| 340 | clusters.append( main.ONOScli1.clusters() ) |
| 341 | |
| 342 | main.step( "Each host has an IP address" ) |
| 343 | ipResult = main.TRUE |
| 344 | for controller in range( 0, len( hosts ) ): |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 345 | controllerStr = str( main.activeNodes[ controller ] + 1 ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 346 | if hosts[ controller ]: |
| 347 | for host in hosts[ controller ]: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 348 | if not host.get( 'ipAddresses', [] ): |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 349 | main.log.error( "Error with host ips on controller" + |
| 350 | controllerStr + ": " + str( host ) ) |
| 351 | ipResult = main.FALSE |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 352 | utilities.assert_equals( |
| 353 | expect=main.TRUE, |
| 354 | actual=ipResult, |
| 355 | onpass="The ips of the hosts aren't empty", |
| 356 | onfail="The ip of at least one host is missing" ) |
| 357 | |
| 358 | # there should always only be one cluster |
| 359 | main.step( "There is only one dataplane cluster" ) |
| 360 | try: |
| 361 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
| 362 | except ( ValueError, TypeError ): |
| 363 | main.log.exception( "Error parsing clusters[0]: " + |
| 364 | repr( clusters[ 0 ] ) ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 365 | numClusters = "ERROR" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 366 | clusterResults = main.FALSE |
| 367 | if numClusters == 1: |
| 368 | clusterResults = main.TRUE |
| 369 | utilities.assert_equals( |
| 370 | expect=1, |
| 371 | actual=numClusters, |
| 372 | onpass="ONOS shows 1 SCC", |
| 373 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
| 374 | |
| 375 | main.step( "Comparing ONOS topology to MN" ) |
| 376 | devicesResults = main.TRUE |
| 377 | linksResults = main.TRUE |
| 378 | hostsResults = main.TRUE |
| 379 | mnSwitches = main.Mininet1.getSwitches() |
| 380 | mnLinks = main.Mininet1.getLinks() |
| 381 | mnHosts = main.Mininet1.getHosts() |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 382 | for controller in main.activeNodes: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 383 | controllerStr = str( main.activeNodes[ controller ] + 1 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 384 | if devices[ controller ] and ports[ controller ] and\ |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 385 | "Error" not in devices[ controller ] and\ |
| 386 | "Error" not in ports[ controller ]: |
| 387 | currentDevicesResult = main.Mininet1.compareSwitches( |
| 388 | mnSwitches, |
| 389 | json.loads( devices[ controller ] ), |
| 390 | json.loads( ports[ controller ] ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 391 | else: |
| 392 | currentDevicesResult = main.FALSE |
| 393 | utilities.assert_equals( expect=main.TRUE, |
| 394 | actual=currentDevicesResult, |
| 395 | onpass="ONOS" + controllerStr + |
| 396 | " Switches view is correct", |
| 397 | onfail="ONOS" + controllerStr + |
| 398 | " Switches view is incorrect" ) |
| 399 | if links[ controller ] and "Error" not in links[ controller ]: |
| 400 | currentLinksResult = main.Mininet1.compareLinks( |
| 401 | mnSwitches, mnLinks, |
| 402 | json.loads( links[ controller ] ) ) |
| 403 | else: |
| 404 | currentLinksResult = main.FALSE |
| 405 | utilities.assert_equals( expect=main.TRUE, |
| 406 | actual=currentLinksResult, |
| 407 | onpass="ONOS" + controllerStr + |
| 408 | " links view is correct", |
| 409 | onfail="ONOS" + controllerStr + |
| 410 | " links view is incorrect" ) |
| 411 | |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 412 | if hosts[ controller ] and "Error" not in hosts[ controller ]: |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 413 | currentHostsResult = main.Mininet1.compareHosts( |
| 414 | mnHosts, |
| 415 | hosts[ controller ] ) |
| 416 | else: |
| 417 | currentHostsResult = main.FALSE |
| 418 | utilities.assert_equals( expect=main.TRUE, |
| 419 | actual=currentHostsResult, |
| 420 | onpass="ONOS" + controllerStr + |
| 421 | " hosts exist in Mininet", |
| 422 | onfail="ONOS" + controllerStr + |
| 423 | " hosts don't match Mininet" ) |
| 424 | |
| 425 | devicesResults = devicesResults and currentDevicesResult |
| 426 | linksResults = linksResults and currentLinksResult |
| 427 | hostsResults = hostsResults and currentHostsResult |
| 428 | |
| 429 | main.step( "Device information is correct" ) |
| 430 | utilities.assert_equals( |
| 431 | expect=main.TRUE, |
| 432 | actual=devicesResults, |
| 433 | onpass="Device information is correct", |
| 434 | onfail="Device information is incorrect" ) |
| 435 | |
| 436 | main.step( "Links are correct" ) |
| 437 | utilities.assert_equals( |
| 438 | expect=main.TRUE, |
| 439 | actual=linksResults, |
| 440 | onpass="Link are correct", |
| 441 | onfail="Links are incorrect" ) |
| 442 | |
| 443 | main.step( "Hosts are correct" ) |
| 444 | utilities.assert_equals( |
| 445 | expect=main.TRUE, |
| 446 | actual=hostsResults, |
| 447 | onpass="Hosts are correct", |
| 448 | onfail="Hosts are incorrect" ) |
| 449 | |
| 450 | def CASE6( self, main ): |
| 451 | """ |
| 452 | The Failure case. |
| 453 | """ |
| 454 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 455 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 456 | assert main, "main not defined" |
| 457 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 458 | |
| 459 | # Reset non-persistent variables |
| 460 | try: |
| 461 | iCounterValue = 0 |
| 462 | except NameError: |
| 463 | main.log.error( "iCounterValue not defined, setting to 0" ) |
| 464 | iCounterValue = 0 |
| 465 | |
| 466 | main.case( "Restart ONOS node" ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 467 | main.caseExplanation = "Killing ONOS process and restart cli " +\ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 468 | "sessions once onos is up." |
Jon Hall | 96091e6 | 2015-09-21 17:34:17 -0700 | [diff] [blame] | 469 | |
| 470 | main.step( "Checking ONOS Logs for errors" ) |
| 471 | for node in main.nodes: |
| 472 | main.log.debug( "Checking logs for errors on " + node.name + ":" ) |
| 473 | main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) ) |
| 474 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 475 | main.step( "Killing ONOS processes" ) |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 476 | killResult = main.ONOSbench.onosKill( main.nodes[ 0 ].ip_address ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 477 | start = time.time() |
| 478 | utilities.assert_equals( expect=main.TRUE, actual=killResult, |
| 479 | onpass="ONOS Killed", |
| 480 | onfail="Error killing ONOS" ) |
| 481 | |
| 482 | main.step( "Checking if ONOS is up yet" ) |
| 483 | count = 0 |
| 484 | while count < 10: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 485 | onos1Isup = main.ONOSbench.isup( main.nodes[ 0 ].ip_address ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 486 | if onos1Isup == main.TRUE: |
| 487 | elapsed = time.time() - start |
| 488 | break |
| 489 | else: |
| 490 | count = count + 1 |
| 491 | utilities.assert_equals( expect=main.TRUE, actual=onos1Isup, |
| 492 | onpass="ONOS is back up", |
| 493 | onfail="ONOS failed to start" ) |
| 494 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 495 | main.step( "Starting ONOS CLI sessions" ) |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 496 | cliResults = main.ONOScli1.startOnosCli( main.nodes[ 0 ].ip_address ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 497 | utilities.assert_equals( expect=main.TRUE, actual=cliResults, |
| 498 | onpass="ONOS cli startup successful", |
| 499 | onfail="ONOS cli startup failed" ) |
| 500 | |
| 501 | if elapsed: |
| 502 | main.log.info( "ESTIMATE: ONOS took %s seconds to restart" % |
| 503 | str( elapsed ) ) |
| 504 | main.restartTime = elapsed |
| 505 | else: |
| 506 | main.restartTime = -1 |
| 507 | time.sleep( 5 ) |
| 508 | # rerun on election apps |
| 509 | main.ONOScli1.electionTestRun() |
| 510 | |
| 511 | def CASE7( self, main ): |
| 512 | """ |
| 513 | Check state after ONOS failure |
| 514 | """ |
| 515 | import json |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 516 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 517 | assert main, "main not defined" |
| 518 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 519 | main.case( "Running ONOS Constant State Tests" ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 520 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 521 | main.step( "Check that each switch has a master" ) |
| 522 | # Assert that each device has a master |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 523 | rolesNotNull = main.TRUE |
| 524 | threads = [] |
| 525 | for i in main.activeNodes: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 526 | t = main.Thread( target=main.CLIs[ i ].rolesNotNull, |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 527 | name="rolesNotNull-" + str( i ), |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 528 | args=[] ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 529 | threads.append( t ) |
| 530 | t.start() |
| 531 | |
| 532 | for t in threads: |
| 533 | t.join() |
| 534 | rolesNotNull = rolesNotNull and t.result |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 535 | utilities.assert_equals( |
| 536 | expect=main.TRUE, |
| 537 | actual=rolesNotNull, |
| 538 | onpass="Each device has a master", |
| 539 | onfail="Some devices don't have a master assigned" ) |
| 540 | |
| 541 | main.step( "Check if switch roles are consistent across all nodes" ) |
| 542 | ONOS1Mastership = main.ONOScli1.roles() |
| 543 | # FIXME: Refactor this whole case for single instance |
| 544 | if "Error" in ONOS1Mastership or not ONOS1Mastership: |
| 545 | main.log.error( "Error in getting ONOS mastership" ) |
| 546 | main.log.warn( "ONOS1 mastership response: " + |
| 547 | repr( ONOS1Mastership ) ) |
| 548 | consistentMastership = main.FALSE |
| 549 | else: |
| 550 | consistentMastership = main.TRUE |
| 551 | utilities.assert_equals( |
| 552 | expect=main.TRUE, |
| 553 | actual=consistentMastership, |
| 554 | onpass="Switch roles are consistent across all ONOS nodes", |
| 555 | onfail="ONOS nodes have different views of switch roles" ) |
| 556 | |
| 557 | description2 = "Compare switch roles from before failure" |
| 558 | main.step( description2 ) |
| 559 | |
| 560 | currentJson = json.loads( ONOS1Mastership ) |
| 561 | oldJson = json.loads( mastershipState ) |
| 562 | mastershipCheck = main.TRUE |
| 563 | for i in range( 1, 29 ): |
| 564 | switchDPID = str( |
| 565 | main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) ) |
| 566 | |
| 567 | current = [ switch[ 'master' ] for switch in currentJson |
| 568 | if switchDPID in switch[ 'id' ] ] |
| 569 | old = [ switch[ 'master' ] for switch in oldJson |
| 570 | if switchDPID in switch[ 'id' ] ] |
| 571 | if current == old: |
| 572 | mastershipCheck = mastershipCheck and main.TRUE |
| 573 | else: |
| 574 | main.log.warn( "Mastership of switch %s changed" % switchDPID ) |
| 575 | mastershipCheck = main.FALSE |
| 576 | utilities.assert_equals( |
| 577 | expect=main.TRUE, |
| 578 | actual=mastershipCheck, |
| 579 | onpass="Mastership of Switches was not changed", |
| 580 | onfail="Mastership of some switches changed" ) |
| 581 | mastershipCheck = mastershipCheck and consistentMastership |
| 582 | |
| 583 | main.step( "Get the intents and compare across all nodes" ) |
| 584 | ONOS1Intents = main.ONOScli1.intents( jsonFormat=True ) |
| 585 | intentCheck = main.FALSE |
| 586 | if "Error" in ONOS1Intents or not ONOS1Intents: |
| 587 | main.log.error( "Error in getting ONOS intents" ) |
| 588 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) ) |
| 589 | else: |
| 590 | intentCheck = main.TRUE |
| 591 | utilities.assert_equals( |
| 592 | expect=main.TRUE, |
| 593 | actual=intentCheck, |
| 594 | onpass="Intents are consistent across all ONOS nodes", |
| 595 | onfail="ONOS nodes have different views of intents" ) |
| 596 | # Print the intent states |
| 597 | intents = [] |
| 598 | intents.append( ONOS1Intents ) |
| 599 | intentStates = [] |
| 600 | for node in intents: # Iter through ONOS nodes |
| 601 | nodeStates = [] |
| 602 | # Iter through intents of a node |
| 603 | for intent in json.loads( node ): |
| 604 | nodeStates.append( intent[ 'state' ] ) |
| 605 | intentStates.append( nodeStates ) |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 606 | out = [ ( i, nodeStates.count( i ) ) for i in set( nodeStates ) ] |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 607 | main.log.info( dict( out ) ) |
| 608 | |
| 609 | # NOTE: Store has no durability, so intents are lost across system |
| 610 | # restarts |
| 611 | """ |
| 612 | main.step( "Compare current intents with intents before the failure" ) |
| 613 | # NOTE: this requires case 5 to pass for intentState to be set. |
| 614 | # maybe we should stop the test if that fails? |
| 615 | sameIntents = main.FALSE |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 616 | try: |
| 617 | intentState |
| 618 | except NameError: |
| 619 | main.log.warn( "No previous intent state was saved" ) |
| 620 | else: |
| 621 | if intentState and intentState == ONOSIntents[ 0 ]: |
| 622 | sameIntents = main.TRUE |
| 623 | main.log.info( "Intents are consistent with before failure" ) |
| 624 | # TODO: possibly the states have changed? we may need to figure out |
| 625 | # what the acceptable states are |
| 626 | elif len( intentState ) == len( ONOSIntents[ 0 ] ): |
| 627 | sameIntents = main.TRUE |
| 628 | try: |
| 629 | before = json.loads( intentState ) |
| 630 | after = json.loads( ONOSIntents[ 0 ] ) |
| 631 | for intent in before: |
| 632 | if intent not in after: |
| 633 | sameIntents = main.FALSE |
| 634 | main.log.debug( "Intent is not currently in ONOS " + |
| 635 | "(at least in the same form):" ) |
| 636 | main.log.debug( json.dumps( intent ) ) |
| 637 | except ( ValueError, TypeError ): |
| 638 | main.log.exception( "Exception printing intents" ) |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 639 | main.log.debug( repr( ONOSIntents[ 0 ] ) ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 640 | main.log.debug( repr( intentState ) ) |
| 641 | if sameIntents == main.FALSE: |
| 642 | try: |
| 643 | main.log.debug( "ONOS intents before: " ) |
| 644 | main.log.debug( json.dumps( json.loads( intentState ), |
| 645 | sort_keys=True, indent=4, |
| 646 | separators=( ',', ': ' ) ) ) |
| 647 | main.log.debug( "Current ONOS intents: " ) |
| 648 | main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ), |
| 649 | sort_keys=True, indent=4, |
| 650 | separators=( ',', ': ' ) ) ) |
| 651 | except ( ValueError, TypeError ): |
| 652 | main.log.exception( "Exception printing intents" ) |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 653 | main.log.debug( repr( ONOSIntents[ 0 ] ) ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 654 | main.log.debug( repr( intentState ) ) |
| 655 | utilities.assert_equals( |
| 656 | expect=main.TRUE, |
| 657 | actual=sameIntents, |
| 658 | onpass="Intents are consistent with before failure", |
| 659 | onfail="The Intents changed during failure" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 660 | intentCheck = intentCheck and sameIntents |
| 661 | """ |
| 662 | main.step( "Get the OF Table entries and compare to before " + |
| 663 | "component failure" ) |
| 664 | FlowTables = main.TRUE |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 665 | for i in range( 28 ): |
| 666 | main.log.info( "Checking flow table on s" + str( i + 1 ) ) |
GlennRC | 68467eb | 2015-11-16 18:01:01 -0800 | [diff] [blame] | 667 | tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3", debug=False ) |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 668 | curSwitch = main.Mininet1.flowTableComp( flows[ i ], tmpFlows ) |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 669 | FlowTables = FlowTables and curSwitch |
| 670 | if curSwitch == main.FALSE: |
GlennRC | 68467eb | 2015-11-16 18:01:01 -0800 | [diff] [blame] | 671 | main.log.warn( "Differences in flow table for switch: s{}".format( i + 1 ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 672 | utilities.assert_equals( |
| 673 | expect=main.TRUE, |
| 674 | actual=FlowTables, |
| 675 | onpass="No changes were found in the flow tables", |
| 676 | onfail="Changes were found in the flow tables" ) |
| 677 | |
| 678 | main.step( "Leadership Election is still functional" ) |
| 679 | # Test of LeadershipElection |
| 680 | |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 681 | leader = main.nodes[ main.activeNodes[ 0 ] ].ip_address |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 682 | leaderResult = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 683 | for controller in range( 1, main.numCtrls + 1 ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 684 | # loop through ONOScli handlers |
| 685 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
| 686 | leaderN = node.electionTestLeader() |
| 687 | # verify leader is ONOS1 |
| 688 | # NOTE even though we restarted ONOS, it is the only one so onos 1 |
| 689 | # must be leader |
| 690 | if leaderN == leader: |
| 691 | # all is well |
| 692 | pass |
| 693 | elif leaderN == main.FALSE: |
| 694 | # error in response |
| 695 | main.log.error( "Something is wrong with " + |
| 696 | "electionTestLeader function, check the" + |
| 697 | " error logs" ) |
| 698 | leaderResult = main.FALSE |
| 699 | elif leader != leaderN: |
| 700 | leaderResult = main.FALSE |
| 701 | main.log.error( "ONOS" + str( controller ) + " sees " + |
| 702 | str( leaderN ) + |
| 703 | " as the leader of the election app. " + |
| 704 | "Leader should be " + str( leader ) ) |
| 705 | utilities.assert_equals( |
| 706 | expect=main.TRUE, |
| 707 | actual=leaderResult, |
| 708 | onpass="Leadership election passed", |
| 709 | onfail="Something went wrong with Leadership election" ) |
| 710 | |
| 711 | def CASE8( self, main ): |
| 712 | """ |
| 713 | Compare topo |
| 714 | """ |
| 715 | import json |
| 716 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 717 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 718 | assert main, "main not defined" |
| 719 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 720 | |
| 721 | main.case( "Compare ONOS Topology view to Mininet topology" ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 722 | main.caseExplanation = "Compare topology objects between Mininet" +\ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 723 | " and ONOS" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 724 | topoResult = main.FALSE |
| 725 | elapsed = 0 |
| 726 | count = 0 |
Jon Hall | e9b1fa3 | 2015-12-08 15:32:21 -0800 | [diff] [blame] | 727 | main.step( "Comparing ONOS topology to MN topology" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 728 | startTime = time.time() |
| 729 | # Give time for Gossip to work |
Jon Hall | e9b1fa3 | 2015-12-08 15:32:21 -0800 | [diff] [blame] | 730 | while topoResult == main.FALSE and ( elapsed < 60 or count < 3 ): |
Jon Hall | 96091e6 | 2015-09-21 17:34:17 -0700 | [diff] [blame] | 731 | devicesResults = main.TRUE |
| 732 | linksResults = main.TRUE |
| 733 | hostsResults = main.TRUE |
| 734 | hostAttachmentResults = True |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 735 | count += 1 |
| 736 | cliStart = time.time() |
| 737 | devices = [] |
| 738 | devices.append( main.ONOScli1.devices() ) |
| 739 | hosts = [] |
| 740 | hosts.append( json.loads( main.ONOScli1.hosts() ) ) |
| 741 | ipResult = main.TRUE |
| 742 | for controller in range( 0, len( hosts ) ): |
| 743 | controllerStr = str( controller + 1 ) |
| 744 | for host in hosts[ controller ]: |
| 745 | if host is None or host.get( 'ipAddresses', [] ) == []: |
| 746 | main.log.error( |
| 747 | "DEBUG:Error with host ips on controller" + |
| 748 | controllerStr + ": " + str( host ) ) |
| 749 | ipResult = main.FALSE |
| 750 | ports = [] |
| 751 | ports.append( main.ONOScli1.ports() ) |
| 752 | links = [] |
| 753 | links.append( main.ONOScli1.links() ) |
| 754 | clusters = [] |
| 755 | clusters.append( main.ONOScli1.clusters() ) |
| 756 | |
| 757 | elapsed = time.time() - startTime |
| 758 | cliTime = time.time() - cliStart |
| 759 | print "CLI time: " + str( cliTime ) |
| 760 | |
| 761 | mnSwitches = main.Mininet1.getSwitches() |
| 762 | mnLinks = main.Mininet1.getLinks() |
| 763 | mnHosts = main.Mininet1.getHosts() |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 764 | for controller in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 765 | controllerStr = str( controller + 1 ) |
| 766 | if devices[ controller ] and ports[ controller ] and\ |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 767 | "Error" not in devices[ controller ] and\ |
| 768 | "Error" not in ports[ controller ]: |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 769 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 770 | try: |
| 771 | currentDevicesResult = main.Mininet1.compareSwitches( |
| 772 | mnSwitches, |
| 773 | json.loads( devices[ controller ] ), |
| 774 | json.loads( ports[ controller ] ) ) |
| 775 | except ( TypeError, ValueError ) as e: |
| 776 | main.log.exception( "Object not as expected; devices={!r}\nports={!r}".format( |
| 777 | devices[ controller ], ports[ controller ] ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 778 | else: |
| 779 | currentDevicesResult = main.FALSE |
| 780 | utilities.assert_equals( expect=main.TRUE, |
| 781 | actual=currentDevicesResult, |
| 782 | onpass="ONOS" + controllerStr + |
| 783 | " Switches view is correct", |
| 784 | onfail="ONOS" + controllerStr + |
| 785 | " Switches view is incorrect" ) |
| 786 | |
| 787 | if links[ controller ] and "Error" not in links[ controller ]: |
| 788 | currentLinksResult = main.Mininet1.compareLinks( |
| 789 | mnSwitches, mnLinks, |
| 790 | json.loads( links[ controller ] ) ) |
| 791 | else: |
| 792 | currentLinksResult = main.FALSE |
| 793 | utilities.assert_equals( expect=main.TRUE, |
| 794 | actual=currentLinksResult, |
| 795 | onpass="ONOS" + controllerStr + |
| 796 | " links view is correct", |
| 797 | onfail="ONOS" + controllerStr + |
| 798 | " links view is incorrect" ) |
| 799 | |
| 800 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 801 | currentHostsResult = main.Mininet1.compareHosts( |
| 802 | mnHosts, |
| 803 | hosts[ controller ] ) |
| 804 | else: |
| 805 | currentHostsResult = main.FALSE |
| 806 | utilities.assert_equals( expect=main.TRUE, |
| 807 | actual=currentHostsResult, |
| 808 | onpass="ONOS" + controllerStr + |
| 809 | " hosts exist in Mininet", |
| 810 | onfail="ONOS" + controllerStr + |
| 811 | " hosts don't match Mininet" ) |
| 812 | # CHECKING HOST ATTACHMENT POINTS |
| 813 | hostAttachment = True |
| 814 | zeroHosts = False |
| 815 | # FIXME: topo-HA/obelisk specific mappings: |
| 816 | # key is mac and value is dpid |
| 817 | mappings = {} |
| 818 | for i in range( 1, 29 ): # hosts 1 through 28 |
| 819 | # set up correct variables: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 820 | macId = "00:" * 5 + hex( i ).split( "0x" )[ 1 ].upper().zfill( 2 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 821 | if i == 1: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 822 | deviceId = "1000".zfill( 16 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 823 | elif i == 2: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 824 | deviceId = "2000".zfill( 16 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 825 | elif i == 3: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 826 | deviceId = "3000".zfill( 16 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 827 | elif i == 4: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 828 | deviceId = "3004".zfill( 16 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 829 | elif i == 5: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 830 | deviceId = "5000".zfill( 16 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 831 | elif i == 6: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 832 | deviceId = "6000".zfill( 16 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 833 | elif i == 7: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 834 | deviceId = "6007".zfill( 16 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 835 | elif i >= 8 and i <= 17: |
| 836 | dpid = '3' + str( i ).zfill( 3 ) |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 837 | deviceId = dpid.zfill( 16 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 838 | elif i >= 18 and i <= 27: |
| 839 | dpid = '6' + str( i ).zfill( 3 ) |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 840 | deviceId = dpid.zfill( 16 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 841 | elif i == 28: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 842 | deviceId = "2800".zfill( 16 ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 843 | mappings[ macId ] = deviceId |
| 844 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 845 | if hosts[ controller ] == []: |
| 846 | main.log.warn( "There are no hosts discovered" ) |
| 847 | zeroHosts = True |
| 848 | else: |
| 849 | for host in hosts[ controller ]: |
| 850 | mac = None |
| 851 | location = None |
| 852 | device = None |
| 853 | port = None |
| 854 | try: |
| 855 | mac = host.get( 'mac' ) |
| 856 | assert mac, "mac field could not be found for this host object" |
| 857 | |
Jeremy Ronquillo | 0e538bc | 2017-06-13 15:16:09 -0700 | [diff] [blame] | 858 | location = host.get( 'locations' )[ 0 ] |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 859 | assert location, "location field could not be found for this host object" |
| 860 | |
| 861 | # Trim the protocol identifier off deviceId |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 862 | device = str( location.get( 'elementId' ) ).split( ':' )[ 1 ] |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 863 | assert device, "elementId field could not be found for this host location object" |
| 864 | |
| 865 | port = location.get( 'port' ) |
| 866 | assert port, "port field could not be found for this host location object" |
| 867 | |
| 868 | # Now check if this matches where they should be |
| 869 | if mac and device and port: |
| 870 | if str( port ) != "1": |
| 871 | main.log.error( "The attachment port is incorrect for " + |
| 872 | "host " + str( mac ) + |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 873 | ". Expected: 1 Actual: " + str( port ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 874 | hostAttachment = False |
| 875 | if device != mappings[ str( mac ) ]: |
| 876 | main.log.error( "The attachment device is incorrect for " + |
| 877 | "host " + str( mac ) + |
| 878 | ". Expected: " + mappings[ str( mac ) ] + |
| 879 | " Actual: " + device ) |
| 880 | hostAttachment = False |
| 881 | else: |
| 882 | hostAttachment = False |
| 883 | except AssertionError: |
| 884 | main.log.exception( "Json object not as expected" ) |
| 885 | main.log.error( repr( host ) ) |
| 886 | hostAttachment = False |
| 887 | else: |
| 888 | main.log.error( "No hosts json output or \"Error\"" + |
| 889 | " in output. hosts = " + |
| 890 | repr( hosts[ controller ] ) ) |
| 891 | if zeroHosts is False: |
| 892 | hostAttachment = True |
| 893 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 894 | devicesResults = devicesResults and currentDevicesResult |
| 895 | linksResults = linksResults and currentLinksResult |
| 896 | hostsResults = hostsResults and currentHostsResult |
| 897 | hostAttachmentResults = hostAttachmentResults and\ |
| 898 | hostAttachment |
| 899 | |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 900 | # "consistent" results don't make sense for single instance |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 901 | # there should always only be one cluster |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 902 | clusterResults = main.FALSE |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 903 | try: |
| 904 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
| 905 | except ( ValueError, TypeError ): |
| 906 | main.log.exception( "Error parsing clusters[0]: " + |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 907 | repr( clusters[ 0 ] ) ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 908 | numClusters = "ERROR" |
| 909 | clusterResults = main.FALSE |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 910 | if numClusters == 1: |
| 911 | clusterResults = main.TRUE |
| 912 | utilities.assert_equals( |
| 913 | expect=1, |
| 914 | actual=numClusters, |
| 915 | onpass="ONOS shows 1 SCC", |
| 916 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
| 917 | |
| 918 | topoResult = ( devicesResults and linksResults |
| 919 | and hostsResults and ipResult and clusterResults and |
| 920 | hostAttachmentResults ) |
| 921 | |
| 922 | topoResult = topoResult and int( count <= 2 ) |
| 923 | note = "note it takes about " + str( int( cliTime ) ) + \ |
| 924 | " seconds for the test to make all the cli calls to fetch " +\ |
| 925 | "the topology from each ONOS instance" |
| 926 | main.log.info( |
| 927 | "Very crass estimate for topology discovery/convergence( " + |
| 928 | str( note ) + " ): " + str( elapsed ) + " seconds, " + |
| 929 | str( count ) + " tries" ) |
| 930 | utilities.assert_equals( expect=main.TRUE, actual=topoResult, |
| 931 | onpass="Topology Check Test successful", |
| 932 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 933 | main.step( "Checking ONOS nodes" ) |
| 934 | nodeResults = utilities.retry( main.HA.nodesCheck, |
| 935 | False, |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 936 | args=[ main.activeNodes ], |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 937 | attempts=5 ) |
| 938 | |
| 939 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 940 | onpass="Nodes check successful", |
| 941 | onfail="Nodes check NOT successful" ) |
| 942 | if not nodeResults: |
| 943 | for i in main.activeNodes: |
| 944 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 945 | main.CLIs[ i ].name, |
| 946 | main.CLIs[ i ].sendline( "scr:list | grep -v ACTIVE" ) ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 947 | |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 948 | if not topoResult: |
| 949 | main.cleanup() |
| 950 | main.exit() |
| 951 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 952 | def CASE9( self, main ): |
| 953 | """ |
| 954 | Link s3-s28 down |
| 955 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 956 | main.HA.linkDown( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 957 | |
| 958 | def CASE10( self, main ): |
| 959 | """ |
| 960 | Link s3-s28 up |
| 961 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 962 | main.HA.linkUp( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 963 | |
| 964 | def CASE11( self, main ): |
| 965 | """ |
| 966 | Switch Down |
| 967 | """ |
| 968 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 969 | main.HA.switchDown( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 970 | |
| 971 | def CASE12( self, main ): |
| 972 | """ |
| 973 | Switch Up |
| 974 | """ |
| 975 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 976 | main.HA.switchUp( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 977 | |
| 978 | def CASE13( self, main ): |
| 979 | """ |
| 980 | Clean up |
| 981 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 982 | main.HAlabels.append( "Restart" ) |
| 983 | main.HAdata.append( str( main.restartTime ) ) |
| 984 | main.HA.cleanUp( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 985 | |
| 986 | def CASE14( self, main ): |
| 987 | """ |
| 988 | start election app on all onos nodes |
| 989 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 990 | main.HA.startElectionApp( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 991 | |
| 992 | def CASE15( self, main ): |
| 993 | """ |
| 994 | Check that Leadership Election is still functional |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 995 | 15.1 Run election on each node |
| 996 | 15.2 Check that each node has the same leaders and candidates |
| 997 | 15.3 Find current leader and withdraw |
| 998 | 15.4 Check that a new node was elected leader |
| 999 | 15.5 Check that that new leader was the candidate of old leader |
| 1000 | 15.6 Run for election on old leader |
| 1001 | 15.7 Check that oldLeader is a candidate, and leader if only 1 node |
| 1002 | 15.8 Make sure that the old leader was added to the candidate list |
| 1003 | |
| 1004 | old and new variable prefixes refer to data from before vs after |
| 1005 | withdrawl and later before withdrawl vs after re-election |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1006 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1007 | main.HA.isElectionFunctional( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1008 | |
| 1009 | def CASE16( self, main ): |
| 1010 | """ |
| 1011 | Install Distributed Primitives app |
| 1012 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1013 | main.HA.installDistributedPrimitiveApp( main ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1014 | |
| 1015 | def CASE17( self, main ): |
| 1016 | """ |
| 1017 | Check for basic functionality with distributed primitives |
| 1018 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1019 | main.HA.checkDistPrimitivesFunc( main ) |