Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 1 | """ |
| 2 | Description: This test is to determine if ONOS can handle |
| 3 | a full network partion |
| 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 |
| 12 | CASE61: The Failure inducing case. |
| 13 | CASE62: The Failure recovery case. |
| 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 | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 26 | class HAfullNetPartition: |
| 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 | """ |
| 49 | import imp |
| 50 | import pexpect |
| 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: Partition ONOS nodes into two sub-clusters - " + |
| 54 | "initialization" ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [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 | 6e70975 | 2016-02-01 13:38:46 -0800 | [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 | 6e70975 | 2016-02-01 13:38:46 -0800 | [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( "HAfullNetPartition" ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [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 | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 86 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 87 | main.HA.initialSetUp() |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 88 | |
Jon Hall | 9d2dcad | 2016-04-08 10:15:20 -0700 | [diff] [blame] | 89 | |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 90 | def CASE2( self, main ): |
| 91 | """ |
| 92 | Assign devices to controllers |
| 93 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 94 | main.HA.assignDevices( main ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 95 | |
| 96 | def CASE21( self, main ): |
| 97 | """ |
| 98 | Assign mastership to controllers |
| 99 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 100 | main.HA.assignMastership( main ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [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 | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 107 | |
| 108 | def CASE4( self, main ): |
| 109 | """ |
| 110 | Ping across added host intents |
| 111 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 112 | main.HA.pingAcrossHostIntent( main, True, True ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 113 | |
| 114 | def CASE5( self, main ): |
| 115 | """ |
| 116 | Reading state of ONOS |
| 117 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 118 | main.HA.readingState( main ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 119 | |
| 120 | def CASE61( self, main ): |
| 121 | """ |
| 122 | The Failure case. |
| 123 | """ |
| 124 | import math |
| 125 | assert main.numCtrls, "main.numCtrls not defined" |
| 126 | assert main, "main not defined" |
| 127 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 128 | assert main.CLIs, "main.CLIs not defined" |
| 129 | assert main.nodes, "main.nodes not defined" |
| 130 | main.case( "Partition ONOS nodes into two distinct partitions" ) |
| 131 | |
| 132 | main.step( "Checking ONOS Logs for errors" ) |
| 133 | for node in main.nodes: |
| 134 | main.log.debug( "Checking logs for errors on " + node.name + ":" ) |
| 135 | main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) ) |
| 136 | |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 137 | main.log.debug( main.CLIs[ 0 ].roles( jsonFormat=False ) ) |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 138 | |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 139 | n = len( main.nodes ) # Number of nodes |
| 140 | p = ( ( n + 1 ) / 2 ) + 1 # Number of partitions |
| 141 | main.partition = [ 0 ] # ONOS node to partition, listed by index in main.nodes |
| 142 | if n > 3: |
| 143 | main.partition.append( p - 1 ) |
| 144 | # NOTE: This only works for cluster sizes of 3,5, or 7. |
| 145 | |
| 146 | main.step( "Partitioning ONOS nodes" ) |
| 147 | nodeList = [ str( i + 1 ) for i in main.partition ] |
| 148 | main.log.info( "Nodes to be partitioned: " + str( nodeList ) ) |
| 149 | partitionResults = main.TRUE |
| 150 | for i in range( 0, n ): |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 151 | this = main.nodes[ i ] |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 152 | if i not in main.partition: |
| 153 | for j in main.partition: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 154 | foe = main.nodes[ j ] |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 155 | main.log.warn( "Setting IP Tables rule from {} to {}. ".format( this.ip_address, foe.ip_address ) ) |
| 156 | #CMD HERE |
| 157 | cmdStr = "sudo iptables -A {} -d {} -s {} -j DROP".format( "INPUT", this.ip_address, foe.ip_address ) |
| 158 | this.handle.sendline( cmdStr ) |
| 159 | this.handle.expect( "\$" ) |
| 160 | main.log.debug( this.handle.before ) |
| 161 | else: |
| 162 | for j in range( 0, n ): |
| 163 | if j not in main.partition: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 164 | foe = main.nodes[ j ] |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 165 | main.log.warn( "Setting IP Tables rule from {} to {}. ".format( this.ip_address, foe.ip_address ) ) |
| 166 | #CMD HERE |
| 167 | cmdStr = "sudo iptables -A {} -d {} -s {} -j DROP".format( "INPUT", this.ip_address, foe.ip_address ) |
| 168 | this.handle.sendline( cmdStr ) |
| 169 | this.handle.expect( "\$" ) |
| 170 | main.log.debug( this.handle.before ) |
| 171 | main.activeNodes.remove( i ) |
| 172 | # NOTE: When dynamic clustering is finished, we need to start checking |
| 173 | # main.partion nodes still work when partitioned |
| 174 | utilities.assert_equals( expect=main.TRUE, actual=partitionResults, |
| 175 | onpass="Firewall rules set successfully", |
| 176 | onfail="Error setting firewall rules" ) |
| 177 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 178 | main.step( "Sleeping 60 seconds" ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 179 | time.sleep( 60 ) |
| 180 | |
| 181 | def CASE62( self, main ): |
| 182 | """ |
| 183 | Healing Partition |
| 184 | """ |
| 185 | import time |
| 186 | assert main.numCtrls, "main.numCtrls not defined" |
| 187 | assert main, "main not defined" |
| 188 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 189 | assert main.CLIs, "main.CLIs not defined" |
| 190 | assert main.nodes, "main.nodes not defined" |
| 191 | assert main.partition, "main.partition not defined" |
| 192 | main.case( "Healing Partition" ) |
| 193 | |
| 194 | main.step( "Deleteing firewall rules" ) |
| 195 | healResults = main.TRUE |
| 196 | for node in main.nodes: |
| 197 | cmdStr = "sudo iptables -F" |
| 198 | node.handle.sendline( cmdStr ) |
| 199 | node.handle.expect( "\$" ) |
| 200 | main.log.debug( node.handle.before ) |
| 201 | utilities.assert_equals( expect=main.TRUE, actual=healResults, |
| 202 | onpass="Firewall rules removed", |
| 203 | onfail="Error removing firewall rules" ) |
| 204 | |
| 205 | for node in main.partition: |
| 206 | main.activeNodes.append( node ) |
| 207 | main.activeNodes.sort() |
| 208 | try: |
| 209 | assert list( set( main.activeNodes ) ) == main.activeNodes,\ |
| 210 | "List of active nodes has duplicates, this likely indicates something was run out of order" |
| 211 | except AssertionError: |
| 212 | main.log.exception( "" ) |
| 213 | main.cleanup() |
| 214 | main.exit() |
| 215 | |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 216 | main.step( "Checking ONOS nodes" ) |
| 217 | nodeResults = utilities.retry( main.HA.nodesCheck, |
| 218 | False, |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 219 | args=[ main.activeNodes ], |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 220 | sleep=15, |
| 221 | attempts=5 ) |
| 222 | |
| 223 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 224 | onpass="Nodes check successful", |
| 225 | onfail="Nodes check NOT successful" ) |
| 226 | |
| 227 | if not nodeResults: |
| 228 | for i in main.activeNodes: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 229 | cli = main.CLIs[ i ] |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 230 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
| 231 | cli.name, |
| 232 | cli.sendline( "scr:list | grep -v ACTIVE" ) ) ) |
| 233 | main.log.error( "Failed to start ONOS, stopping test" ) |
| 234 | main.cleanup() |
| 235 | main.exit() |
| 236 | |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 237 | def CASE7( self, main ): |
| 238 | """ |
| 239 | Check state after ONOS failure |
| 240 | """ |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 241 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 242 | main.HA.checkStateAfterONOS( main, afterWhich=0 ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 243 | |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 244 | main.step( "Leadership Election is still functional" ) |
| 245 | # Test of LeadershipElection |
| 246 | leaderList = [] |
| 247 | |
| 248 | partitioned = [] |
| 249 | for i in main.partition: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 250 | partitioned.append( main.nodes[ i ].ip_address ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 251 | leaderResult = main.TRUE |
| 252 | |
| 253 | for i in main.activeNodes: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 254 | cli = main.CLIs[ i ] |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 255 | leaderN = cli.electionTestLeader() |
| 256 | leaderList.append( leaderN ) |
| 257 | if leaderN == main.FALSE: |
| 258 | # error in response |
| 259 | main.log.error( "Something is wrong with " + |
| 260 | "electionTestLeader function, check the" + |
| 261 | " error logs" ) |
| 262 | leaderResult = main.FALSE |
| 263 | elif leaderN is None: |
| 264 | main.log.error( cli.name + |
| 265 | " shows no leader for the election-app was" + |
| 266 | " elected after the old one died" ) |
| 267 | leaderResult = main.FALSE |
| 268 | elif leaderN in partitioned: |
| 269 | main.log.error( cli.name + " shows " + str( leaderN ) + |
| 270 | " as leader for the election-app, but it " + |
| 271 | "was partitioned" ) |
| 272 | leaderResult = main.FALSE |
| 273 | if len( set( leaderList ) ) != 1: |
| 274 | leaderResult = main.FALSE |
| 275 | main.log.error( |
| 276 | "Inconsistent view of leader for the election test app" ) |
| 277 | # TODO: print the list |
| 278 | utilities.assert_equals( |
| 279 | expect=main.TRUE, |
| 280 | actual=leaderResult, |
| 281 | onpass="Leadership election passed", |
| 282 | onfail="Something went wrong with Leadership election" ) |
| 283 | |
| 284 | def CASE8( self, main ): |
| 285 | """ |
| 286 | Compare topo |
| 287 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 288 | main.HA.compareTopo( main ) |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 289 | |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 290 | def CASE9( self, main ): |
| 291 | """ |
| 292 | Link s3-s28 down |
| 293 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 294 | main.HA.linkDown( main ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 295 | |
| 296 | def CASE10( self, main ): |
| 297 | """ |
| 298 | Link s3-s28 up |
| 299 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 300 | main.HA.linkUp( main ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 301 | |
| 302 | def CASE11( self, main ): |
| 303 | """ |
| 304 | Switch Down |
| 305 | """ |
| 306 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 307 | main.HA.switchDown( main ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 308 | |
| 309 | def CASE12( self, main ): |
| 310 | """ |
| 311 | Switch Up |
| 312 | """ |
| 313 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 314 | main.HA.switchUp( main ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 315 | |
| 316 | def CASE13( self, main ): |
| 317 | """ |
| 318 | Clean up |
| 319 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 320 | main.HA.cleanUp( main ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 321 | |
| 322 | def CASE14( self, main ): |
| 323 | """ |
| 324 | start election app on all onos nodes |
| 325 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 326 | main.HA.startElectionApp( main ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 327 | |
| 328 | def CASE15( self, main ): |
| 329 | """ |
| 330 | Check that Leadership Election is still functional |
| 331 | 15.1 Run election on each node |
| 332 | 15.2 Check that each node has the same leaders and candidates |
| 333 | 15.3 Find current leader and withdraw |
| 334 | 15.4 Check that a new node was elected leader |
| 335 | 15.5 Check that that new leader was the candidate of old leader |
| 336 | 15.6 Run for election on old leader |
| 337 | 15.7 Check that oldLeader is a candidate, and leader if only 1 node |
| 338 | 15.8 Make sure that the old leader was added to the candidate list |
| 339 | |
| 340 | old and new variable prefixes refer to data from before vs after |
| 341 | withdrawl and later before withdrawl vs after re-election |
| 342 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 343 | main.HA.isElectionFunctional( main ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 344 | |
| 345 | def CASE16( self, main ): |
| 346 | """ |
| 347 | Install Distributed Primitives app |
| 348 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 349 | main.HA.installDistributedPrimitiveApp( main ) |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 350 | |
| 351 | def CASE17( self, main ): |
| 352 | """ |
| 353 | Check for basic functionality with distributed primitives |
| 354 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 355 | main.HA.checkDistPrimitivesFunc( main ) |