blob: ceabcafef71bba1c1bfdfa55a7ad0f31801d2eef [file] [log] [blame]
Jon Hall69b2b982016-05-11 12:04:59 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070021"""
Jon Hall69b2b982016-05-11 12:04:59 -070022Description: This test is to determine if ONOS can handle
23 dynamic swapping of cluster nodes.
24
25List of test cases:
26CASE1: Compile ONOS and push it to the test machines
27CASE2: Assign devices to controllers
28CASE21: Assign mastership to controllers
29CASE3: Assign intents
30CASE4: Ping across added host intents
31CASE5: Reading state of ONOS
32CASE6: Swap nodes
33CASE7: Check state after control plane failure
34CASE8: Compare topo
35CASE9: Link s3-s28 down
36CASE10: Link s3-s28 up
37CASE11: Switch down
38CASE12: Switch up
39CASE13: Clean up
40CASE14: start election app on all onos nodes
41CASE15: Check that Leadership Election is still functional
42CASE16: Install Distributed Primitives app
43CASE17: Check for basic functionality with distributed primitives
44"""
Jon Hall69b2b982016-05-11 12:04:59 -070045class HAswapNodes:
46
47 def __init__( self ):
48 self.default = ''
49
50 def CASE1( self, main ):
51 """
52 CASE1 is to compile ONOS and push it to the test machines
53
54 Startup sequence:
55 cell <name>
56 onos-verify-cell
57 NOTE: temporary - onos-remove-raft-logs
58 onos-uninstall
59 start mininet
60 git pull
61 mvn clean install
62 onos-package
63 onos-install -f
64 onos-wait-for-start
65 start cli sessions
66 start tcpdump
67 """
Jon Hall69b2b982016-05-11 12:04:59 -070068 main.log.info( "ONOS HA test: Restart all ONOS nodes - " +
69 "initialization" )
Jon Hall69b2b982016-05-11 12:04:59 -070070 # set global variables
71 # These are for csv plotting in jenkins
Devin Lim58046fa2017-07-05 16:55:00 -070072 main.HAlabels = []
73 main.HAdata = []
74 try:
75 from tests.dependencies.ONOSSetup import ONOSSetup
76 main.testSetUp = ONOSSetup()
77 except ImportError:
78 main.log.error( "ONOSSetup not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070079 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070080 main.testSetUp.envSetupDescription()
Jon Hall69b2b982016-05-11 12:04:59 -070081 try:
82 from tests.HA.dependencies.HA import HA
83 main.HA = HA()
Devin Lim58046fa2017-07-05 16:55:00 -070084 # load some variables from the params file
85 cellName = main.params[ 'ENV' ][ 'cellName' ]
86 main.apps = main.params[ 'ENV' ][ 'appString' ]
Jon Hallab611372018-02-21 15:26:05 -080087 stepResult = main.testSetUp.envSetup( includeCaseDesc=False )
Jon Hall69b2b982016-05-11 12:04:59 -070088 except Exception as e:
Devin Lim58046fa2017-07-05 16:55:00 -070089 main.testSetUp.envSetupException( e )
Jon Hallaa1d9b82020-07-30 13:49:42 -070090 main.testSetUp.envSetupConclusion( stepResult )
Jon Hall69b2b982016-05-11 12:04:59 -070091
Jon Hall5a5c8432018-11-28 11:39:57 -080092 applyFuncs = [ main.HA.removeKarafConsoleLogging, main.HA.swapNodeMetadata ]
93 applyArgs = [ None, None ]
Jon Hallab611372018-02-21 15:26:05 -080094 try:
95 if main.params[ 'topology' ][ 'topoFile' ]:
96 main.log.info( 'Skipping start of Mininet in this case, make sure you start it elsewhere' )
97 else:
98 applyFuncs.append( main.HA.startingMininet )
99 applyArgs.append( None )
100 except (KeyError, IndexError):
101 applyFuncs.append( main.HA.startingMininet )
102 applyArgs.append( None )
103
Jon Hall3e6edb32018-08-21 16:20:30 -0700104 main.testSetUp.ONOSSetUp( main.Cluster, cellName=cellName,
Jon Hallab611372018-02-21 15:26:05 -0800105 extraApply=applyFuncs,
106 applyArgs=applyArgs,
Jon Hallab611372018-02-21 15:26:05 -0800107 installMax=True,
108 includeCaseDesc=False )
Jon Hall3e6edb32018-08-21 16:20:30 -0700109 main.HA.initialSetUp()
Jon Hallab611372018-02-21 15:26:05 -0800110
111 main.step( 'Set logging levels' )
112 logging = True
113 try:
114 logs = main.params.get( 'ONOS_Logging', False )
115 if logs:
116 for namespace, level in logs.items():
117 for ctrl in main.Cluster.active():
118 ctrl.CLI.logSet( level, namespace )
119 except AttributeError:
120 logging = False
121 utilities.assert_equals( expect=True, actual=logging,
122 onpass="Set log levels",
123 onfail="Failed to set log levels" )
Jon Hall69b2b982016-05-11 12:04:59 -0700124
125 def CASE2( self, main ):
126 """
127 Assign devices to controllers
128 """
Devin Lim58046fa2017-07-05 16:55:00 -0700129 main.HA.assignDevices( main )
Jon Hall69b2b982016-05-11 12:04:59 -0700130
Jon Hallab611372018-02-21 15:26:05 -0800131 def CASE102( self, main ):
132 """
133 Set up Spine-Leaf fabric topology in Mininet
134 """
135 main.HA.startTopology( main )
136
Jon Hall69b2b982016-05-11 12:04:59 -0700137 def CASE21( self, main ):
138 """
139 Assign mastership to controllers
140 """
Devin Lim58046fa2017-07-05 16:55:00 -0700141 main.HA.assignMastership( main )
Jon Hall69b2b982016-05-11 12:04:59 -0700142
143 def CASE3( self, main ):
144 """
145 Assign intents
146 """
Devin Lim58046fa2017-07-05 16:55:00 -0700147 main.HA.assignIntents( main )
Jon Hall69b2b982016-05-11 12:04:59 -0700148
149 def CASE4( self, main ):
150 """
151 Ping across added host intents
152 """
Jon Hallca319892017-06-15 15:25:22 -0700153 main.HA.pingAcrossHostIntent( main )
Jon Hall69b2b982016-05-11 12:04:59 -0700154
Jon Hallab611372018-02-21 15:26:05 -0800155 def CASE104( self, main ):
156 """
157 Ping Hosts
158 """
159 main.case( "Check connectivity" )
160 main.step( "Ping between all hosts" )
161 pingResult = main.Mininet1.pingall()
162 utilities.assert_equals( expect=main.TRUE, actual=pingResult,
163 onpass="All Pings Passed",
164 onfail="Failed to ping between all hosts" )
165
Jon Hall69b2b982016-05-11 12:04:59 -0700166 def CASE5( self, main ):
167 """
168 Reading state of ONOS
169 """
Devin Lim58046fa2017-07-05 16:55:00 -0700170 main.HA.readingState( main )
Jon Hall69b2b982016-05-11 12:04:59 -0700171
172 def CASE6( self, main ):
173 """
174 The Scaling case.
175 """
Jon Hall69b2b982016-05-11 12:04:59 -0700176 assert main, "main not defined"
177 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall69b2b982016-05-11 12:04:59 -0700178 try:
Devin Lim58046fa2017-07-05 16:55:00 -0700179 main.HAlabels
180 except ( NameError, AttributeError ):
181 main.log.error( "main.HAlabels not defined, setting to []" )
182 main.HAlabels = []
Jon Hall69b2b982016-05-11 12:04:59 -0700183 try:
Devin Lim58046fa2017-07-05 16:55:00 -0700184 main.HAdata
185 except ( NameError, AttributeError ):
186 main.log.error( "main.HAdata not defined, setting to []" )
187 main.HAdata = []
Jon Hall69b2b982016-05-11 12:04:59 -0700188
189 main.case( "Swap some of the ONOS nodes" )
190
191 main.step( "Checking ONOS Logs for errors" )
Devin Lim142b5342017-07-20 15:22:39 -0700192 for ctrl in main.Cluster.active():
193 main.log.debug( "Checking logs for errors on " + ctrl.name + ":" )
194 main.log.warn( main.ONOSbench.checkLogs( ctrl.ipAddress ) )
Jon Hall69b2b982016-05-11 12:04:59 -0700195
Devin Lim142b5342017-07-20 15:22:39 -0700196 activeNodes = main.Cluster.getRunningPos()
Devin Lim142b5342017-07-20 15:22:39 -0700197 old = [ activeNodes[ 1 ], activeNodes[ -2 ] ]
198 new = range( main.Cluster.maxCtrls )[ -2: ]
Jon Hall69b2b982016-05-11 12:04:59 -0700199 assert len( old ) == len( new ), "Length of nodes to swap don't match"
200 handle = main.ONOSbench.handle
201 for x, y in zip( old, new ):
202 handle.sendline( "export OC{}=$OC{}".format( x + 1, y + 1 ) )
203 handle.expect( "\$" ) # from the variable
204 ret = handle.before
205 handle.expect( "\$" ) # From the prompt
206 ret += handle.before
207 main.log.debug( ret )
Devin Lim142b5342017-07-20 15:22:39 -0700208 activeNodes.remove( x )
209 activeNodes.append( y )
Jon Hall69b2b982016-05-11 12:04:59 -0700210
Jon Halla1e8e512018-05-11 13:30:57 -0700211 main.Cluster.clearActive()
Devin Lim142b5342017-07-20 15:22:39 -0700212 # Note : done up to this point.
Jon Hall69b2b982016-05-11 12:04:59 -0700213 main.step( "Start new nodes" ) # OR stop old nodes?
214 started = main.TRUE
Jon Hall3e6edb32018-08-21 16:20:30 -0700215 stopped = main.TRUE
Jon Hall69b2b982016-05-11 12:04:59 -0700216 for i in new:
Jon Hall3e6edb32018-08-21 16:20:30 -0700217 started = main.ONOSbench.onosStart( main.Cluster.controllers[ i ].ipAddress ) and started
Jon Hall69b2b982016-05-11 12:04:59 -0700218 utilities.assert_equals( expect=main.TRUE, actual=started,
219 onpass="ONOS started",
220 onfail="ONOS start NOT successful" )
Jon Hall3e6edb32018-08-21 16:20:30 -0700221 for i in old:
222 main.log.debug( "Stopping " + str( main.Cluster.controllers[ i ].ipAddress ) )
223 stopped = main.ONOSbench.onosStop( main.Cluster.controllers[ i ].ipAddress ) and stopped
224 utilities.assert_equals( expect=main.TRUE, actual=stopped,
225 onpass="ONOS stopped",
226 onfail="ONOS stop NOT successful" )
Jon Hall69b2b982016-05-11 12:04:59 -0700227
Devin Lim142b5342017-07-20 15:22:39 -0700228 main.Cluster.setRunningNode( activeNodes )
Jon Hall69b2b982016-05-11 12:04:59 -0700229
Devin Lim142b5342017-07-20 15:22:39 -0700230 main.testSetUp.setupSsh( main.Cluster )
231 main.testSetUp.checkOnosService( main.Cluster )
Jon Hall69b2b982016-05-11 12:04:59 -0700232
Devin Lim142b5342017-07-20 15:22:39 -0700233 main.testSetUp.startOnosClis( main.Cluster )
Jon Hall69b2b982016-05-11 12:04:59 -0700234
Jon Hall30668ff2019-02-27 17:43:09 -0800235 main.testSetUp.checkOnosNodes( main.Cluster )
Jon Hall69b2b982016-05-11 12:04:59 -0700236
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700237 ready = utilities.retry( main.Cluster.command,
Jon Hall3e6edb32018-08-21 16:20:30 -0700238 False,
239 kwargs={ "function": "summary", "contentCheck": True },
240 sleep=30,
241 attempts=10 )
Jon Hall69b2b982016-05-11 12:04:59 -0700242 utilities.assert_equals( expect=True, actual=ready,
243 onpass="ONOS summary command succeded",
244 onfail="ONOS summary command failed" )
245 if not ready:
Devin Lim44075962017-08-11 10:56:37 -0700246 main.cleanAndExit()
Jon Hall69b2b982016-05-11 12:04:59 -0700247
248 # Rerun for election on new nodes
249 runResults = main.TRUE
Devin Lim142b5342017-07-20 15:22:39 -0700250 for ctrl in main.Cluster.active():
251 run = ctrl.CLI.electionTestRun()
Jon Hall69b2b982016-05-11 12:04:59 -0700252 if run != main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -0700253 main.log.error( "Error running for election on " + ctrl.name )
Jon Hall69b2b982016-05-11 12:04:59 -0700254 runResults = runResults and run
255 utilities.assert_equals( expect=main.TRUE, actual=runResults,
256 onpass="Reran for election",
257 onfail="Failed to rerun for election" )
258
Devin Lim142b5342017-07-20 15:22:39 -0700259 main.HA.commonChecks()
260
Jon Hall69b2b982016-05-11 12:04:59 -0700261 def CASE7( self, main ):
262 """
263 Check state after ONOS scaling
264 """
Devin Lim142b5342017-07-20 15:22:39 -0700265 main.HA.checkStateAfterEvent( main, afterWhich=1 )
Jon Hall69b2b982016-05-11 12:04:59 -0700266
Jon Hall69b2b982016-05-11 12:04:59 -0700267 main.step( "Leadership Election is still functional" )
268 # Test of LeadershipElection
269 leaderList = []
270 leaderResult = main.TRUE
271
Devin Lim142b5342017-07-20 15:22:39 -0700272 for ctrl in main.Cluster.active():
273 leaderN = ctrl.CLI.electionTestLeader()
Jon Hall69b2b982016-05-11 12:04:59 -0700274 leaderList.append( leaderN )
275 if leaderN == main.FALSE:
276 # error in response
277 main.log.error( "Something is wrong with " +
278 "electionTestLeader function, check the" +
279 " error logs" )
280 leaderResult = main.FALSE
281 elif leaderN is None:
Devin Lim142b5342017-07-20 15:22:39 -0700282 main.log.error( ctrl.name +
Jon Hall69b2b982016-05-11 12:04:59 -0700283 " shows no leader for the election-app." )
284 leaderResult = main.FALSE
285 if len( set( leaderList ) ) != 1:
286 leaderResult = main.FALSE
287 main.log.error(
288 "Inconsistent view of leader for the election test app" )
Jon Hallab611372018-02-21 15:26:05 -0800289 main.log.debug( leaderList )
Jon Hall69b2b982016-05-11 12:04:59 -0700290 utilities.assert_equals(
291 expect=main.TRUE,
292 actual=leaderResult,
293 onpass="Leadership election passed",
294 onfail="Something went wrong with Leadership election" )
295
296 def CASE8( self, main ):
297 """
298 Compare topo
299 """
Devin Lim58046fa2017-07-05 16:55:00 -0700300 main.HA.compareTopo( main )
Jon Halld2871c22016-07-26 11:01:14 -0700301
Jon Hall69b2b982016-05-11 12:04:59 -0700302 def CASE9( self, main ):
303 """
Jon Hallab611372018-02-21 15:26:05 -0800304 Link down
Jon Hall69b2b982016-05-11 12:04:59 -0700305 """
Jon Hallab611372018-02-21 15:26:05 -0800306 src = main.params['kill']['linkSrc']
307 dst = main.params['kill']['linkDst']
308 main.HA.linkDown( main, src, dst )
Jon Hall69b2b982016-05-11 12:04:59 -0700309
310 def CASE10( self, main ):
311 """
Jon Hallab611372018-02-21 15:26:05 -0800312 Link up
Jon Hall69b2b982016-05-11 12:04:59 -0700313 """
Jon Hallab611372018-02-21 15:26:05 -0800314 src = main.params['kill']['linkSrc']
315 dst = main.params['kill']['linkDst']
316 main.HA.linkUp( main, src, dst )
Jon Hall69b2b982016-05-11 12:04:59 -0700317
318 def CASE11( self, main ):
319 """
320 Switch Down
321 """
322 # NOTE: You should probably run a topology check after this
Devin Lim58046fa2017-07-05 16:55:00 -0700323 main.HA.switchDown( main )
Jon Hall69b2b982016-05-11 12:04:59 -0700324
325 def CASE12( self, main ):
326 """
327 Switch Up
328 """
329 # NOTE: You should probably run a topology check after this
Devin Lim58046fa2017-07-05 16:55:00 -0700330 main.HA.switchUp( main )
Jon Hall69b2b982016-05-11 12:04:59 -0700331
332 def CASE13( self, main ):
333 """
334 Clean up
335 """
Devin Lim58046fa2017-07-05 16:55:00 -0700336 main.HA.cleanUp( main )
Jon Hall69b2b982016-05-11 12:04:59 -0700337
Jon Hall69b2b982016-05-11 12:04:59 -0700338 def CASE14( self, main ):
339 """
Jon Hallab611372018-02-21 15:26:05 -0800340 Start election app on all onos nodes
Jon Hall69b2b982016-05-11 12:04:59 -0700341 """
Devin Lim58046fa2017-07-05 16:55:00 -0700342 main.HA.startElectionApp( main )
Jon Hall69b2b982016-05-11 12:04:59 -0700343
344 def CASE15( self, main ):
345 """
346 Check that Leadership Election is still functional
347 15.1 Run election on each node
348 15.2 Check that each node has the same leaders and candidates
349 15.3 Find current leader and withdraw
350 15.4 Check that a new node was elected leader
351 15.5 Check that that new leader was the candidate of old leader
352 15.6 Run for election on old leader
353 15.7 Check that oldLeader is a candidate, and leader if only 1 node
354 15.8 Make sure that the old leader was added to the candidate list
355
356 old and new variable prefixes refer to data from before vs after
357 withdrawl and later before withdrawl vs after re-election
358 """
Devin Lim58046fa2017-07-05 16:55:00 -0700359 main.HA.isElectionFunctional( main )
Jon Hall69b2b982016-05-11 12:04:59 -0700360
361 def CASE16( self, main ):
362 """
363 Install Distributed Primitives app
364 """
Devin Lim58046fa2017-07-05 16:55:00 -0700365 main.HA.installDistributedPrimitiveApp( main )
Jon Hall69b2b982016-05-11 12:04:59 -0700366
367 def CASE17( self, main ):
368 """
369 Check for basic functionality with distributed primitives
370 """
Devin Lim58046fa2017-07-05 16:55:00 -0700371 main.HA.checkDistPrimitivesFunc( main )