Jon Hall | b548801 | 2017-06-21 14:08:36 -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 |
| 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 | """ |
| 26 | class HAcontinuousStopNodes: |
| 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 |
| 52 | import json |
| 53 | main.log.info( "ONOS HA test: Stop a minority of ONOS nodes - " + |
| 54 | "initialization" ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 55 | # set global variables |
Jon Hall | b548801 | 2017-06-21 14:08:36 -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 | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 66 | try: |
| 67 | from tests.HA.dependencies.HA import HA |
| 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 | b548801 | 2017-06-21 14:08:36 -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( "HAcontinuousStopNodes" ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -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 | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 86 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 87 | main.HA.initialSetUp() |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 88 | |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 89 | |
| 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 | b548801 | 2017-06-21 14:08:36 -0700 | [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 | b548801 | 2017-06-21 14:08:36 -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 | b548801 | 2017-06-21 14:08:36 -0700 | [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, False ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [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 | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 119 | |
| 120 | def CASE61( self, main ): |
| 121 | """ |
| 122 | The Failure case. |
| 123 | """ |
| 124 | assert main.numCtrls, "main.numCtrls not defined" |
| 125 | assert main, "main not defined" |
| 126 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 127 | assert main.CLIs, "main.CLIs not defined" |
| 128 | assert main.nodes, "main.nodes not defined" |
| 129 | try: |
| 130 | assert main.nodeIndex is not None, "main.nodeIndex not defined" |
| 131 | assert main.killCount is not None, "main.killCount not defined" |
| 132 | except AttributeError as e: |
| 133 | main.log.warn( "Node to kill not selected, defaulting to node 1" ) |
| 134 | main.nodeIndex = 0 |
| 135 | main.killCount = 1 |
| 136 | |
| 137 | main.case( "Stopping ONOS nodes - iteration " + str( main.killCount ) ) |
| 138 | |
| 139 | main.step( "Checking ONOS Logs for errors" ) |
| 140 | for node in main.nodes: |
| 141 | main.log.debug( "Checking logs for errors on " + node.name + ":" ) |
| 142 | main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) ) |
| 143 | |
| 144 | # NOTE: For now only kill one node. If we move to killing more, we need to |
| 145 | # make sure we don't lose any partitions |
| 146 | n = len( main.nodes ) # Number of nodes |
| 147 | main.nodeIndex = ( main.nodeIndex + 1 ) % n |
| 148 | main.kill = [ main.nodeIndex ] # ONOS node to kill, listed by index in main.nodes |
| 149 | |
| 150 | # TODO: Be able to configure bringing up old node vs. a new/fresh installation |
| 151 | main.step( "Stopping " + str( len( main.kill ) ) + " ONOS nodes" ) |
| 152 | killResults = main.TRUE |
| 153 | for i in main.kill: |
| 154 | killResults = killResults and\ |
| 155 | main.ONOSbench.onosStop( main.nodes[ i ].ip_address ) |
| 156 | main.activeNodes.remove( i ) |
| 157 | utilities.assert_equals( expect=main.TRUE, actual=killResults, |
| 158 | onpass="ONOS nodes stopped successfully", |
| 159 | onfail="ONOS nodes NOT successfully stopped" ) |
| 160 | |
| 161 | main.step( "Checking ONOS nodes" ) |
| 162 | nodeResults = utilities.retry( main.HA.nodesCheck, |
| 163 | False, |
| 164 | args=[ main.activeNodes ], |
| 165 | sleep=15, |
| 166 | attempts=5 ) |
| 167 | |
| 168 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 169 | onpass="Nodes check successful", |
| 170 | onfail="Nodes check NOT successful" ) |
| 171 | |
| 172 | if not nodeResults: |
| 173 | for i in main.activeNodes: |
| 174 | cli = main.CLIs[ i ] |
| 175 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
| 176 | cli.name, |
| 177 | cli.sendline( "scr:list | grep -v ACTIVE" ) ) ) |
| 178 | main.log.error( "Failed to start ONOS, stopping test" ) |
| 179 | main.cleanup() |
| 180 | main.exit() |
| 181 | |
| 182 | main.killCount += 1 |
| 183 | |
| 184 | def CASE62( self, main ): |
| 185 | """ |
| 186 | The bring up stopped nodes |
| 187 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 188 | main.HA.bringUpStoppedNode( main ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 189 | |
| 190 | def CASE7( self, main ): |
| 191 | """ |
| 192 | Check state after ONOS failure |
| 193 | """ |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 194 | try: |
| 195 | main.kill |
| 196 | except AttributeError: |
| 197 | main.kill = [] |
| 198 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 199 | main.HA.checkStateAfterONOS( main, afterWhich=0 ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 200 | |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 201 | main.step( "Leadership Election is still functional" ) |
| 202 | # Test of LeadershipElection |
| 203 | leaderList = [] |
| 204 | |
| 205 | restarted = [] |
| 206 | for i in main.kill: |
| 207 | restarted.append( main.nodes[ i ].ip_address ) |
| 208 | leaderResult = main.TRUE |
| 209 | |
| 210 | for i in main.activeNodes: |
| 211 | cli = main.CLIs[ i ] |
| 212 | leaderN = cli.electionTestLeader() |
| 213 | leaderList.append( leaderN ) |
| 214 | if leaderN == main.FALSE: |
| 215 | # error in response |
| 216 | main.log.error( "Something is wrong with " + |
| 217 | "electionTestLeader function, check the" + |
| 218 | " error logs" ) |
| 219 | leaderResult = main.FALSE |
| 220 | elif leaderN is None: |
| 221 | main.log.error( cli.name + |
| 222 | " shows no leader for the election-app was" + |
| 223 | " elected after the old one died" ) |
| 224 | leaderResult = main.FALSE |
| 225 | elif leaderN in restarted: |
| 226 | main.log.error( cli.name + " shows " + str( leaderN ) + |
| 227 | " as leader for the election-app, but it " + |
| 228 | "was restarted" ) |
| 229 | leaderResult = main.FALSE |
| 230 | if len( set( leaderList ) ) != 1: |
| 231 | leaderResult = main.FALSE |
| 232 | main.log.error( |
| 233 | "Inconsistent view of leader for the election test app" ) |
| 234 | # TODO: print the list |
| 235 | utilities.assert_equals( |
| 236 | expect=main.TRUE, |
| 237 | actual=leaderResult, |
| 238 | onpass="Leadership election passed", |
| 239 | onfail="Something went wrong with Leadership election" ) |
| 240 | |
| 241 | def CASE8( self, main ): |
| 242 | """ |
| 243 | Compare topo |
| 244 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 245 | main.HA.compareTopo( main ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 246 | |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 247 | |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 248 | |
| 249 | def CASE9( self, main ): |
| 250 | """ |
| 251 | Link s3-s28 down |
| 252 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 253 | main.HA.linkDown( main ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 254 | |
| 255 | def CASE10( self, main ): |
| 256 | """ |
| 257 | Link s3-s28 up |
| 258 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 259 | main.HA.linkUp( main ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 260 | |
| 261 | def CASE11( self, main ): |
| 262 | """ |
| 263 | Switch Down |
| 264 | """ |
| 265 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 266 | main.HA.switchDown( main ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 267 | |
| 268 | def CASE12( self, main ): |
| 269 | """ |
| 270 | Switch Up |
| 271 | """ |
| 272 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 273 | main.HA.switchUp( main ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 274 | |
| 275 | def CASE13( self, main ): |
| 276 | """ |
| 277 | Clean up |
| 278 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 279 | main.HAlabels.append( "Restart" ) |
| 280 | main.HAdata.append( str( main.restartTime ) ) |
| 281 | main.HA.cleanUp( main ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 282 | |
| 283 | def CASE14( self, main ): |
| 284 | """ |
| 285 | start election app on all onos nodes |
| 286 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 287 | main.HA.startElectionApp( main ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 288 | |
| 289 | def CASE15( self, main ): |
| 290 | """ |
| 291 | Check that Leadership Election is still functional |
| 292 | 15.1 Run election on each node |
| 293 | 15.2 Check that each node has the same leaders and candidates |
| 294 | 15.3 Find current leader and withdraw |
| 295 | 15.4 Check that a new node was elected leader |
| 296 | 15.5 Check that that new leader was the candidate of old leader |
| 297 | 15.6 Run for election on old leader |
| 298 | 15.7 Check that oldLeader is a candidate, and leader if only 1 node |
| 299 | 15.8 Make sure that the old leader was added to the candidate list |
| 300 | |
| 301 | old and new variable prefixes refer to data from before vs after |
| 302 | withdrawl and later before withdrawl vs after re-election |
| 303 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 304 | main.HA.isElectionFunctional( main ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 305 | |
| 306 | def CASE16( self, main ): |
| 307 | """ |
| 308 | Install Distributed Primitives app |
| 309 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 310 | main.HA.installDistributedPrimitiveApp( main ) |
Jon Hall | b548801 | 2017-06-21 14:08:36 -0700 | [diff] [blame] | 311 | |
| 312 | def CASE17( self, main ): |
| 313 | """ |
| 314 | Check for basic functionality with distributed primitives |
| 315 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 316 | main.HA.checkDistPrimitivesFunc( main ) |