blob: c4a4eb6b1a7ed5a2d5fd9608b4a2cd18f8520bf9 [file] [log] [blame]
shahshreya3140b1a2015-04-28 14:22:15 -07001
2# Testing the basic functionality of ONOS Next
3# For sanity and driver functionality excercises only.
4
5import time
6# import sys
7# import os
8# import re
9import json
10
11time.sleep( 1 )
12
13class IpOptical:
14
15 def __init__( self ):
16 self.default = ''
17
18 def CASE1( self, main ):
19 import time
20 """
21 Startup sequence:
22 cell <name>
23 onos-verify-cell
24 onos-remove-raft-log
25 git pull
26 mvn clean install
27 onos-package
28 onos-install -f
29 onos-wait-for-start
30 """
31 cellName = main.params[ 'ENV' ][ 'cellName' ]
32 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
33
34 main.case( "Setting up test environment" )
35 main.log.report(
36 "This testcase is testing setting up test environment" )
37 main.log.report( "__________________________________" )
38
39 main.step( "Applying cell variable to environment" )
40 cellResult = main.ONOSbench.setCell( cellName )
41 verifyResult = main.ONOSbench.verifyCell()
42
43 main.step( "Removing raft logs before a clen installation of ONOS" )
44 main.ONOSbench.onosRemoveRaftLogs()
45
46 main.step( "Git checkout and get version" )
47 #main.ONOSbench.gitCheckout( "master" )
48 gitPullResult = main.ONOSbench.gitPull()
49 main.log.info( "git_pull_result = " + str( gitPullResult ))
50 main.ONOSbench.getVersion( report=True )
51
shahshreyaa47ebf42015-05-20 13:29:18 -070052 if gitPullResult == 100:
shahshreya3140b1a2015-04-28 14:22:15 -070053 main.step( "Using mvn clean & install" )
54 main.ONOSbench.cleanInstall()
55 elif gitPullResult == 0:
56 main.log.report(
57 "Git Pull Failed, look into logs for detailed reason" )
58 main.cleanup()
59 main.exit()
60
61 main.step( "Creating ONOS package" )
62 packageResult = main.ONOSbench.onosPackage()
63
64 main.step( "Uninstalling ONOS package" )
65 ONOSip1 = main.params[ 'CTRL' ][ 'ip1' ]
66 onosUninstallResult = main.ONOSbench.onosUninstall( nodeIp = ONOSip1)
67 if onosUninstallResult:
68 main.log.report( "Uninstalling ONOS package successful" )
69 else:
70 main.log.report( "Uninstalled ONOS package unsucessful" )
71 time.sleep( 5 )
72 main.step( "Installing ONOS package" )
73 onosInstallResult = main.ONOSbench.onosInstall( node = ONOSip1 )
74 if onosInstallResult == main.TRUE:
75 main.log.report( "Installing ONOS package successful" )
76 else:
77 main.log.report( "Installing ONOS package failed" )
78
79 onos1Isup = main.ONOSbench.isup()
80 if onos1Isup == main.TRUE:
81 main.log.report( "ONOS instance is up and ready" )
82 else:
83 main.log.report( "ONOS instance may not be up" )
84
85 main.step( "Starting ONOS service" )
86 startResult = main.ONOSbench.onosStart( ONOS1Ip )
87
88 main.ONOS2.startOnosCli( ONOSIp=main.params[ 'CTRL' ][ 'ip1' ] )
89 main.step( "Starting Mininet CLI..." )
90
shahshreya3140b1a2015-04-28 14:22:15 -070091 def CASE20( self ):
92 """
93 Exit from mininet cli
94 reinstall ONOS
95 """
96 import time
97 cellName = main.params[ 'ENV' ][ 'cellName' ]
98 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
99
100 main.log.report( "This testcase exits the mininet cli and reinstalls" +
101 "ONOS to switch over to Packet Optical topology" )
102 main.log.report( "_____________________________________________" )
103 main.case( "Disconnecting mininet and restarting ONOS" )
104
105 main.step( "Disconnecting mininet and restarting ONOS" )
106 step1Result = main.TRUE
107 mininetDisconnect = main.Mininet1.disconnect()
108 print "mininetDisconnect = ", mininetDisconnect
109 step1Result = mininetDisconnect
110 utilities.assert_equals(
111 expect=main.TRUE,
112 actual=step1Result,
113 onpass="Mininet disconnect successfully",
114 onfail="Mininet failed to disconnect")
115 """
116 main.step( "Removing raft logs before a clean installation of ONOS" )
117 step2Result = main.TRUE
118 removeRaftLogsResult = main.ONOSbench.onosRemoveRaftLogs()
119 step2Result = removeRaftLogsResult
120 utilities.assert_equals(
121 expect=main.TRUE,
122 actual=step2Result,
123 onpass="Raft logs removed successfully",
124 onfail="Failed to remove raft logs")
125 """
126 main.step( "Applying cell variable to environment" )
127 step3Result = main.TRUE
128 setCellResult = main.ONOSbench.setCell( cellName )
129 verifyCellResult = main.ONOSbench.verifyCell()
130 step3Result = setCellResult and verifyCellResult
131 utilities.assert_equals(
132 expect=main.TRUE,
133 actual=step3Result,
134 onpass="Cell applied successfully",
135 onfail="Failed to apply cell")
136
137 main.step( "Uninstalling ONOS package" )
138 step4Result = main.TRUE
139 ONOSip1 = main.params[ 'CTRL' ][ 'ip1' ]
140 onosUninstallResult = main.ONOSbench.onosUninstall( nodeIp = ONOSip1)
141 step4Result = onosUninstallResult
142 utilities.assert_equals(
143 expect=main.TRUE,
144 actual=step4Result,
145 onpass="Successfully uninstalled ONOS",
146 onfail="Failed to uninstall ONOS")
147
148 time.sleep( 5 )
149 main.step( "Installing ONOS package" )
150 step5Result = main.TRUE
151 onosInstallResult = main.ONOSbench.onosInstall( node = ONOSip1 )
152 step5Result = onosInstallResult
153 utilities.assert_equals(
154 expect=main.TRUE,
155 actual=step5Result,
156 onpass="Successfully installed ONOS",
157 onfail="Failed to install ONOS")
158
159 onos1Isup = main.ONOSbench.isup()
160 if onos1Isup == main.TRUE:
161 main.log.report( "ONOS instance is up and ready" )
162 else:
163 main.log.report( "ONOS instance may not be up" )
164
165 main.step( "Starting ONOS service" )
166 step6Result = main.TRUE
167 startResult = main.ONOSbench.onosStart( ONOS1Ip )
168 step6Result = startResult
169 utilities.assert_equals(
170 expect=main.TRUE,
171 actual=step6Result,
172 onpass="Successfully started ONOS",
173 onfail="Failed to start ONOS")
174
175 main.step( "Starting ONOS cli" )
176 step7Result = main.TRUE
177 cliResult = main.ONOS2.startOnosCli( ONOSIp=main.params[ 'CTRL' ][ 'ip1' ] )
178 step7Result = cliResult
179 utilities.assert_equals(
180 expect=main.TRUE,
181 actual=step7Result,
182 onpass="Successfully started ONOS cli",
183 onfail="Failed to start ONOS cli")
184
shahshreya3140b1a2015-04-28 14:22:15 -0700185 def CASE21( self, main ):
186 """
187 On ONOS bench, run this command:
188 sudo -E python ~/onos/tools/test/topos/opticalTest.py -OC1
189 which spawns packet optical topology and copies the links
190 json file to the onos instance.
191 Note that in case of Packet Optical, the links are not learnt
192 from the topology, instead the links are learnt
193 from the json config file
194 """
195 import time
196 main.log.report(
197 "This testcase starts the packet layer topology and REST" )
198 main.log.report( "_____________________________________________" )
199 main.case( "Starting LINC-OE and other components" )
200
201 main.step( "Activate optical app" )
202 step1Result = main.TRUE
203 activateOpticalResult = main.ONOS2.activateApp( "org.onosproject.optical" )
204 step1Result = activateOpticalResult
205 utilities.assert_equals(
206 expect=main.TRUE,
207 actual=step1Result,
208 onpass="Successfully activated optical app",
209 onfail="Failed to activate optical app")
210
211 appCheck = main.ONOS2.appToIDCheck()
212 if appCheck != main.TRUE:
213 main.log.warn( main.ONOS2.apps() )
214 main.log.warn( main.ONOS2.appIDs() )
215
216 main.step( "Starting mininet and LINC-OE" )
217 step2Result = main.TRUE
218 time.sleep( 10 )
219 opticalMnScript = main.LincOE2.runOpticalMnScript(ctrllerIP = main.params[ 'CTRL' ][ 'ip1' ])
220 step2Result = opticalMnScript
221 utilities.assert_equals(
222 expect=main.TRUE,
223 actual=step2Result,
224 onpass="Started the topology successfully ",
225 onfail="Failed to start the topology")
226
shahshreya3140b1a2015-04-28 14:22:15 -0700227 def CASE22( self, main ):
228 """
229 Curretly we use, 10 optical switches(ROADM's) and
230 6 packet layer mininet switches each with one host.
231 Therefore, the roadmCount variable = 10,
232 packetLayerSWCount variable = 6, hostCount=6 and
shahshreyaa47ebf42015-05-20 13:29:18 -0700233 links=46.
shahshreya3140b1a2015-04-28 14:22:15 -0700234 All this is hardcoded in the testcase. If the topology changes,
235 these hardcoded values need to be changed
236 """
237 import time
238 main.log.report(
239 "This testcase compares the optical+packet topology against what" +
240 " is expected" )
241 main.case( "Topology comparision" )
242
243 main.step( "Starts new ONOS cli" )
244 step1Result = main.TRUE
245 cliResult = main.ONOS3.startOnosCli( ONOSIp=main.params[ 'CTRL' ]\
246 [ 'ip1' ] )
247 step1Result = cliResult
248 utilities.assert_equals(
249 expect=main.TRUE,
250 actual=step1Result,
251 onpass="Successfully starts a new cli",
252 onfail="Failed to start new cli" )
253
254 main.step( "Compare topology" )
255 step2Result = main.TRUE
256 devicesResult = main.ONOS3.devices( jsonFormat=False )
257 print "devices_result :\n", devicesResult
258 devicesLinewise = devicesResult.split( "\n" )
259 roadmCount = 0
260 packetLayerSWCount = 0
261 for line in devicesLinewise:
262 components = line.split( "," )
263 availability = components[ 1 ].split( "=" )[ 1 ]
264 type = components[ 3 ].split( "=" )[ 1 ]
265 if availability == 'true' and type == 'ROADM':
266 roadmCount += 1
267 elif availability == 'true' and type == 'SWITCH':
268 packetLayerSWCount += 1
269 if roadmCount == 10:
270 print "Number of Optical Switches = %d and is" % roadmCount +\
271 " correctly detected"
272 main.log.info(
273 "Number of Optical Switches = " +
274 str( roadmCount ) +
275 " and is correctly detected" )
276 opticalSWResult = main.TRUE
277 else:
278 print "Number of Optical Switches = %d and is wrong" % roadmCount
279 main.log.info(
280 "Number of Optical Switches = " +
281 str( roadmCount ) +
282 " and is wrong" )
283 opticalSWResult = main.FALSE
284 if packetLayerSWCount == 6:
285 print "Number of Packet layer or mininet Switches = %d "\
286 % packetLayerSWCount + "and is correctly detected"
287 main.log.info(
288 "Number of Packet layer or mininet Switches = " +
289 str( packetLayerSWCount ) +
290 " and is correctly detected" )
291 packetSWResult = main.TRUE
292 else:
293 print "Number of Packet layer or mininet Switches = %d and"\
294 % packetLayerSWCount + " is wrong"
295 main.log.info(
296 "Number of Packet layer or mininet Switches = " +
297 str( packetLayerSWCount ) +
298 " and is wrong" )
299 packetSWResult = main.FALSE
300 # sleeps for sometime so the state of the switches will be active
301 time.sleep( 30 )
302 print "_________________________________"
303 linksResult = main.ONOS3.links( jsonFormat=False )
304 print "links_result = ", linksResult
305 print "_________________________________"
306 linkActiveCount = linksResult.count("state=ACTIVE")
307 main.log.info( "linkActiveCount = " + str( linkActiveCount ))
shahshreyaa47ebf42015-05-20 13:29:18 -0700308 if linkActiveCount == 46:
shahshreya3140b1a2015-04-28 14:22:15 -0700309 linkActiveResult = main.TRUE
310 main.log.info(
311 "Number of links in ACTIVE state are correct")
312 else:
313 linkActiveResult = main.FALSE
314 main.log.info(
315 "Number of links in ACTIVE state are wrong")
316 step2Result = opticalSWResult and packetSWResult and \
317 linkActiveResult
318 utilities.assert_equals(
319 expect=main.TRUE,
320 actual=step2Result,
321 onpass="Successfully loaded packet optical topology",
322 onfail="Failed to load packet optical topology" )
323
shahshreya3140b1a2015-04-28 14:22:15 -0700324 def CASE23( self, main ):
325 import time
326 """
327 Add bidirectional point intents between 2 packet layer( mininet )
328 devices and
329 ping mininet hosts
330 """
331 main.log.report(
332 "This testcase adds bidirectional point intents between 2 " +
333 "packet layer( mininet ) devices and ping mininet hosts" )
334 main.case( "Install point intents between 2 packet layer device and " +
335 "ping the hosts" )
336
337 main.step( "Adding point intents" )
shahshreyabf739d82015-06-10 11:22:31 -0700338 checkFlowResult = main.TRUE
shahshreya3140b1a2015-04-28 14:22:15 -0700339 step1Result = main.TRUE
shahshreyaa47ebf42015-05-20 13:29:18 -0700340 main.pIntentsId = []
shahshreya3140b1a2015-04-28 14:22:15 -0700341 pIntent1 = main.ONOS3.addPointIntent(
342 "of:0000ffffffff0001/1",
343 "of:0000ffffffff0005/1" )
shahshreyabf739d82015-06-10 11:22:31 -0700344 time.sleep( 10 )
shahshreya3140b1a2015-04-28 14:22:15 -0700345 pIntent2 = main.ONOS3.addPointIntent(
346 "of:0000ffffffff0005/1",
347 "of:0000ffffffff0001/1" )
shahshreyaa47ebf42015-05-20 13:29:18 -0700348 main.pIntentsId.append( pIntent1 )
349 main.pIntentsId.append( pIntent2 )
350 time.sleep( 10 )
shahshreya3140b1a2015-04-28 14:22:15 -0700351 main.log.info( "Checking intents state")
shahshreyaa47ebf42015-05-20 13:29:18 -0700352 checkStateResult = main.ONOS3.checkIntentState(
353 intentsId = main.pIntentsId )
354 time.sleep( 10 )
shahshreya3140b1a2015-04-28 14:22:15 -0700355 main.log.info( "Checking flows state")
356 checkFlowResult = main.ONOS3.checkFlowsState()
357 # Sleep for 30 seconds to provide time for the intent state to change
shahshreyaa47ebf42015-05-20 13:29:18 -0700358 time.sleep( 10 )
shahshreya3140b1a2015-04-28 14:22:15 -0700359 main.log.info( "Checking intents state one more time")
shahshreyaa47ebf42015-05-20 13:29:18 -0700360 checkStateResult = main.ONOS3.checkIntentState(
361 intentsId = main.pIntentsId )
shahshreya3140b1a2015-04-28 14:22:15 -0700362 step1Result = checkStateResult and checkFlowResult
363 utilities.assert_equals(
364 expect=main.TRUE,
365 actual=step1Result,
366 onpass="Successfully added point intents",
367 onfail="Failed to add point intents")
368
shahshreyabf739d82015-06-10 11:22:31 -0700369 print main.ONOS3.intents()
370
shahshreya3140b1a2015-04-28 14:22:15 -0700371 main.step( "Ping h1 and h5" )
372 step2Result = main.TRUE
373 main.log.info( "\n\nh1 is Pinging h5" )
374 pingResult = main.LincOE2.pingHostOptical( src="h1", target="h5" )
375 step2Result = pingResult
376 utilities.assert_equals(
377 expect=main.TRUE,
378 actual=step2Result,
379 onpass="Successfully pinged h1 and h5",
380 onfail="Failed to ping between h1 and h5")
shahshreya234a1682015-05-27 15:41:56 -0700381
shahshreya3140b1a2015-04-28 14:22:15 -0700382 def CASE24( self, main ):
383 import time
384 import json
385 """
386 LINC uses its own switch IDs. You can use the following
387 command on the LINC console to find the mapping between
388 DPIDs and LINC IDs.
389 rp(application:get_all_key(linc)).
390
391 Test Rerouting of Packet Optical by bringing a port down
392 ( port 20 ) of a switch( switchID=1, or LincOE switchID =9 ),
393 so that link
394 ( between switch1 port20 - switch5 port50 ) is inactive
395 and do a ping test. If rerouting is successful,
396 ping should pass. also check the flows
397 """
398 main.log.report(
399 "This testcase tests rerouting and pings mininet hosts" )
400 main.case( "Test rerouting and pings mininet hosts" )
401
402 main.step( "Attach to the Linc-OE session" )
403 step1Result = main.TRUE
404 attachConsole = main.LincOE1.attachLincOESession()
405 step1Result = attachConsole
406 utilities.assert_equals(
407 expect=main.TRUE,
408 actual=step1Result,
409 onpass="Successfully attached Linc-OE session",
410 onfail="Failed to attached Linc-OE session")
411
412 main.step( "Bring a port down and verify the link state" )
413 step2Result = main.TRUE
414 main.LincOE1.portDown( swId="9", ptId="20" )
415 linksNonjson = main.ONOS3.links( jsonFormat=False )
416 main.log.info( "links = " + linksNonjson )
417 linkInactiveCount = linksNonjson.count( "state=INACTIVE" )
418 main.log.info( "linkInactiveCount = " + str( linkInactiveCount ))
419 if linkInactiveCount == 2:
420 main.log.info(
421 "Number of links in INACTIVE state are correct")
422 else:
423 main.log.info(
424 "Number of links in INACTIVE state are wrong")
425 links = main.ONOS3.links()
426 main.log.info( "links = " + links )
427 linksResult = json.loads( links )
428 linksStateResult = main.FALSE
429 for item in linksResult:
430 if item[ 'src' ][ 'device' ] == "of:0000ffffffffff01" and item[
431 'src' ][ 'port' ] == "20":
432 if item[ 'dst' ][ 'device' ] == "of:0000ffffffffff05" and item[
433 'dst' ][ 'port' ] == "50":
434 linksState = item[ 'state' ]
435 if linksState == "INACTIVE":
436 main.log.info(
437 "Links state is inactive as expected due to one" +
438 " of the ports being down" )
439 main.log.report(
440 "Links state is inactive as expected due to one" +
441 " of the ports being down" )
442 linksStateResult = main.TRUE
443 break
444 else:
445 main.log.info(
446 "Links state is not inactive as expected" )
447 main.log.report(
448 "Links state is not inactive as expected" )
449 linksStateResult = main.FALSE
450 time.sleep( 10 )
shahshreyabf739d82015-06-10 11:22:31 -0700451 #checkFlowsState = main.ONOS3.checkFlowsState()
shahshreya3140b1a2015-04-28 14:22:15 -0700452 step2Result = linksStateResult
453 utilities.assert_equals(
454 expect=main.TRUE,
455 actual=step2Result,
456 onpass="Successfuly brought down a link",
457 onfail="Failed to bring down a link")
458
459 main.step( "Verify Rerouting by a ping test" )
460 step3Result = main.TRUE
461 main.log.info( "\n\nh1 is Pinging h5" )
462 pingResult = main.LincOE2.pingHostOptical( src="h1", target="h5" )
463 step3Result = pingResult
464 utilities.assert_equals(
465 expect=main.TRUE,
466 actual=step3Result,
467 onpass="Successfully pinged h1 and h5",
468 onfail="Failed to ping between h1 and h5")
469
470 main.step( "Bring the downed port up and verify the link state" )
471 step4Result = main.TRUE
472 main.LincOE1.portUp( swId="9", ptId="20" )
473 linksNonjson = main.ONOS3.links( jsonFormat=False )
474 main.log.info( "links = " + linksNonjson )
475 linkInactiveCount = linksNonjson.count( "state=INACTIVE" )
shahshreyabf739d82015-06-10 11:22:31 -0700476 time.sleep( 30 )
shahshreya3140b1a2015-04-28 14:22:15 -0700477 main.log.info( "linkInactiveCount = " + str( linkInactiveCount ))
478 if linkInactiveCount == 0:
479 main.log.info(
480 "Number of links in INACTIVE state are correct")
481 else:
482 main.log.info(
483 "Number of links in INACTIVE state are wrong")
484 step4Result = main.FALSE
485 utilities.assert_equals(
486 expect=main.TRUE,
487 actual=step4Result,
488 onpass="Successfully brought the port up",
489 onfail="Failed to bring the port up")
shahshreyaa47ebf42015-05-20 13:29:18 -0700490 """
491 main.step( "Removing host intents" )
492 step5Result = main.TRUE
493 removeResult = main.TRUE
494 # Check remaining intents
495 intentsJson = json.loads( main.ONOS3.intents() )
496 main.ONOS3.removeIntent( intentId=intent1, purge=True )
497 main.ONOS3.removeIntent( intentId=intent2, purge=True )
498 for intents in intentsJson:
499 main.ONOS3.removeIntent( intentId=intents.get( 'id' ),
500 app='org.onosproject.optical',
501 purge=True )
502 print json.loads( main.ONOS3.intents() )
503 if len( json.loads( main.ONOS3.intents() ) ):
504 removeResult = main.FALSE
505 step5Result = removeResult
shahshreya3140b1a2015-04-28 14:22:15 -0700506 utilities.assert_equals( expect=main.TRUE,
shahshreyaa47ebf42015-05-20 13:29:18 -0700507 actual=step5Result,
508 onpass="Successfully removed host intents",
509 onfail="Failed to remove host intents" )
510 """
shahshreya3140b1a2015-04-28 14:22:15 -0700511 def CASE10( self ):
512 main.log.report(
513 "This testcase uninstalls the reactive forwarding app" )
514 main.log.report( "__________________________________" )
515 main.case( "Uninstalling reactive forwarding app" )
516 main.step( "Uninstalling reactive forwarding app" )
517 step1Result = main.TRUE
518 # Unistall onos-app-fwd app to disable reactive forwarding
519 main.log.info( "deactivate reactive forwarding app" )
520 appUninstallResult = main.ONOS2.deactivateApp( "org.onosproject.fwd" )
521 appCheck = main.ONOS2.appToIDCheck()
522 if appCheck != main.TRUE:
523 main.log.warn( main.ONOS2.apps() )
524 main.log.warn( main.ONOS2.appIDs() )
525 step1Result = appUninstallResult
526 utilities.assert_equals(
527 expect=main.TRUE,
528 actual=step1Result,
529 onpass="Successfully deactivate reactive forwarding app",
530 onfail="Failed to deactivate reactive forwarding app")
531 # After reactive forwarding is disabled, the reactive flows on
532 # switches timeout in 10-15s
533 # So sleep for 15s
534 time.sleep( 15 )
535 flows = main.ONOS2.flows()
536 main.log.info( flows )
537
shahshreya3140b1a2015-04-28 14:22:15 -0700538 def CASE25( self ):
539 """
540 Add host intents between 2 packet layer host
541 """
542 import time
543 import json
544 main.log.report( "Adding host intents between 2 optical layer host" )
545 main.case( "Test add host intents between optical layer host" )
546
shahshreya7bf64442015-04-28 16:28:54 -0700547 main.step( "Discover host using arping" )
shahshreya3140b1a2015-04-28 14:22:15 -0700548 step1Result = main.TRUE
549 main.hostMACs = []
550 main.hostId = []
551 #Listing host MAC addresses
552 for i in range( 1 , 7 ):
553 main.hostMACs.append( "00:00:00:00:00:" +
554 str( hex( i )[ 2: ] ).zfill( 2 ).upper() )
555 for macs in main.hostMACs:
556 main.hostId.append( macs + "/-1" )
557 host1 = main.hostId[ 0 ]
558 host2 = main.hostId[ 1 ]
559 # Use arping to discover the hosts
560 main.LincOE2.arping( host = "h1" )
561 main.LincOE2.arping( host = "h2" )
562 time.sleep( 5 )
563 hostsDict = main.ONOS3.hosts()
564 if not len( hostsDict ):
565 step1Result = main.FALSE
566 # Adding host intent
567 utilities.assert_equals(
568 expect=main.TRUE,
569 actual=step1Result,
570 onpass="Hosts discovered",
571 onfail="Failed to discover hosts")
572
shahshreya7bf64442015-04-28 16:28:54 -0700573 main.step( "Adding host intents to h1 and h2" )
shahshreya3140b1a2015-04-28 14:22:15 -0700574 step2Result = main.TRUE
575 intentsId = []
576 intent1 = main.ONOS3.addHostIntent( hostIdOne = host1,
577 hostIdTwo = host2 )
578 intentsId.append( intent1 )
shahshreyabf739d82015-06-10 11:22:31 -0700579 """
shahshreya3140b1a2015-04-28 14:22:15 -0700580 intent2 = main.ONOS3.addHostIntent( hostIdOne = host2,
581 hostIdTwo = host1 )
582 intentsId.append( intent2 )
shahshreyabf739d82015-06-10 11:22:31 -0700583 """
shahshreya3140b1a2015-04-28 14:22:15 -0700584 # Checking intents state before pinging
585 main.log.info( "Checking intents state" )
586 time.sleep( 15 )
587 intentResult = main.ONOS3.checkIntentState( intentsId = intentsId )
588 #check intent state again if intents are not in installed state
shahshreyabf739d82015-06-10 11:22:31 -0700589 print main.ONOS3.intents()
shahshreya3140b1a2015-04-28 14:22:15 -0700590 if not intentResult:
591 intentResult = main.ONOS3.checkIntentState( intentsId = intentsId )
592 step2Result = intentResult
593 utilities.assert_equals( expect=main.TRUE,
594 actual=step2Result,
595 onpass="All intents are in INSTALLED state ",
596 onfail="Some of the intents are not in " +
597 "INSTALLED state " )
598
599 # pinging h1 to h2 and then ping h2 to h1
shahshreya7bf64442015-04-28 16:28:54 -0700600 main.step( "Pinging h1 and h2" )
shahshreya3140b1a2015-04-28 14:22:15 -0700601 step3Result = main.TRUE
602 pingResult = main.TRUE
603 pingResult = main.LincOE2.pingHostOptical( src="h1", target="h2" )
604 pingResult = pingResult and main.LincOE2.pingHostOptical( src="h2",
605 target="h1" )
shahshreya7bf64442015-04-28 16:28:54 -0700606 step3Result = pingResult
shahshreya3140b1a2015-04-28 14:22:15 -0700607 utilities.assert_equals( expect=main.TRUE,
shahshreya7bf64442015-04-28 16:28:54 -0700608 actual=step3Result,
shahshreya3140b1a2015-04-28 14:22:15 -0700609 onpass="Pinged successfully between h1 and h2",
610 onfail="Pinged failed between h1 and h2" )
shahshreya7bf64442015-04-28 16:28:54 -0700611 # Removed all added host intents
612 main.step( "Removing host intents" )
613 step4Result = main.TRUE
614 removeResult = main.TRUE
615 # Check remaining intents
616 intentsJson = json.loads( main.ONOS3.intents() )
617 main.ONOS3.removeIntent( intentId=intent1, purge=True )
shahshreyabf739d82015-06-10 11:22:31 -0700618 #main.ONOS3.removeIntent( intentId=intent2, purge=True )
shahshreya7bf64442015-04-28 16:28:54 -0700619 for intents in intentsJson:
620 main.ONOS3.removeIntent( intentId=intents.get( 'id' ),
621 app='org.onosproject.optical',
622 purge=True )
623 print json.loads( main.ONOS3.intents() )
624 if len( json.loads( main.ONOS3.intents() ) ):
625 removeResult = main.FALSE
626 step4Result = removeResult
627 utilities.assert_equals( expect=main.TRUE,
628 actual=step4Result,
629 onpass="Successfully removed host intents",
630 onfail="Failed to remove host intents" )