Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 1 | """ |
| 2 | Description: This test is to determine if the HA test setup is |
| 3 | working correctly. There are no failures so this test should |
| 4 | have a 100% pass rate |
| 5 | |
| 6 | List of test cases: |
| 7 | CASE1: Compile ONOS and push it to the test machines |
| 8 | CASE2: Assign devices to controllers |
| 9 | CASE21: Assign mastership to controllers |
| 10 | CASE3: Assign intents |
| 11 | CASE4: Ping across added host intents |
| 12 | CASE5: Reading state of ONOS |
| 13 | CASE6: The Failure case. Since this is the Sanity test, we do nothing. |
| 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 | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 26 | class HAsanity: |
| 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 | f3d16e7 | 2015-12-16 17:45:08 -0800 | [diff] [blame] | 50 | import time |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 51 | import json |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 52 | main.log.info( "ONOS HA Sanity test - initialization" ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 53 | # These are for csv plotting in jenkins |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 54 | main.HAlabels = [] |
| 55 | main.HAdata = [] |
| 56 | try: |
| 57 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 58 | main.testSetUp = ONOSSetup() |
| 59 | except ImportError: |
| 60 | main.log.error( "ONOSSetup not found exiting the test" ) |
| 61 | main.exit() |
| 62 | main.testSetUp.envSetupDescription() |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 63 | try: |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 64 | from tests.HA.dependencies.HA import HA |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 65 | main.HA = HA() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 66 | # load some variables from the params file |
| 67 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 68 | main.apps = main.params[ 'ENV' ][ 'appString' ] |
| 69 | main.numCtrls = int( main.params[ 'num_controllers' ] ) |
| 70 | if main.ONOSbench.maxNodes and \ |
| 71 | main.ONOSbench.maxNodes < main.numCtrls: |
| 72 | main.numCtrls = int( main.ONOSbench.maxNodes ) |
| 73 | main.maxNodes = main.numCtrls |
| 74 | stepResult = main.testSetUp.envSetup( hasNode=True ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 75 | except Exception as e: |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 76 | main.testSetUp.envSetupException( e ) |
| 77 | main.testSetUp.evnSetupConclusion( stepResult ) |
| 78 | main.HA.generateGraph( "HAsanity" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 79 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 80 | main.testSetUp.ONOSSetUp( main.Mininet1, cellName=cellName, removeLog=True, |
| 81 | extraApply=main.HA.startingMininet ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 82 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 83 | main.HA.initialSetUp() |
Jon Hall | 9d2dcad | 2016-04-08 10:15:20 -0700 | [diff] [blame] | 84 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 85 | def CASE2( self, main ): |
| 86 | """ |
| 87 | Assign devices to controllers |
| 88 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 89 | main.HA.assignDevices( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 90 | |
| 91 | def CASE21( self, main ): |
| 92 | """ |
| 93 | Assign mastership to controllers |
| 94 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 95 | main.HA.assignMastership( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 96 | |
| 97 | def CASE3( self, main ): |
| 98 | """ |
| 99 | Assign intents |
| 100 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 101 | main.HA.assignIntents( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 102 | |
| 103 | def CASE4( self, main ): |
| 104 | """ |
| 105 | Ping across added host intents |
| 106 | """ |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 107 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 108 | main.HA.pingAcrossHostIntent( main, True, True ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 109 | |
| 110 | def CASE5( self, main ): |
| 111 | """ |
| 112 | Reading state of ONOS |
| 113 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 114 | main.HA.readingState( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 115 | |
| 116 | def CASE6( self, main ): |
| 117 | """ |
| 118 | The Failure case. Since this is the Sanity test, we do nothing. |
| 119 | """ |
| 120 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 121 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 122 | assert main, "main not defined" |
| 123 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 124 | assert main.CLIs, "main.CLIs not defined" |
| 125 | assert main.nodes, "main.nodes not defined" |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 126 | main.case( "Wait 60 seconds instead of inducing a failure" ) |
| 127 | time.sleep( 60 ) |
| 128 | utilities.assert_equals( |
| 129 | expect=main.TRUE, |
| 130 | actual=main.TRUE, |
| 131 | onpass="Sleeping 60 seconds", |
| 132 | onfail="Something is terribly wrong with my math" ) |
| 133 | |
| 134 | def CASE7( self, main ): |
| 135 | """ |
| 136 | Check state after ONOS failure |
| 137 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 138 | main.HA.checkStateAfterONOS( main, afterWhich=0, compareSwitch=True ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 139 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 140 | main.step( "Leadership Election is still functional" ) |
| 141 | # Test of LeadershipElection |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 142 | leaderList = [] |
| 143 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 144 | # NOTE: this only works for the sanity test. In case of failures, |
| 145 | # leader will likely change |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 146 | leader = main.nodes[ main.activeNodes[ 0 ] ].ip_address |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 147 | leaderResult = main.TRUE |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 148 | |
| 149 | for i in main.activeNodes: |
Jon Hall | f37d44d | 2017-05-24 10:37:30 -0700 | [diff] [blame] | 150 | cli = main.CLIs[ i ] |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 151 | leaderN = cli.electionTestLeader() |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 152 | leaderList.append( leaderN ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 153 | # verify leader is ONOS1 |
| 154 | if leaderN == leader: |
| 155 | # all is well |
| 156 | # NOTE: In failure scenario, this could be a new node, maybe |
| 157 | # check != ONOS1 |
| 158 | pass |
| 159 | elif leaderN == main.FALSE: |
| 160 | # error in response |
| 161 | main.log.error( "Something is wrong with " + |
| 162 | "electionTestLeader function, check the" + |
| 163 | " error logs" ) |
| 164 | leaderResult = main.FALSE |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 165 | elif leaderN is None: |
| 166 | main.log.error( cli.name + |
| 167 | " shows no leader for the election-app was" + |
| 168 | " elected after the old one died" ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 169 | leaderResult = main.FALSE |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 170 | if len( set( leaderList ) ) != 1: |
| 171 | leaderResult = main.FALSE |
| 172 | main.log.error( |
| 173 | "Inconsistent view of leader for the election test app" ) |
| 174 | # TODO: print the list |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 175 | utilities.assert_equals( |
| 176 | expect=main.TRUE, |
| 177 | actual=leaderResult, |
| 178 | onpass="Leadership election passed", |
| 179 | onfail="Something went wrong with Leadership election" ) |
| 180 | |
| 181 | def CASE8( self, main ): |
| 182 | """ |
| 183 | Compare topo |
| 184 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 185 | main.HA.compareTopo( main ) |
Jon Hall | d2871c2 | 2016-07-26 11:01:14 -0700 | [diff] [blame] | 186 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 187 | def CASE9( self, main ): |
| 188 | """ |
| 189 | Link s3-s28 down |
| 190 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 191 | main.HA.linkDown( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 192 | |
| 193 | def CASE10( self, main ): |
| 194 | """ |
| 195 | Link s3-s28 up |
| 196 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 197 | main.HA.linkUp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 198 | |
| 199 | def CASE11( self, main ): |
| 200 | """ |
| 201 | Switch Down |
| 202 | """ |
| 203 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 204 | main.HA.switchDown( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 205 | |
| 206 | def CASE12( self, main ): |
| 207 | """ |
| 208 | Switch Up |
| 209 | """ |
| 210 | # NOTE: You should probably run a topology check after this |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 211 | main.HA.switchUp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 212 | |
| 213 | def CASE13( self, main ): |
| 214 | """ |
| 215 | Clean up |
| 216 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 217 | main.HA.cleanUp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 218 | |
| 219 | def CASE14( self, main ): |
| 220 | """ |
| 221 | start election app on all onos nodes |
| 222 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 223 | main.HA.startElectionApp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 224 | |
| 225 | def CASE15( self, main ): |
| 226 | """ |
| 227 | Check that Leadership Election is still functional |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 228 | 15.1 Run election on each node |
| 229 | 15.2 Check that each node has the same leaders and candidates |
| 230 | 15.3 Find current leader and withdraw |
| 231 | 15.4 Check that a new node was elected leader |
| 232 | 15.5 Check that that new leader was the candidate of old leader |
| 233 | 15.6 Run for election on old leader |
| 234 | 15.7 Check that oldLeader is a candidate, and leader if only 1 node |
| 235 | 15.8 Make sure that the old leader was added to the candidate list |
| 236 | |
| 237 | old and new variable prefixes refer to data from before vs after |
| 238 | withdrawl and later before withdrawl vs after re-election |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 239 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 240 | main.HA.isElectionFunctional( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 241 | |
| 242 | def CASE16( self, main ): |
| 243 | """ |
| 244 | Install Distributed Primitives app |
| 245 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 246 | main.HA.installDistributedPrimitiveApp( main ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 247 | |
| 248 | def CASE17( self, main ): |
| 249 | """ |
| 250 | Check for basic functionality with distributed primitives |
| 251 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 252 | main.HA.checkDistPrimitivesFunc( main ) |