Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 1 | """ |
| 2 | Description: This test is to determine if ONOS can handle |
| 3 | a minority of it's nodes restarting |
| 4 | |
| 5 | List of test cases: |
| 6 | CASE1: Compile ONOS and push it to the test machines |
| 7 | CASE2: Assign devices to controllers |
| 8 | CASE21: Assign mastership to controllers |
| 9 | CASE3: Assign intents |
| 10 | CASE4: Ping across added host intents |
| 11 | CASE5: Reading state of ONOS |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 12 | CASE61: The Failure inducing case. |
| 13 | CASE62: The Failure recovery case. |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 14 | CASE7: Check state after control plane failure |
| 15 | CASE8: Compare topo |
| 16 | CASE9: Link s3-s28 down |
| 17 | CASE10: Link s3-s28 up |
| 18 | CASE11: Switch down |
| 19 | CASE12: Switch up |
| 20 | CASE13: Clean up |
| 21 | CASE14: start election app on all onos nodes |
| 22 | CASE15: Check that Leadership Election is still functional |
| 23 | CASE16: Install Distributed Primitives app |
| 24 | CASE17: Check for basic functionality with distributed primitives |
| 25 | """ |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 26 | class HAkillNodes: |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 27 | |
| 28 | def __init__( self ): |
| 29 | self.default = '' |
| 30 | |
| 31 | def CASE1( self, main ): |
| 32 | """ |
| 33 | CASE1 is to compile ONOS and push it to the test machines |
| 34 | |
| 35 | Startup sequence: |
| 36 | cell <name> |
| 37 | onos-verify-cell |
| 38 | NOTE: temporary - onos-remove-raft-logs |
| 39 | onos-uninstall |
| 40 | start mininet |
| 41 | git pull |
| 42 | mvn clean install |
| 43 | onos-package |
| 44 | onos-install -f |
| 45 | onos-wait-for-start |
| 46 | start cli sessions |
| 47 | start tcpdump |
| 48 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 49 | import imp |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 50 | import pexpect |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 51 | import time |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 52 | import json |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 53 | main.log.info( "ONOS HA test: Restart a minority of ONOS nodes - " + |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 54 | "initialization" ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 55 | # set global variables |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 56 | # These are for csv plotting in jenkins |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 57 | main.HAlabels = [] |
| 58 | main.HAdata = [] |
| 59 | try: |
| 60 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 61 | main.testSetUp = ONOSSetup() |
| 62 | except ImportError: |
| 63 | main.log.error( "ONOSSetup not found. exiting the test" ) |
| 64 | main.exit() |
| 65 | main.testSetUp.envSetupDescription() |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 66 | try: |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 67 | from tests.HA.dependencies.HA import HA |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 68 | main.HA = HA() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 69 | # load some variables from the params file |
| 70 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 71 | main.apps = main.params[ 'ENV' ][ 'appString' ] |
| 72 | main.numCtrls = int( main.params[ 'num_controllers' ] ) |
| 73 | if main.ONOSbench.maxNodes and\ |
| 74 | main.ONOSbench.maxNodes < main.numCtrls: |
| 75 | main.numCtrls = int( main.ONOSbench.maxNodes ) |
| 76 | main.maxNodes = main.numCtrls |
| 77 | stepResult = main.testSetUp.envSetup( hasNode=True ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 78 | except Exception as e: |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 79 | main.testSetUp.envSetupException( e ) |
| 80 | main.testSetUp.evnSetupConclusion( stepResult ) |
| 81 | main.HA.generateGraph( "HAkillNodes" ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 82 | |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 83 | main.step( "Make sure ONOS service doesn't automatically respawn" ) |
| 84 | handle = main.ONOSbench.handle |
| 85 | handle.sendline( "sed -i -e 's/^respawn$/#respawn/g' tools/package/init/onos.conf" ) |
| 86 | handle.expect( "\$" ) # $ from the command |
Jon Hall | 334ba94 | 2017-01-19 17:02:17 -0800 | [diff] [blame] | 87 | handle.sendline( "sed -i -e 's/^Restart=always/Restart=no/g' tools/package/init/onos.service" ) |
| 88 | handle.expect( "\$" ) # $ from the command |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 89 | handle.expect( "\$" ) # $ from the prompt |
| 90 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 91 | main.testSetUp.ONOSSetUp( main.Mininet1, cellName=cellName, removeLog=True, |
| 92 | extraApply=main.HA.customizeOnosGenPartitions, |
| 93 | extraClean=main.HA.cleanUpGenPartition ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 94 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 95 | main.HA.initialSetUp() |
Jon Hall | 9d2dcad | 2016-04-08 10:15:20 -0700 | [diff] [blame] | 96 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 97 | def CASE2( self, main ): |
| 98 | """ |
| 99 | Assign devices to controllers |
| 100 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 101 | main.HA.assignDevices( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 102 | |
| 103 | def CASE21( self, main ): |
| 104 | """ |
| 105 | Assign mastership to controllers |
| 106 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 107 | main.HA.assignMastership( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 108 | |
| 109 | def CASE3( self, main ): |
| 110 | """ |
| 111 | Assign intents |
| 112 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 113 | main.HA.assignIntents( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 114 | |
| 115 | def CASE4( self, main ): |
| 116 | """ |
| 117 | Ping across added host intents |
| 118 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 119 | main.HA.pingAcrossHostIntent( main, True, False ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 120 | |
| 121 | def CASE5( self, main ): |
| 122 | """ |
| 123 | Reading state of ONOS |
| 124 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 125 | main.HA.readingState( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 126 | |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 127 | def CASE61( self, main ): |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 128 | """ |
| 129 | The Failure case. |
| 130 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 131 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 132 | assert main, "main not defined" |
| 133 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 134 | assert main.CLIs, "main.CLIs not defined" |
| 135 | assert main.nodes, "main.nodes not defined" |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 136 | main.case( "Kill minority of ONOS nodes" ) |
Jon Hall | 96091e6 | 2015-09-21 17:34:17 -0700 | [diff] [blame] | 137 | |
| 138 | main.step( "Checking ONOS Logs for errors" ) |
| 139 | for node in main.nodes: |
| 140 | main.log.debug( "Checking logs for errors on " + node.name + ":" ) |
| 141 | main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) ) |
| 142 | |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 143 | n = len( main.nodes ) # Number of nodes |
| 144 | p = ( ( n + 1 ) / 2 ) + 1 # Number of partitions |
| 145 | main.kill = [ 0 ] # ONOS node to kill, listed by index in main.nodes |
| 146 | if n > 3: |
| 147 | main.kill.append( p - 1 ) |
| 148 | # NOTE: This only works for cluster sizes of 3,5, or 7. |
| 149 | |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 150 | main.step( "Kill " + str( len( main.kill ) ) + " ONOS nodes" ) |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 151 | killResults = main.TRUE |
| 152 | for i in main.kill: |
| 153 | killResults = killResults and\ |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 154 | main.ONOSbench.onosKill( main.nodes[ i ].ip_address ) |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 155 | main.activeNodes.remove( i ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 156 | utilities.assert_equals( expect=main.TRUE, actual=killResults, |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 157 | onpass="ONOS nodes killed successfully", |
| 158 | onfail="ONOS nodes NOT successfully killed" ) |
| 159 | |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 160 | main.step( "Checking ONOS nodes" ) |
| 161 | nodeResults = utilities.retry( main.HA.nodesCheck, |
| 162 | False, |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 163 | args=[ main.activeNodes ], |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 164 | sleep=15, |
| 165 | attempts=5 ) |
| 166 | |
| 167 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 168 | onpass="Nodes check successful", |
| 169 | onfail="Nodes check NOT successful" ) |
| 170 | |
| 171 | if not nodeResults: |
| 172 | for i in main.activeNodes: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 173 | cli = main.CLIs[ i ] |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 174 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
| 175 | cli.name, |
| 176 | cli.sendline( "scr:list | grep -v ACTIVE" ) ) ) |
| 177 | main.log.error( "Failed to start ONOS, stopping test" ) |
| 178 | main.cleanup() |
| 179 | main.exit() |
| 180 | |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 181 | def CASE62( self, main ): |
| 182 | """ |
| 183 | The bring up stopped nodes |
| 184 | """ |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 185 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 186 | main.HA.bringUpStoppedNode( main ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 187 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 188 | def CASE7( self, main ): |
| 189 | """ |
| 190 | Check state after ONOS failure |
| 191 | """ |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 192 | try: |
| 193 | main.kill |
| 194 | except AttributeError: |
| 195 | main.kill = [] |
| 196 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 197 | main.HA.checkStateAfterONOS( main, afterWhich=0 ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 198 | main.step( "Leadership Election is still functional" ) |
| 199 | # Test of LeadershipElection |
| 200 | leaderList = [] |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 201 | |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 202 | restarted = [] |
| 203 | for i in main.kill: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 204 | restarted.append( main.nodes[ i ].ip_address ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 205 | leaderResult = main.TRUE |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 206 | |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 207 | for i in main.activeNodes: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 208 | cli = main.CLIs[ i ] |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 209 | leaderN = cli.electionTestLeader() |
| 210 | leaderList.append( leaderN ) |
| 211 | if leaderN == main.FALSE: |
| 212 | # error in response |
| 213 | main.log.error( "Something is wrong with " + |
| 214 | "electionTestLeader function, check the" + |
| 215 | " error logs" ) |
| 216 | leaderResult = main.FALSE |
| 217 | elif leaderN is None: |
| 218 | main.log.error( cli.name + |
| 219 | " shows no leader for the election-app was" + |
| 220 | " elected after the old one died" ) |
| 221 | leaderResult = main.FALSE |
| 222 | elif leaderN in restarted: |
| 223 | main.log.error( cli.name + " shows " + str( leaderN ) + |
| 224 | " as leader for the election-app, but it " + |
| 225 | "was restarted" ) |
| 226 | leaderResult = main.FALSE |
| 227 | if len( set( leaderList ) ) != 1: |
| 228 | leaderResult = main.FALSE |
| 229 | main.log.error( |
| 230 | "Inconsistent view of leader for the election test app" ) |
| 231 | # TODO: print the list |
| 232 | utilities.assert_equals( |
| 233 | expect=main.TRUE, |
| 234 | actual=leaderResult, |
| 235 | onpass="Leadership election passed", |
| 236 | onfail="Something went wrong with Leadership election" ) |
| 237 | |
| 238 | def CASE8( self, main ): |
| 239 | """ |
| 240 | Compare topo |
| 241 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 242 | main.HA.compareTopo( main ) |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 243 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 244 | def CASE9( self, main ): |
| 245 | """ |
| 246 | Link s3-s28 down |
| 247 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 248 | main.HA.linkDown( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 249 | |
| 250 | def CASE10( self, main ): |
| 251 | """ |
| 252 | Link s3-s28 up |
| 253 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 254 | main.HA.linkUp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 255 | |
| 256 | def CASE11( self, main ): |
| 257 | """ |
| 258 | Switch Down |
| 259 | """ |
| 260 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 261 | main.HA.switchDown( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 262 | |
| 263 | def CASE12( self, main ): |
| 264 | """ |
| 265 | Switch Up |
| 266 | """ |
| 267 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 268 | main.HA.switchUp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 269 | |
| 270 | def CASE13( self, main ): |
| 271 | """ |
| 272 | Clean up |
| 273 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 274 | main.HAlabels.append( "Restart" ) |
| 275 | main.HAdata.append( str( main.restartTime ) ) |
| 276 | main.HA.cleanUp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 277 | |
| 278 | def CASE14( self, main ): |
| 279 | """ |
| 280 | start election app on all onos nodes |
| 281 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 282 | main.HA.startElectionApp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 283 | |
| 284 | def CASE15( self, main ): |
| 285 | """ |
| 286 | Check that Leadership Election is still functional |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 287 | 15.1 Run election on each node |
| 288 | 15.2 Check that each node has the same leaders and candidates |
| 289 | 15.3 Find current leader and withdraw |
| 290 | 15.4 Check that a new node was elected leader |
| 291 | 15.5 Check that that new leader was the candidate of old leader |
| 292 | 15.6 Run for election on old leader |
| 293 | 15.7 Check that oldLeader is a candidate, and leader if only 1 node |
| 294 | 15.8 Make sure that the old leader was added to the candidate list |
| 295 | |
| 296 | old and new variable prefixes refer to data from before vs after |
| 297 | withdrawl and later before withdrawl vs after re-election |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 298 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 299 | main.HA.isElectionFunctional( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 300 | |
| 301 | def CASE16( self, main ): |
| 302 | """ |
| 303 | Install Distributed Primitives app |
| 304 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 305 | main.HA.installDistributedPrimitiveApp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 306 | |
| 307 | def CASE17( self, main ): |
| 308 | """ |
| 309 | Check for basic functionality with distributed primitives |
| 310 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 311 | main.HA.checkDistPrimitivesFunc( main ) |