blob: c40c785202a87369d039a737adff1af56e595607 [file] [log] [blame]
Jon Hall5cf14d52015-07-16 12:15:19 -07001"""
2Description: 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
6List of test cases:
7CASE1: Compile ONOS and push it to the test machines
8CASE2: Assign devices to controllers
9CASE21: Assign mastership to controllers
10CASE3: Assign intents
11CASE4: Ping across added host intents
12CASE5: Reading state of ONOS
13CASE6: The Failure case. Since this is the Sanity test, we do nothing.
14CASE7: Check state after control plane failure
15CASE8: Compare topo
16CASE9: Link s3-s28 down
17CASE10: Link s3-s28 up
18CASE11: Switch down
19CASE12: Switch up
20CASE13: Clean up
21CASE14: start election app on all onos nodes
22CASE15: Check that Leadership Election is still functional
23CASE16: Install Distributed Primitives app
24CASE17: Check for basic functionality with distributed primitives
25"""
Jon Hall5cf14d52015-07-16 12:15:19 -070026class 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 Halle1a3b752015-07-22 13:02:46 -070049 import imp
Jon Hallf3d16e72015-12-16 17:45:08 -080050 import time
Jon Halla440e872016-03-31 15:15:50 -070051 import json
Jon Hall5cf14d52015-07-16 12:15:19 -070052 main.log.info( "ONOS HA Sanity test - initialization" )
Jon Halla440e872016-03-31 15:15:50 -070053 # These are for csv plotting in jenkins
Devin Lim58046fa2017-07-05 16:55:00 -070054 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 Halle1a3b752015-07-22 13:02:46 -070063 try:
Jon Hall53c5e662016-04-13 16:06:56 -070064 from tests.HA.dependencies.HA import HA
Jon Hall41d39f12016-04-11 22:54:35 -070065 main.HA = HA()
Devin Lim58046fa2017-07-05 16:55:00 -070066 # 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 Halle1a3b752015-07-22 13:02:46 -070075 except Exception as e:
Devin Lim58046fa2017-07-05 16:55:00 -070076 main.testSetUp.envSetupException( e )
77 main.testSetUp.evnSetupConclusion( stepResult )
78 main.HA.generateGraph( "HAsanity" )
Jon Halle1a3b752015-07-22 13:02:46 -070079
Devin Lim58046fa2017-07-05 16:55:00 -070080 main.testSetUp.ONOSSetUp( main.Mininet1, cellName=cellName, removeLog=True,
81 extraApply=main.HA.startingMininet )
Jon Hall5cf14d52015-07-16 12:15:19 -070082
Devin Lim58046fa2017-07-05 16:55:00 -070083 main.HA.initialSetUp()
Jon Hall9d2dcad2016-04-08 10:15:20 -070084
Jon Hall5cf14d52015-07-16 12:15:19 -070085 def CASE2( self, main ):
86 """
87 Assign devices to controllers
88 """
Devin Lim58046fa2017-07-05 16:55:00 -070089 main.HA.assignDevices( main )
Jon Hall5cf14d52015-07-16 12:15:19 -070090
91 def CASE21( self, main ):
92 """
93 Assign mastership to controllers
94 """
Devin Lim58046fa2017-07-05 16:55:00 -070095 main.HA.assignMastership( main )
Jon Hall5cf14d52015-07-16 12:15:19 -070096
97 def CASE3( self, main ):
98 """
99 Assign intents
100 """
Devin Lim58046fa2017-07-05 16:55:00 -0700101 main.HA.assignIntents( main )
Jon Hall5cf14d52015-07-16 12:15:19 -0700102
103 def CASE4( self, main ):
104 """
105 Ping across added host intents
106 """
Jon Hall5cf14d52015-07-16 12:15:19 -0700107
Devin Lim58046fa2017-07-05 16:55:00 -0700108 main.HA.pingAcrossHostIntent( main, True, True )
Jon Hall5cf14d52015-07-16 12:15:19 -0700109
110 def CASE5( self, main ):
111 """
112 Reading state of ONOS
113 """
Devin Lim58046fa2017-07-05 16:55:00 -0700114 main.HA.readingState( main )
Jon Hall5cf14d52015-07-16 12:15:19 -0700115
116 def CASE6( self, main ):
117 """
118 The Failure case. Since this is the Sanity test, we do nothing.
119 """
120 import time
Jon Halle1a3b752015-07-22 13:02:46 -0700121 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700122 assert main, "main not defined"
123 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700124 assert main.CLIs, "main.CLIs not defined"
125 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700126 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 Lim58046fa2017-07-05 16:55:00 -0700138 main.HA.checkStateAfterONOS( main, afterWhich=0, compareSwitch=True )
Jon Hall5cf14d52015-07-16 12:15:19 -0700139
Jon Hall5cf14d52015-07-16 12:15:19 -0700140 main.step( "Leadership Election is still functional" )
141 # Test of LeadershipElection
Jon Halla440e872016-03-31 15:15:50 -0700142 leaderList = []
143
Jon Hall5cf14d52015-07-16 12:15:19 -0700144 # NOTE: this only works for the sanity test. In case of failures,
145 # leader will likely change
Jon Halla440e872016-03-31 15:15:50 -0700146 leader = main.nodes[ main.activeNodes[ 0 ] ].ip_address
Jon Hall5cf14d52015-07-16 12:15:19 -0700147 leaderResult = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -0700148
149 for i in main.activeNodes:
Jon Hallf37d44d2017-05-24 10:37:30 -0700150 cli = main.CLIs[ i ]
Jon Hall5cf14d52015-07-16 12:15:19 -0700151 leaderN = cli.electionTestLeader()
Jon Halla440e872016-03-31 15:15:50 -0700152 leaderList.append( leaderN )
Jon Hall5cf14d52015-07-16 12:15:19 -0700153 # 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 Halla440e872016-03-31 15:15:50 -0700165 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 Hall5cf14d52015-07-16 12:15:19 -0700169 leaderResult = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -0700170 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 Hall5cf14d52015-07-16 12:15:19 -0700175 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 Lim58046fa2017-07-05 16:55:00 -0700185 main.HA.compareTopo( main )
Jon Halld2871c22016-07-26 11:01:14 -0700186
Jon Hall5cf14d52015-07-16 12:15:19 -0700187 def CASE9( self, main ):
188 """
189 Link s3-s28 down
190 """
Devin Lim58046fa2017-07-05 16:55:00 -0700191 main.HA.linkDown( main )
Jon Hall5cf14d52015-07-16 12:15:19 -0700192
193 def CASE10( self, main ):
194 """
195 Link s3-s28 up
196 """
Devin Lim58046fa2017-07-05 16:55:00 -0700197 main.HA.linkUp( main )
Jon Hall5cf14d52015-07-16 12:15:19 -0700198
199 def CASE11( self, main ):
200 """
201 Switch Down
202 """
203 # NOTE: You should probably run a topology check after this
Devin Lim58046fa2017-07-05 16:55:00 -0700204 main.HA.switchDown( main )
Jon Hall5cf14d52015-07-16 12:15:19 -0700205
206 def CASE12( self, main ):
207 """
208 Switch Up
209 """
210 # NOTE: You should probably run a topology check after this
Devin Lim58046fa2017-07-05 16:55:00 -0700211 main.HA.switchUp( main )
Jon Hall5cf14d52015-07-16 12:15:19 -0700212
213 def CASE13( self, main ):
214 """
215 Clean up
216 """
Devin Lim58046fa2017-07-05 16:55:00 -0700217 main.HA.cleanUp( main )
Jon Hall5cf14d52015-07-16 12:15:19 -0700218
219 def CASE14( self, main ):
220 """
221 start election app on all onos nodes
222 """
Devin Lim58046fa2017-07-05 16:55:00 -0700223 main.HA.startElectionApp( main )
Jon Hall5cf14d52015-07-16 12:15:19 -0700224
225 def CASE15( self, main ):
226 """
227 Check that Leadership Election is still functional
acsmars71adceb2015-08-31 15:09:26 -0700228 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 Hall5cf14d52015-07-16 12:15:19 -0700239 """
Devin Lim58046fa2017-07-05 16:55:00 -0700240 main.HA.isElectionFunctional( main )
Jon Hall5cf14d52015-07-16 12:15:19 -0700241
242 def CASE16( self, main ):
243 """
244 Install Distributed Primitives app
245 """
Devin Lim58046fa2017-07-05 16:55:00 -0700246 main.HA.installDistributedPrimitiveApp( main )
Jon Hall5cf14d52015-07-16 12:15:19 -0700247
248 def CASE17( self, main ):
249 """
250 Check for basic functionality with distributed primitives
251 """
Devin Lim58046fa2017-07-05 16:55:00 -0700252 main.HA.checkDistPrimitivesFunc( main )