blob: 3be5cbb1748d9d65c159ab013877a09c6b019c87 [file] [log] [blame]
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001import time
2import sys
3import os
4import re
5import time
6import json
7import itertools
8
kelvin8ec71442015-01-15 16:57:00 -08009
Hari Krishnaa43d4e92014-12-19 13:22:40 -080010class OnosCHO:
kelvin8ec71442015-01-15 16:57:00 -080011
kelvin-onlab8a832582015-01-16 17:06:11 -080012 def __init__( self ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -080013 self.default = ''
14 global deviceDPIDs
15 global hostMACs
16 global deviceLinks
17 global deviceActiveLinksCount
18 global devicePortsEnabledCount
19 global installedIntents
20 global randomLink1, randomLink2, randomLink3, numSwitches, numLinks
kelvin8ec71442015-01-15 16:57:00 -080021
kelvin-onlab8a832582015-01-16 17:06:11 -080022 def CASE1( self, main ):
23 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -080024 Startup sequence:
25 git pull
26 mvn clean install
27 onos-package
28 cell <name>
29 onos-verify-cell
30 onos-install -f
31 onos-wait-for-start
kelvin-onlab8a832582015-01-16 17:06:11 -080032 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -080033 import time
kelvin-onlab8a832582015-01-16 17:06:11 -080034 cell_name = main.params[ 'ENV' ][ 'cellName' ]
35 git_pull = main.params[ 'GIT' ][ 'autoPull' ]
36 numCtrls = main.params[ 'CTRL' ][ 'numCtrl' ]
37 git_branch = main.params[ 'GIT' ][ 'branch' ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -080038
kelvin-onlab8a832582015-01-16 17:06:11 -080039 main.case( "Set up test environment" )
40 main.log.report( "Set up test environment" )
41 main.log.report( "_______________________" )
42
43 main.step( "Git checkout and pull " + git_branch )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080044 if git_pull == 'on':
kelvin-onlab8a832582015-01-16 17:06:11 -080045 checkout_result = main.ONOSbench.git_checkout( git_branch )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080046 pull_result = main.ONOSbench.git_pull()
kelvin-onlab8a832582015-01-16 17:06:11 -080047 cp_result = ( checkout_result and pull_result )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080048 else:
49 checkout_result = main.TRUE
50 pull_result = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -080051 main.log.info( "Skipped git checkout and pull" )
52 cp_result = ( checkout_result and pull_result )
53 utilities.assert_equals( expect=main.TRUE, actual=cp_result,
54 onpass="Test step PASS",
55 onfail="Test step FAIL" )
56
57 main.step( "mvn clean & install" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080058 mvn_result = main.ONOSbench.clean_install()
kelvin-onlab8a832582015-01-16 17:06:11 -080059 utilities.assert_equals( expect=main.TRUE, actual=mvn_result,
60 onpass="Test step PASS",
61 onfail="Test step FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080062
kelvin-onlab8a832582015-01-16 17:06:11 -080063 main.ONOSbench.get_version( report=True )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080064
kelvin-onlab8a832582015-01-16 17:06:11 -080065 main.step( "Apply Cell environment for ONOS" )
66 cell_result = main.ONOSbench.set_cell( cell_name )
67 utilities.assert_equals( expect=main.TRUE, actual=cell_result,
68 onpass="Test step PASS",
69 onfail="Test step FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080070
kelvin-onlab8a832582015-01-16 17:06:11 -080071 main.step( "Create ONOS package" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080072 packageResult = main.ONOSbench.onos_package()
kelvin-onlab8a832582015-01-16 17:06:11 -080073 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
74 onpass="Test step PASS",
75 onfail="Test step FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080076
kelvin-onlab8a832582015-01-16 17:06:11 -080077 main.step( "Uninstall ONOS package on all Nodes" )
78 uninstallResult = main.TRUE
79 for i in range( 1, int( numCtrls ) + 1 ):
80 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
81 main.log.info( "Unintsalling package on ONOS Node IP: " + ONOS_ip )
82 u_result = main.ONOSbench.onos_uninstall( ONOS_ip )
83 utilities.assert_equals( expect=main.TRUE, actual=u_result,
84 onpass="Test step PASS",
85 onfail="Test step FAIL" )
86 uninstallResult = ( uninstallResult and u_result )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080087
kelvin-onlab8a832582015-01-16 17:06:11 -080088 main.step( "Removing copy-cat logs from ONOS nodes" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080089 main.ONOSbench.onos_remove_raft_logs()
90
kelvin-onlab8a832582015-01-16 17:06:11 -080091 main.step( "Install ONOS package on all Nodes" )
92 installResult = main.TRUE
93 for i in range( 1, int( numCtrls ) + 1 ):
94 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
95 main.log.info( "Intsalling package on ONOS Node IP: " + ONOS_ip )
96 i_result = main.ONOSbench.onos_install( node=ONOS_ip )
97 utilities.assert_equals( expect=main.TRUE, actual=i_result,
98 onpass="Test step PASS",
99 onfail="Test step FAIL" )
100 installResult = ( installResult and i_result )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800101
kelvin-onlab8a832582015-01-16 17:06:11 -0800102 main.step( "Verify ONOS nodes UP status" )
103 statusResult = main.TRUE
104 for i in range( 1, int( numCtrls ) + 1 ):
105 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
106 main.log.info( "ONOS Node " + ONOS_ip + " status:" )
107 onos_status = main.ONOSbench.onos_status( node=ONOS_ip )
108 utilities.assert_equals( expect=main.TRUE, actual=onos_status,
109 onpass="Test step PASS",
110 onfail="Test step FAIL" )
111 statusResult = ( statusResult and onos_status )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800112
kelvin-onlab8a832582015-01-16 17:06:11 -0800113 main.step( "Start ONOS CLI on all nodes" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800114 cliResult = main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800115 karafTimeout = "3600000"
kelvin-onlab8a832582015-01-16 17:06:11 -0800116 # need to wait here for sometime. This will be removed once ONOS is
117 # stable enough
118 time.sleep( 15 )
119 for i in range( 1, int( numCtrls ) + 1 ):
120 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
121 ONOScli = 'ONOScli' + str( i )
122 main.log.info( "ONOS Node " + ONOS_ip + " cli start:" )
123 exec "startcli=main." + ONOScli + \
124 ".start_onos_cli(ONOS_ip, karafTimeout=karafTimeout)"
125 utilities.assert_equals( expect=main.TRUE, actual=startcli,
126 onpass="Test step PASS",
127 onfail="Test step FAIL" )
128 cliResult = ( cliResult and startcli )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800129
kelvin-onlab8a832582015-01-16 17:06:11 -0800130 case1Result = ( cp_result and cell_result
131 and packageResult and installResult and statusResult and cliResult )
132 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
133 onpass="Set up test environment PASS",
134 onfail="Set up test environment FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800135
kelvin-onlab8a832582015-01-16 17:06:11 -0800136 def CASE2( self, main ):
137 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800138 This test script still needs more refactoring
kelvin-onlab8a832582015-01-16 17:06:11 -0800139 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800140 import re
141 import time
142 import copy
kelvin-onlab8a832582015-01-16 17:06:11 -0800143 numCtrls = main.params[ 'CTRL' ][ 'numCtrl' ]
144 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
145 ONOS2_ip = main.params[ 'CTRL' ][ 'ip2' ]
146 ONOS3_ip = main.params[ 'CTRL' ][ 'ip3' ]
147 ONOS4_ip = main.params[ 'CTRL' ][ 'ip4' ]
148 ONOS5_ip = main.params[ 'CTRL' ][ 'ip5' ]
149 ONOS1_port = main.params[ 'CTRL' ][ 'port1' ]
150 ONOS2_port = main.params[ 'CTRL' ][ 'port2' ]
151 ONOS3_port = main.params[ 'CTRL' ][ 'port3' ]
152 ONOS4_port = main.params[ 'CTRL' ][ 'port4' ]
153 ONOS5_port = main.params[ 'CTRL' ][ 'port5' ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800154
kelvin-onlab8a832582015-01-16 17:06:11 -0800155 numCtrls = main.params[ 'CTRL' ][ 'numCtrl' ]
156 main.log.report(
157 "Assign and Balance all Mininet switches across controllers" )
158 main.log.report(
159 "_________________________________________________________" )
160 # need to wait here for sometime. This will be removed once ONOS is
161 # stable enough
162 time.sleep( 15 )
163 main.case(
164 "Assign and Balance all Mininet switches across controllers" )
165 main.step( "Assign switches to controllers" )
166 for i in range( 1, 26 ): # 1 to ( num of switches +1 )
167 main.Mininet1.assign_sw_controller(
168 sw=str( i ),
169 count=int( numCtrls ),
170 ip1=ONOS1_ip,
171 port1=ONOS1_port,
172 ip2=ONOS2_ip,
173 port2=ONOS2_port,
174 ip3=ONOS3_ip,
175 port3=ONOS3_port,
176 ip4=ONOS4_ip,
177 port4=ONOS4_port,
178 ip5=ONOS5_ip,
179 port5=ONOS5_port )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800180
181 switch_mastership = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -0800182 for i in range( 1, 26 ):
183 response = main.Mininet1.get_sw_controller( "s" + str( i ) )
184 print( "Response is " + str( response ) )
185 if re.search( "tcp:" + ONOS1_ip, response ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800186 switch_mastership = switch_mastership and main.TRUE
187 else:
188 switch_mastership = main.FALSE
189
190 if switch_mastership == main.TRUE:
kelvin-onlab8a832582015-01-16 17:06:11 -0800191 main.log.report( "Controller assignment successfull" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800192 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800193 main.log.report( "Controller assignment failed" )
194 time.sleep( 5 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800195
kelvin-onlab8a832582015-01-16 17:06:11 -0800196 main.step( "Balance devices across controllers" )
197 for i in range( int( numCtrls ) ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800198 balanceResult = main.ONOScli1.balance_masters()
kelvin-onlab8a832582015-01-16 17:06:11 -0800199 # giving some breathing time for ONOS to complete re-balance
200 time.sleep( 3 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800201
kelvin-onlab8a832582015-01-16 17:06:11 -0800202 utilities.assert_equals(
203 expect=main.TRUE,
204 actual=balanceResult,
205 onpass="Assign and Balance devices test PASS",
206 onfail="Assign and Balance devices test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800207
kelvin-onlab8a832582015-01-16 17:06:11 -0800208 def CASE3( self, main ):
209 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800210 This Test case will be extended to collect and store more data related
211 ONOS state.
kelvin-onlab8a832582015-01-16 17:06:11 -0800212 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800213 import re
214 import copy
215 deviceDPIDs = []
216 hostMACs = []
217 deviceLinks = []
218 deviceActiveLinksCount = []
219 devicePortsEnabledCount = []
220
kelvin-onlab8a832582015-01-16 17:06:11 -0800221 main.log.report(
222 "Collect and Store topology details from ONOS before running any Tests" )
223 main.log.report(
224 "____________________________________________________________________" )
225 main.case( "Collect and Store Topology Deatils from ONOS" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800226
kelvin-onlab8a832582015-01-16 17:06:11 -0800227 main.step( "Collect and store current number of switches and links" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800228 topology_output = main.ONOScli1.topology()
kelvin-onlab8a832582015-01-16 17:06:11 -0800229 topology_result = main.ONOSbench.get_topology( topology_output )
230 numSwitches = topology_result[ 'devices' ]
231 numLinks = topology_result[ 'links' ]
232 main.log.info(
233 "Currently there are %s switches and %s links" %
234 ( str( numSwitches ), str( numLinks ) ) )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800235
kelvin-onlab8a832582015-01-16 17:06:11 -0800236 main.step( "Store Device DPIDs" )
237 for i in range( 1, 26 ):
238 deviceDPIDs.append( "of:00000000000000" + format( i, '02x' ) )
239 print "Device DPIDs in Store: \n", str( deviceDPIDs )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800240
kelvin-onlab8a832582015-01-16 17:06:11 -0800241 main.step( "Store Host MACs" )
242 for i in range( 1, 26 ):
243 hostMACs.append( "00:00:00:00:00:" + format( i, '02x' ) + "/-1" )
244 print "Host MACs in Store: \n", str( hostMACs )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800245
kelvin-onlab8a832582015-01-16 17:06:11 -0800246 main.step( "Collect and store all Devices Links" )
247 linksResult = main.ONOScli1.links( json_format=False )
248 ansi_escape = re.compile( r'\x1b[^m]*m' )
249 linksResult = ansi_escape.sub( '', linksResult )
250 linksResult = linksResult.replace( " links", "" ).replace( "\r\r", "" )
251 linksResult = linksResult.splitlines()
252 linksResult = linksResult[ 1: ]
253 deviceLinks = copy.copy( linksResult )
254 print "Device Links Stored: \n", str( deviceLinks )
255 # this will be asserted to check with the params provided count of
256 # links
257 print "Length of Links Store", len( deviceLinks )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800258
kelvin-onlab8a832582015-01-16 17:06:11 -0800259 main.step( "Collect and store each Device ports enabled Count" )
260 for i in range( 1, 26 ):
261 portResult = main.ONOScli1.getDevicePortsEnabledCount(
262 "of:00000000000000" +
263 format(
264 i,
265 '02x' ) )
266 portTemp = re.split( r'\t+', portResult )
267 portCount = portTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
268 devicePortsEnabledCount.append( portCount )
269 print "Device Enabled Port Counts Stored: \n", str( devicePortsEnabledCount )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800270
kelvin-onlab8a832582015-01-16 17:06:11 -0800271 main.step( "Collect and store each Device active links Count" )
272 for i in range( 1, 26 ):
273 linkCountResult = main.ONOScli1.getDeviceLinksActiveCount(
274 "of:00000000000000" +
275 format(
276 i,
277 '02x' ) )
278 linkCountTemp = re.split( r'\t+', linkCountResult )
279 linkCount = linkCountTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
280 deviceActiveLinksCount.append( linkCount )
281 print "Device Active Links Count Stored: \n", str( deviceActiveLinksCount )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800282
kelvin-onlab8a832582015-01-16 17:06:11 -0800283 # just returning TRUE for now as this one just collects data
284 caseResult = main.TRUE
285 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
286 onpass="Saving ONOS topology data test PASS",
287 onfail="Saving ONOS topology data test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800288
kelvin-onlab8a832582015-01-16 17:06:11 -0800289 def CASE4( self, main ):
290 """
291 Enable onos-app-fwd, Verify Reactive forwarding through ping all and Disable it
292 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800293 import re
294 import copy
295 import time
kelvin-onlab8a832582015-01-16 17:06:11 -0800296 numCtrls = main.params[ 'CTRL' ][ 'numCtrl' ]
297 main.log.report( "Enable Reactive forwarding and Verify ping all" )
298 main.log.report( "______________________________________________" )
299 main.case( "Enable Reactive forwarding and Verify ping all" )
300 main.step( "Enable Reactive forwarding" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800301 installResult = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -0800302 for i in range( 1, int( numCtrls ) + 1 ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800303 onosFeature = 'onos-app-fwd'
kelvin-onlab8a832582015-01-16 17:06:11 -0800304 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
305 ONOScli = 'ONOScli' + str( i )
306 main.log.info( "Enabling Reactive mode on ONOS Node " + ONOS_ip )
307 exec "inResult=main." + ONOScli + ".feature_install(onosFeature)"
308 time.sleep( 3 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800309 installResult = inResult and installResult
310
kelvin-onlab8a832582015-01-16 17:06:11 -0800311 time.sleep( 5 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800312
kelvin-onlab8a832582015-01-16 17:06:11 -0800313 main.step( "Verify Pingall" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800314 ping_result = main.FALSE
315 time1 = time.time()
316 ping_result = main.Mininet1.pingall()
317 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800318 timeDiff = round( ( time2 - time1 ), 2 )
319 main.log.report(
320 "Time taken for Ping All: " +
321 str( timeDiff ) +
322 " seconds" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800323
324 if ping_result == main.TRUE:
kelvin-onlab8a832582015-01-16 17:06:11 -0800325 main.log.report( "Pingall Test in Reactive mode successful" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800326 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800327 main.log.report( "Pingall Test in Reactive mode failed" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800328
kelvin-onlab8a832582015-01-16 17:06:11 -0800329 main.step( "Disable Reactive forwarding" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800330 uninstallResult = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -0800331 for i in range( 1, int( numCtrls ) + 1 ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800332 onosFeature = 'onos-app-fwd'
kelvin-onlab8a832582015-01-16 17:06:11 -0800333 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
334 ONOScli = 'ONOScli' + str( i )
335 main.log.info( "Disabling Reactive mode on ONOS Node " + ONOS_ip )
336 exec "unResult=main." + ONOScli + ".feature_uninstall(onosFeature)"
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800337 uninstallResult = unResult and uninstallResult
338
kelvin-onlab8a832582015-01-16 17:06:11 -0800339 # Waiting for reative flows to be cleared.
340 time.sleep( 10 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800341
342 case3Result = installResult and ping_result and uninstallResult
kelvin-onlab8a832582015-01-16 17:06:11 -0800343 utilities.assert_equals( expect=main.TRUE, actual=case3Result,
344 onpass="Reactive Mode Pingall test PASS",
345 onfail="Reactive Mode Pingall test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800346
kelvin-onlab8a832582015-01-16 17:06:11 -0800347 def CASE5( self, main ):
348 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800349 Compare current ONOS topology with reference data
kelvin-onlab8a832582015-01-16 17:06:11 -0800350 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800351 import re
352 devicesDPID_tmp = []
353 hostMACs_tmp = []
354 deviceLinks_tmp = []
355 deviceActiveLinksCount_tmp = []
356 devicePortsEnabledCount_tmp = []
357
kelvin-onlab8a832582015-01-16 17:06:11 -0800358 main.log.report(
359 "Compare ONOS topology with reference data in Stores" )
360 main.log.report( "__________________________________________________" )
361 main.case( "Compare ONOS topology with reference data" )
362
363 main.step( "Compare current Device ports enabled with reference" )
364 for i in range( 1, 26 ):
365 portResult = main.ONOScli1.getDevicePortsEnabledCount(
366 "of:00000000000000" +
367 format(
368 i,
369 '02x' ) )
370 portTemp = re.split( r'\t+', portResult )
371 portCount = portTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
372 devicePortsEnabledCount_tmp.append( portCount )
373 time.sleep( 2 )
374 print (
375 "Device Enabled ports EXPECTED: \n" +
376 str( devicePortsEnabledCount ) )
377 print (
378 "Device Enabled ports ACTUAL: \n" +
379 str( devicePortsEnabledCount_tmp ) )
380 if ( cmp( devicePortsEnabledCount,
381 devicePortsEnabledCount_tmp ) == 0 ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800382 stepResult1 = main.TRUE
383 else:
384 stepResult1 = main.FALSE
385
kelvin-onlab8a832582015-01-16 17:06:11 -0800386 main.step( "Compare Device active links with reference" )
387 for i in range( 1, 26 ):
388 linkResult = main.ONOScli1.getDeviceLinksActiveCount(
389 "of:00000000000000" +
390 format(
391 i,
392 '02x' ) )
393 linkTemp = re.split( r'\t+', linkResult )
394 linkCount = linkTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
395 deviceActiveLinksCount_tmp.append( linkCount )
396 time.sleep( 3 )
397 print (
398 "Device Active links EXPECTED: \n" +
399 str( deviceActiveLinksCount ) )
400 print (
401 "Device Active links ACTUAL: \n" +
402 str( deviceActiveLinksCount_tmp ) )
403 if ( cmp( deviceActiveLinksCount, deviceActiveLinksCount_tmp ) == 0 ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800404 stepResult2 = main.TRUE
405 else:
406 stepResult2 = main.FALSE
407
kelvin-onlab8a832582015-01-16 17:06:11 -0800408 """
409 place holder for comparing devices, hosts and paths if required.
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800410 Links and ports data would be incorrect with out devices anyways.
kelvin-onlab8a832582015-01-16 17:06:11 -0800411 """
412 caseResult = ( stepResult1 and stepResult2 )
413 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
414 onpass="Compare Topology test PASS",
415 onfail="Compare Topology test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800416 if caseResult == main.TRUE:
kelvin-onlab8a832582015-01-16 17:06:11 -0800417 main.log.report( "Compare Topology test Pass" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800418
kelvin-onlab8a832582015-01-16 17:06:11 -0800419 def CASE6( self ):
420 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800421 Install 300 host intents and verify ping all
kelvin-onlab8a832582015-01-16 17:06:11 -0800422 """
423 main.log.report( "Add 300 host intents and verify pingall" )
424 main.log.report( "_______________________________________" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800425 import itertools
kelvin-onlab8a832582015-01-16 17:06:11 -0800426 main.case( "Install 300 host intents" )
427 main.step( "Add host Intents" )
428 intentResult = main.TRUE
429 hostCombos = list( itertools.combinations( hostMACs, 2 ) )
430 for i in range( len( hostCombos ) ):
431 iResult = main.ONOScli1.add_host_intent(
432 hostCombos[ i ][ 0 ],
433 hostCombos[ i ][ 1 ] )
434 intentResult = ( intentResult and iResult )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800435
kelvin-onlab8a832582015-01-16 17:06:11 -0800436 main.step( "Verify Ping across all hosts" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800437 pingResult = main.FALSE
438 time1 = time.time()
439 pingResult = main.Mininet1.pingall()
440 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800441 timeDiff = round( ( time2 - time1 ), 2 )
442 main.log.report(
443 "Time taken for Ping All: " +
444 str( timeDiff ) +
445 " seconds" )
446 utilities.assert_equals( expect=main.TRUE, actual=pingResult,
447 onpass="PING ALL PASS",
448 onfail="PING ALL FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800449
kelvin-onlab8a832582015-01-16 17:06:11 -0800450 case4Result = ( intentResult and pingResult )
451 utilities.assert_equals(
452 expect=main.TRUE,
453 actual=case4Result,
454 onpass="Install 300 Host Intents and Ping All test PASS",
455 onfail="Install 300 Host Intents and Ping All test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800456
kelvin-onlab8a832582015-01-16 17:06:11 -0800457 def CASE70( self, main ):
458 """
459 Randomly bring some core links down and verify ping all ( Host Intents Scenario )
460 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800461 import random
kelvin-onlab8a832582015-01-16 17:06:11 -0800462 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
463 link1End1 = main.params[ 'CORELINKS' ][ 'linkS3a' ]
464 link1End2 = main.params[ 'CORELINKS' ][ 'linkS3b' ].split( ',' )
465 link2End1 = main.params[ 'CORELINKS' ][ 'linkS14a' ]
466 link2End2 = main.params[ 'CORELINKS' ][ 'linkS14b' ].split( ',' )
467 link3End1 = main.params[ 'CORELINKS' ][ 'linkS18a' ]
468 link3End2 = main.params[ 'CORELINKS' ][ 'linkS18b' ].split( ',' )
469 switchLinksToToggle = main.params[ 'CORELINKS' ][ 'toggleLinks' ]
470 link_sleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800471
kelvin-onlab8a832582015-01-16 17:06:11 -0800472 main.log.report(
473 "Host intents - Randomly bring some core links down and verify ping all" )
474 main.log.report(
475 "_________________________________________________________________" )
476 main.case(
477 "Host intents - Randomly bring some core links down and verify ping all" )
478 main.step(
479 "Verify number of Switch links to toggle on each Core Switch are between 1 - 5" )
480 if ( int( switchLinksToToggle ) ==
481 0 or int( switchLinksToToggle ) > 5 ):
482 main.log.info(
483 "Please check you PARAMS file. Valid range for number of switch links to toggle is between 1 to 5" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800484 main.cleanup()
485 main.exit()
486 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800487 main.log.info(
488 "User provided Core switch links range to toggle is correct, proceeding to run the test" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800489
kelvin-onlab8a832582015-01-16 17:06:11 -0800490 main.step( "Cut links on Core devices using user provided range" )
491 randomLink1 = random.sample( link1End2, int( switchLinksToToggle ) )
492 randomLink2 = random.sample( link2End2, int( switchLinksToToggle ) )
493 randomLink3 = random.sample( link3End2, int( switchLinksToToggle ) )
494 for i in range( int( switchLinksToToggle ) ):
495 main.Mininet1.link(
496 END1=link1End1,
497 END2=randomLink1[ i ],
498 OPTION="down" )
499 main.Mininet1.link(
500 END1=link2End1,
501 END2=randomLink2[ i ],
502 OPTION="down" )
503 main.Mininet1.link(
504 END1=link3End1,
505 END2=randomLink3[ i ],
506 OPTION="down" )
507 time.sleep( link_sleep )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800508
509 topology_output = main.ONOScli2.topology()
kelvin-onlab8a832582015-01-16 17:06:11 -0800510 linkDown = main.ONOSbench.check_status(
511 topology_output, numSwitches, str(
512 int( numLinks ) - int( switchLinksToToggle ) * 6 ) )
513 utilities.assert_equals(
514 expect=main.TRUE,
515 actual=linkDown,
516 onpass="Link Down discovered properly",
517 onfail="Link down was not discovered in " +
518 str( link_sleep ) +
519 " seconds" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800520
kelvin-onlab8a832582015-01-16 17:06:11 -0800521 main.step( "Verify Ping across all hosts" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800522 pingResultLinkDown = main.FALSE
523 time1 = time.time()
524 pingResultLinkDown = main.Mininet1.pingall()
525 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800526 timeDiff = round( ( time2 - time1 ), 2 )
527 main.log.report(
528 "Time taken for Ping All: " +
529 str( timeDiff ) +
530 " seconds" )
531 utilities.assert_equals( expect=main.TRUE, actual=pingResultLinkDown,
532 onpass="PING ALL PASS",
533 onfail="PING ALL FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800534
535 caseResult7 = linkDown and pingResultLinkDown
kelvin-onlab8a832582015-01-16 17:06:11 -0800536 utilities.assert_equals( expect=main.TRUE, actual=caseResult7,
537 onpass="Random Link cut Test PASS",
538 onfail="Random Link cut Test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800539
kelvin-onlab8a832582015-01-16 17:06:11 -0800540 def CASE80( self, main ):
541 """
542 Bring the core links up that are down and verify ping all ( Host Intents Scenario )
543 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800544 import random
kelvin-onlab8a832582015-01-16 17:06:11 -0800545 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
546 link1End1 = main.params[ 'CORELINKS' ][ 'linkS3a' ]
547 link2End1 = main.params[ 'CORELINKS' ][ 'linkS14a' ]
548 link3End1 = main.params[ 'CORELINKS' ][ 'linkS18a' ]
549 link_sleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
550 switchLinksToToggle = main.params[ 'CORELINKS' ][ 'toggleLinks' ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800551
kelvin-onlab8a832582015-01-16 17:06:11 -0800552 main.log.report(
553 "Host intents - Bring the core links up that are down and verify ping all" )
554 main.log.report(
555 "__________________________________________________________________" )
556 main.case(
557 "Host intents - Bring the core links up that are down and verify ping all" )
558 main.step( "Bring randomly cut links on Core devices up" )
559 for i in range( int( switchLinksToToggle ) ):
560 main.Mininet1.link(
561 END1=link1End1,
562 END2=randomLink1[ i ],
563 OPTION="up" )
564 main.Mininet1.link(
565 END1=link2End1,
566 END2=randomLink2[ i ],
567 OPTION="up" )
568 main.Mininet1.link(
569 END1=link3End1,
570 END2=randomLink3[ i ],
571 OPTION="up" )
572 time.sleep( link_sleep )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800573
574 topology_output = main.ONOScli2.topology()
kelvin-onlab8a832582015-01-16 17:06:11 -0800575 linkUp = main.ONOSbench.check_status(
576 topology_output,
577 numSwitches,
578 str( numLinks ) )
579 utilities.assert_equals(
580 expect=main.TRUE,
581 actual=linkUp,
582 onpass="Link up discovered properly",
583 onfail="Link up was not discovered in " +
584 str( link_sleep ) +
585 " seconds" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800586
kelvin-onlab8a832582015-01-16 17:06:11 -0800587 main.step( "Verify Ping across all hosts" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800588 pingResultLinkUp = main.FALSE
589 time1 = time.time()
590 pingResultLinkUp = main.Mininet1.pingall()
591 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800592 timeDiff = round( ( time2 - time1 ), 2 )
593 main.log.report(
594 "Time taken for Ping All: " +
595 str( timeDiff ) +
596 " seconds" )
597 utilities.assert_equals( expect=main.TRUE, actual=pingResultLinkUp,
598 onpass="PING ALL PASS",
599 onfail="PING ALL FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800600
601 caseResult8 = linkUp and pingResultLinkUp
kelvin-onlab8a832582015-01-16 17:06:11 -0800602 utilities.assert_equals( expect=main.TRUE, actual=caseResult8,
603 onpass="Link Up Test PASS",
604 onfail="Link Up Test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800605
kelvin-onlab8a832582015-01-16 17:06:11 -0800606 def CASE71( self, main ):
607 """
608 Randomly bring some core links down and verify ping all ( Point Intents Scenario )
609 """
kelvin8ec71442015-01-15 16:57:00 -0800610 import random
kelvin-onlab8a832582015-01-16 17:06:11 -0800611 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
612 link1End1 = main.params[ 'CORELINKS' ][ 'linkS3a' ]
613 link1End2 = main.params[ 'CORELINKS' ][ 'linkS3b' ].split( ',' )
614 link2End1 = main.params[ 'CORELINKS' ][ 'linkS14a' ]
615 link2End2 = main.params[ 'CORELINKS' ][ 'linkS14b' ].split( ',' )
616 link3End1 = main.params[ 'CORELINKS' ][ 'linkS18a' ]
617 link3End2 = main.params[ 'CORELINKS' ][ 'linkS18b' ].split( ',' )
618 switchLinksToToggle = main.params[ 'CORELINKS' ][ 'toggleLinks' ]
619 link_sleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
kelvin8ec71442015-01-15 16:57:00 -0800620
kelvin-onlab8a832582015-01-16 17:06:11 -0800621 main.log.report(
622 "Point Intents - Randomly bring some core links down and verify ping all" )
623 main.log.report(
624 "__________________________________________________________________" )
625 main.case(
626 "Point Intents - Randomly bring some core links down and verify ping all" )
627 main.step(
628 "Verify number of Switch links to toggle on each Core Switch are between 1 - 5" )
629 if ( int( switchLinksToToggle ) ==
630 0 or int( switchLinksToToggle ) > 5 ):
631 main.log.info(
632 "Please check you PARAMS file. Valid range for number of switch links to toggle is between 1 to 5" )
kelvin8ec71442015-01-15 16:57:00 -0800633 main.cleanup()
634 main.exit()
635 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800636 main.log.info(
637 "User provided Core switch links range to toggle is correct, proceeding to run the test" )
kelvin8ec71442015-01-15 16:57:00 -0800638
kelvin-onlab8a832582015-01-16 17:06:11 -0800639 main.step( "Cut links on Core devices using user provided range" )
640 randomLink1 = random.sample( link1End2, int( switchLinksToToggle ) )
641 randomLink2 = random.sample( link2End2, int( switchLinksToToggle ) )
642 randomLink3 = random.sample( link3End2, int( switchLinksToToggle ) )
643 for i in range( int( switchLinksToToggle ) ):
644 main.Mininet1.link(
645 END1=link1End1,
646 END2=randomLink1[ i ],
647 OPTION="down" )
648 main.Mininet1.link(
649 END1=link2End1,
650 END2=randomLink2[ i ],
651 OPTION="down" )
652 main.Mininet1.link(
653 END1=link3End1,
654 END2=randomLink3[ i ],
655 OPTION="down" )
656 time.sleep( link_sleep )
kelvin8ec71442015-01-15 16:57:00 -0800657
658 topology_output = main.ONOScli2.topology()
kelvin-onlab8a832582015-01-16 17:06:11 -0800659 linkDown = main.ONOSbench.check_status(
660 topology_output, numSwitches, str(
661 int( numLinks ) - int( switchLinksToToggle ) * 6 ) )
662 utilities.assert_equals(
663 expect=main.TRUE,
664 actual=linkDown,
665 onpass="Link Down discovered properly",
666 onfail="Link down was not discovered in " +
667 str( link_sleep ) +
668 " seconds" )
kelvin8ec71442015-01-15 16:57:00 -0800669
kelvin-onlab8a832582015-01-16 17:06:11 -0800670 main.step( "Verify Ping across all hosts" )
kelvin8ec71442015-01-15 16:57:00 -0800671 pingResultLinkDown = main.FALSE
672 time1 = time.time()
673 pingResultLinkDown = main.Mininet1.pingall()
674 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800675 timeDiff = round( ( time2 - time1 ), 2 )
676 main.log.report(
677 "Time taken for Ping All: " +
678 str( timeDiff ) +
679 " seconds" )
680 utilities.assert_equals( expect=main.TRUE, actual=pingResultLinkDown,
681 onpass="PING ALL PASS",
682 onfail="PING ALL FAIL" )
kelvin8ec71442015-01-15 16:57:00 -0800683
684 caseResult7 = linkDown and pingResultLinkDown
kelvin-onlab8a832582015-01-16 17:06:11 -0800685 utilities.assert_equals( expect=main.TRUE, actual=caseResult7,
686 onpass="Random Link cut Test PASS",
687 onfail="Random Link cut Test FAIL" )
kelvin8ec71442015-01-15 16:57:00 -0800688
kelvin-onlab8a832582015-01-16 17:06:11 -0800689 def CASE81( self, main ):
690 """
691 Bring the core links up that are down and verify ping all ( Point Intents Scenario )
692 """
kelvin8ec71442015-01-15 16:57:00 -0800693 import random
kelvin-onlab8a832582015-01-16 17:06:11 -0800694 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
695 link1End1 = main.params[ 'CORELINKS' ][ 'linkS3a' ]
696 link2End1 = main.params[ 'CORELINKS' ][ 'linkS14a' ]
697 link3End1 = main.params[ 'CORELINKS' ][ 'linkS18a' ]
698 link_sleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
699 switchLinksToToggle = main.params[ 'CORELINKS' ][ 'toggleLinks' ]
kelvin8ec71442015-01-15 16:57:00 -0800700
kelvin-onlab8a832582015-01-16 17:06:11 -0800701 main.log.report(
702 "Point intents - Bring the core links up that are down and verify ping all" )
703 main.log.report(
704 "___________________________________________________________________" )
705 main.case(
706 "Point intents - Bring the core links up that are down and verify ping all" )
707 main.step( "Bring randomly cut links on Core devices up" )
708 for i in range( int( switchLinksToToggle ) ):
709 main.Mininet1.link(
710 END1=link1End1,
711 END2=randomLink1[ i ],
712 OPTION="up" )
713 main.Mininet1.link(
714 END1=link2End1,
715 END2=randomLink2[ i ],
716 OPTION="up" )
717 main.Mininet1.link(
718 END1=link3End1,
719 END2=randomLink3[ i ],
720 OPTION="up" )
721 time.sleep( link_sleep )
kelvin8ec71442015-01-15 16:57:00 -0800722
723 topology_output = main.ONOScli2.topology()
kelvin-onlab8a832582015-01-16 17:06:11 -0800724 linkUp = main.ONOSbench.check_status(
725 topology_output,
726 numSwitches,
727 str( numLinks ) )
728 utilities.assert_equals(
729 expect=main.TRUE,
730 actual=linkUp,
731 onpass="Link up discovered properly",
732 onfail="Link up was not discovered in " +
733 str( link_sleep ) +
734 " seconds" )
kelvin8ec71442015-01-15 16:57:00 -0800735
kelvin-onlab8a832582015-01-16 17:06:11 -0800736 main.step( "Verify Ping across all hosts" )
kelvin8ec71442015-01-15 16:57:00 -0800737 pingResultLinkUp = main.FALSE
738 time1 = time.time()
739 pingResultLinkUp = main.Mininet1.pingall()
740 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800741 timeDiff = round( ( time2 - time1 ), 2 )
742 main.log.report(
743 "Time taken for Ping All: " +
744 str( timeDiff ) +
745 " seconds" )
746 utilities.assert_equals( expect=main.TRUE, actual=pingResultLinkUp,
747 onpass="PING ALL PASS",
748 onfail="PING ALL FAIL" )
kelvin8ec71442015-01-15 16:57:00 -0800749
750 caseResult8 = linkUp and pingResultLinkUp
kelvin-onlab8a832582015-01-16 17:06:11 -0800751 utilities.assert_equals( expect=main.TRUE, actual=caseResult8,
752 onpass="Link Up Test PASS",
753 onfail="Link Up Test FAIL" )
kelvin8ec71442015-01-15 16:57:00 -0800754
kelvin-onlab8a832582015-01-16 17:06:11 -0800755 def CASE9( self ):
756 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800757 Install 114 point intents and verify Ping all works
kelvin-onlab8a832582015-01-16 17:06:11 -0800758 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800759 import copy
kelvin-onlab8a832582015-01-16 17:06:11 -0800760 main.log.report( "Install 114 point intents and verify Ping all" )
761 main.log.report( "___________________________________________" )
762 main.case( "Install 114 point intents and Ping all" )
763 deviceLinks_copy = copy.copy( deviceLinks )
764 main.step( "Install 114 point intents" )
765 for i in range( len( deviceLinks_copy ) ):
766 pointLink = str(
767 deviceLinks_copy[ i ] ).replace(
768 "src=",
769 "" ).replace(
770 "dst=",
771 "" ).split( ',' )
772 point1 = pointLink[ 0 ].split( '/' )
773 point2 = pointLink[ 1 ].split( '/' )
774 installResult = main.ONOScli1.add_point_intent(
775 point1[ 0 ], point2[ 0 ], int(
776 point1[ 1 ] ), int(
777 point2[ 1 ] ) )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800778 if installResult == main.TRUE:
kelvin-onlab8a832582015-01-16 17:06:11 -0800779 print "Installed Point intent between :", point1[ 0 ], int( point1[ 1 ] ), point2[ 0 ], int( point2[ 1 ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800780
kelvin-onlab8a832582015-01-16 17:06:11 -0800781 main.step( "Obtain the intent id's" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800782 intentsList = main.ONOScli1.getAllIntentIds()
kelvin-onlab8a832582015-01-16 17:06:11 -0800783 ansi_escape = re.compile( r'\x1b[^m]*m' )
784 intentsList = ansi_escape.sub( '', intentsList )
785 intentsList = intentsList.replace(
786 " onos:intents | grep id=",
787 "" ).replace(
788 "id=",
789 "" ).replace(
790 "\r\r",
791 "" )
792 intentsList = intentsList.splitlines()
793 intentsList = intentsList[ 1: ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800794 intentIdList = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800795 for i in range( len( intentsList ) ):
796 intentsTemp = intentsList[ i ].split( ',' )
797 intentIdList.append( intentsTemp[ 0 ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800798 print "Intent IDs: ", intentIdList
kelvin-onlab8a832582015-01-16 17:06:11 -0800799 print "Total Intents installed: ", len( intentIdList )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800800
kelvin-onlab8a832582015-01-16 17:06:11 -0800801 main.step( "Verify Ping across all hosts" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800802 pingResult = main.FALSE
803 time1 = time.time()
804 pingResult = main.Mininet1.pingall()
805 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800806 timeDiff = round( ( time2 - time1 ), 2 )
807 main.log.report(
808 "Time taken for Ping All: " +
809 str( timeDiff ) +
810 " seconds" )
811 utilities.assert_equals( expect=main.TRUE, actual=pingResult,
812 onpass="PING ALL PASS",
813 onfail="PING ALL FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800814
815 case8_result = installResult and pingResult
kelvin-onlab8a832582015-01-16 17:06:11 -0800816 utilities.assert_equals(
817 expect=main.TRUE,
818 actual=case8_result,
819 onpass="Ping all test after Point intents addition successful",
820 onfail="Ping all test after Point intents addition failed" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800821
kelvin-onlab8a832582015-01-16 17:06:11 -0800822 def CASE10( self ):
823 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800824 Remove all Intents
kelvin-onlab8a832582015-01-16 17:06:11 -0800825 """
826 main.log.report( "Remove all intents that were installed previously" )
827 main.log.report( "______________________________________________" )
828 main.log.info( "Remove all intents" )
829 main.case( "Removing intents" )
830 main.step( "Obtain the intent id's first" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800831 intentsList = main.ONOScli1.getAllIntentIds()
kelvin-onlab8a832582015-01-16 17:06:11 -0800832 ansi_escape = re.compile( r'\x1b[^m]*m' )
833 intentsList = ansi_escape.sub( '', intentsList )
834 intentsList = intentsList.replace(
835 " onos:intents | grep id=",
836 "" ).replace(
837 "id=",
838 "" ).replace(
839 "\r\r",
840 "" )
841 intentsList = intentsList.splitlines()
842 intentsList = intentsList[ 1: ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800843 intentIdList = []
844 step1Result = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -0800845 if ( len( intentsList ) > 1 ):
846 for i in range( len( intentsList ) ):
847 intentsTemp = intentsList[ i ].split( ',' )
848 intentIdList.append( intentsTemp[ 0 ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800849 print "Intent IDs: ", intentIdList
kelvin-onlab8a832582015-01-16 17:06:11 -0800850 for id in range( len( intentIdList ) ):
851 print "Removing intent id (round 1) :", intentIdList[ id ]
852 main.ONOScli1.remove_intent( intent_id=intentIdList[ id ] )
853 time.sleep( 1 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800854
kelvin-onlab8a832582015-01-16 17:06:11 -0800855 main.log.info(
856 "Verify all intents are removed and if any leftovers try remove one more time" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800857 intentsList1 = main.ONOScli1.getAllIntentIds()
kelvin-onlab8a832582015-01-16 17:06:11 -0800858 ansi_escape = re.compile( r'\x1b[^m]*m' )
859 intentsList1 = ansi_escape.sub( '', intentsList1 )
860 intentsList1 = intentsList1.replace(
861 " onos:intents | grep id=",
862 "" ).replace(
863 " state=",
864 "" ).replace(
865 "\r\r",
866 "" )
867 intentsList1 = intentsList1.splitlines()
868 intentsList1 = intentsList1[ 1: ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800869 print "Round 2 (leftover) intents to remove: ", intentsList1
870 intentIdList1 = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800871 if ( len( intentsList1 ) > 1 ):
872 for i in range( len( intentsList1 ) ):
873 intentsTemp1 = intentsList[ i ].split( ',' )
874 intentIdList1.append( intentsTemp1[ 0 ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800875 print "Leftover Intent IDs: ", intentIdList1
kelvin-onlab8a832582015-01-16 17:06:11 -0800876 for id in range( len( intentIdList1 ) ):
877 print "Removing intent id (round 2):", intentIdList1[ id ]
878 main.ONOScli1.remove_intent(
879 intent_id=intentIdList1[ id ] )
880 time.sleep( 2 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800881 else:
882 print "There are no more intents that need to be removed"
883 step1Result = main.TRUE
884 else:
885 print "No Intent IDs found in Intents list: ", intentsList
886 step1Result = main.FALSE
887
888 caseResult7 = step1Result
kelvin-onlab8a832582015-01-16 17:06:11 -0800889 utilities.assert_equals( expect=main.TRUE, actual=caseResult7,
890 onpass="Intent removal test successful",
891 onfail="Intent removal test failed" )