blob: d05b7c93278cffe9b5dcef32319c6e64ded6911e [file] [log] [blame]
Jon Hall6aec96b2015-01-19 14:49:31 -08001"""
Jon Hallb1290e82014-11-18 16:17:48 -05002Description: 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 mastership to controllers
9CASE3: Assign intents
10CASE4: Ping across added host intents
11CASE5: Reading state of ONOS
12CASE6: The Failure case. Since this is the Sanity test, we do nothing.
Jon Hall368769f2014-11-19 15:43:35 -080013CASE7: Check state after control plane failure
Jon Hallb1290e82014-11-18 16:17:48 -050014CASE8: Compare topo
15CASE9: Link s3-s28 down
16CASE10: Link s3-s28 up
17CASE11: Switch down
18CASE12: Switch up
19CASE13: Clean up
Jon Hall669173b2014-12-17 11:36:30 -080020CASE14: start election app on all onos nodes
21CASE15: Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -080022"""
Jon Hallb1290e82014-11-18 16:17:48 -050023class HATestSanity:
24
Jon Hall6aec96b2015-01-19 14:49:31 -080025 def __init__( self ):
Jon Hallb1290e82014-11-18 16:17:48 -050026 self.default = ''
27
Jon Hall6aec96b2015-01-19 14:49:31 -080028 def CASE1( self, main ):
29 """
Jon Hallb1290e82014-11-18 16:17:48 -050030 CASE1 is to compile ONOS and push it to the test machines
31
32 Startup sequence:
33 git pull
34 mvn clean install
35 onos-package
36 cell <name>
37 onos-verify-cell
38 NOTE: temporary - onos-remove-raft-logs
39 onos-install -f
40 onos-wait-for-start
Jon Hall6aec96b2015-01-19 14:49:31 -080041 """
42 main.log.report( "ONOS HA Sanity test - initialization" )
43 main.case( "Setting up test environment" )
44 # TODO: save all the timers and output them for plotting
Jon Hallb1290e82014-11-18 16:17:48 -050045
46 # load some vairables from the params file
47 PULL_CODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080048 if main.params[ 'Git' ] == 'True':
Jon Hallb1290e82014-11-18 16:17:48 -050049 PULL_CODE = True
Jon Hallb1290e82014-11-18 16:17:48 -050050
Jon Hall6aec96b2015-01-19 14:49:31 -080051 cell_name = main.params[ 'ENV' ][ 'cellName' ]
52
53 # set global variables
Jon Hallb1290e82014-11-18 16:17:48 -050054 global ONOS1_ip
55 global ONOS1_port
56 global ONOS2_ip
57 global ONOS2_port
58 global ONOS3_ip
59 global ONOS3_port
60 global ONOS4_ip
61 global ONOS4_port
62 global ONOS5_ip
63 global ONOS5_port
64 global ONOS6_ip
65 global ONOS6_port
66 global ONOS7_ip
67 global ONOS7_port
Jon Hall669173b2014-12-17 11:36:30 -080068 global num_controllers
Jon Hallb1290e82014-11-18 16:17:48 -050069
Jon Hall6aec96b2015-01-19 14:49:31 -080070 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
71 ONOS1_port = main.params[ 'CTRL' ][ 'port1' ]
72 ONOS2_ip = main.params[ 'CTRL' ][ 'ip2' ]
73 ONOS2_port = main.params[ 'CTRL' ][ 'port2' ]
74 ONOS3_ip = main.params[ 'CTRL' ][ 'ip3' ]
75 ONOS3_port = main.params[ 'CTRL' ][ 'port3' ]
76 ONOS4_ip = main.params[ 'CTRL' ][ 'ip4' ]
77 ONOS4_port = main.params[ 'CTRL' ][ 'port4' ]
78 ONOS5_ip = main.params[ 'CTRL' ][ 'ip5' ]
79 ONOS5_port = main.params[ 'CTRL' ][ 'port5' ]
80 ONOS6_ip = main.params[ 'CTRL' ][ 'ip6' ]
81 ONOS6_port = main.params[ 'CTRL' ][ 'port6' ]
82 ONOS7_ip = main.params[ 'CTRL' ][ 'ip7' ]
83 ONOS7_port = main.params[ 'CTRL' ][ 'port7' ]
84 num_controllers = int( main.params[ 'num_controllers' ] )
Jon Hallb1290e82014-11-18 16:17:48 -050085
Jon Hall6aec96b2015-01-19 14:49:31 -080086 main.step( "Applying cell variable to environment" )
87 cell_result = main.ONOSbench.set_cell( cell_name )
Jon Hallb1290e82014-11-18 16:17:48 -050088 verify_result = main.ONOSbench.verify_cell()
Jon Hall368769f2014-11-19 15:43:35 -080089
Jon Hall6aec96b2015-01-19 14:49:31 -080090 # FIXME:this is short term fix
91 main.log.report( "Removing raft logs" )
Jon Hallb1290e82014-11-18 16:17:48 -050092 main.ONOSbench.onos_remove_raft_logs()
Jon Hall6aec96b2015-01-19 14:49:31 -080093 main.log.report( "Uninstalling ONOS" )
94 main.ONOSbench.onos_uninstall( ONOS1_ip )
95 main.ONOSbench.onos_uninstall( ONOS2_ip )
96 main.ONOSbench.onos_uninstall( ONOS3_ip )
97 main.ONOSbench.onos_uninstall( ONOS4_ip )
98 main.ONOSbench.onos_uninstall( ONOS5_ip )
99 main.ONOSbench.onos_uninstall( ONOS6_ip )
100 main.ONOSbench.onos_uninstall( ONOS7_ip )
Jon Hallb1290e82014-11-18 16:17:48 -0500101
102 clean_install_result = main.TRUE
103 git_pull_result = main.TRUE
104
Jon Hall6aec96b2015-01-19 14:49:31 -0800105 main.step( "Compiling the latest version of ONOS" )
Jon Hallb1290e82014-11-18 16:17:48 -0500106 if PULL_CODE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800107 # TODO Configure branch in params
108 main.step( "Git checkout and pull master" )
109 main.ONOSbench.git_checkout( "master" )
Jon Hallb1290e82014-11-18 16:17:48 -0500110 git_pull_result = main.ONOSbench.git_pull()
111
Jon Hall6aec96b2015-01-19 14:49:31 -0800112 main.step( "Using mvn clean & install" )
Jon Hallb1290e82014-11-18 16:17:48 -0500113 clean_install_result = main.TRUE
114 if git_pull_result == main.TRUE:
115 clean_install_result = main.ONOSbench.clean_install()
116 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800117 main.log.warn( "Did not pull new code so skipping mvn " +
118 "clean install" )
119 main.ONOSbench.get_version( report=True )
Jon Hallb1290e82014-11-18 16:17:48 -0500120
Jon Hall6aec96b2015-01-19 14:49:31 -0800121 main.step( "Creating ONOS package" )
Jon Hallb1290e82014-11-18 16:17:48 -0500122 package_result = main.ONOSbench.onos_package()
123
Jon Hall6aec96b2015-01-19 14:49:31 -0800124 main.step( "Installing ONOS package" )
125 onos1_install_result = main.ONOSbench.onos_install( options="-f",
126 node=ONOS1_ip )
127 onos2_install_result = main.ONOSbench.onos_install( options="-f",
128 node=ONOS2_ip )
129 onos3_install_result = main.ONOSbench.onos_install( options="-f",
130 node=ONOS3_ip )
131 onos4_install_result = main.ONOSbench.onos_install( options="-f",
132 node=ONOS4_ip )
133 onos5_install_result = main.ONOSbench.onos_install( options="-f",
134 node=ONOS5_ip )
135 onos6_install_result = main.ONOSbench.onos_install( options="-f",
136 node=ONOS6_ip )
137 onos7_install_result = main.ONOSbench.onos_install( options="-f",
138 node=ONOS7_ip )
Jon Hallb1290e82014-11-18 16:17:48 -0500139 onos_install_result = onos1_install_result and onos2_install_result\
Jon Hall6aec96b2015-01-19 14:49:31 -0800140 and onos3_install_result and onos4_install_result\
141 and onos5_install_result and onos6_install_result\
142 and onos7_install_result
Jon Hallb1290e82014-11-18 16:17:48 -0500143
Jon Hall6aec96b2015-01-19 14:49:31 -0800144 main.step( "Checking if ONOS is up yet" )
145 # TODO check bundle:list?
146 for i in range( 2 ):
147 onos1_isup = main.ONOSbench.isup( ONOS1_ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800148 if not onos1_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800149 main.log.report( "ONOS1 didn't start!" )
150 onos2_isup = main.ONOSbench.isup( ONOS2_ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800151 if not onos2_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800152 main.log.report( "ONOS2 didn't start!" )
153 onos3_isup = main.ONOSbench.isup( ONOS3_ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800154 if not onos3_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800155 main.log.report( "ONOS3 didn't start!" )
156 onos4_isup = main.ONOSbench.isup( ONOS4_ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800157 if not onos4_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800158 main.log.report( "ONOS4 didn't start!" )
159 onos5_isup = main.ONOSbench.isup( ONOS5_ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800160 if not onos5_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800161 main.log.report( "ONOS5 didn't start!" )
162 onos6_isup = main.ONOSbench.isup( ONOS6_ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800163 if not onos6_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800164 main.log.report( "ONOS6 didn't start!" )
165 onos7_isup = main.ONOSbench.isup( ONOS7_ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800166 if not onos7_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800167 main.log.report( "ONOS7 didn't start!" )
Jon Hallffb386d2014-11-21 13:43:38 -0800168 onos_isup_result = onos1_isup and onos2_isup and onos3_isup\
Jon Hall6aec96b2015-01-19 14:49:31 -0800169 and onos4_isup and onos5_isup and onos6_isup and onos7_isup
Jon Hallffb386d2014-11-21 13:43:38 -0800170 if onos_isup_result == main.TRUE:
171 break
Jon Hallb1290e82014-11-18 16:17:48 -0500172
Jon Hall6aec96b2015-01-19 14:49:31 -0800173 cli_result1 = main.ONOScli1.start_onos_cli( ONOS1_ip )
174 cli_result2 = main.ONOScli2.start_onos_cli( ONOS2_ip )
175 cli_result3 = main.ONOScli3.start_onos_cli( ONOS3_ip )
176 cli_result4 = main.ONOScli4.start_onos_cli( ONOS4_ip )
177 cli_result5 = main.ONOScli5.start_onos_cli( ONOS5_ip )
178 cli_result6 = main.ONOScli6.start_onos_cli( ONOS6_ip )
179 cli_result7 = main.ONOScli7.start_onos_cli( ONOS7_ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800180 cli_results = cli_result1 and cli_result2 and cli_result3 and\
Jon Hall6aec96b2015-01-19 14:49:31 -0800181 cli_result4 and cli_result5 and cli_result6 and cli_result7
Jon Hallb1290e82014-11-18 16:17:48 -0500182
Jon Hall6aec96b2015-01-19 14:49:31 -0800183 main.step( "Start Packet Capture MN" )
Jon Hall368769f2014-11-19 15:43:35 -0800184 main.Mininet2.start_tcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800185 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
186 + "-MN.pcap",
187 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
188 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hallb1290e82014-11-18 16:17:48 -0500189
Jon Hall6aec96b2015-01-19 14:49:31 -0800190 case1_result = ( clean_install_result and package_result and
191 cell_result and verify_result and onos_install_result
192 and onos_isup_result and cli_results )
Jon Hallb1290e82014-11-18 16:17:48 -0500193
Jon Hall6aec96b2015-01-19 14:49:31 -0800194 utilities.assert_equals( expect=main.TRUE, actual=case1_result,
195 onpass="Test startup successful",
196 onfail="Test startup NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -0500197
Jon Hall6aec96b2015-01-19 14:49:31 -0800198 if case1_result == main.FALSE:
Jon Hallffb386d2014-11-21 13:43:38 -0800199 main.cleanup()
200 main.exit()
Jon Hallb1290e82014-11-18 16:17:48 -0500201
Jon Hall6aec96b2015-01-19 14:49:31 -0800202 def CASE2( self, main ):
203 """
Jon Hallb1290e82014-11-18 16:17:48 -0500204 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800205 """
Jon Hallb1290e82014-11-18 16:17:48 -0500206 import re
207
Jon Hall6aec96b2015-01-19 14:49:31 -0800208 main.log.report( "Assigning switches to controllers" )
209 main.case( "Assigning Controllers" )
210 main.step( "Assign switches to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500211
Jon Hall6aec96b2015-01-19 14:49:31 -0800212 for i in range( 1, 29 ):
213 main.Mininet1.assign_sw_controller(
214 sw=str( i ),
215 count=num_controllers,
216 ip1=ONOS1_ip, port1=ONOS1_port,
217 ip2=ONOS2_ip, port2=ONOS2_port,
218 ip3=ONOS3_ip, port3=ONOS3_port,
219 ip4=ONOS4_ip, port4=ONOS4_port,
220 ip5=ONOS5_ip, port5=ONOS5_port,
221 ip6=ONOS6_ip, port6=ONOS6_port,
222 ip7=ONOS7_ip, port7=ONOS7_port )
Jon Hallb1290e82014-11-18 16:17:48 -0500223
224 mastership_check = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800225 for i in range( 1, 29 ):
226 response = main.Mininet1.get_sw_controller( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800227 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800228 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800229 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800230 main.log.info( repr( response ) )
231 if re.search( "tcp:" + ONOS1_ip, response )\
232 and re.search( "tcp:" + ONOS2_ip, response )\
233 and re.search( "tcp:" + ONOS3_ip, response )\
234 and re.search( "tcp:" + ONOS4_ip, response )\
235 and re.search( "tcp:" + ONOS5_ip, response )\
236 and re.search( "tcp:" + ONOS6_ip, response )\
237 and re.search( "tcp:" + ONOS7_ip, response ):
Jon Hallb1290e82014-11-18 16:17:48 -0500238 mastership_check = mastership_check and main.TRUE
239 else:
240 mastership_check = main.FALSE
241 if mastership_check == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800242 main.log.report( "Switch mastership assigned correctly" )
243 utilities.assert_equals(
244 expect=main.TRUE,
245 actual=mastership_check,
246 onpass="Switch mastership assigned correctly",
247 onfail="Switches not assigned correctly to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500248
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 # Manually assign mastership to the controller we want
Jon Hall94fd0472014-12-08 11:52:42 -0800250 role_call = main.TRUE
251 role_check = main.TRUE
252
Jon Hall6aec96b2015-01-19 14:49:31 -0800253 # Assign switch
254 device_id = main.ONOScli1.get_device( "1000" ).get( 'id' )
255 role_call = role_call and main.ONOScli1.device_role(
256 device_id,
257 ONOS1_ip )
258 # Check assignment
259 if ONOS1_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800260 role_check = role_check and main.TRUE
261 else:
262 role_check = role_check and main.FALSE
263
Jon Hall6aec96b2015-01-19 14:49:31 -0800264 # Assign switch
265 device_id = main.ONOScli1.get_device( "2800" ).get( 'id' )
266 role_call = role_call and main.ONOScli1.device_role(
267 device_id,
268 ONOS1_ip )
269 # Check assignment
270 if ONOS1_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800271 role_check = role_check and main.TRUE
272 else:
273 role_check = role_check and main.FALSE
274
Jon Hall6aec96b2015-01-19 14:49:31 -0800275 # Assign switch
276 device_id = main.ONOScli1.get_device( "2000" ).get( 'id' )
277 role_call = role_call and main.ONOScli1.device_role(
278 device_id,
279 ONOS2_ip )
280 # Check assignment
281 if ONOS2_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800282 role_check = role_check and main.TRUE
283 else:
284 role_check = role_check and main.FALSE
285
Jon Hall6aec96b2015-01-19 14:49:31 -0800286 # Assign switch
287 device_id = main.ONOScli1.get_device( "3000" ).get( 'id' )
288 role_call = role_call and main.ONOScli1.device_role(
289 device_id,
290 ONOS2_ip )
291 # Check assignment
292 if ONOS2_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800293 role_check = role_check and main.TRUE
294 else:
295 role_check = role_check and main.FALSE
296
Jon Hall6aec96b2015-01-19 14:49:31 -0800297 # Assign switch
298 device_id = main.ONOScli1.get_device( "5000" ).get( 'id' )
299 role_call = role_call and main.ONOScli1.device_role(
300 device_id,
301 ONOS3_ip )
302 # Check assignment
303 if ONOS3_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800304 role_check = role_check and main.TRUE
305 else:
306 role_check = role_check and main.FALSE
307
Jon Hall6aec96b2015-01-19 14:49:31 -0800308 # Assign switch
309 device_id = main.ONOScli1.get_device( "6000" ).get( 'id' )
310 role_call = role_call and main.ONOScli1.device_role(
311 device_id,
312 ONOS3_ip )
313 # Check assignment
314 if ONOS3_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800315 role_check = role_check and main.TRUE
316 else:
317 role_check = role_check and main.FALSE
318
Jon Hall6aec96b2015-01-19 14:49:31 -0800319 # Assign switch
320 device_id = main.ONOScli1.get_device( "3004" ).get( 'id' )
321 role_call = role_call and main.ONOScli1.device_role(
322 device_id,
323 ONOS4_ip )
324 # Check assignment
325 if ONOS4_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800326 role_check = role_check and main.TRUE
327 else:
328 role_check = role_check and main.FALSE
329
Jon Hall6aec96b2015-01-19 14:49:31 -0800330 for i in range( 8, 18 ):
331 dpid = '3' + str( i ).zfill( 3 )
332 device_id = main.ONOScli1.get_device( dpid ).get( 'id' )
333 role_call = role_call and main.ONOScli1.device_role(
334 device_id,
335 ONOS5_ip )
336 # Check assignment
337 if ONOS5_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
338 role_check = role_check and main.TRUE
339 else:
340 role_check = role_check and main.FALSE
341
342 device_id = main.ONOScli1.get_device( "6007" ).get( 'id' )
343 role_call = role_call and main.ONOScli1.device_role(
344 device_id,
345 ONOS6_ip )
346 # Check assignment
347 if ONOS6_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800348 role_check = role_check and main.TRUE
349 else:
350 role_check = role_check and main.FALSE
351
Jon Hall6aec96b2015-01-19 14:49:31 -0800352 for i in range( 18, 28 ):
353 dpid = '6' + str( i ).zfill( 3 )
354 device_id = main.ONOScli1.get_device( dpid ).get( 'id' )
355 role_call = role_call and main.ONOScli1.device_role(
356 device_id,
357 ONOS7_ip )
358 # Check assignment
359 if ONOS7_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
360 role_check = role_check and main.TRUE
361 else:
362 role_check = role_check and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800363
Jon Hall6aec96b2015-01-19 14:49:31 -0800364 utilities.assert_equals(
365 expect=main.TRUE,
366 actual=role_call,
367 onpass="Re-assigned switch mastership to designated controller",
368 onfail="Something wrong with device_role calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800369
Jon Hall6aec96b2015-01-19 14:49:31 -0800370 utilities.assert_equals(
371 expect=main.TRUE,
372 actual=role_check,
373 onpass="Switches were successfully reassigned to designated " +
374 "controller",
375 onfail="Switches were not successfully reassigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800376 mastership_check = mastership_check and role_call and role_check
Jon Hall6aec96b2015-01-19 14:49:31 -0800377 utilities.assert_equals( expect=main.TRUE, actual=mastership_check,
378 onpass="Switch mastership correctly assigned",
379 onfail="Error in (re)assigning switch" +
380 " mastership" )
Jon Hallb1290e82014-11-18 16:17:48 -0500381
Jon Hall6aec96b2015-01-19 14:49:31 -0800382 def CASE3( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500383 """
384 Assign intents
Jon Hallb1290e82014-11-18 16:17:48 -0500385 """
386 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800387 main.log.report( "Adding host intents" )
388 main.case( "Adding host Intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500389
Jon Hall6aec96b2015-01-19 14:49:31 -0800390 main.step( "Discovering Hosts( Via pingall for now)" )
391 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hallb1290e82014-11-18 16:17:48 -0500392
Jon Hall6aec96b2015-01-19 14:49:31 -0800393 # install onos-app-fwd
394 main.log.info( "Install reactive forwarding app" )
395 main.ONOScli1.feature_install( "onos-app-fwd" )
396 main.ONOScli2.feature_install( "onos-app-fwd" )
397 main.ONOScli3.feature_install( "onos-app-fwd" )
398 main.ONOScli4.feature_install( "onos-app-fwd" )
399 main.ONOScli5.feature_install( "onos-app-fwd" )
400 main.ONOScli6.feature_install( "onos-app-fwd" )
401 main.ONOScli7.feature_install( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800402
Jon Hall6aec96b2015-01-19 14:49:31 -0800403 # REACTIVE FWD test
Jon Hallb1290e82014-11-18 16:17:48 -0500404 ping_result = main.FALSE
405 time1 = time.time()
406 ping_result = main.Mininet1.pingall()
407 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800408 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500409
Jon Hall6aec96b2015-01-19 14:49:31 -0800410 # uninstall onos-app-fwd
411 main.log.info( "Uninstall reactive forwarding app" )
412 main.ONOScli1.feature_uninstall( "onos-app-fwd" )
413 main.ONOScli2.feature_uninstall( "onos-app-fwd" )
414 main.ONOScli3.feature_uninstall( "onos-app-fwd" )
415 main.ONOScli4.feature_uninstall( "onos-app-fwd" )
416 main.ONOScli5.feature_uninstall( "onos-app-fwd" )
417 main.ONOScli6.feature_uninstall( "onos-app-fwd" )
418 main.ONOScli7.feature_uninstall( "onos-app-fwd" )
419 # timeout for fwd flows
420 time.sleep( 10 )
Jon Hallb1290e82014-11-18 16:17:48 -0500421
Jon Hall6aec96b2015-01-19 14:49:31 -0800422 main.step( "Add host intents" )
423 # TODO: move the host numbers to params
Jon Hall94fd0472014-12-08 11:52:42 -0800424 intent_add_result = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800425 for i in range( 8, 18 ):
426 main.log.info( "Adding host intent between h" + str( i ) +
427 " and h" + str( i + 10 ) )
428 host1 = "00:00:00:00:00:" + \
429 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
430 host2 = "00:00:00:00:00:" + \
431 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
432 host1_id = main.ONOScli1.get_host( host1 )[ 'id' ]
433 host2_id = main.ONOScli1.get_host( host2 )[ 'id' ]
434 # NOTE: get host can return None
Jon Hall669173b2014-12-17 11:36:30 -0800435 if host1_id and host2_id:
Jon Hall6aec96b2015-01-19 14:49:31 -0800436 tmp_result = main.ONOScli1.add_host_intent(
437 host1_id,
438 host2_id )
Jon Hall669173b2014-12-17 11:36:30 -0800439 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800440 main.log.error( "Error, get_host() failed" )
Jon Hall669173b2014-12-17 11:36:30 -0800441 tmp_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800442 intent_add_result = bool( ping_result and intent_add_result
443 and tmp_result )
444 utilities.assert_equals(
445 expect=True,
446 actual=intent_add_result,
447 onpass="Switch mastership correctly assigned",
448 onfail="Error in (re)assigning switch mastership" )
449 # TODO Check if intents all exist in datastore
Jon Hallb1290e82014-11-18 16:17:48 -0500450
Jon Hall6aec96b2015-01-19 14:49:31 -0800451 def CASE4( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500452 """
453 Ping across added host intents
454 """
Jon Hall368769f2014-11-19 15:43:35 -0800455 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800456 main.log.report( description )
457 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -0500458 Ping_Result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800459 for i in range( 8, 18 ):
460 ping = main.Mininet1.pingHost(
461 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500462 Ping_Result = Ping_Result and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800463 if ping == main.FALSE:
464 main.log.warn( "Ping failed between h" + str( i ) +
465 " and h" + str( i + 10 ) )
466 elif ping == main.TRUE:
467 main.log.info( "Ping test passed!" )
Jon Hallb1290e82014-11-18 16:17:48 -0500468 Ping_Result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800469 if Ping_Result == main.FALSE:
470 main.log.report(
471 "Intents have not been installed correctly, pings failed." )
472 if Ping_Result == main.TRUE:
473 main.log.report(
474 "Intents have been installed correctly and verified by pings" )
475 utilities.assert_equals(
476 expect=main.TRUE,
477 actual=Ping_Result,
478 onpass="Intents have been installed correctly and pings work",
479 onfail="Intents have not been installed correctly, pings failed." )
Jon Hallb1290e82014-11-18 16:17:48 -0500480
Jon Hall6aec96b2015-01-19 14:49:31 -0800481 def CASE5( self, main ):
482 """
Jon Hallb1290e82014-11-18 16:17:48 -0500483 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800484 """
Jon Hallb1290e82014-11-18 16:17:48 -0500485 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800486 # assumes that sts is already in you PYTHONPATH
487 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -0500488
Jon Hall6aec96b2015-01-19 14:49:31 -0800489 main.log.report( "Setting up and gathering data for current state" )
490 main.case( "Setting up and gathering data for current state" )
491 # The general idea for this test case is to pull the state of
492 # ( intents,flows, topology,... ) from each ONOS node
493 # We can then compare them with eachother and also with past states
Jon Hallb1290e82014-11-18 16:17:48 -0500494
Jon Hall6aec96b2015-01-19 14:49:31 -0800495 main.step( "Get the Mastership of each switch from each controller" )
Jon Hallb1290e82014-11-18 16:17:48 -0500496 global mastership_state
Jon Hall94fd0472014-12-08 11:52:42 -0800497 mastership_state = []
498
Jon Hall6aec96b2015-01-19 14:49:31 -0800499 # Assert that each device has a master
Jon Hall94fd0472014-12-08 11:52:42 -0800500 ONOS1_master_not_null = main.ONOScli1.roles_not_null()
501 ONOS2_master_not_null = main.ONOScli2.roles_not_null()
502 ONOS3_master_not_null = main.ONOScli3.roles_not_null()
503 ONOS4_master_not_null = main.ONOScli4.roles_not_null()
504 ONOS5_master_not_null = main.ONOScli5.roles_not_null()
505 ONOS6_master_not_null = main.ONOScli6.roles_not_null()
506 ONOS7_master_not_null = main.ONOScli7.roles_not_null()
507 roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\
Jon Hall6aec96b2015-01-19 14:49:31 -0800508 ONOS3_master_not_null and ONOS4_master_not_null and\
509 ONOS5_master_not_null and ONOS6_master_not_null and\
510 ONOS7_master_not_null
511 utilities.assert_equals(
512 expect=main.TRUE,
513 actual=roles_not_null,
514 onpass="Each device has a master",
515 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800516
Jon Hallb1290e82014-11-18 16:17:48 -0500517 ONOS1_mastership = main.ONOScli1.roles()
518 ONOS2_mastership = main.ONOScli2.roles()
519 ONOS3_mastership = main.ONOScli3.roles()
520 ONOS4_mastership = main.ONOScli4.roles()
521 ONOS5_mastership = main.ONOScli5.roles()
522 ONOS6_mastership = main.ONOScli6.roles()
523 ONOS7_mastership = main.ONOScli7.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800524 # print json.dumps( json.loads( ONOS1_mastership ), sort_keys=True,
525 # indent=4, separators=( ',', ': ' ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800526 if "Error" in ONOS1_mastership or not ONOS1_mastership\
527 or "Error" in ONOS2_mastership or not ONOS2_mastership\
528 or "Error" in ONOS3_mastership or not ONOS3_mastership\
529 or "Error" in ONOS4_mastership or not ONOS4_mastership\
530 or "Error" in ONOS5_mastership or not ONOS5_mastership\
531 or "Error" in ONOS6_mastership or not ONOS6_mastership\
532 or "Error" in ONOS7_mastership or not ONOS7_mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800533 main.log.report( "Error in getting ONOS roles" )
534 main.log.warn(
535 "ONOS1 mastership response: " +
536 repr( ONOS1_mastership ) )
537 main.log.warn(
538 "ONOS2 mastership response: " +
539 repr( ONOS2_mastership ) )
540 main.log.warn(
541 "ONOS3 mastership response: " +
542 repr( ONOS3_mastership ) )
543 main.log.warn(
544 "ONOS4 mastership response: " +
545 repr( ONOS4_mastership ) )
546 main.log.warn(
547 "ONOS5 mastership response: " +
548 repr( ONOS5_mastership ) )
549 main.log.warn(
550 "ONOS6 mastership response: " +
551 repr( ONOS6_mastership ) )
552 main.log.warn(
553 "ONOS7 mastership response: " +
554 repr( ONOS7_mastership ) )
555 consistent_mastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800556 elif ONOS1_mastership == ONOS2_mastership\
Jon Hallb1290e82014-11-18 16:17:48 -0500557 and ONOS1_mastership == ONOS3_mastership\
558 and ONOS1_mastership == ONOS4_mastership\
559 and ONOS1_mastership == ONOS5_mastership\
560 and ONOS1_mastership == ONOS6_mastership\
561 and ONOS1_mastership == ONOS7_mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800562 mastership_state = ONOS1_mastership
563 consistent_mastership = main.TRUE
564 main.log.report(
565 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500566 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800567 main.log.warn(
568 "ONOS1 roles: ",
569 json.dumps(
570 json.loads( ONOS1_mastership ),
571 sort_keys=True,
572 indent=4,
573 separators=(
574 ',',
575 ': ' ) ) )
576 main.log.warn(
577 "ONOS2 roles: ",
578 json.dumps(
579 json.loads( ONOS2_mastership ),
580 sort_keys=True,
581 indent=4,
582 separators=(
583 ',',
584 ': ' ) ) )
585 main.log.warn(
586 "ONOS3 roles: ",
587 json.dumps(
588 json.loads( ONOS3_mastership ),
589 sort_keys=True,
590 indent=4,
591 separators=(
592 ',',
593 ': ' ) ) )
594 main.log.warn(
595 "ONOS4 roles: ",
596 json.dumps(
597 json.loads( ONOS4_mastership ),
598 sort_keys=True,
599 indent=4,
600 separators=(
601 ',',
602 ': ' ) ) )
603 main.log.warn(
604 "ONOS5 roles: ",
605 json.dumps(
606 json.loads( ONOS5_mastership ),
607 sort_keys=True,
608 indent=4,
609 separators=(
610 ',',
611 ': ' ) ) )
612 main.log.warn(
613 "ONOS6 roles: ",
614 json.dumps(
615 json.loads( ONOS6_mastership ),
616 sort_keys=True,
617 indent=4,
618 separators=(
619 ',',
620 ': ' ) ) )
621 main.log.warn(
622 "ONOS7 roles: ",
623 json.dumps(
624 json.loads( ONOS7_mastership ),
625 sort_keys=True,
626 indent=4,
627 separators=(
628 ',',
629 ': ' ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500630 consistent_mastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800631 utilities.assert_equals(
632 expect=main.TRUE,
633 actual=consistent_mastership,
634 onpass="Switch roles are consistent across all ONOS nodes",
635 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -0500636
Jon Hall6aec96b2015-01-19 14:49:31 -0800637 main.step( "Get the intents from each controller" )
Jon Hallb1290e82014-11-18 16:17:48 -0500638 global intent_state
Jon Hall94fd0472014-12-08 11:52:42 -0800639 intent_state = []
Jon Hallb1290e82014-11-18 16:17:48 -0500640 ONOS1_intents = main.ONOScli1.intents( json_format=True )
641 ONOS2_intents = main.ONOScli2.intents( json_format=True )
642 ONOS3_intents = main.ONOScli3.intents( json_format=True )
643 ONOS4_intents = main.ONOScli4.intents( json_format=True )
644 ONOS5_intents = main.ONOScli5.intents( json_format=True )
645 ONOS6_intents = main.ONOScli6.intents( json_format=True )
646 ONOS7_intents = main.ONOScli7.intents( json_format=True )
647 intent_check = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800648 if "Error" in ONOS1_intents or not ONOS1_intents\
649 or "Error" in ONOS2_intents or not ONOS2_intents\
650 or "Error" in ONOS3_intents or not ONOS3_intents\
651 or "Error" in ONOS4_intents or not ONOS4_intents\
652 or "Error" in ONOS5_intents or not ONOS5_intents\
653 or "Error" in ONOS6_intents or not ONOS6_intents\
654 or "Error" in ONOS7_intents or not ONOS7_intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800655 main.log.report( "Error in getting ONOS intents" )
656 main.log.warn( "ONOS1 intents response: " + repr( ONOS1_intents ) )
657 main.log.warn( "ONOS2 intents response: " + repr( ONOS2_intents ) )
658 main.log.warn( "ONOS3 intents response: " + repr( ONOS3_intents ) )
659 main.log.warn( "ONOS4 intents response: " + repr( ONOS4_intents ) )
660 main.log.warn( "ONOS5 intents response: " + repr( ONOS5_intents ) )
661 main.log.warn( "ONOS6 intents response: " + repr( ONOS6_intents ) )
662 main.log.warn( "ONOS7 intents response: " + repr( ONOS7_intents ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500663 elif ONOS1_intents == ONOS2_intents\
664 and ONOS1_intents == ONOS3_intents\
665 and ONOS1_intents == ONOS4_intents\
666 and ONOS1_intents == ONOS5_intents\
667 and ONOS1_intents == ONOS6_intents\
668 and ONOS1_intents == ONOS7_intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800669 intent_state = ONOS1_intents
670 intent_check = main.TRUE
671 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500672 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800673 main.log.warn(
674 "ONOS1 intents: ",
675 json.dumps(
676 json.loads( ONOS1_intents ),
677 sort_keys=True,
678 indent=4,
679 separators=(
680 ',',
681 ': ' ) ) )
682 main.log.warn(
683 "ONOS2 intents: ",
684 json.dumps(
685 json.loads( ONOS2_intents ),
686 sort_keys=True,
687 indent=4,
688 separators=(
689 ',',
690 ': ' ) ) )
691 main.log.warn(
692 "ONOS3 intents: ",
693 json.dumps(
694 json.loads( ONOS3_intents ),
695 sort_keys=True,
696 indent=4,
697 separators=(
698 ',',
699 ': ' ) ) )
700 main.log.warn(
701 "ONOS4 intents: ",
702 json.dumps(
703 json.loads( ONOS4_intents ),
704 sort_keys=True,
705 indent=4,
706 separators=(
707 ',',
708 ': ' ) ) )
709 main.log.warn(
710 "ONOS5 intents: ",
711 json.dumps(
712 json.loads( ONOS5_intents ),
713 sort_keys=True,
714 indent=4,
715 separators=(
716 ',',
717 ': ' ) ) )
718 main.log.warn(
719 "ONOS6 intents: ",
720 json.dumps(
721 json.loads( ONOS6_intents ),
722 sort_keys=True,
723 indent=4,
724 separators=(
725 ',',
726 ': ' ) ) )
727 main.log.warn(
728 "ONOS7 intents: ",
729 json.dumps(
730 json.loads( ONOS7_intents ),
731 sort_keys=True,
732 indent=4,
733 separators=(
734 ',',
735 ': ' ) ) )
736 utilities.assert_equals(
737 expect=main.TRUE,
738 actual=intent_check,
739 onpass="Intents are consistent across all ONOS nodes",
740 onfail="ONOS nodes have different views of intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500741
Jon Hall6aec96b2015-01-19 14:49:31 -0800742 main.step( "Get the flows from each controller" )
Jon Hallb1290e82014-11-18 16:17:48 -0500743 global flow_state
Jon Hall94fd0472014-12-08 11:52:42 -0800744 flow_state = []
Jon Hallb1290e82014-11-18 16:17:48 -0500745 ONOS1_flows = main.ONOScli1.flows( json_format=True )
746 ONOS2_flows = main.ONOScli2.flows( json_format=True )
747 ONOS3_flows = main.ONOScli3.flows( json_format=True )
748 ONOS4_flows = main.ONOScli4.flows( json_format=True )
749 ONOS5_flows = main.ONOScli5.flows( json_format=True )
750 ONOS6_flows = main.ONOScli6.flows( json_format=True )
751 ONOS7_flows = main.ONOScli7.flows( json_format=True )
Jon Hall6aec96b2015-01-19 14:49:31 -0800752 ONOS1_flows_json = json.loads( ONOS1_flows )
753 ONOS2_flows_json = json.loads( ONOS2_flows )
754 ONOS3_flows_json = json.loads( ONOS3_flows )
755 ONOS4_flows_json = json.loads( ONOS4_flows )
756 ONOS5_flows_json = json.loads( ONOS5_flows )
757 ONOS6_flows_json = json.loads( ONOS6_flows )
758 ONOS7_flows_json = json.loads( ONOS7_flows )
Jon Hallb1290e82014-11-18 16:17:48 -0500759 flow_check = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800760 if "Error" in ONOS1_flows or not ONOS1_flows\
761 or "Error" in ONOS2_flows or not ONOS2_flows\
762 or "Error" in ONOS3_flows or not ONOS3_flows\
763 or "Error" in ONOS4_flows or not ONOS4_flows\
764 or "Error" in ONOS5_flows or not ONOS5_flows\
765 or "Error" in ONOS6_flows or not ONOS6_flows\
766 or "Error" in ONOS7_flows or not ONOS7_flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800767 main.log.report( "Error in getting ONOS intents" )
768 main.log.warn( "ONOS1 flows repsponse: " + ONOS1_flows )
769 main.log.warn( "ONOS2 flows repsponse: " + ONOS2_flows )
770 main.log.warn( "ONOS3 flows repsponse: " + ONOS3_flows )
771 main.log.warn( "ONOS4 flows repsponse: " + ONOS4_flows )
772 main.log.warn( "ONOS5 flows repsponse: " + ONOS5_flows )
773 main.log.warn( "ONOS6 flows repsponse: " + ONOS6_flows )
774 main.log.warn( "ONOS7 flows repsponse: " + ONOS7_flows )
775 elif len( ONOS1_flows_json ) == len( ONOS2_flows_json )\
776 and len( ONOS1_flows_json ) == len( ONOS3_flows_json )\
777 and len( ONOS1_flows_json ) == len( ONOS4_flows_json )\
778 and len( ONOS1_flows_json ) == len( ONOS5_flows_json )\
779 and len( ONOS1_flows_json ) == len( ONOS6_flows_json )\
780 and len( ONOS1_flows_json ) == len( ONOS7_flows_json ):
781 # TODO: Do a better check, maybe compare flows on switches?
782 flow_state = ONOS1_flows
783 flow_check = main.TRUE
784 main.log.report( "Flow count is consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500785 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800786 main.log.warn( "ONOS1 flows: " +
787 json.dumps( ONOS1_flows_json, sort_keys=True,
788 indent=4, separators=( ',', ': ' ) ) )
789 main.log.warn( "ONOS2 flows: " +
790 json.dumps( ONOS2_flows_json, sort_keys=True,
791 indent=4, separators=( ',', ': ' ) ) )
792 main.log.warn( "ONOS3 flows: " +
793 json.dumps( ONOS3_flows_json, sort_keys=True,
794 indent=4, separators=( ',', ': ' ) ) )
795 main.log.warn( "ONOS4 flows: " +
796 json.dumps( ONOS4_flows_json, sort_keys=True,
797 indent=4, separators=( ',', ': ' ) ) )
798 main.log.warn( "ONOS5 flows: " +
799 json.dumps( ONOS5_flows_json, sort_keys=True,
800 indent=4, separators=( ',', ': ' ) ) )
801 main.log.warn( "ONOS6 flows: " +
802 json.dumps( ONOS6_flows_json, sort_keys=True,
803 indent=4, separators=( ',', ': ' ) ) )
804 main.log.warn( "ONOS7 flows: " +
805 json.dumps( ONOS7_flows_json, sort_keys=True,
806 indent=4, separators=( ',', ': ' ) ) )
807 utilities.assert_equals(
808 expect=main.TRUE,
809 actual=flow_check,
810 onpass="The flow count is consistent across all ONOS nodes",
811 onfail="ONOS nodes have different flow counts" )
Jon Hallb1290e82014-11-18 16:17:48 -0500812
Jon Hall6aec96b2015-01-19 14:49:31 -0800813 main.step( "Get the OF Table entries" )
Jon Hallb1290e82014-11-18 16:17:48 -0500814 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800815 flows = []
816 for i in range( 1, 29 ):
817 flows.append( main.Mininet2.get_flowTable( 1.3, "s" + str( i ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500818
Jon Hall6aec96b2015-01-19 14:49:31 -0800819 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hallb1290e82014-11-18 16:17:48 -0500820
Jon Hall6aec96b2015-01-19 14:49:31 -0800821 main.step( "Start continuous pings" )
822 main.Mininet2.pingLong(
823 src=main.params[ 'PING' ][ 'source1' ],
824 target=main.params[ 'PING' ][ 'target1' ],
825 pingTime=500 )
826 main.Mininet2.pingLong(
827 src=main.params[ 'PING' ][ 'source2' ],
828 target=main.params[ 'PING' ][ 'target2' ],
829 pingTime=500 )
830 main.Mininet2.pingLong(
831 src=main.params[ 'PING' ][ 'source3' ],
832 target=main.params[ 'PING' ][ 'target3' ],
833 pingTime=500 )
834 main.Mininet2.pingLong(
835 src=main.params[ 'PING' ][ 'source4' ],
836 target=main.params[ 'PING' ][ 'target4' ],
837 pingTime=500 )
838 main.Mininet2.pingLong(
839 src=main.params[ 'PING' ][ 'source5' ],
840 target=main.params[ 'PING' ][ 'target5' ],
841 pingTime=500 )
842 main.Mininet2.pingLong(
843 src=main.params[ 'PING' ][ 'source6' ],
844 target=main.params[ 'PING' ][ 'target6' ],
845 pingTime=500 )
846 main.Mininet2.pingLong(
847 src=main.params[ 'PING' ][ 'source7' ],
848 target=main.params[ 'PING' ][ 'target7' ],
849 pingTime=500 )
850 main.Mininet2.pingLong(
851 src=main.params[ 'PING' ][ 'source8' ],
852 target=main.params[ 'PING' ][ 'target8' ],
853 pingTime=500 )
854 main.Mininet2.pingLong(
855 src=main.params[ 'PING' ][ 'source9' ],
856 target=main.params[ 'PING' ][ 'target9' ],
857 pingTime=500 )
858 main.Mininet2.pingLong(
859 src=main.params[ 'PING' ][ 'source10' ],
860 target=main.params[ 'PING' ][ 'target10' ],
861 pingTime=500 )
Jon Hallb1290e82014-11-18 16:17:48 -0500862
Jon Hall6aec96b2015-01-19 14:49:31 -0800863 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -0500864 ctrls = []
865 count = 1
866 while True:
867 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800868 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
869 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
870 temp = temp + ( "ONOS" + str( count ), )
871 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
872 temp = temp + \
873 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
874 ctrls.append( temp )
Jon Hallb1290e82014-11-18 16:17:48 -0500875 count = count + 1
876 else:
877 break
Jon Hall6aec96b2015-01-19 14:49:31 -0800878 MNTopo = TestONTopology(
879 main.Mininet1,
880 ctrls ) # can also add Intent API info for intent operations
Jon Hallb1290e82014-11-18 16:17:48 -0500881
Jon Hall6aec96b2015-01-19 14:49:31 -0800882 main.step( "Collecting topology information from ONOS" )
Jon Hallb1290e82014-11-18 16:17:48 -0500883 devices = []
884 devices.append( main.ONOScli1.devices() )
885 devices.append( main.ONOScli2.devices() )
886 devices.append( main.ONOScli3.devices() )
887 devices.append( main.ONOScli4.devices() )
888 devices.append( main.ONOScli5.devices() )
889 devices.append( main.ONOScli6.devices() )
890 devices.append( main.ONOScli7.devices() )
Jon Hallb1290e82014-11-18 16:17:48 -0500891 hosts = []
892 hosts.append( main.ONOScli1.hosts() )
893 hosts.append( main.ONOScli2.hosts() )
894 hosts.append( main.ONOScli3.hosts() )
895 hosts.append( main.ONOScli4.hosts() )
896 hosts.append( main.ONOScli5.hosts() )
897 hosts.append( main.ONOScli6.hosts() )
898 hosts.append( main.ONOScli7.hosts() )
Jon Hallb1290e82014-11-18 16:17:48 -0500899 ports = []
900 ports.append( main.ONOScli1.ports() )
901 ports.append( main.ONOScli2.ports() )
902 ports.append( main.ONOScli3.ports() )
903 ports.append( main.ONOScli4.ports() )
904 ports.append( main.ONOScli5.ports() )
905 ports.append( main.ONOScli6.ports() )
906 ports.append( main.ONOScli7.ports() )
907 links = []
908 links.append( main.ONOScli1.links() )
909 links.append( main.ONOScli2.links() )
910 links.append( main.ONOScli3.links() )
911 links.append( main.ONOScli4.links() )
912 links.append( main.ONOScli5.links() )
913 links.append( main.ONOScli6.links() )
914 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800915 clusters = []
916 clusters.append( main.ONOScli1.clusters() )
917 clusters.append( main.ONOScli2.clusters() )
918 clusters.append( main.ONOScli3.clusters() )
919 clusters.append( main.ONOScli4.clusters() )
920 clusters.append( main.ONOScli5.clusters() )
921 clusters.append( main.ONOScli6.clusters() )
922 clusters.append( main.ONOScli7.clusters() )
923 paths = []
924 temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800925 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800926 temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800927 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800928 temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800929 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800930 temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800931 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800932 temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800933 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800934 temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800935 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800936 temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800937 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800938
Jon Hall6aec96b2015-01-19 14:49:31 -0800939 # Compare json objects for hosts, dataplane clusters and paths
Jon Hall94fd0472014-12-08 11:52:42 -0800940
Jon Hall6aec96b2015-01-19 14:49:31 -0800941 # hosts
Jon Hall94fd0472014-12-08 11:52:42 -0800942 consistent_hosts_result = main.TRUE
943 for controller in range( len( hosts ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800944 controller_str = str( controller + 1 )
945 if "Error" not in hosts[ controller ]:
946 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800947 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800948 else: # hosts not consistent
949 main.log.report( "hosts from ONOS" +
950 controller_str +
951 " is inconsistent with ONOS1" )
952 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800953 consistent_hosts_result = main.FALSE
954
955 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800956 main.log.report( "Error in getting ONOS hosts from ONOS" +
957 controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -0800958 consistent_hosts_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800959 main.log.warn( "ONOS" + controller_str +
960 " hosts response: " +
961 repr( hosts[ controller ] ) )
962 utilities.assert_equals(
963 expect=main.TRUE,
964 actual=consistent_hosts_result,
965 onpass="Hosts view is consistent across all ONOS nodes",
966 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -0800967
Jon Hall6aec96b2015-01-19 14:49:31 -0800968 # Strongly connected clusters of devices
Jon Hall94fd0472014-12-08 11:52:42 -0800969 consistent_clusters_result = main.TRUE
970 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800971 if "Error" not in clusters[ controller ]:
972 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800973 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800974 else: # clusters not consistent
975 main.log.report( "clusters from ONOS" +
976 controller_str +
977 " is inconsistent with ONOS1" )
Jon Hall94fd0472014-12-08 11:52:42 -0800978 consistent_clusters_result = main.FALSE
979
980 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800981 main.log.report( "Error in getting dataplane clusters " +
982 "from ONOS" + controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -0800983 consistent_clusters_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800984 main.log.warn( "ONOS" + controller_str +
985 " clusters response: " +
986 repr( clusters[ controller ] ) )
987 utilities.assert_equals(
988 expect=main.TRUE,
989 actual=consistent_clusters_result,
990 onpass="Clusters view is consistent across all ONOS nodes",
991 onfail="ONOS nodes have different views of clusters" )
992 # there should always only be one cluster
993 num_clusters = len( json.loads( clusters[ 0 ] ) )
994 utilities.assert_equals(
995 expect=1,
996 actual=num_clusters,
997 onpass="ONOS shows 1 SCC",
998 onfail="ONOS shows " +
999 str( num_clusters ) +
1000 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001001
Jon Hall6aec96b2015-01-19 14:49:31 -08001002 # paths
Jon Hall94fd0472014-12-08 11:52:42 -08001003 consistent_paths_result = main.TRUE
1004 for controller in range( len( paths ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001005 controller_str = str( controller + 1 )
1006 if "Error" not in paths[ controller ]:
1007 if paths[ controller ] == paths[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001008 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001009 else: # paths not consistent
1010 main.log.report( "paths from ONOS" + controller_str +
1011 " is inconsistent with ONOS1" )
Jon Hall94fd0472014-12-08 11:52:42 -08001012 consistent_paths_result = main.FALSE
1013
1014 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001015 main.log.report( "Error in getting paths from ONOS" +
1016 controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -08001017 consistent_paths_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001018 main.log.warn( "ONOS" + controller_str + " paths response: " +
1019 repr( paths[ controller ] ) )
1020 utilities.assert_equals(
1021 expect=main.TRUE,
1022 actual=consistent_paths_result,
1023 onpass="Paths count is consistent across all ONOS nodes",
1024 onfail="ONOS nodes have different counts of paths" )
Jon Hallb1290e82014-11-18 16:17:48 -05001025
Jon Hall6aec96b2015-01-19 14:49:31 -08001026 main.step( "Comparing ONOS topology to MN" )
Jon Hallb1290e82014-11-18 16:17:48 -05001027 devices_results = main.TRUE
1028 ports_results = main.TRUE
1029 links_results = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001030 for controller in range( num_controllers ):
1031 controller_str = str( controller + 1 )
1032 if devices[ controller ] or "Error" not in devices[ controller ]:
1033 current_devices_result = main.Mininet1.compare_switches(
1034 MNTopo,
1035 json.loads(
1036 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001037 else:
1038 current_devices_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001039 utilities.assert_equals( expect=main.TRUE,
1040 actual=current_devices_result,
1041 onpass="ONOS" + controller_str +
1042 " Switches view is correct",
1043 onfail="ONOS" + controller_str +
1044 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001045
Jon Hall6aec96b2015-01-19 14:49:31 -08001046 if ports[ controller ] or "Error" not in ports[ controller ]:
1047 current_ports_result = main.Mininet1.compare_ports(
1048 MNTopo,
1049 json.loads(
1050 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001051 else:
1052 current_ports_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001053 utilities.assert_equals( expect=main.TRUE,
1054 actual=current_ports_result,
1055 onpass="ONOS" + controller_str +
1056 " ports view is correct",
1057 onfail="ONOS" + controller_str +
1058 " ports view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001059
Jon Hall6aec96b2015-01-19 14:49:31 -08001060 if links[ controller ] or "Error" not in links[ controller ]:
1061 current_links_result = main.Mininet1.compare_links(
1062 MNTopo,
1063 json.loads(
1064 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001065 else:
1066 current_links_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001067 utilities.assert_equals( expect=main.TRUE,
1068 actual=current_links_result,
1069 onpass="ONOS" + controller_str +
1070 " links view is correct",
1071 onfail="ONOS" + controller_str +
1072 " links view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001073
1074 devices_results = devices_results and current_devices_result
1075 ports_results = ports_results and current_ports_result
1076 links_results = links_results and current_links_result
1077
Jon Hall94fd0472014-12-08 11:52:42 -08001078 topo_result = devices_results and ports_results and links_results\
Jon Hall6aec96b2015-01-19 14:49:31 -08001079 and consistent_hosts_result and consistent_clusters_result\
1080 and consistent_paths_result
1081 utilities.assert_equals( expect=main.TRUE, actual=topo_result,
1082 onpass="Topology Check Test successful",
1083 onfail="Topology Check Test NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001084
1085 final_assert = main.TRUE
1086 final_assert = final_assert and topo_result and flow_check \
Jon Hall6aec96b2015-01-19 14:49:31 -08001087 and intent_check and consistent_mastership and roles_not_null
1088 utilities.assert_equals( expect=main.TRUE, actual=final_assert,
1089 onpass="State check successful",
1090 onfail="State check NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001091
Jon Hall6aec96b2015-01-19 14:49:31 -08001092 def CASE6( self, main ):
1093 """
Jon Hallb1290e82014-11-18 16:17:48 -05001094 The Failure case. Since this is the Sanity test, we do nothing.
Jon Hall6aec96b2015-01-19 14:49:31 -08001095 """
Jon Hall368769f2014-11-19 15:43:35 -08001096 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001097 main.log.report( "Wait 60 seconds instead of inducing a failure" )
1098 time.sleep( 60 )
1099 utilities.assert_equals(
1100 expect=main.TRUE,
1101 actual=main.TRUE,
1102 onpass="Sleeping 60 seconds",
1103 onfail="Something is terribly wrong with my math" )
Jon Hallb1290e82014-11-18 16:17:48 -05001104
Jon Hall6aec96b2015-01-19 14:49:31 -08001105 def CASE7( self, main ):
1106 """
Jon Hall368769f2014-11-19 15:43:35 -08001107 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001108 """
Jon Hallb1290e82014-11-18 16:17:48 -05001109 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001110 main.case( "Running ONOS Constant State Tests" )
Jon Hallb1290e82014-11-18 16:17:48 -05001111
Jon Hall6aec96b2015-01-19 14:49:31 -08001112 # Assert that each device has a master
Jon Hall94fd0472014-12-08 11:52:42 -08001113 ONOS1_master_not_null = main.ONOScli1.roles_not_null()
1114 ONOS2_master_not_null = main.ONOScli2.roles_not_null()
1115 ONOS3_master_not_null = main.ONOScli3.roles_not_null()
1116 ONOS4_master_not_null = main.ONOScli4.roles_not_null()
1117 ONOS5_master_not_null = main.ONOScli5.roles_not_null()
1118 ONOS6_master_not_null = main.ONOScli6.roles_not_null()
1119 ONOS7_master_not_null = main.ONOScli7.roles_not_null()
1120 roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\
Jon Hall6aec96b2015-01-19 14:49:31 -08001121 ONOS3_master_not_null and ONOS4_master_not_null and\
1122 ONOS5_master_not_null and ONOS6_master_not_null and\
1123 ONOS7_master_not_null
1124 utilities.assert_equals(
1125 expect=main.TRUE,
1126 actual=roles_not_null,
1127 onpass="Each device has a master",
1128 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001129
Jon Hall6aec96b2015-01-19 14:49:31 -08001130 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001131 ONOS1_mastership = main.ONOScli1.roles()
1132 ONOS2_mastership = main.ONOScli2.roles()
1133 ONOS3_mastership = main.ONOScli3.roles()
1134 ONOS4_mastership = main.ONOScli4.roles()
1135 ONOS5_mastership = main.ONOScli5.roles()
1136 ONOS6_mastership = main.ONOScli6.roles()
1137 ONOS7_mastership = main.ONOScli7.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -08001138 # print json.dumps( json.loads( ONOS1_mastership ), sort_keys=True,
1139 # indent=4, separators=( ',', ': ' ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001140 if "Error" in ONOS1_mastership or not ONOS1_mastership\
1141 or "Error" in ONOS2_mastership or not ONOS2_mastership\
1142 or "Error" in ONOS3_mastership or not ONOS3_mastership\
1143 or "Error" in ONOS4_mastership or not ONOS4_mastership\
1144 or "Error" in ONOS5_mastership or not ONOS5_mastership\
1145 or "Error" in ONOS6_mastership or not ONOS6_mastership\
1146 or "Error" in ONOS7_mastership or not ONOS7_mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001147 main.log.error( "Error in getting ONOS mastership" )
1148 main.log.warn( "ONOS1 mastership response: " +
1149 repr( ONOS1_mastership ) )
1150 main.log.warn( "ONOS2 mastership response: " +
1151 repr( ONOS2_mastership ) )
1152 main.log.warn( "ONOS3 mastership response: " +
1153 repr( ONOS3_mastership ) )
1154 main.log.warn( "ONOS4 mastership response: " +
1155 repr( ONOS4_mastership ) )
1156 main.log.warn( "ONOS5 mastership response: " +
1157 repr( ONOS5_mastership ) )
1158 main.log.warn( "ONOS6 mastership response: " +
1159 repr( ONOS6_mastership ) )
1160 main.log.warn( "ONOS7 mastership response: " +
1161 repr( ONOS7_mastership ) )
1162 consistent_mastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001163 elif ONOS1_mastership == ONOS2_mastership\
Jon Hallb1290e82014-11-18 16:17:48 -05001164 and ONOS1_mastership == ONOS3_mastership\
1165 and ONOS1_mastership == ONOS4_mastership\
1166 and ONOS1_mastership == ONOS5_mastership\
1167 and ONOS1_mastership == ONOS6_mastership\
1168 and ONOS1_mastership == ONOS7_mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001169 consistent_mastership = main.TRUE
1170 main.log.report(
1171 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001172 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001173 main.log.warn( "ONOS1 roles: ", json.dumps(
1174 json.loads( ONOS1_mastership ), sort_keys=True, indent=4,
1175 separators=( ',', ': ' ) ) )
1176 main.log.warn( "ONOS2 roles: ", json.dumps(
1177 json.loads( ONOS2_mastership ), sort_keys=True, indent=4,
1178 separators=( ',', ': ' ) ) )
1179 main.log.warn( "ONOS3 roles: ", json.dumps(
1180 json.loads( ONOS3_mastership ), sort_keys=True, indent=4,
1181 separators=( ',', ': ' ) ) )
1182 main.log.warn( "ONOS4 roles: ", json.dumps(
1183 json.loads( ONOS4_mastership ), sort_keys=True, indent=4,
1184 separators=( ',', ': ' ) ) )
1185 main.log.warn( "ONOS5 roles: ", json.dumps(
1186 json.loads( ONOS5_mastership ), sort_keys=True, indent=4,
1187 separators=( ',', ': ' ) ) )
1188 main.log.warn( "ONOS6 roles: ", json.dumps(
1189 json.loads( ONOS6_mastership ), sort_keys=True, indent=4,
1190 separators=( ',', ': ' ) ) )
1191 main.log.warn( "ONOS7 roles: ", json.dumps(
1192 json.loads( ONOS7_mastership ), sort_keys=True, indent=4,
1193 separators=( ',', ': ' ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001194 consistent_mastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001195 utilities.assert_equals(
1196 expect=main.TRUE,
1197 actual=consistent_mastership,
1198 onpass="Switch roles are consistent across all ONOS nodes",
1199 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -05001200
1201 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001202 main.step( description2 )
Jon Hallb1290e82014-11-18 16:17:48 -05001203
Jon Hall6aec96b2015-01-19 14:49:31 -08001204 current_json = json.loads( ONOS1_mastership )
1205 old_json = json.loads( mastership_state )
Jon Hallb1290e82014-11-18 16:17:48 -05001206 mastership_check = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001207 for i in range( 1, 29 ):
1208 switchDPID = str(
1209 main.Mininet1.getSwitchDPID(
1210 switch="s" +
1211 str( i ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001212
Jon Hall6aec96b2015-01-19 14:49:31 -08001213 current = [ switch[ 'master' ] for switch in current_json
1214 if switchDPID in switch[ 'id' ] ]
1215 old = [ switch[ 'master' ] for switch in old_json
1216 if switchDPID in switch[ 'id' ] ]
Jon Hallb1290e82014-11-18 16:17:48 -05001217 if current == old:
1218 mastership_check = mastership_check and main.TRUE
1219 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001220 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hallb1290e82014-11-18 16:17:48 -05001221 mastership_check = main.FALSE
1222 if mastership_check == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001223 main.log.report( "Mastership of Switches was not changed" )
1224 utilities.assert_equals(
1225 expect=main.TRUE,
1226 actual=mastership_check,
1227 onpass="Mastership of Switches was not changed",
1228 onfail="Mastership of some switches changed" )
Jon Hallb1290e82014-11-18 16:17:48 -05001229 mastership_check = mastership_check and consistent_mastership
1230
Jon Hall6aec96b2015-01-19 14:49:31 -08001231 main.step( "Get the intents and compare across all nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001232 ONOS1_intents = main.ONOScli1.intents( json_format=True )
1233 ONOS2_intents = main.ONOScli2.intents( json_format=True )
1234 ONOS3_intents = main.ONOScli3.intents( json_format=True )
1235 ONOS4_intents = main.ONOScli4.intents( json_format=True )
1236 ONOS5_intents = main.ONOScli5.intents( json_format=True )
1237 ONOS6_intents = main.ONOScli6.intents( json_format=True )
1238 ONOS7_intents = main.ONOScli7.intents( json_format=True )
1239 intent_check = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001240 if "Error" in ONOS1_intents or not ONOS1_intents\
1241 or "Error" in ONOS2_intents or not ONOS2_intents\
1242 or "Error" in ONOS3_intents or not ONOS3_intents\
1243 or "Error" in ONOS4_intents or not ONOS4_intents\
1244 or "Error" in ONOS5_intents or not ONOS5_intents\
1245 or "Error" in ONOS6_intents or not ONOS6_intents\
1246 or "Error" in ONOS7_intents or not ONOS7_intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001247 main.log.report( "Error in getting ONOS intents" )
1248 main.log.warn( "ONOS1 intents response: " + repr( ONOS1_intents ) )
1249 main.log.warn( "ONOS2 intents response: " + repr( ONOS2_intents ) )
1250 main.log.warn( "ONOS3 intents response: " + repr( ONOS3_intents ) )
1251 main.log.warn( "ONOS4 intents response: " + repr( ONOS4_intents ) )
1252 main.log.warn( "ONOS5 intents response: " + repr( ONOS5_intents ) )
1253 main.log.warn( "ONOS6 intents response: " + repr( ONOS6_intents ) )
1254 main.log.warn( "ONOS7 intents response: " + repr( ONOS7_intents ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001255 elif ONOS1_intents == ONOS2_intents\
1256 and ONOS1_intents == ONOS3_intents\
1257 and ONOS1_intents == ONOS4_intents\
1258 and ONOS1_intents == ONOS5_intents\
1259 and ONOS1_intents == ONOS6_intents\
1260 and ONOS1_intents == ONOS7_intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001261 intent_check = main.TRUE
1262 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001263 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001264 main.log.warn( "ONOS1 intents: " )
1265 print json.dumps( json.loads( ONOS1_intents ), sort_keys=True,
1266 indent=4, separators=( ',', ': ' ) )
1267 main.log.warn( "ONOS2 intents: " )
1268 print json.dumps( json.loads( ONOS2_intents ), sort_keys=True,
1269 indent=4, separators=( ',', ': ' ) )
1270 main.log.warn( "ONOS3 intents: " )
1271 print json.dumps( json.loads( ONOS3_intents ), sort_keys=True,
1272 indent=4, separators=( ',', ': ' ) )
1273 main.log.warn( "ONOS4 intents: " )
1274 print json.dumps( json.loads( ONOS4_intents ), sort_keys=True,
1275 indent=4, separators=( ',', ': ' ) )
1276 main.log.warn( "ONOS5 intents: " )
1277 print json.dumps( json.loads( ONOS5_intents ), sort_keys=True,
1278 indent=4, separators=( ',', ': ' ) )
1279 main.log.warn( "ONOS6 intents: " )
1280 print json.dumps( json.loads( ONOS6_intents ), sort_keys=True,
1281 indent=4, separators=( ',', ': ' ) )
1282 main.log.warn( "ONOS7 intents: " )
1283 print json.dumps( json.loads( ONOS7_intents ), sort_keys=True,
1284 indent=4, separators=( ',', ': ' ) )
1285 utilities.assert_equals(
1286 expect=main.TRUE,
1287 actual=intent_check,
1288 onpass="Intents are consistent across all ONOS nodes",
1289 onfail="ONOS nodes have different views of intents" )
Jon Hallb1290e82014-11-18 16:17:48 -05001290
Jon Hall6aec96b2015-01-19 14:49:31 -08001291 # NOTE: Hazelcast has no durability, so intents are lost across system
1292 # restarts
1293 main.step( "Compare current intents with intents before the failure" )
1294 # NOTE: this requires case 5 to pass for intent_state to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001295 # maybe we should stop the test if that fails?
Jon Hallb1290e82014-11-18 16:17:48 -05001296 if intent_state == ONOS1_intents:
1297 same_intents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001298 main.log.report( "Intents are consistent with before failure" )
1299 # TODO: possibly the states have changed? we may need to figure out
1300 # what the aceptable states are
Jon Hallb1290e82014-11-18 16:17:48 -05001301 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001302 try:
1303 main.log.warn( "ONOS1 intents: " )
1304 print json.dumps( json.loads( ONOS1_intents ),
1305 sort_keys=True, indent=4,
1306 separators=( ',', ': ' ) )
1307 except:
1308 pass
Jon Hallb1290e82014-11-18 16:17:48 -05001309 same_intents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001310 utilities.assert_equals(
1311 expect=main.TRUE,
1312 actual=same_intents,
1313 onpass="Intents are consistent with before failure",
1314 onfail="The Intents changed during failure" )
Jon Hallb1290e82014-11-18 16:17:48 -05001315 intent_check = intent_check and same_intents
1316
Jon Hall6aec96b2015-01-19 14:49:31 -08001317 main.step( "Get the OF Table entries and compare to before " +
1318 "component failure" )
Jon Hallb1290e82014-11-18 16:17:48 -05001319 Flow_Tables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001320 flows2 = []
1321 for i in range( 28 ):
1322 main.log.info( "Checking flow table on s" + str( i + 1 ) )
1323 tmp_flows = main.Mininet2.get_flowTable( 1.3, "s" + str( i + 1 ) )
1324 flows2.append( tmp_flows )
1325 temp_result = main.Mininet2.flow_comp(
1326 flow1=flows[ i ],
1327 flow2=tmp_flows )
Jon Hall94fd0472014-12-08 11:52:42 -08001328 Flow_Tables = Flow_Tables and temp_result
Jon Hallb1290e82014-11-18 16:17:48 -05001329 if Flow_Tables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001330 main.log.info( "Differences in flow table for switch: s" +
1331 str( i + 1 ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001332 if Flow_Tables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001333 main.log.report( "No changes were found in the flow tables" )
1334 utilities.assert_equals(
1335 expect=main.TRUE,
1336 actual=Flow_Tables,
1337 onpass="No changes were found in the flow tables",
1338 onfail="Changes were found in the flow tables" )
Jon Hallb1290e82014-11-18 16:17:48 -05001339
Jon Hall6aec96b2015-01-19 14:49:31 -08001340 main.step( "Check the continuous pings to ensure that no packets " +
1341 "were dropped during component failure" )
1342 # FIXME: This check is always failing. Investigate cause
1343 # NOTE: this may be something to do with file permsissions
Jon Hallb1290e82014-11-18 16:17:48 -05001344 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001345 main.Mininet2.pingKill(
1346 main.params[ 'TESTONUSER' ],
1347 main.params[ 'TESTONIP' ] )
1348 Loss_In_Pings = main.FALSE
1349 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1350 for i in range( 8, 18 ):
1351 main.log.info(
1352 "Checking for a loss in pings along flow from s" +
1353 str( i ) )
1354 Loss_In_Pings = main.Mininet2.checkForLoss(
1355 "/tmp/ping.h" +
1356 str( i ) ) or Loss_In_Pings
Jon Hallb1290e82014-11-18 16:17:48 -05001357 if Loss_In_Pings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001358 main.log.info( "Loss in ping detected" )
Jon Hallb1290e82014-11-18 16:17:48 -05001359 elif Loss_In_Pings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001360 main.log.info( "There are multiple mininet process running" )
Jon Hallb1290e82014-11-18 16:17:48 -05001361 elif Loss_In_Pings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001362 main.log.info( "No Loss in the pings" )
1363 main.log.report( "No loss of dataplane connectivity" )
1364 utilities.assert_equals(
1365 expect=main.FALSE,
1366 actual=Loss_In_Pings,
1367 onpass="No Loss of connectivity",
1368 onfail="Loss of dataplane connectivity detected" )
Jon Hallb1290e82014-11-18 16:17:48 -05001369
Jon Hall6aec96b2015-01-19 14:49:31 -08001370 # Test of LeadershipElection
1371 # NOTE: this only works for the sanity test. In case of failures,
1372 # leader will likely change
Jon Hall669173b2014-12-17 11:36:30 -08001373 leader = ONOS1_ip
1374 leader_result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001375 for controller in range( 1, num_controllers + 1 ):
1376 # loop through ONOScli handlers
1377 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall669173b2014-12-17 11:36:30 -08001378 leaderN = node.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001379 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001380 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001381 # all is well
1382 # NOTE: In failure scenario, this could be a new node, maybe
1383 # check != ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001384 pass
1385 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001386 # error in response
1387 main.log.report( "Something is wrong with " +
1388 "election_test_leader function," +
1389 " check the error logs" )
Jon Hall669173b2014-12-17 11:36:30 -08001390 leader_result = main.FALSE
1391 elif leader != leaderN:
1392 leader_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001393 main.log.report( "ONOS" + str( controller ) + " sees " +
1394 str( leaderN ) +
1395 " as the leader of the election app. " +
1396 "Leader should be " + str( leader ) )
Jon Hall669173b2014-12-17 11:36:30 -08001397 if leader_result:
Jon Hall6aec96b2015-01-19 14:49:31 -08001398 main.log.report( "Leadership election tests passed(consistent " +
1399 "view of leader across listeners and a new " +
1400 "leader was re-elected if applicable)" )
1401 utilities.assert_equals(
1402 expect=main.TRUE,
1403 actual=leader_result,
1404 onpass="Leadership election passed",
1405 onfail="Something went wrong with Leadership election" )
Jon Hallb1290e82014-11-18 16:17:48 -05001406
Jon Hall6aec96b2015-01-19 14:49:31 -08001407 result = mastership_check and intent_check and Flow_Tables and\
1408 ( not Loss_In_Pings ) and roles_not_null and leader_result
1409 result = int( result )
Jon Hallb1290e82014-11-18 16:17:48 -05001410 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001411 main.log.report( "Constant State Tests Passed" )
1412 utilities.assert_equals( expect=main.TRUE, actual=result,
1413 onpass="Constant State Tests Passed",
1414 onfail="Constant state tests failed" )
Jon Hallb1290e82014-11-18 16:17:48 -05001415
Jon Hall6aec96b2015-01-19 14:49:31 -08001416 def CASE8( self, main ):
1417 """
Jon Hallb1290e82014-11-18 16:17:48 -05001418 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001419 """
Jon Hallb1290e82014-11-18 16:17:48 -05001420 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001421 # FIXME add this path to params
1422 sys.path.append( "/home/admin/sts" )
1423 # assumes that sts is already in you PYTHONPATH
1424 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -05001425 import json
Jon Hall73cf9cc2014-11-20 22:28:38 -08001426 import time
Jon Hallb1290e82014-11-18 16:17:48 -05001427
Jon Hall6aec96b2015-01-19 14:49:31 -08001428 description = "Compare ONOS Topology view to Mininet topology"
1429 main.case( description )
1430 main.log.report( description )
1431 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -05001432 ctrls = []
1433 count = 1
1434 while True:
1435 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001436 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1437 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1438 temp = temp + ( "ONOS" + str( count ), )
1439 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1440 temp = temp + \
1441 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1442 ctrls.append( temp )
Jon Hallb1290e82014-11-18 16:17:48 -05001443 count = count + 1
1444 else:
1445 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001446 MNTopo = TestONTopology(
1447 main.Mininet1,
1448 ctrls ) # can also add Intent API info for intent operations
Jon Hallb1290e82014-11-18 16:17:48 -05001449
Jon Hall6aec96b2015-01-19 14:49:31 -08001450 main.step( "Comparing ONOS topology to MN" )
Jon Hallb1290e82014-11-18 16:17:48 -05001451 devices_results = main.TRUE
1452 ports_results = main.TRUE
1453 links_results = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001454 topo_result = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001455 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001456 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001457 main.step( "Collecting topology information from ONOS" )
Jon Hall94fd0472014-12-08 11:52:42 -08001458 start_time = time.time()
1459 while topo_result == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001460 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001461 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001462 # TODO: Depricate STS usage
1463 MNTopo = TestONTopology(
1464 main.Mininet1,
1465 ctrls )
Jon Hall94fd0472014-12-08 11:52:42 -08001466 cli_start = time.time()
1467 devices = []
1468 devices.append( main.ONOScli1.devices() )
1469 devices.append( main.ONOScli2.devices() )
1470 devices.append( main.ONOScli3.devices() )
1471 devices.append( main.ONOScli4.devices() )
1472 devices.append( main.ONOScli5.devices() )
1473 devices.append( main.ONOScli6.devices() )
1474 devices.append( main.ONOScli7.devices() )
1475 hosts = []
1476 hosts.append( main.ONOScli1.hosts() )
1477 hosts.append( main.ONOScli2.hosts() )
1478 hosts.append( main.ONOScli3.hosts() )
1479 hosts.append( main.ONOScli4.hosts() )
1480 hosts.append( main.ONOScli5.hosts() )
1481 hosts.append( main.ONOScli6.hosts() )
1482 hosts.append( main.ONOScli7.hosts() )
1483 ports = []
1484 ports.append( main.ONOScli1.ports() )
1485 ports.append( main.ONOScli2.ports() )
1486 ports.append( main.ONOScli3.ports() )
1487 ports.append( main.ONOScli4.ports() )
1488 ports.append( main.ONOScli5.ports() )
1489 ports.append( main.ONOScli6.ports() )
1490 ports.append( main.ONOScli7.ports() )
1491 links = []
1492 links.append( main.ONOScli1.links() )
1493 links.append( main.ONOScli2.links() )
1494 links.append( main.ONOScli3.links() )
1495 links.append( main.ONOScli4.links() )
1496 links.append( main.ONOScli5.links() )
1497 links.append( main.ONOScli6.links() )
1498 links.append( main.ONOScli7.links() )
1499 clusters = []
1500 clusters.append( main.ONOScli1.clusters() )
1501 clusters.append( main.ONOScli2.clusters() )
1502 clusters.append( main.ONOScli3.clusters() )
1503 clusters.append( main.ONOScli4.clusters() )
1504 clusters.append( main.ONOScli5.clusters() )
1505 clusters.append( main.ONOScli6.clusters() )
1506 clusters.append( main.ONOScli7.clusters() )
1507 paths = []
1508 temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001509 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001510 temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001511 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001512 temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001513 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001514 temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001515 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001516 temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001517 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001518 temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001519 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001520 temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001521 paths.append( temp_topo.get( 'paths', False ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001522
Jon Hall94fd0472014-12-08 11:52:42 -08001523 elapsed = time.time() - start_time
1524 cli_time = time.time() - cli_start
Jon Hall6aec96b2015-01-19 14:49:31 -08001525 print "CLI time: " + str( cli_time )
Jon Hallb1290e82014-11-18 16:17:48 -05001526
Jon Hall6aec96b2015-01-19 14:49:31 -08001527 for controller in range( num_controllers ):
1528 controller_str = str( controller + 1 )
1529 if devices[ controller ] or "Error" not in devices[
1530 controller ]:
1531 current_devices_result = main.Mininet1.compare_switches(
1532 MNTopo,
1533 json.loads(
1534 devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001535 else:
1536 current_devices_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001537 utilities.assert_equals( expect=main.TRUE,
1538 actual=current_devices_result,
1539 onpass="ONOS" + controller_str +
1540 " Switches view is correct",
1541 onfail="ONOS" + controller_str +
1542 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001543
Jon Hall6aec96b2015-01-19 14:49:31 -08001544 if ports[ controller ] or "Error" not in ports[ controller ]:
1545 current_ports_result = main.Mininet1.compare_ports(
1546 MNTopo,
1547 json.loads(
1548 ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001549 else:
1550 current_ports_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001551 utilities.assert_equals( expect=main.TRUE,
1552 actual=current_ports_result,
1553 onpass="ONOS" + controller_str +
1554 " ports view is correct",
1555 onfail="ONOS" + controller_str +
1556 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001557
Jon Hall6aec96b2015-01-19 14:49:31 -08001558 if links[ controller ] or "Error" not in links[ controller ]:
1559 current_links_result = main.Mininet1.compare_links(
1560 MNTopo,
1561 json.loads(
1562 links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001563 else:
1564 current_links_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001565 utilities.assert_equals( expect=main.TRUE,
1566 actual=current_links_result,
1567 onpass="ONOS" + controller_str +
1568 " links view is correct",
1569 onfail="ONOS" + controller_str +
1570 " links view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001571 devices_results = devices_results and current_devices_result
1572 ports_results = ports_results and current_ports_result
1573 links_results = links_results and current_links_result
Jon Hall94fd0472014-12-08 11:52:42 -08001574
Jon Hall6aec96b2015-01-19 14:49:31 -08001575 # Compare json objects for hosts, dataplane clusters and paths
Jon Hall94fd0472014-12-08 11:52:42 -08001576
Jon Hall6aec96b2015-01-19 14:49:31 -08001577 # hosts
Jon Hall94fd0472014-12-08 11:52:42 -08001578 consistent_hosts_result = main.TRUE
1579 for controller in range( len( hosts ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001580 controller_str = str( controller + 1 )
1581 if "Error" not in hosts[ controller ]:
1582 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001583 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001584 else: # hosts not consistent
1585 main.log.report( "hosts from ONOS" + controller_str +
1586 " is inconsistent with ONOS1" )
1587 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001588 consistent_hosts_result = main.FALSE
1589
1590 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001591 main.log.report( "Error in getting ONOS hosts from ONOS" +
1592 controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -08001593 consistent_hosts_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001594 main.log.warn( "ONOS" + controller_str +
1595 " hosts response: " +
1596 repr( hosts[ controller ] ) )
1597 utilities.assert_equals(
1598 expect=main.TRUE,
1599 actual=consistent_hosts_result,
1600 onpass="Hosts view is consistent across all ONOS nodes",
1601 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001602
Jon Hall6aec96b2015-01-19 14:49:31 -08001603 # Strongly connected clusters of devices
Jon Hall94fd0472014-12-08 11:52:42 -08001604 consistent_clusters_result = main.TRUE
1605 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001606 controller_str = str( controller + 1 )
1607 if "Error" not in clusters[ controller ]:
1608 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001609 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001610 else: # clusters not consistent
1611 main.log.report( "clusters from ONOS" +
1612 controller_str +
1613 " is inconsistent with ONOS1" )
Jon Hall94fd0472014-12-08 11:52:42 -08001614 consistent_clusters_result = main.FALSE
1615
1616 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001617 main.log.report( "Error in getting dataplane clusters " +
1618 "from ONOS" + controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -08001619 consistent_clusters_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001620 main.log.warn( "ONOS" + controller_str +
1621 " clusters response: " +
1622 repr( clusters[ controller ] ) )
1623 utilities.assert_equals(
1624 expect=main.TRUE,
1625 actual=consistent_clusters_result,
1626 onpass="Clusters view is consistent across all ONOS nodes",
1627 onfail="ONOS nodes have different views of clusters" )
1628 # there should always only be one cluster
1629 num_clusters = len( json.loads( clusters[ 0 ] ) )
1630 utilities.assert_equals(
1631 expect=1,
1632 actual=num_clusters,
1633 onpass="ONOS shows 1 SCC",
1634 onfail="ONOS shows " +
1635 str( num_clusters ) +
1636 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001637
Jon Hall6aec96b2015-01-19 14:49:31 -08001638 # paths
Jon Hall94fd0472014-12-08 11:52:42 -08001639 consistent_paths_result = main.TRUE
1640 for controller in range( len( paths ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001641 controller_str = str( controller + 1 )
1642 if "Error" not in paths[ controller ]:
1643 if paths[ controller ] == paths[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001644 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001645 else: # paths not consistent
1646 main.log.report( "paths from ONOS" + controller_str +
1647 " is inconsistent with ONOS1" )
Jon Hall94fd0472014-12-08 11:52:42 -08001648 consistent_paths_result = main.FALSE
1649
1650 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001651 main.log.report( "Error in getting paths from ONOS" +
1652 controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -08001653 consistent_paths_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001654 main.log.warn( "ONOS" + controller_str +
1655 " paths response: " +
1656 repr( paths[ controller ] ) )
1657 utilities.assert_equals(
1658 expect=main.TRUE,
1659 actual=consistent_paths_result,
1660 onpass="Paths count is consistent across all ONOS nodes",
1661 onfail="ONOS nodes have different counts of paths" )
Jon Hall94fd0472014-12-08 11:52:42 -08001662
Jon Hall6aec96b2015-01-19 14:49:31 -08001663 topo_result = ( devices_results and ports_results and links_results
1664 and consistent_hosts_result
1665 and consistent_clusters_result
1666 and consistent_paths_result )
Jon Hall94fd0472014-12-08 11:52:42 -08001667
Jon Hall6aec96b2015-01-19 14:49:31 -08001668 topo_result = topo_result and int( count <= 2 )
1669 note = "note it takes about " + str( int( cli_time ) ) + \
1670 " seconds for the test to make all the cli calls to fetch " +\
1671 "the topology from each ONOS instance"
1672 main.log.report(
1673 "Very crass estimate for topology discovery/convergence(" +
1674 str( note ) + "): " + str( elapsed ) + " seconds, " +
1675 str( count ) + " tries" )
1676 utilities.assert_equals( expect=main.TRUE, actual=topo_result,
1677 onpass="Topology Check Test successful",
1678 onfail="Topology Check Test NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001679 if topo_result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001680 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hallb1290e82014-11-18 16:17:48 -05001681
Jon Hall6aec96b2015-01-19 14:49:31 -08001682 def CASE9( self, main ):
1683 """
Jon Hallb1290e82014-11-18 16:17:48 -05001684 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001685 """
1686 import time
1687 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001688
Jon Hall6aec96b2015-01-19 14:49:31 -08001689 link_sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001690
Jon Hall6aec96b2015-01-19 14:49:31 -08001691 description = "Turn off a link to ensure that Link Discovery " +\
1692 "is working properly"
1693 main.log.report( description )
1694 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001695
Jon Hall6aec96b2015-01-19 14:49:31 -08001696 main.step( "Kill Link between s3 and s28" )
1697 Link_Down = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
1698 main.log.info(
1699 "Waiting " +
1700 str( link_sleep ) +
1701 " seconds for link down to be discovered" )
1702 time.sleep( link_sleep )
1703 utilities.assert_equals( expect=main.TRUE, actual=Link_Down,
1704 onpass="Link down succesful",
1705 onfail="Failed to bring link down" )
1706 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001707
Jon Hall6aec96b2015-01-19 14:49:31 -08001708 def CASE10( self, main ):
1709 """
Jon Hallb1290e82014-11-18 16:17:48 -05001710 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001711 """
1712 import time
1713 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001714
Jon Hall6aec96b2015-01-19 14:49:31 -08001715 link_sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001716
Jon Hall6aec96b2015-01-19 14:49:31 -08001717 description = "Restore a link to ensure that Link Discovery is " + \
1718 "working properly"
1719 main.log.report( description )
1720 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001721
Jon Hall6aec96b2015-01-19 14:49:31 -08001722 main.step( "Bring link between s3 and s28 back up" )
1723 Link_Up = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
1724 main.log.info(
1725 "Waiting " +
1726 str( link_sleep ) +
1727 " seconds for link up to be discovered" )
1728 time.sleep( link_sleep )
1729 utilities.assert_equals( expect=main.TRUE, actual=Link_Up,
1730 onpass="Link up succesful",
1731 onfail="Failed to bring link up" )
1732 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001733
Jon Hall6aec96b2015-01-19 14:49:31 -08001734 def CASE11( self, main ):
1735 """
Jon Hallb1290e82014-11-18 16:17:48 -05001736 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001737 """
1738 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001739 import time
1740
Jon Hall6aec96b2015-01-19 14:49:31 -08001741 switch_sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001742
1743 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001744 main.log.report( description )
1745 main.case( description )
1746 switch = main.params[ 'kill' ][ 'switch' ]
1747 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hallb1290e82014-11-18 16:17:48 -05001748
Jon Hall6aec96b2015-01-19 14:49:31 -08001749 # TODO: Make this switch parameterizable
1750 main.step( "Kill " + switch )
1751 main.log.report( "Deleting " + switch )
1752 main.Mininet1.del_switch( switch )
1753 main.log.info( "Waiting " + str( switch_sleep ) +
1754 " seconds for switch down to be discovered" )
1755 time.sleep( switch_sleep )
1756 device = main.ONOScli1.get_device( dpid=switchDPID )
1757 # Peek at the deleted switch
1758 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001759 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001760 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001761 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001762 utilities.assert_equals( expect=main.TRUE, actual=result,
1763 onpass="Kill switch succesful",
1764 onfail="Failed to kill switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001765
Jon Hall6aec96b2015-01-19 14:49:31 -08001766 def CASE12( self, main ):
1767 """
Jon Hallb1290e82014-11-18 16:17:48 -05001768 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001769 """
1770 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001771 import time
Jon Hall669173b2014-12-17 11:36:30 -08001772
Jon Hall6aec96b2015-01-19 14:49:31 -08001773 switch_sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
1774 switch = main.params[ 'kill' ][ 'switch' ]
1775 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1776 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hallb1290e82014-11-18 16:17:48 -05001777 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001778 main.log.report( description )
1779 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001780
Jon Hall6aec96b2015-01-19 14:49:31 -08001781 main.step( "Add back " + switch )
1782 main.log.report( "Adding back " + switch )
1783 main.Mininet1.add_switch( switch, dpid=switchDPID )
1784 # TODO: New dpid or same? Ask Thomas?
1785 for peer in links:
1786 main.Mininet1.add_link( switch, peer )
1787 main.Mininet1.assign_sw_controller(
1788 sw=switch.split( 's' )[ 1 ],
1789 count=num_controllers,
1790 ip1=ONOS1_ip,
1791 port1=ONOS1_port,
1792 ip2=ONOS2_ip,
1793 port2=ONOS2_port,
1794 ip3=ONOS3_ip,
1795 port3=ONOS3_port,
1796 ip4=ONOS4_ip,
1797 port4=ONOS4_port,
1798 ip5=ONOS5_ip,
1799 port5=ONOS5_port,
1800 ip6=ONOS6_ip,
1801 port6=ONOS6_port,
1802 ip7=ONOS7_ip,
1803 port7=ONOS7_port )
1804 main.log.info(
1805 "Waiting " +
1806 str( switch_sleep ) +
1807 " seconds for switch up to be discovered" )
1808 time.sleep( switch_sleep )
1809 device = main.ONOScli1.get_device( dpid=switchDPID )
1810 # Peek at the deleted switch
1811 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001812 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001813 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001814 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001815 utilities.assert_equals( expect=main.TRUE, actual=result,
1816 onpass="add switch succesful",
1817 onfail="Failed to add switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001818
Jon Hall6aec96b2015-01-19 14:49:31 -08001819 def CASE13( self, main ):
1820 """
Jon Hallb1290e82014-11-18 16:17:48 -05001821 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001822 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001823 import os
1824 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001825 # TODO: make use of this elsewhere
1826 ips = []
1827 ips.append(ONOS1_ip)
1828 ips.append(ONOS2_ip)
1829 ips.append(ONOS3_ip)
1830 ips.append(ONOS4_ip)
1831 ips.append(ONOS5_ip)
1832 ips.append(ONOS6_ip)
1833 ips.append(ONOS7_ip)
1834
1835 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001836 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001837 colors[ 'cyan' ] = '\033[96m'
1838 colors[ 'purple' ] = '\033[95m'
1839 colors[ 'blue' ] = '\033[94m'
1840 colors[ 'green' ] = '\033[92m'
1841 colors[ 'yellow' ] = '\033[93m'
1842 colors[ 'red' ] = '\033[91m'
1843 colors[ 'end' ] = '\033[0m'
Jon Hall368769f2014-11-19 15:43:35 -08001844 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001845 main.log.report( description )
1846 main.case( description )
1847 main.step( "Killing tcpdumps" )
Jon Hallb1290e82014-11-18 16:17:48 -05001848 main.Mininet2.stop_tcpdump()
1849
Jon Hall6aec96b2015-01-19 14:49:31 -08001850 main.step( "Checking ONOS Logs for errors" )
1851 for i in range(7):
1852 print colors[ 'purple' ] + "Checking logs for errors on " + \
1853 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
1854 print main.ONOSbench.check_logs( ips[i] )
Jon Hall94fd0472014-12-08 11:52:42 -08001855
Jon Hall6aec96b2015-01-19 14:49:31 -08001856 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hallb1290e82014-11-18 16:17:48 -05001857 testname = main.TEST
Jon Hall6aec96b2015-01-19 14:49:31 -08001858 teststation_user = main.params[ 'TESTONUSER' ]
1859 teststation_IP = main.params[ 'TESTONIP' ]
1860 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001861 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001862 # FIXME: scp
1863 # mn files
1864 # TODO: Load these from params
1865 # NOTE: must end in /
Jon Hall73cf9cc2014-11-20 22:28:38 -08001866 log_folder = "/opt/onos/log/"
Jon Hall6aec96b2015-01-19 14:49:31 -08001867 log_files = [ "karaf.log", "karaf.log.1" ]
1868 # NOTE: must end in /
Jon Hall73cf9cc2014-11-20 22:28:38 -08001869 dst_dir = "~/packet_captures/"
1870 for f in log_files:
Jon Hall6aec96b2015-01-19 14:49:31 -08001871 for i in range(7):
1872 main.ONOSbench.handle.sendline( "scp sdn@" + ips[i] + ":" +
1873 log_folder + f + " " +
1874 teststation_user + "@" +
1875 teststation_IP + ":" +
1876 dst_dir + str( testname ) +
1877 "-ONOS" + str( i + 1 ) + "-" +
1878 f )
1879 # std*.log's
1880 # NOTE: must end in /
Jon Hall73cf9cc2014-11-20 22:28:38 -08001881 log_folder = "/opt/onos/var/"
Jon Hall6aec96b2015-01-19 14:49:31 -08001882 log_files = [ "stderr.log", "stdout.log" ]
1883 # NOTE: must end in /
Jon Hall73cf9cc2014-11-20 22:28:38 -08001884 dst_dir = "~/packet_captures/"
1885 for f in log_files:
Jon Hall6aec96b2015-01-19 14:49:31 -08001886 for i in range(7):
1887 main.ONOSbench.handle.sendline( "scp sdn@" + ips[i] + ":" +
1888 log_folder + f + " " +
1889 teststation_user + "@" +
1890 teststation_IP + ":" +
1891 dst_dir + str( testname ) +
1892 "-ONOS" + str( i + 1 ) + "-" +
1893 f )
1894 # sleep so scp can finish
1895 time.sleep( 10 )
1896 main.step( "Packing and rotating pcap archives" )
1897 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001898
Jon Hall6aec96b2015-01-19 14:49:31 -08001899 # TODO: actually check something here
1900 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
1901 onpass="Test cleanup successful",
1902 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001903
Jon Hall6aec96b2015-01-19 14:49:31 -08001904 def CASE14( self, main ):
1905 """
Jon Hall94fd0472014-12-08 11:52:42 -08001906 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001907 """
Jon Hall669173b2014-12-17 11:36:30 -08001908 leader_result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001909 # install app on onos 1
1910 main.log.info( "Install leadership election app" )
1911 main.ONOScli1.feature_install( "onos-app-election" )
1912 # wait for election
1913 # check for leader
Jon Hall669173b2014-12-17 11:36:30 -08001914 leader = main.ONOScli1.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001915 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001916 if leader == ONOS1_ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001917 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001918 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001919 elif leader is None:
1920 # No leader elected
1921 main.log.report( "No leader was elected" )
Jon Hall669173b2014-12-17 11:36:30 -08001922 leader_result = main.FALSE
1923 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001924 # error in response
1925 # TODO: add check for "Command not found:" in the driver, this
1926 # means the app isn't loaded
1927 main.log.report( "Something is wrong with election_test_leader" +
1928 " function, check the error logs" )
Jon Hall669173b2014-12-17 11:36:30 -08001929 leader_result = main.FALSE
1930 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001931 # error in response
1932 main.log.report(
1933 "Unexpected response from election_test_leader function:'" +
1934 str(leader) +
1935 "'" )
Jon Hall669173b2014-12-17 11:36:30 -08001936 leader_result = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001937
Jon Hall6aec96b2015-01-19 14:49:31 -08001938 # install on other nodes and check for leader.
1939 # Should be onos1 and each app should show the same leader
1940 for controller in range( 2, num_controllers + 1 ):
1941 # loop through ONOScli handlers
1942 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
1943 node.feature_install( "onos-app-election" )
Jon Hall669173b2014-12-17 11:36:30 -08001944 leaderN = node.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001945 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001946 if leaderN == ONOS1_ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001947 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001948 pass
1949 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001950 # error in response
1951 # TODO: add check for "Command not found:" in the driver, this
1952 # means the app isn't loaded
1953 main.log.report( "Something is wrong with " +
1954 "election_test_leader function, check the" +
1955 " error logs" )
Jon Hall669173b2014-12-17 11:36:30 -08001956 leader_result = main.FALSE
1957 elif leader != leaderN:
1958 leader_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001959 main.log.report( "ONOS" + str( controller ) + " sees " +
1960 str( leaderN ) +
1961 " as the leader of the election app. Leader" +
1962 " should be " +
1963 str( leader ) )
Jon Hall669173b2014-12-17 11:36:30 -08001964 if leader_result:
Jon Hall6aec96b2015-01-19 14:49:31 -08001965 main.log.report( "Leadership election tests passed( consistent " +
1966 "view of leader across listeners and a leader " +
1967 "was elected)" )
1968 utilities.assert_equals(
1969 expect=main.TRUE,
1970 actual=leader_result,
1971 onpass="Leadership election passed",
1972 onfail="Something went wrong with Leadership election" )
Jon Hall94fd0472014-12-08 11:52:42 -08001973
Jon Hall6aec96b2015-01-19 14:49:31 -08001974 def CASE15( self, main ):
1975 """
Jon Hall669173b2014-12-17 11:36:30 -08001976 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001977 """
Jon Hall669173b2014-12-17 11:36:30 -08001978 leader_result = main.TRUE
1979 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001980 main.log.report( description )
1981 main.case( description )
1982 main.step( "Find current leader and withdraw" )
Jon Hall669173b2014-12-17 11:36:30 -08001983 leader = main.ONOScli1.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001984 # TODO: do some sanity checking on leader before using it
Jon Hall669173b2014-12-17 11:36:30 -08001985 withdraw_result = main.FALSE
1986 if leader == ONOS1_ip:
1987 old_leader = getattr( main, "ONOScli1" )
1988 elif leader == ONOS2_ip:
1989 old_leader = getattr( main, "ONOScli2" )
1990 elif leader == ONOS3_ip:
1991 old_leader = getattr( main, "ONOScli3" )
1992 elif leader == ONOS4_ip:
1993 old_leader = getattr( main, "ONOScli4" )
1994 elif leader == ONOS5_ip:
1995 old_leader = getattr( main, "ONOScli5" )
1996 elif leader == ONOS6_ip:
1997 old_leader = getattr( main, "ONOScli6" )
1998 elif leader == ONOS7_ip:
1999 old_leader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002000 elif leader is None or leader == main.FALSE:
2001 main.log.report(
2002 "Leader for the election app should be an ONOS node," +
2003 "instead got '" +
2004 str(leader) +
2005 "'" )
Jon Hall669173b2014-12-17 11:36:30 -08002006 leader_result = main.FALSE
2007 withdraw_result = old_leader.election_test_withdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08002008 utilities.assert_equals(
2009 expect=main.TRUE,
2010 actual=withdraw_result,
2011 onpass="App was withdrawn from election",
2012 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08002013
Jon Hall6aec96b2015-01-19 14:49:31 -08002014 main.step( "Make sure new leader is elected" )
Jon Hall669173b2014-12-17 11:36:30 -08002015 leader_list = []
Jon Hall6aec96b2015-01-19 14:49:31 -08002016 for controller in range( 1, num_controllers + 1 ):
2017 # loop through ONOScli handlers
2018 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall669173b2014-12-17 11:36:30 -08002019 leader_list.append( node.election_test_leader() )
2020 for leaderN in leader_list:
2021 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08002022 main.log.report(
2023 "ONOS" +
2024 str( controller ) +
2025 " still sees " +
2026 str( leader ) +
2027 " as leader after they withdrew" )
Jon Hall669173b2014-12-17 11:36:30 -08002028 leader_result = main.FALSE
2029 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002030 # error in response
2031 # TODO: add check for "Command not found:" in the driver, this
2032 # means the app isn't loaded
2033 main.log.report( "Something is wrong with " +
2034 "election_test_leader function, " +
2035 "check the error logs" )
Jon Hall669173b2014-12-17 11:36:30 -08002036 leader_result = main.FALSE
2037 consistent_leader = main.FALSE
2038 if len( set( leader_list ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002039 main.log.info( "Each Election-app sees '" +
2040 str(leader_list[0]) +
2041 "' as the leader" )
Jon Hall669173b2014-12-17 11:36:30 -08002042 consistent_leader = main.TRUE
2043 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002044 main.log.report(
2045 "Inconsistent responses for leader of Election-app:" )
2046 for n in range( len( leader_list ) ):
2047 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
2048 str( leader_list[ n ] ) )
Jon Hall669173b2014-12-17 11:36:30 -08002049 if leader_result:
Jon Hall6aec96b2015-01-19 14:49:31 -08002050 main.log.report( "Leadership election tests passed(consistent " +
2051 "view of leader across listeners and a new " +
2052 "leader was elected when the old leader " +
2053 "resigned)" )
2054 utilities.assert_equals(
2055 expect=main.TRUE,
2056 actual=leader_result,
2057 onpass="Leadership election passed",
2058 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002059
Jon Hall6aec96b2015-01-19 14:49:31 -08002060 main.step(
2061 "Run for election on old leader(just so everyone is in the hat)" )
Jon Hall669173b2014-12-17 11:36:30 -08002062 run_result = old_leader.election_test_run()
Jon Hall6aec96b2015-01-19 14:49:31 -08002063 utilities.assert_equals(
2064 expect=main.TRUE,
2065 actual=run_result,
2066 onpass="App re-ran for election",
2067 onfail="App failed to run for election" )
Jon Hall669173b2014-12-17 11:36:30 -08002068 if consistent_leader == main.TRUE:
2069 after_run = main.ONOScli1.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002070 # verify leader didn't just change
2071 if after_run == leader_list[ 0 ]:
Jon Hall669173b2014-12-17 11:36:30 -08002072 leader_result = main.TRUE
2073 else:
2074 leader_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002075 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002076
Jon Hall6aec96b2015-01-19 14:49:31 -08002077 utilities.assert_equals(
2078 expect=main.TRUE,
2079 actual=leader_result,
2080 onpass="Leadership election passed",
2081 onfail="Something went wrong with Leadership election after " +
2082 "the old leader re-ran for election" )