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 HAstopNodes: |
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 | f3d16e7 | 2015-12-16 17:45:08 -0800 | [diff] [blame] | 51 | import time |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 52 | import json |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 53 | main.log.info( "ONOS HA test: Stop a minority of ONOS nodes - " + |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 54 | "initialization" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -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( "HAstopNodes" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 82 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 83 | main.testSetUp.ONOSSetUp( main.Mininet1, cellName=cellName, removeLog=True, |
| 84 | extraApply=main.HA.customizeOnosGenPartitions, |
| 85 | extraClean=main.HA.cleanUpGenPartition ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 86 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 87 | main.HA.initialSetUp() |
Jon Hall | 9d2dcad | 2016-04-08 10:15:20 -0700 | [diff] [blame] | 88 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 89 | def CASE2( self, main ): |
| 90 | """ |
| 91 | Assign devices to controllers |
| 92 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 93 | main.HA.assignDevices( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 94 | |
| 95 | def CASE21( self, main ): |
| 96 | """ |
| 97 | Assign mastership to controllers |
| 98 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 99 | main.HA.assignMastership( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 100 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 101 | |
| 102 | def CASE3( self, main ): |
| 103 | """ |
| 104 | Assign intents |
| 105 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 106 | main.HA.assignIntents( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 107 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 108 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 109 | |
| 110 | def CASE4( self, main ): |
| 111 | """ |
| 112 | Ping across added host intents |
| 113 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 114 | main.HA.pingAcrossHostIntent( main, True, False ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 115 | |
| 116 | def CASE5( self, main ): |
| 117 | """ |
| 118 | Reading state of ONOS |
| 119 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 120 | main.HA.readingState( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 121 | |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 122 | def CASE61( self, main ): |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 123 | """ |
| 124 | The Failure case. |
| 125 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 126 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 127 | assert main, "main not defined" |
| 128 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 129 | assert main.CLIs, "main.CLIs not defined" |
| 130 | assert main.nodes, "main.nodes not defined" |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 131 | main.case( "Stop minority of ONOS nodes" ) |
Jon Hall | 96091e6 | 2015-09-21 17:34:17 -0700 | [diff] [blame] | 132 | |
| 133 | main.step( "Checking ONOS Logs for errors" ) |
| 134 | for node in main.nodes: |
| 135 | main.log.debug( "Checking logs for errors on " + node.name + ":" ) |
| 136 | main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) ) |
| 137 | |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 138 | n = len( main.nodes ) # Number of nodes |
| 139 | p = ( ( n + 1 ) / 2 ) + 1 # Number of partitions |
| 140 | main.kill = [ 0 ] # ONOS node to kill, listed by index in main.nodes |
| 141 | if n > 3: |
| 142 | main.kill.append( p - 1 ) |
| 143 | # NOTE: This only works for cluster sizes of 3,5, or 7. |
| 144 | |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 145 | main.step( "Stopping " + str( len( main.kill ) ) + " ONOS nodes" ) |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 146 | killResults = main.TRUE |
| 147 | for i in main.kill: |
| 148 | killResults = killResults and\ |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 149 | main.ONOSbench.onosStop( main.nodes[ i ].ip_address ) |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 150 | main.activeNodes.remove( i ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 151 | utilities.assert_equals( expect=main.TRUE, actual=killResults, |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 152 | onpass="ONOS nodes stopped successfully", |
| 153 | onfail="ONOS nodes NOT successfully stopped" ) |
| 154 | |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 155 | main.step( "Checking ONOS nodes" ) |
| 156 | nodeResults = utilities.retry( main.HA.nodesCheck, |
| 157 | False, |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 158 | args=[ main.activeNodes ], |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 159 | sleep=15, |
| 160 | attempts=5 ) |
| 161 | |
| 162 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 163 | onpass="Nodes check successful", |
| 164 | onfail="Nodes check NOT successful" ) |
| 165 | |
| 166 | if not nodeResults: |
| 167 | for i in main.activeNodes: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 168 | cli = main.CLIs[ i ] |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 169 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
| 170 | cli.name, |
| 171 | cli.sendline( "scr:list | grep -v ACTIVE" ) ) ) |
| 172 | main.log.error( "Failed to start ONOS, stopping test" ) |
| 173 | main.cleanup() |
| 174 | main.exit() |
| 175 | |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 176 | def CASE62( self, main ): |
| 177 | """ |
| 178 | The bring up stopped nodes |
| 179 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 180 | main.HA.bringUpStoppedNode( main ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 181 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 182 | def CASE7( self, main ): |
| 183 | """ |
| 184 | Check state after ONOS failure |
| 185 | """ |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 186 | try: |
| 187 | main.kill |
| 188 | except AttributeError: |
| 189 | main.kill = [] |
| 190 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 191 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 192 | main.HA.checkStateAfterONOS( main, afterWhich=0 ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 193 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 194 | main.step( "Leadership Election is still functional" ) |
| 195 | # Test of LeadershipElection |
| 196 | leaderList = [] |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 197 | |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 198 | restarted = [] |
| 199 | for i in main.kill: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 200 | restarted.append( main.nodes[ i ].ip_address ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 201 | leaderResult = main.TRUE |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 202 | |
Jon Hall | b3ed8ed | 2015-10-28 16:43:55 -0700 | [diff] [blame] | 203 | for i in main.activeNodes: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 204 | cli = main.CLIs[ i ] |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 205 | leaderN = cli.electionTestLeader() |
| 206 | leaderList.append( leaderN ) |
| 207 | if leaderN == main.FALSE: |
| 208 | # error in response |
| 209 | main.log.error( "Something is wrong with " + |
| 210 | "electionTestLeader function, check the" + |
| 211 | " error logs" ) |
| 212 | leaderResult = main.FALSE |
| 213 | elif leaderN is None: |
| 214 | main.log.error( cli.name + |
| 215 | " shows no leader for the election-app was" + |
| 216 | " elected after the old one died" ) |
| 217 | leaderResult = main.FALSE |
| 218 | elif leaderN in restarted: |
| 219 | main.log.error( cli.name + " shows " + str( leaderN ) + |
| 220 | " as leader for the election-app, but it " + |
| 221 | "was restarted" ) |
| 222 | leaderResult = main.FALSE |
| 223 | if len( set( leaderList ) ) != 1: |
| 224 | leaderResult = main.FALSE |
| 225 | main.log.error( |
| 226 | "Inconsistent view of leader for the election test app" ) |
| 227 | # TODO: print the list |
| 228 | utilities.assert_equals( |
| 229 | expect=main.TRUE, |
| 230 | actual=leaderResult, |
| 231 | onpass="Leadership election passed", |
| 232 | onfail="Something went wrong with Leadership election" ) |
| 233 | |
| 234 | def CASE8( self, main ): |
| 235 | """ |
| 236 | Compare topo |
| 237 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 238 | main.HA.compareTopo( main ) |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 239 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 240 | def CASE9( self, main ): |
| 241 | """ |
| 242 | Link s3-s28 down |
| 243 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 244 | main.HA.linkDown( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 245 | |
| 246 | def CASE10( self, main ): |
| 247 | """ |
| 248 | Link s3-s28 up |
| 249 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 250 | main.HA.linkUp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 251 | |
| 252 | def CASE11( self, main ): |
| 253 | """ |
| 254 | Switch Down |
| 255 | """ |
| 256 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 257 | main.HA.switchDown( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 258 | |
| 259 | def CASE12( self, main ): |
| 260 | """ |
| 261 | Switch Up |
| 262 | """ |
| 263 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 264 | main.HA.switchUp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 265 | |
| 266 | def CASE13( self, main ): |
| 267 | """ |
| 268 | Clean up |
| 269 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 270 | main.HAlabels.append( "Restart" ) |
| 271 | main.HAdata.append( str( main.restartTime ) ) |
| 272 | main.HA.cleanUp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 273 | |
| 274 | def CASE14( self, main ): |
| 275 | """ |
| 276 | start election app on all onos nodes |
| 277 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 278 | main.HA.startElectionApp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 279 | |
| 280 | def CASE15( self, main ): |
| 281 | """ |
| 282 | Check that Leadership Election is still functional |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 283 | 15.1 Run election on each node |
| 284 | 15.2 Check that each node has the same leaders and candidates |
| 285 | 15.3 Find current leader and withdraw |
| 286 | 15.4 Check that a new node was elected leader |
| 287 | 15.5 Check that that new leader was the candidate of old leader |
| 288 | 15.6 Run for election on old leader |
| 289 | 15.7 Check that oldLeader is a candidate, and leader if only 1 node |
| 290 | 15.8 Make sure that the old leader was added to the candidate list |
| 291 | |
| 292 | old and new variable prefixes refer to data from before vs after |
| 293 | withdrawl and later before withdrawl vs after re-election |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 294 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 295 | main.HA.isElectionFunctional( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 296 | |
| 297 | def CASE16( self, main ): |
| 298 | """ |
| 299 | Install Distributed Primitives app |
| 300 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 301 | main.HA.installDistributedPrimitiveApp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 302 | |
| 303 | def CASE17( self, main ): |
| 304 | """ |
| 305 | Check for basic functionality with distributed primitives |
| 306 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 307 | main.HA.checkDistPrimitivesFunc( main ) |