blob: 16df59c4f04c12884468920075d434552684f39d [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 Hall8f89dda2015-01-22 16:03:33 -080023
24
Jon Hallb1290e82014-11-18 16:17:48 -050025class HATestSanity:
26
Jon Hall6aec96b2015-01-19 14:49:31 -080027 def __init__( self ):
Jon Hallb1290e82014-11-18 16:17:48 -050028 self.default = ''
29
Jon Hall6aec96b2015-01-19 14:49:31 -080030 def CASE1( self, main ):
31 """
Jon Hallb1290e82014-11-18 16:17:48 -050032 CASE1 is to compile ONOS and push it to the test machines
33
34 Startup sequence:
35 git pull
36 mvn clean install
37 onos-package
38 cell <name>
39 onos-verify-cell
40 NOTE: temporary - onos-remove-raft-logs
41 onos-install -f
42 onos-wait-for-start
Jon Hall6aec96b2015-01-19 14:49:31 -080043 """
44 main.log.report( "ONOS HA Sanity test - initialization" )
45 main.case( "Setting up test environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080046 # main.step( "This is a multiline \
47 # comment\
48 # this is \
49 # a long \comment" )
50 print "First Line"
Jon Hall6aec96b2015-01-19 14:49:31 -080051 # TODO: save all the timers and output them for plotting
Jon Hallb1290e82014-11-18 16:17:48 -050052
53 # load some vairables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080054 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080055 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080056 PULLCODE = True
Jon Hallb1290e82014-11-18 16:17:48 -050057
Jon Hall8f89dda2015-01-22 16:03:33 -080058 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080059
60 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080061 global ONOS1Ip
62 global ONOS1Port
63 global ONOS2Ip
64 global ONOS2Port
65 global ONOS3Ip
66 global ONOS3Port
67 global ONOS4Ip
68 global ONOS4Port
69 global ONOS5Ip
70 global ONOS5Port
71 global ONOS6Ip
72 global ONOS6Port
73 global ONOS7Ip
74 global ONOS7Port
75 global numControllers
Jon Hallb1290e82014-11-18 16:17:48 -050076
Jon Hall8f89dda2015-01-22 16:03:33 -080077 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
78 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
79 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
80 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
81 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
82 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
83 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
84 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
85 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
86 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
87 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
88 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
89 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
90 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
91 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hallb1290e82014-11-18 16:17:48 -050092
Jon Hall6aec96b2015-01-19 14:49:31 -080093 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080094 cellResult = main.ONOSbench.setCell( cellName )
95 verifyResult = main.ONOSbench.verifyCell()
Jon Hall368769f2014-11-19 15:43:35 -080096
Jon Hall6aec96b2015-01-19 14:49:31 -080097 # FIXME:this is short term fix
98 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080099 main.ONOSbench.onosRemoveRaftLogs()
Jon Hall6aec96b2015-01-19 14:49:31 -0800100 main.log.report( "Uninstalling ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800101 main.ONOSbench.onosUninstall( ONOS1Ip )
102 main.ONOSbench.onosUninstall( ONOS2Ip )
103 main.ONOSbench.onosUninstall( ONOS3Ip )
104 main.ONOSbench.onosUninstall( ONOS4Ip )
105 main.ONOSbench.onosUninstall( ONOS5Ip )
106 main.ONOSbench.onosUninstall( ONOS6Ip )
107 main.ONOSbench.onosUninstall( ONOS7Ip )
Jon Hallb1290e82014-11-18 16:17:48 -0500108
Jon Hall8f89dda2015-01-22 16:03:33 -0800109 cleanInstallResult = main.TRUE
110 gitPullResult = main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -0500111
Jon Hall6aec96b2015-01-19 14:49:31 -0800112 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800113 if PULLCODE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800114 # TODO Configure branch in params
115 main.step( "Git checkout and pull master" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800116 main.ONOSbench.gitCheckout( "master" )
117 gitPullResult = main.ONOSbench.gitPull()
Jon Hallb1290e82014-11-18 16:17:48 -0500118
Jon Hall6aec96b2015-01-19 14:49:31 -0800119 main.step( "Using mvn clean & install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800120 cleanInstallResult = main.TRUE
121
122 if gitPullResult == main.TRUE:
123 cleanInstallResult = main.ONOSbench.cleanInstall()
Jon Hallb1290e82014-11-18 16:17:48 -0500124 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800125 main.log.warn( "Did not pull new code so skipping mvn " +
126 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800127 main.ONOSbench.getVersion( report=True )
Jon Hallb1290e82014-11-18 16:17:48 -0500128
Jon Hall6aec96b2015-01-19 14:49:31 -0800129 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800130 packageResult = main.ONOSbench.onosPackage()
Jon Hallb1290e82014-11-18 16:17:48 -0500131
Jon Hall6aec96b2015-01-19 14:49:31 -0800132 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800133 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
134 node=ONOS1Ip )
135 onos2InstallResult = main.ONOSbench.onosInstall( options="-f",
136 node=ONOS2Ip )
137 onos3InstallResult = main.ONOSbench.onosInstall( options="-f",
138 node=ONOS3Ip )
139 onos4InstallResult = main.ONOSbench.onosInstall( options="-f",
140 node=ONOS4Ip )
141 onos5InstallResult = main.ONOSbench.onosInstall( options="-f",
142 node=ONOS5Ip )
143 onos6InstallResult = main.ONOSbench.onosInstall( options="-f",
144 node=ONOS6Ip )
145 onos7InstallResult = main.ONOSbench.onosInstall( options="-f",
146 node=ONOS7Ip )
147 onosInstallResult = onos1InstallResult and onos2InstallResult\
148 and onos3InstallResult and onos4InstallResult\
149 and onos5InstallResult and onos6InstallResult\
150 and onos7InstallResult
Jon Hallb1290e82014-11-18 16:17:48 -0500151
Jon Hall6aec96b2015-01-19 14:49:31 -0800152 main.step( "Checking if ONOS is up yet" )
153 # TODO check bundle:list?
154 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800155 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
156 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800157 main.log.report( "ONOS1 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800158 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
159 if not onos2Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800160 main.log.report( "ONOS2 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800161 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
162 if not onos3Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800163 main.log.report( "ONOS3 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800164 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
165 if not onos4Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800166 main.log.report( "ONOS4 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800167 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
168 if not onos5Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800169 main.log.report( "ONOS5 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800170 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
171 if not onos6Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800172 main.log.report( "ONOS6 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800173 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
174 if not onos7Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800175 main.log.report( "ONOS7 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800176 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
177 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
178 if onosIsupResult == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -0800179 break
Jon Hallb1290e82014-11-18 16:17:48 -0500180
Jon Hall8f89dda2015-01-22 16:03:33 -0800181 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
182 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
183 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
184 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
185 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
186 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
187 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
188 cliResults = cliResult1 and cliResult2 and cliResult3 and\
189 cliResult4 and cliResult5 and cliResult6 and cliResult7
Jon Hallb1290e82014-11-18 16:17:48 -0500190
Jon Hall6aec96b2015-01-19 14:49:31 -0800191 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800192 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800193 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
194 + "-MN.pcap",
195 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
196 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hallb1290e82014-11-18 16:17:48 -0500197
Jon Hall8f89dda2015-01-22 16:03:33 -0800198 case1Result = ( cleanInstallResult and packageResult and
199 cellResult and verifyResult and onosInstallResult
200 and onosIsupResult and cliResults )
Jon Hallb1290e82014-11-18 16:17:48 -0500201
Jon Hall8f89dda2015-01-22 16:03:33 -0800202 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
203 onpass="Test startup successful",
204 onfail="Test startup NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -0500205
Jon Hall8f89dda2015-01-22 16:03:33 -0800206 if case1Result == main.FALSE:
Jon Hallffb386d2014-11-21 13:43:38 -0800207 main.cleanup()
208 main.exit()
Jon Hallb1290e82014-11-18 16:17:48 -0500209
Jon Hall6aec96b2015-01-19 14:49:31 -0800210 def CASE2( self, main ):
211 """
Jon Hallb1290e82014-11-18 16:17:48 -0500212 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800213 """
Jon Hallb1290e82014-11-18 16:17:48 -0500214 import re
215
Jon Hall6aec96b2015-01-19 14:49:31 -0800216 main.log.report( "Assigning switches to controllers" )
217 main.case( "Assigning Controllers" )
218 main.step( "Assign switches to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500219
Jon Hall6aec96b2015-01-19 14:49:31 -0800220 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800221 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800222 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800223 count=numControllers,
224 ip1=ONOS1Ip, port1=ONOS1Port,
225 ip2=ONOS2Ip, port2=ONOS2Port,
226 ip3=ONOS3Ip, port3=ONOS3Port,
227 ip4=ONOS4Ip, port4=ONOS4Port,
228 ip5=ONOS5Ip, port5=ONOS5Port,
229 ip6=ONOS6Ip, port6=ONOS6Port,
230 ip7=ONOS7Ip, port7=ONOS7Port )
Jon Hallb1290e82014-11-18 16:17:48 -0500231
Jon Hall8f89dda2015-01-22 16:03:33 -0800232 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800233 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800234 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800235 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800236 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800237 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800238 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800239 if re.search( "tcp:" + ONOS1Ip, response )\
240 and re.search( "tcp:" + ONOS2Ip, response )\
241 and re.search( "tcp:" + ONOS3Ip, response )\
242 and re.search( "tcp:" + ONOS4Ip, response )\
243 and re.search( "tcp:" + ONOS5Ip, response )\
244 and re.search( "tcp:" + ONOS6Ip, response )\
245 and re.search( "tcp:" + ONOS7Ip, response ):
246 mastershipCheck = mastershipCheck and main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -0500247 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800248 mastershipCheck = main.FALSE
249 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800250 main.log.report( "Switch mastership assigned correctly" )
251 utilities.assert_equals(
252 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800253 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800254 onpass="Switch mastership assigned correctly",
255 onfail="Switches not assigned correctly to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500256
Jon Hall6aec96b2015-01-19 14:49:31 -0800257 # Manually assign mastership to the controller we want
Jon Hall8f89dda2015-01-22 16:03:33 -0800258 roleCall = main.TRUE
259 roleCheck = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800260
Jon Hall6aec96b2015-01-19 14:49:31 -0800261 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800262 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
263 roleCall = roleCall and main.ONOScli1.deviceRole(
264 deviceId,
265 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800266 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800267 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
268 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800269 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800270 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800271
Jon Hall6aec96b2015-01-19 14:49:31 -0800272 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800273 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
274 roleCall = roleCall and main.ONOScli1.deviceRole(
275 deviceId,
276 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800277 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800278 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
279 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800280 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800281 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800282
Jon Hall6aec96b2015-01-19 14:49:31 -0800283 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800284 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
285 roleCall = roleCall and main.ONOScli1.deviceRole(
286 deviceId,
287 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800288 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800289 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
290 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800291 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800292 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800293
Jon Hall6aec96b2015-01-19 14:49:31 -0800294 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800295 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
296 roleCall = roleCall and main.ONOScli1.deviceRole(
297 deviceId,
298 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800299 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800300 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
301 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800302 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800303 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800304
Jon Hall6aec96b2015-01-19 14:49:31 -0800305 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800306 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
307 roleCall = roleCall and main.ONOScli1.deviceRole(
308 deviceId,
309 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800310 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800311 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
312 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800313 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800314 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800315
Jon Hall6aec96b2015-01-19 14:49:31 -0800316 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800317 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
318 roleCall = roleCall and main.ONOScli1.deviceRole(
319 deviceId,
320 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800321 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800322 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
323 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800324 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800325 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800326
Jon Hall6aec96b2015-01-19 14:49:31 -0800327 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800328 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
329 roleCall = roleCall and main.ONOScli1.deviceRole(
330 deviceId,
331 ONOS4Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800332 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800333 if ONOS4Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
334 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800335 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800336 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800337
Jon Hall6aec96b2015-01-19 14:49:31 -0800338 for i in range( 8, 18 ):
339 dpid = '3' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800340 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
341 roleCall = roleCall and main.ONOScli1.deviceRole(
342 deviceId,
343 ONOS5Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800344 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800345 if ONOS5Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
346 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800347 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800348 roleCheck = roleCheck and main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800349
Jon Hall8f89dda2015-01-22 16:03:33 -0800350 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
351 roleCall = roleCall and main.ONOScli1.deviceRole(
352 deviceId,
353 ONOS6Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800354 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800355 if ONOS6Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
356 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800357 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800358 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800359
Jon Hall6aec96b2015-01-19 14:49:31 -0800360 for i in range( 18, 28 ):
361 dpid = '6' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800362 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
363 roleCall = roleCall and main.ONOScli1.deviceRole(
364 deviceId,
365 ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800366 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800367 if ONOS7Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
368 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800369 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800370 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800371
Jon Hall6aec96b2015-01-19 14:49:31 -0800372 utilities.assert_equals(
373 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800374 actual=roleCall,
Jon Hall6aec96b2015-01-19 14:49:31 -0800375 onpass="Re-assigned switch mastership to designated controller",
Jon Hall8f89dda2015-01-22 16:03:33 -0800376 onfail="Something wrong with deviceRole calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800377
Jon Hall6aec96b2015-01-19 14:49:31 -0800378 utilities.assert_equals(
379 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800380 actual=roleCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800381 onpass="Switches were successfully reassigned to designated " +
382 "controller",
383 onfail="Switches were not successfully reassigned" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800384 mastershipCheck = mastershipCheck and roleCall and roleCheck
385 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800386 onpass="Switch mastership correctly assigned",
387 onfail="Error in (re)assigning switch" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800388 " mastership" )
Jon Hallb1290e82014-11-18 16:17:48 -0500389
Jon Hall6aec96b2015-01-19 14:49:31 -0800390 def CASE3( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500391 """
392 Assign intents
Jon Hallb1290e82014-11-18 16:17:48 -0500393 """
394 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800395 main.log.report( "Adding host intents" )
396 main.case( "Adding host Intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500397
Jon Hall8f89dda2015-01-22 16:03:33 -0800398 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800399 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hallb1290e82014-11-18 16:17:48 -0500400
Jon Hall6aec96b2015-01-19 14:49:31 -0800401 # install onos-app-fwd
402 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800403 main.ONOScli1.featureInstall( "onos-app-fwd" )
404 main.ONOScli2.featureInstall( "onos-app-fwd" )
405 main.ONOScli3.featureInstall( "onos-app-fwd" )
406 main.ONOScli4.featureInstall( "onos-app-fwd" )
407 main.ONOScli5.featureInstall( "onos-app-fwd" )
408 main.ONOScli6.featureInstall( "onos-app-fwd" )
409 main.ONOScli7.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800410
Jon Hall6aec96b2015-01-19 14:49:31 -0800411 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800412 pingResult = main.FALSE
Jon Hallb1290e82014-11-18 16:17:48 -0500413 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800414 pingResult = main.Mininet1.pingall()
Jon Hallb1290e82014-11-18 16:17:48 -0500415 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800416 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500417
Jon Hall6aec96b2015-01-19 14:49:31 -0800418 # uninstall onos-app-fwd
419 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800420 main.ONOScli1.featureUninstall( "onos-app-fwd" )
421 main.ONOScli2.featureUninstall( "onos-app-fwd" )
422 main.ONOScli3.featureUninstall( "onos-app-fwd" )
423 main.ONOScli4.featureUninstall( "onos-app-fwd" )
424 main.ONOScli5.featureUninstall( "onos-app-fwd" )
425 main.ONOScli6.featureUninstall( "onos-app-fwd" )
426 main.ONOScli7.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800427 # timeout for fwd flows
428 time.sleep( 10 )
Jon Hallb1290e82014-11-18 16:17:48 -0500429
Jon Hall6aec96b2015-01-19 14:49:31 -0800430 main.step( "Add host intents" )
431 # TODO: move the host numbers to params
Jon Hall8f89dda2015-01-22 16:03:33 -0800432 intentAddResult = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800433 for i in range( 8, 18 ):
434 main.log.info( "Adding host intent between h" + str( i ) +
435 " and h" + str( i + 10 ) )
436 host1 = "00:00:00:00:00:" + \
437 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
438 host2 = "00:00:00:00:00:" + \
439 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall8f89dda2015-01-22 16:03:33 -0800440 host1Id = main.ONOScli1.getHost( host1 )[ 'id' ]
441 host2Id = main.ONOScli1.getHost( host2 )[ 'id' ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800442 # NOTE: get host can return None
Jon Hall8f89dda2015-01-22 16:03:33 -0800443 if host1Id and host2Id:
444 tmpResult = main.ONOScli1.addHostIntent(
445 host1Id,
446 host2Id )
Jon Hall669173b2014-12-17 11:36:30 -0800447 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800448 main.log.error( "Error, getHost() failed" )
449 tmpResult = main.FALSE
450 intentAddResult = bool( pingResult and intentAddResult
451 and tmpResult )
452 # TODO Check that intents were added?
Jon Hall6aec96b2015-01-19 14:49:31 -0800453 utilities.assert_equals(
454 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800455 actual=intentAddResult,
456 onpass="Pushed host intents to ONOS",
457 onfail="Error in pushing host intents to ONOS" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800458 # TODO Check if intents all exist in datastore
Jon Hallb1290e82014-11-18 16:17:48 -0500459
Jon Hall6aec96b2015-01-19 14:49:31 -0800460 def CASE4( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500461 """
462 Ping across added host intents
463 """
Jon Hall368769f2014-11-19 15:43:35 -0800464 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800465 main.log.report( description )
466 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800467 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800468 for i in range( 8, 18 ):
469 ping = main.Mininet1.pingHost(
470 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800471 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800472 if ping == main.FALSE:
473 main.log.warn( "Ping failed between h" + str( i ) +
474 " and h" + str( i + 10 ) )
475 elif ping == main.TRUE:
476 main.log.info( "Ping test passed!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800477 PingResult = main.TRUE
478 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800479 main.log.report(
480 "Intents have not been installed correctly, pings failed." )
Jon Hall8f89dda2015-01-22 16:03:33 -0800481 main.log.info( main.ONOScli1.intents() )
482 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800483 main.log.report(
484 "Intents have been installed correctly and verified by pings" )
485 utilities.assert_equals(
486 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800487 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800488 onpass="Intents have been installed correctly and pings work",
489 onfail="Intents have not been installed correctly, pings failed." )
Jon Hallb1290e82014-11-18 16:17:48 -0500490
Jon Hall6aec96b2015-01-19 14:49:31 -0800491 def CASE5( self, main ):
492 """
Jon Hallb1290e82014-11-18 16:17:48 -0500493 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800494 """
Jon Hallb1290e82014-11-18 16:17:48 -0500495 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800496 # assumes that sts is already in you PYTHONPATH
497 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -0500498
Jon Hall6aec96b2015-01-19 14:49:31 -0800499 main.log.report( "Setting up and gathering data for current state" )
500 main.case( "Setting up and gathering data for current state" )
501 # The general idea for this test case is to pull the state of
502 # ( intents,flows, topology,... ) from each ONOS node
503 # We can then compare them with eachother and also with past states
Jon Hallb1290e82014-11-18 16:17:48 -0500504
Jon Hall6aec96b2015-01-19 14:49:31 -0800505 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800506 global mastershipState
507 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800508
Jon Hall6aec96b2015-01-19 14:49:31 -0800509 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800510 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
511 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
512 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
513 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
514 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
515 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
516 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
517 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
518 ONOS3MasterNotNull and ONOS4MasterNotNull and\
519 ONOS5MasterNotNull and ONOS6MasterNotNull and\
520 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -0800521 utilities.assert_equals(
522 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800523 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800524 onpass="Each device has a master",
525 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800526
Jon Hall8f89dda2015-01-22 16:03:33 -0800527 ONOS1Mastership = main.ONOScli1.roles()
528 ONOS2Mastership = main.ONOScli2.roles()
529 ONOS3Mastership = main.ONOScli3.roles()
530 ONOS4Mastership = main.ONOScli4.roles()
531 ONOS5Mastership = main.ONOScli5.roles()
532 ONOS6Mastership = main.ONOScli6.roles()
533 ONOS7Mastership = main.ONOScli7.roles()
534 # print json.dumps( json.loads( ONOS1Mastership ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800535 # indent=4, separators=( ',', ': ' ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800536 if "Error" in ONOS1Mastership or not ONOS1Mastership\
537 or "Error" in ONOS2Mastership or not ONOS2Mastership\
538 or "Error" in ONOS3Mastership or not ONOS3Mastership\
539 or "Error" in ONOS4Mastership or not ONOS4Mastership\
540 or "Error" in ONOS5Mastership or not ONOS5Mastership\
541 or "Error" in ONOS6Mastership or not ONOS6Mastership\
542 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800543 main.log.report( "Error in getting ONOS roles" )
544 main.log.warn(
545 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800546 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800547 main.log.warn(
548 "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800549 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800550 main.log.warn(
551 "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800552 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800553 main.log.warn(
554 "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800555 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800556 main.log.warn(
557 "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800558 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800559 main.log.warn(
560 "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800561 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800562 main.log.warn(
563 "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800564 repr( ONOS7Mastership ) )
565 consistentMastership = main.FALSE
566 elif ONOS1Mastership == ONOS2Mastership\
567 and ONOS1Mastership == ONOS3Mastership\
568 and ONOS1Mastership == ONOS4Mastership\
569 and ONOS1Mastership == ONOS5Mastership\
570 and ONOS1Mastership == ONOS6Mastership\
571 and ONOS1Mastership == ONOS7Mastership:
572 mastershipState = ONOS1Mastership
573 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800574 main.log.report(
575 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500576 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800577 main.log.warn(
578 "ONOS1 roles: ",
579 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800580 json.loads( ONOS1Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800581 sort_keys=True,
582 indent=4,
583 separators=(
584 ',',
585 ': ' ) ) )
586 main.log.warn(
587 "ONOS2 roles: ",
588 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800589 json.loads( ONOS2Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800590 sort_keys=True,
591 indent=4,
592 separators=(
593 ',',
594 ': ' ) ) )
595 main.log.warn(
596 "ONOS3 roles: ",
597 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800598 json.loads( ONOS3Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800599 sort_keys=True,
600 indent=4,
601 separators=(
602 ',',
603 ': ' ) ) )
604 main.log.warn(
605 "ONOS4 roles: ",
606 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800607 json.loads( ONOS4Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800608 sort_keys=True,
609 indent=4,
610 separators=(
611 ',',
612 ': ' ) ) )
613 main.log.warn(
614 "ONOS5 roles: ",
615 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800616 json.loads( ONOS5Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800617 sort_keys=True,
618 indent=4,
619 separators=(
620 ',',
621 ': ' ) ) )
622 main.log.warn(
623 "ONOS6 roles: ",
624 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800625 json.loads( ONOS6Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800626 sort_keys=True,
627 indent=4,
628 separators=(
629 ',',
630 ': ' ) ) )
631 main.log.warn(
632 "ONOS7 roles: ",
633 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800634 json.loads( ONOS7Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800635 sort_keys=True,
636 indent=4,
637 separators=(
638 ',',
639 ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800640 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800641 utilities.assert_equals(
642 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800643 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800644 onpass="Switch roles are consistent across all ONOS nodes",
645 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -0500646
Jon Hall6aec96b2015-01-19 14:49:31 -0800647 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800648 global intentState
649 intentState = []
650 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
651 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
652 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
653 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
654 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
655 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
656 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
657 intentCheck = main.FALSE
658 if "Error" in ONOS1Intents or not ONOS1Intents\
659 or "Error" in ONOS2Intents or not ONOS2Intents\
660 or "Error" in ONOS3Intents or not ONOS3Intents\
661 or "Error" in ONOS4Intents or not ONOS4Intents\
662 or "Error" in ONOS5Intents or not ONOS5Intents\
663 or "Error" in ONOS6Intents or not ONOS6Intents\
664 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800665 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800666 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
667 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
668 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
669 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
670 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
671 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
672 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
673 elif ONOS1Intents == ONOS2Intents\
674 and ONOS1Intents == ONOS3Intents\
675 and ONOS1Intents == ONOS4Intents\
676 and ONOS1Intents == ONOS5Intents\
677 and ONOS1Intents == ONOS6Intents\
678 and ONOS1Intents == ONOS7Intents:
679 intentState = ONOS1Intents
680 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800681 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500682 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800683 main.log.warn(
684 "ONOS1 intents: ",
685 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800686 json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800687 sort_keys=True,
688 indent=4,
689 separators=(
690 ',',
691 ': ' ) ) )
692 main.log.warn(
693 "ONOS2 intents: ",
694 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800695 json.loads( ONOS2Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800696 sort_keys=True,
697 indent=4,
698 separators=(
699 ',',
700 ': ' ) ) )
701 main.log.warn(
702 "ONOS3 intents: ",
703 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800704 json.loads( ONOS3Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800705 sort_keys=True,
706 indent=4,
707 separators=(
708 ',',
709 ': ' ) ) )
710 main.log.warn(
711 "ONOS4 intents: ",
712 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800713 json.loads( ONOS4Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800714 sort_keys=True,
715 indent=4,
716 separators=(
717 ',',
718 ': ' ) ) )
719 main.log.warn(
720 "ONOS5 intents: ",
721 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800722 json.loads( ONOS5Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800723 sort_keys=True,
724 indent=4,
725 separators=(
726 ',',
727 ': ' ) ) )
728 main.log.warn(
729 "ONOS6 intents: ",
730 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800731 json.loads( ONOS6Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800732 sort_keys=True,
733 indent=4,
734 separators=(
735 ',',
736 ': ' ) ) )
737 main.log.warn(
738 "ONOS7 intents: ",
739 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800740 json.loads( ONOS7Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800741 sort_keys=True,
742 indent=4,
743 separators=(
744 ',',
745 ': ' ) ) )
746 utilities.assert_equals(
747 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800748 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800749 onpass="Intents are consistent across all ONOS nodes",
750 onfail="ONOS nodes have different views of intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500751
Jon Hall6aec96b2015-01-19 14:49:31 -0800752 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800753 global flowState
754 flowState = []
755 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
756 ONOS2Flows = main.ONOScli2.flows( jsonFormat=True )
757 ONOS3Flows = main.ONOScli3.flows( jsonFormat=True )
758 ONOS4Flows = main.ONOScli4.flows( jsonFormat=True )
759 ONOS5Flows = main.ONOScli5.flows( jsonFormat=True )
760 ONOS6Flows = main.ONOScli6.flows( jsonFormat=True )
761 ONOS7Flows = main.ONOScli7.flows( jsonFormat=True )
762 ONOS1FlowsJson = json.loads( ONOS1Flows )
763 ONOS2FlowsJson = json.loads( ONOS2Flows )
764 ONOS3FlowsJson = json.loads( ONOS3Flows )
765 ONOS4FlowsJson = json.loads( ONOS4Flows )
766 ONOS5FlowsJson = json.loads( ONOS5Flows )
767 ONOS6FlowsJson = json.loads( ONOS6Flows )
768 ONOS7FlowsJson = json.loads( ONOS7Flows )
769 flowCheck = main.FALSE
770 if "Error" in ONOS1Flows or not ONOS1Flows\
771 or "Error" in ONOS2Flows or not ONOS2Flows\
772 or "Error" in ONOS3Flows or not ONOS3Flows\
773 or "Error" in ONOS4Flows or not ONOS4Flows\
774 or "Error" in ONOS5Flows or not ONOS5Flows\
775 or "Error" in ONOS6Flows or not ONOS6Flows\
776 or "Error" in ONOS7Flows or not ONOS7Flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800777 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800778 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
779 main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows )
780 main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows )
781 main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows )
782 main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows )
783 main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows )
784 main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows )
785 elif len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\
786 and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\
787 and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\
788 and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\
789 and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\
790 and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800791 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800792 flowState = ONOS1Flows
793 flowCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800794 main.log.report( "Flow count is consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500795 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800796 main.log.warn( "ONOS1 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800797 json.dumps( ONOS1FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800798 indent=4, separators=( ',', ': ' ) ) )
799 main.log.warn( "ONOS2 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800800 json.dumps( ONOS2FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800801 indent=4, separators=( ',', ': ' ) ) )
802 main.log.warn( "ONOS3 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800803 json.dumps( ONOS3FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800804 indent=4, separators=( ',', ': ' ) ) )
805 main.log.warn( "ONOS4 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800806 json.dumps( ONOS4FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800807 indent=4, separators=( ',', ': ' ) ) )
808 main.log.warn( "ONOS5 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800809 json.dumps( ONOS5FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800810 indent=4, separators=( ',', ': ' ) ) )
811 main.log.warn( "ONOS6 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800812 json.dumps( ONOS6FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800813 indent=4, separators=( ',', ': ' ) ) )
814 main.log.warn( "ONOS7 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800815 json.dumps( ONOS7FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800816 indent=4, separators=( ',', ': ' ) ) )
817 utilities.assert_equals(
818 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800819 actual=flowCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800820 onpass="The flow count is consistent across all ONOS nodes",
821 onfail="ONOS nodes have different flow counts" )
Jon Hallb1290e82014-11-18 16:17:48 -0500822
Jon Hall6aec96b2015-01-19 14:49:31 -0800823 main.step( "Get the OF Table entries" )
Jon Hallb1290e82014-11-18 16:17:48 -0500824 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800825 flows = []
826 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800827 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500828
Jon Hall6aec96b2015-01-19 14:49:31 -0800829 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hallb1290e82014-11-18 16:17:48 -0500830
Jon Hall6aec96b2015-01-19 14:49:31 -0800831 main.step( "Start continuous pings" )
832 main.Mininet2.pingLong(
833 src=main.params[ 'PING' ][ 'source1' ],
834 target=main.params[ 'PING' ][ 'target1' ],
835 pingTime=500 )
836 main.Mininet2.pingLong(
837 src=main.params[ 'PING' ][ 'source2' ],
838 target=main.params[ 'PING' ][ 'target2' ],
839 pingTime=500 )
840 main.Mininet2.pingLong(
841 src=main.params[ 'PING' ][ 'source3' ],
842 target=main.params[ 'PING' ][ 'target3' ],
843 pingTime=500 )
844 main.Mininet2.pingLong(
845 src=main.params[ 'PING' ][ 'source4' ],
846 target=main.params[ 'PING' ][ 'target4' ],
847 pingTime=500 )
848 main.Mininet2.pingLong(
849 src=main.params[ 'PING' ][ 'source5' ],
850 target=main.params[ 'PING' ][ 'target5' ],
851 pingTime=500 )
852 main.Mininet2.pingLong(
853 src=main.params[ 'PING' ][ 'source6' ],
854 target=main.params[ 'PING' ][ 'target6' ],
855 pingTime=500 )
856 main.Mininet2.pingLong(
857 src=main.params[ 'PING' ][ 'source7' ],
858 target=main.params[ 'PING' ][ 'target7' ],
859 pingTime=500 )
860 main.Mininet2.pingLong(
861 src=main.params[ 'PING' ][ 'source8' ],
862 target=main.params[ 'PING' ][ 'target8' ],
863 pingTime=500 )
864 main.Mininet2.pingLong(
865 src=main.params[ 'PING' ][ 'source9' ],
866 target=main.params[ 'PING' ][ 'target9' ],
867 pingTime=500 )
868 main.Mininet2.pingLong(
869 src=main.params[ 'PING' ][ 'source10' ],
870 target=main.params[ 'PING' ][ 'target10' ],
871 pingTime=500 )
Jon Hallb1290e82014-11-18 16:17:48 -0500872
Jon Hall6aec96b2015-01-19 14:49:31 -0800873 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -0500874 ctrls = []
875 count = 1
876 while True:
877 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800878 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
879 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
880 temp = temp + ( "ONOS" + str( count ), )
881 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
882 temp = temp + \
883 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
884 ctrls.append( temp )
Jon Hallb1290e82014-11-18 16:17:48 -0500885 count = count + 1
886 else:
887 break
Jon Hall6aec96b2015-01-19 14:49:31 -0800888 MNTopo = TestONTopology(
889 main.Mininet1,
890 ctrls ) # can also add Intent API info for intent operations
Jon Hallb1290e82014-11-18 16:17:48 -0500891
Jon Hall6aec96b2015-01-19 14:49:31 -0800892 main.step( "Collecting topology information from ONOS" )
Jon Hallb1290e82014-11-18 16:17:48 -0500893 devices = []
894 devices.append( main.ONOScli1.devices() )
895 devices.append( main.ONOScli2.devices() )
896 devices.append( main.ONOScli3.devices() )
897 devices.append( main.ONOScli4.devices() )
898 devices.append( main.ONOScli5.devices() )
899 devices.append( main.ONOScli6.devices() )
900 devices.append( main.ONOScli7.devices() )
Jon Hallb1290e82014-11-18 16:17:48 -0500901 hosts = []
902 hosts.append( main.ONOScli1.hosts() )
903 hosts.append( main.ONOScli2.hosts() )
904 hosts.append( main.ONOScli3.hosts() )
905 hosts.append( main.ONOScli4.hosts() )
906 hosts.append( main.ONOScli5.hosts() )
907 hosts.append( main.ONOScli6.hosts() )
908 hosts.append( main.ONOScli7.hosts() )
Jon Hallb1290e82014-11-18 16:17:48 -0500909 ports = []
910 ports.append( main.ONOScli1.ports() )
911 ports.append( main.ONOScli2.ports() )
912 ports.append( main.ONOScli3.ports() )
913 ports.append( main.ONOScli4.ports() )
914 ports.append( main.ONOScli5.ports() )
915 ports.append( main.ONOScli6.ports() )
916 ports.append( main.ONOScli7.ports() )
917 links = []
918 links.append( main.ONOScli1.links() )
919 links.append( main.ONOScli2.links() )
920 links.append( main.ONOScli3.links() )
921 links.append( main.ONOScli4.links() )
922 links.append( main.ONOScli5.links() )
923 links.append( main.ONOScli6.links() )
924 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800925 clusters = []
926 clusters.append( main.ONOScli1.clusters() )
927 clusters.append( main.ONOScli2.clusters() )
928 clusters.append( main.ONOScli3.clusters() )
929 clusters.append( main.ONOScli4.clusters() )
930 clusters.append( main.ONOScli5.clusters() )
931 clusters.append( main.ONOScli6.clusters() )
932 clusters.append( main.ONOScli7.clusters() )
933 paths = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800934 tempTopo = main.ONOSbench.getTopology( main.ONOScli1.topology() )
935 paths.append( tempTopo.get( 'paths', False ) )
936 tempTopo = main.ONOSbench.getTopology( main.ONOScli2.topology() )
937 paths.append( tempTopo.get( 'paths', False ) )
938 tempTopo = main.ONOSbench.getTopology( main.ONOScli3.topology() )
939 paths.append( tempTopo.get( 'paths', False ) )
940 tempTopo = main.ONOSbench.getTopology( main.ONOScli4.topology() )
941 paths.append( tempTopo.get( 'paths', False ) )
942 tempTopo = main.ONOSbench.getTopology( main.ONOScli5.topology() )
943 paths.append( tempTopo.get( 'paths', False ) )
944 tempTopo = main.ONOSbench.getTopology( main.ONOScli6.topology() )
945 paths.append( tempTopo.get( 'paths', False ) )
946 tempTopo = main.ONOSbench.getTopology( main.ONOScli7.topology() )
947 paths.append( tempTopo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800948
Jon Hall6aec96b2015-01-19 14:49:31 -0800949 # Compare json objects for hosts, dataplane clusters and paths
Jon Hall94fd0472014-12-08 11:52:42 -0800950
Jon Hall6aec96b2015-01-19 14:49:31 -0800951 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -0800952 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800953 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800954 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800955 if "Error" not in hosts[ controller ]:
956 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800957 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800958 else: # hosts not consistent
959 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800960 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800961 " is inconsistent with ONOS1" )
962 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800963 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800964
965 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800966 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800967 controllerStr )
968 consistentHostsResult = main.FALSE
969 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800970 " hosts response: " +
971 repr( hosts[ controller ] ) )
972 utilities.assert_equals(
973 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800974 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800975 onpass="Hosts view is consistent across all ONOS nodes",
976 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -0800977
Jon Hall6aec96b2015-01-19 14:49:31 -0800978 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -0800979 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800980 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800981 if "Error" not in clusters[ controller ]:
982 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800983 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800984 else: # clusters not consistent
985 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800986 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800987 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800988 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800989
990 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800991 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800992 "from ONOS" + controllerStr )
993 consistentClustersResult = main.FALSE
994 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800995 " clusters response: " +
996 repr( clusters[ controller ] ) )
997 utilities.assert_equals(
998 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800999 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001000 onpass="Clusters view is consistent across all ONOS nodes",
1001 onfail="ONOS nodes have different views of clusters" )
1002 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001003 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001004 utilities.assert_equals(
1005 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001006 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001007 onpass="ONOS shows 1 SCC",
1008 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001009 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001010 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001011
Jon Hall6aec96b2015-01-19 14:49:31 -08001012 # paths
Jon Hall8f89dda2015-01-22 16:03:33 -08001013 consistentPathsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001014 for controller in range( len( paths ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001015 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001016 if "Error" not in paths[ controller ]:
1017 if paths[ controller ] == paths[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001018 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001019 else: # paths not consistent
Jon Hall8f89dda2015-01-22 16:03:33 -08001020 main.log.report( "paths from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001021 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001022 consistentPathsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001023
1024 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001025 main.log.report( "Error in getting paths from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001026 controllerStr )
1027 consistentPathsResult = main.FALSE
1028 main.log.warn( "ONOS" + controllerStr + " paths response: " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001029 repr( paths[ controller ] ) )
1030 utilities.assert_equals(
1031 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001032 actual=consistentPathsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001033 onpass="Paths count is consistent across all ONOS nodes",
1034 onfail="ONOS nodes have different counts of paths" )
Jon Hallb1290e82014-11-18 16:17:48 -05001035
Jon Hall6aec96b2015-01-19 14:49:31 -08001036 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001037 devicesResults = main.TRUE
1038 portsResults = main.TRUE
1039 linksResults = main.TRUE
1040 for controller in range( numControllers ):
1041 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001042 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001043 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001044 MNTopo,
1045 json.loads(
1046 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001047 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001048 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001049 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001050 actual=currentDevicesResult,
1051 onpass="ONOS" + controllerStr +
1052 " Switches view is correct",
1053 onfail="ONOS" + controllerStr +
1054 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001055
Jon Hall6aec96b2015-01-19 14:49:31 -08001056 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001057 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001058 MNTopo,
1059 json.loads(
1060 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001061 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001062 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001063 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001064 actual=currentPortsResult,
1065 onpass="ONOS" + controllerStr +
1066 " ports view is correct",
1067 onfail="ONOS" + controllerStr +
1068 " ports view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001069
Jon Hall6aec96b2015-01-19 14:49:31 -08001070 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001071 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001072 MNTopo,
1073 json.loads(
1074 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001075 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001076 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001077 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001078 actual=currentLinksResult,
1079 onpass="ONOS" + controllerStr +
1080 " links view is correct",
1081 onfail="ONOS" + controllerStr +
1082 " links view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001083
Jon Hall8f89dda2015-01-22 16:03:33 -08001084 devicesResults = devicesResults and currentDevicesResult
1085 portsResults = portsResults and currentPortsResult
1086 linksResults = linksResults and currentLinksResult
Jon Hallb1290e82014-11-18 16:17:48 -05001087
Jon Hall8f89dda2015-01-22 16:03:33 -08001088 topoResult = devicesResults and portsResults and linksResults\
1089 and consistentHostsResult and consistentClustersResult\
1090 and consistentPathsResult
1091 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1092 onpass="Topology Check Test successful",
1093 onfail="Topology Check Test NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001094
Jon Hall8f89dda2015-01-22 16:03:33 -08001095 finalAssert = main.TRUE
1096 finalAssert = finalAssert and topoResult and flowCheck \
1097 and intentCheck and consistentMastership and rolesNotNull
1098 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
1099 onpass="State check successful",
1100 onfail="State check NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001101
Jon Hall6aec96b2015-01-19 14:49:31 -08001102 def CASE6( self, main ):
1103 """
Jon Hallb1290e82014-11-18 16:17:48 -05001104 The Failure case. Since this is the Sanity test, we do nothing.
Jon Hall6aec96b2015-01-19 14:49:31 -08001105 """
Jon Hall368769f2014-11-19 15:43:35 -08001106 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001107 main.log.report( "Wait 60 seconds instead of inducing a failure" )
1108 time.sleep( 60 )
1109 utilities.assert_equals(
1110 expect=main.TRUE,
1111 actual=main.TRUE,
1112 onpass="Sleeping 60 seconds",
1113 onfail="Something is terribly wrong with my math" )
Jon Hallb1290e82014-11-18 16:17:48 -05001114
Jon Hall6aec96b2015-01-19 14:49:31 -08001115 def CASE7( self, main ):
1116 """
Jon Hall368769f2014-11-19 15:43:35 -08001117 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001118 """
Jon Hallb1290e82014-11-18 16:17:48 -05001119 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001120 main.case( "Running ONOS Constant State Tests" )
Jon Hallb1290e82014-11-18 16:17:48 -05001121
Jon Hall6aec96b2015-01-19 14:49:31 -08001122 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001123 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
1124 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
1125 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
1126 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
1127 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
1128 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
1129 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
1130 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
1131 ONOS3MasterNotNull and ONOS4MasterNotNull and\
1132 ONOS5MasterNotNull and ONOS6MasterNotNull and\
1133 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -08001134 utilities.assert_equals(
1135 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001136 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001137 onpass="Each device has a master",
1138 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001139
Jon Hall6aec96b2015-01-19 14:49:31 -08001140 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001141 ONOS1Mastership = main.ONOScli1.roles()
1142 ONOS2Mastership = main.ONOScli2.roles()
1143 ONOS3Mastership = main.ONOScli3.roles()
1144 ONOS4Mastership = main.ONOScli4.roles()
1145 ONOS5Mastership = main.ONOScli5.roles()
1146 ONOS6Mastership = main.ONOScli6.roles()
1147 ONOS7Mastership = main.ONOScli7.roles()
1148 # print json.dumps( json.loads( ONOS1Mastership ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001149 # indent=4, separators=( ',', ': ' ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001150 if "Error" in ONOS1Mastership or not ONOS1Mastership\
1151 or "Error" in ONOS2Mastership or not ONOS2Mastership\
1152 or "Error" in ONOS3Mastership or not ONOS3Mastership\
1153 or "Error" in ONOS4Mastership or not ONOS4Mastership\
1154 or "Error" in ONOS5Mastership or not ONOS5Mastership\
1155 or "Error" in ONOS6Mastership or not ONOS6Mastership\
1156 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001157 main.log.error( "Error in getting ONOS mastership" )
1158 main.log.warn( "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001159 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001160 main.log.warn( "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001161 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001162 main.log.warn( "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001163 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001164 main.log.warn( "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001165 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001166 main.log.warn( "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001167 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001168 main.log.warn( "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001169 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001170 main.log.warn( "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001171 repr( ONOS7Mastership ) )
1172 consistentMastership = main.FALSE
1173 elif ONOS1Mastership == ONOS2Mastership\
1174 and ONOS1Mastership == ONOS3Mastership\
1175 and ONOS1Mastership == ONOS4Mastership\
1176 and ONOS1Mastership == ONOS5Mastership\
1177 and ONOS1Mastership == ONOS6Mastership\
1178 and ONOS1Mastership == ONOS7Mastership:
1179 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001180 main.log.report(
1181 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001182 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001183 main.log.warn( "ONOS1 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001184 json.loads( ONOS1Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001185 separators=( ',', ': ' ) ) )
1186 main.log.warn( "ONOS2 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001187 json.loads( ONOS2Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001188 separators=( ',', ': ' ) ) )
1189 main.log.warn( "ONOS3 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001190 json.loads( ONOS3Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001191 separators=( ',', ': ' ) ) )
1192 main.log.warn( "ONOS4 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001193 json.loads( ONOS4Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001194 separators=( ',', ': ' ) ) )
1195 main.log.warn( "ONOS5 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001196 json.loads( ONOS5Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001197 separators=( ',', ': ' ) ) )
1198 main.log.warn( "ONOS6 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001199 json.loads( ONOS6Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001200 separators=( ',', ': ' ) ) )
1201 main.log.warn( "ONOS7 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001202 json.loads( ONOS7Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001203 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001204 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001205 utilities.assert_equals(
1206 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001207 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001208 onpass="Switch roles are consistent across all ONOS nodes",
1209 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -05001210
1211 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001212 main.step( description2 )
Jon Hallb1290e82014-11-18 16:17:48 -05001213
Jon Hall8f89dda2015-01-22 16:03:33 -08001214 currentJson = json.loads( ONOS1Mastership )
1215 oldJson = json.loads( mastershipState )
1216 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001217 for i in range( 1, 29 ):
1218 switchDPID = str(
1219 main.Mininet1.getSwitchDPID(
1220 switch="s" +
1221 str( i ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001222
Jon Hall8f89dda2015-01-22 16:03:33 -08001223 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001224 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001225 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001226 if switchDPID in switch[ 'id' ] ]
Jon Hallb1290e82014-11-18 16:17:48 -05001227 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001228 mastershipCheck = mastershipCheck and main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -05001229 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001230 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001231 mastershipCheck = main.FALSE
1232 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001233 main.log.report( "Mastership of Switches was not changed" )
1234 utilities.assert_equals(
1235 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001236 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001237 onpass="Mastership of Switches was not changed",
1238 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001239 mastershipCheck = mastershipCheck and consistentMastership
Jon Hallb1290e82014-11-18 16:17:48 -05001240
Jon Hall6aec96b2015-01-19 14:49:31 -08001241 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001242 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1243 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
1244 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
1245 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
1246 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
1247 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
1248 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
1249 intentCheck = main.FALSE
1250 if "Error" in ONOS1Intents or not ONOS1Intents\
1251 or "Error" in ONOS2Intents or not ONOS2Intents\
1252 or "Error" in ONOS3Intents or not ONOS3Intents\
1253 or "Error" in ONOS4Intents or not ONOS4Intents\
1254 or "Error" in ONOS5Intents or not ONOS5Intents\
1255 or "Error" in ONOS6Intents or not ONOS6Intents\
1256 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001257 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001258 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1259 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
1260 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
1261 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
1262 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
1263 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
1264 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
1265 elif ONOS1Intents == ONOS2Intents\
1266 and ONOS1Intents == ONOS3Intents\
1267 and ONOS1Intents == ONOS4Intents\
1268 and ONOS1Intents == ONOS5Intents\
1269 and ONOS1Intents == ONOS6Intents\
1270 and ONOS1Intents == ONOS7Intents:
1271 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001272 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001273 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001274 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001275 print json.dumps( json.loads( ONOS1Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001276 indent=4, separators=( ',', ': ' ) )
1277 main.log.warn( "ONOS2 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001278 print json.dumps( json.loads( ONOS2Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001279 indent=4, separators=( ',', ': ' ) )
1280 main.log.warn( "ONOS3 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001281 print json.dumps( json.loads( ONOS3Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001282 indent=4, separators=( ',', ': ' ) )
1283 main.log.warn( "ONOS4 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001284 print json.dumps( json.loads( ONOS4Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001285 indent=4, separators=( ',', ': ' ) )
1286 main.log.warn( "ONOS5 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001287 print json.dumps( json.loads( ONOS5Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001288 indent=4, separators=( ',', ': ' ) )
1289 main.log.warn( "ONOS6 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001290 print json.dumps( json.loads( ONOS6Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001291 indent=4, separators=( ',', ': ' ) )
1292 main.log.warn( "ONOS7 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001293 print json.dumps( json.loads( ONOS7Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001294 indent=4, separators=( ',', ': ' ) )
1295 utilities.assert_equals(
1296 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001297 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001298 onpass="Intents are consistent across all ONOS nodes",
1299 onfail="ONOS nodes have different views of intents" )
Jon Hallb1290e82014-11-18 16:17:48 -05001300
Jon Hall6aec96b2015-01-19 14:49:31 -08001301 # NOTE: Hazelcast has no durability, so intents are lost across system
1302 # restarts
1303 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001304 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001305 # maybe we should stop the test if that fails?
Jon Hall8f89dda2015-01-22 16:03:33 -08001306 if intentState == ONOS1Intents:
1307 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001308 main.log.report( "Intents are consistent with before failure" )
1309 # TODO: possibly the states have changed? we may need to figure out
1310 # what the aceptable states are
Jon Hallb1290e82014-11-18 16:17:48 -05001311 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001312 try:
1313 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001314 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001315 sort_keys=True, indent=4,
1316 separators=( ',', ': ' ) )
1317 except:
1318 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001319 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001320 utilities.assert_equals(
1321 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001322 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001323 onpass="Intents are consistent with before failure",
1324 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001325 intentCheck = intentCheck and sameIntents
Jon Hallb1290e82014-11-18 16:17:48 -05001326
Jon Hall6aec96b2015-01-19 14:49:31 -08001327 main.step( "Get the OF Table entries and compare to before " +
1328 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001329 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001330 flows2 = []
1331 for i in range( 28 ):
1332 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001333 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1334 flows2.append( tmpFlows )
1335 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001336 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001337 flow2=tmpFlows )
1338 FlowTables = FlowTables and tempResult
1339 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001340 main.log.info( "Differences in flow table for switch: s" +
1341 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001342 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001343 main.log.report( "No changes were found in the flow tables" )
1344 utilities.assert_equals(
1345 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001346 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001347 onpass="No changes were found in the flow tables",
1348 onfail="Changes were found in the flow tables" )
Jon Hallb1290e82014-11-18 16:17:48 -05001349
Jon Hall6aec96b2015-01-19 14:49:31 -08001350 main.step( "Check the continuous pings to ensure that no packets " +
1351 "were dropped during component failure" )
1352 # FIXME: This check is always failing. Investigate cause
1353 # NOTE: this may be something to do with file permsissions
Jon Hallb1290e82014-11-18 16:17:48 -05001354 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001355 main.Mininet2.pingKill(
1356 main.params[ 'TESTONUSER' ],
1357 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001358 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001359 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1360 for i in range( 8, 18 ):
1361 main.log.info(
1362 "Checking for a loss in pings along flow from s" +
1363 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001364 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001365 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001366 str( i ) ) or LossInPings
1367 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001368 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001369 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001370 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001371 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001372 main.log.info( "No Loss in the pings" )
1373 main.log.report( "No loss of dataplane connectivity" )
1374 utilities.assert_equals(
1375 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001376 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001377 onpass="No Loss of connectivity",
1378 onfail="Loss of dataplane connectivity detected" )
Jon Hallb1290e82014-11-18 16:17:48 -05001379
Jon Hall6aec96b2015-01-19 14:49:31 -08001380 # Test of LeadershipElection
1381 # NOTE: this only works for the sanity test. In case of failures,
1382 # leader will likely change
Jon Hall8f89dda2015-01-22 16:03:33 -08001383 leader = ONOS1Ip
1384 leaderResult = main.TRUE
1385 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001386 # loop through ONOScli handlers
1387 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001388 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001389 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001390 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001391 # all is well
1392 # NOTE: In failure scenario, this could be a new node, maybe
1393 # check != ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001394 pass
1395 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001396 # error in response
1397 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001398 "electionTestLeader function," +
Jon Hall6aec96b2015-01-19 14:49:31 -08001399 " check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001400 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001401 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001402 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001403 main.log.report( "ONOS" + str( controller ) + " sees " +
1404 str( leaderN ) +
1405 " as the leader of the election app. " +
1406 "Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001407 if leaderResult:
1408 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001409 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001410 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001411 utilities.assert_equals(
1412 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001413 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001414 onpass="Leadership election passed",
1415 onfail="Something went wrong with Leadership election" )
Jon Hallb1290e82014-11-18 16:17:48 -05001416
Jon Hall8f89dda2015-01-22 16:03:33 -08001417 result = mastershipCheck and intentCheck and FlowTables and\
1418 ( not LossInPings ) and rolesNotNull and leaderResult
Jon Hall6aec96b2015-01-19 14:49:31 -08001419 result = int( result )
Jon Hallb1290e82014-11-18 16:17:48 -05001420 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001421 main.log.report( "Constant State Tests Passed" )
1422 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001423 onpass="Constant State Tests Passed",
1424 onfail="Constant state tests failed" )
Jon Hallb1290e82014-11-18 16:17:48 -05001425
Jon Hall6aec96b2015-01-19 14:49:31 -08001426 def CASE8( self, main ):
1427 """
Jon Hallb1290e82014-11-18 16:17:48 -05001428 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001429 """
Jon Hallb1290e82014-11-18 16:17:48 -05001430 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001431 # FIXME add this path to params
1432 sys.path.append( "/home/admin/sts" )
1433 # assumes that sts is already in you PYTHONPATH
1434 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -05001435 import json
Jon Hall73cf9cc2014-11-20 22:28:38 -08001436 import time
Jon Hallb1290e82014-11-18 16:17:48 -05001437
Jon Hall6aec96b2015-01-19 14:49:31 -08001438 description = "Compare ONOS Topology view to Mininet topology"
1439 main.case( description )
1440 main.log.report( description )
1441 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -05001442 ctrls = []
1443 count = 1
1444 while True:
1445 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001446 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1447 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1448 temp = temp + ( "ONOS" + str( count ), )
1449 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1450 temp = temp + \
1451 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1452 ctrls.append( temp )
Jon Hallb1290e82014-11-18 16:17:48 -05001453 count = count + 1
1454 else:
1455 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001456 MNTopo = TestONTopology(
1457 main.Mininet1,
1458 ctrls ) # can also add Intent API info for intent operations
Jon Hallb1290e82014-11-18 16:17:48 -05001459
Jon Hall6aec96b2015-01-19 14:49:31 -08001460 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001461 devicesResults = main.TRUE
1462 portsResults = main.TRUE
1463 linksResults = main.TRUE
1464 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001465 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001466 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001467 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001468 startTime = time.time()
1469 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001470 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001471 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001472 # TODO: Depricate STS usage
1473 MNTopo = TestONTopology(
1474 main.Mininet1,
1475 ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001476 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001477 devices = []
1478 devices.append( main.ONOScli1.devices() )
1479 devices.append( main.ONOScli2.devices() )
1480 devices.append( main.ONOScli3.devices() )
1481 devices.append( main.ONOScli4.devices() )
1482 devices.append( main.ONOScli5.devices() )
1483 devices.append( main.ONOScli6.devices() )
1484 devices.append( main.ONOScli7.devices() )
1485 hosts = []
1486 hosts.append( main.ONOScli1.hosts() )
1487 hosts.append( main.ONOScli2.hosts() )
1488 hosts.append( main.ONOScli3.hosts() )
1489 hosts.append( main.ONOScli4.hosts() )
1490 hosts.append( main.ONOScli5.hosts() )
1491 hosts.append( main.ONOScli6.hosts() )
1492 hosts.append( main.ONOScli7.hosts() )
1493 ports = []
1494 ports.append( main.ONOScli1.ports() )
1495 ports.append( main.ONOScli2.ports() )
1496 ports.append( main.ONOScli3.ports() )
1497 ports.append( main.ONOScli4.ports() )
1498 ports.append( main.ONOScli5.ports() )
1499 ports.append( main.ONOScli6.ports() )
1500 ports.append( main.ONOScli7.ports() )
1501 links = []
1502 links.append( main.ONOScli1.links() )
1503 links.append( main.ONOScli2.links() )
1504 links.append( main.ONOScli3.links() )
1505 links.append( main.ONOScli4.links() )
1506 links.append( main.ONOScli5.links() )
1507 links.append( main.ONOScli6.links() )
1508 links.append( main.ONOScli7.links() )
1509 clusters = []
1510 clusters.append( main.ONOScli1.clusters() )
1511 clusters.append( main.ONOScli2.clusters() )
1512 clusters.append( main.ONOScli3.clusters() )
1513 clusters.append( main.ONOScli4.clusters() )
1514 clusters.append( main.ONOScli5.clusters() )
1515 clusters.append( main.ONOScli6.clusters() )
1516 clusters.append( main.ONOScli7.clusters() )
1517 paths = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001518 tempTopo = main.ONOSbench.getTopology( main.ONOScli1.topology() )
1519 paths.append( tempTopo.get( 'paths', False ) )
1520 tempTopo = main.ONOSbench.getTopology( main.ONOScli2.topology() )
1521 paths.append( tempTopo.get( 'paths', False ) )
1522 tempTopo = main.ONOSbench.getTopology( main.ONOScli3.topology() )
1523 paths.append( tempTopo.get( 'paths', False ) )
1524 tempTopo = main.ONOSbench.getTopology( main.ONOScli4.topology() )
1525 paths.append( tempTopo.get( 'paths', False ) )
1526 tempTopo = main.ONOSbench.getTopology( main.ONOScli5.topology() )
1527 paths.append( tempTopo.get( 'paths', False ) )
1528 tempTopo = main.ONOSbench.getTopology( main.ONOScli6.topology() )
1529 paths.append( tempTopo.get( 'paths', False ) )
1530 tempTopo = main.ONOSbench.getTopology( main.ONOScli7.topology() )
1531 paths.append( tempTopo.get( 'paths', False ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001532
Jon Hall8f89dda2015-01-22 16:03:33 -08001533 elapsed = time.time() - startTime
1534 cliTime = time.time() - cliStart
1535 print "CLI time: " + str( cliTime )
Jon Hallb1290e82014-11-18 16:17:48 -05001536
Jon Hall8f89dda2015-01-22 16:03:33 -08001537 for controller in range( numControllers ):
1538 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001539 if devices[ controller ] or "Error" not in devices[
1540 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001541 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001542 MNTopo,
1543 json.loads(
1544 devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001545 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001546 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001547 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001548 actual=currentDevicesResult,
1549 onpass="ONOS" + controllerStr +
1550 " Switches view is correct",
1551 onfail="ONOS" + controllerStr +
1552 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001553
Jon Hall6aec96b2015-01-19 14:49:31 -08001554 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001555 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001556 MNTopo,
1557 json.loads(
1558 ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001559 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001560 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001561 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001562 actual=currentPortsResult,
1563 onpass="ONOS" + controllerStr +
1564 " ports view is correct",
1565 onfail="ONOS" + controllerStr +
1566 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001567
Jon Hall6aec96b2015-01-19 14:49:31 -08001568 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001569 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001570 MNTopo,
1571 json.loads(
1572 links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001573 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001574 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001575 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001576 actual=currentLinksResult,
1577 onpass="ONOS" + controllerStr +
1578 " links view is correct",
1579 onfail="ONOS" + controllerStr +
1580 " links view is incorrect" )
1581 devicesResults = devicesResults and currentDevicesResult
1582 portsResults = portsResults and currentPortsResult
1583 linksResults = linksResults and currentLinksResult
Jon Hall94fd0472014-12-08 11:52:42 -08001584
Jon Hall6aec96b2015-01-19 14:49:31 -08001585 # Compare json objects for hosts, dataplane clusters and paths
Jon Hall94fd0472014-12-08 11:52:42 -08001586
Jon Hall6aec96b2015-01-19 14:49:31 -08001587 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001588 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001589 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001590 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001591 if "Error" not in hosts[ controller ]:
1592 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001593 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001594 else: # hosts not consistent
Jon Hall8f89dda2015-01-22 16:03:33 -08001595 main.log.report( "hosts from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001596 " is inconsistent with ONOS1" )
1597 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001598 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001599
1600 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001601 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001602 controllerStr )
1603 consistentHostsResult = main.FALSE
1604 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001605 " hosts response: " +
1606 repr( hosts[ controller ] ) )
1607 utilities.assert_equals(
1608 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001609 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001610 onpass="Hosts view is consistent across all ONOS nodes",
1611 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001612
Jon Hall6aec96b2015-01-19 14:49:31 -08001613 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001614 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001615 for controller in range( len( clusters ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001616 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001617 if "Error" not in clusters[ controller ]:
1618 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001619 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001620 else: # clusters not consistent
1621 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001622 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001623 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001624 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001625
1626 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001627 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001628 "from ONOS" + controllerStr )
1629 consistentClustersResult = main.FALSE
1630 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001631 " clusters response: " +
1632 repr( clusters[ controller ] ) )
1633 utilities.assert_equals(
1634 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001635 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001636 onpass="Clusters view is consistent across all ONOS nodes",
1637 onfail="ONOS nodes have different views of clusters" )
1638 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001639 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001640 utilities.assert_equals(
1641 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001642 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001643 onpass="ONOS shows 1 SCC",
1644 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001645 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001646 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001647
Jon Hall6aec96b2015-01-19 14:49:31 -08001648 # paths
Jon Hall8f89dda2015-01-22 16:03:33 -08001649 consistentPathsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001650 for controller in range( len( paths ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001651 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001652 if "Error" not in paths[ controller ]:
1653 if paths[ controller ] == paths[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001654 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001655 else: # paths not consistent
Jon Hall8f89dda2015-01-22 16:03:33 -08001656 main.log.report( "paths from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001657 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001658 consistentPathsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001659
1660 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001661 main.log.report( "Error in getting paths from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001662 controllerStr )
1663 consistentPathsResult = main.FALSE
1664 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001665 " paths response: " +
1666 repr( paths[ controller ] ) )
1667 utilities.assert_equals(
1668 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001669 actual=consistentPathsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001670 onpass="Paths count is consistent across all ONOS nodes",
1671 onfail="ONOS nodes have different counts of paths" )
Jon Hall94fd0472014-12-08 11:52:42 -08001672
Jon Hall8f89dda2015-01-22 16:03:33 -08001673 topoResult = ( devicesResults and portsResults and linksResults
1674 and consistentHostsResult
1675 and consistentClustersResult
1676 and consistentPathsResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001677
Jon Hall8f89dda2015-01-22 16:03:33 -08001678 topoResult = topoResult and int( count <= 2 )
1679 note = "note it takes about " + str( int( cliTime ) ) + \
1680 " seconds for the test to make all the cli calls to fetch " +\
1681 "the topology from each ONOS instance"
Jon Hall6aec96b2015-01-19 14:49:31 -08001682 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001683 "Very crass estimate for topology discovery/convergence( " +
1684 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001685 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001686 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1687 onpass="Topology Check Test successful",
1688 onfail="Topology Check Test NOT successful" )
1689 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001690 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hallb1290e82014-11-18 16:17:48 -05001691
Jon Hall6aec96b2015-01-19 14:49:31 -08001692 def CASE9( self, main ):
1693 """
Jon Hallb1290e82014-11-18 16:17:48 -05001694 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001695 """
1696 import time
1697 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001698
Jon Hall8f89dda2015-01-22 16:03:33 -08001699 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001700
Jon Hall6aec96b2015-01-19 14:49:31 -08001701 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall8f89dda2015-01-22 16:03:33 -08001702 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001703 main.log.report( description )
1704 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001705
Jon Hall6aec96b2015-01-19 14:49:31 -08001706 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001707 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001708 main.log.info(
1709 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001710 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001711 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001712 time.sleep( linkSleep )
1713 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
1714 onpass="Link down succesful",
1715 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001716 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001717
Jon Hall6aec96b2015-01-19 14:49:31 -08001718 def CASE10( self, main ):
1719 """
Jon Hallb1290e82014-11-18 16:17:48 -05001720 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001721 """
1722 import time
1723 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001724
Jon Hall8f89dda2015-01-22 16:03:33 -08001725 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001726
Jon Hall6aec96b2015-01-19 14:49:31 -08001727 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001728 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001729 main.log.report( description )
1730 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001731
Jon Hall6aec96b2015-01-19 14:49:31 -08001732 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001733 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001734 main.log.info(
1735 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001736 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001737 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001738 time.sleep( linkSleep )
1739 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
1740 onpass="Link up succesful",
1741 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001742 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001743
Jon Hall6aec96b2015-01-19 14:49:31 -08001744 def CASE11( self, main ):
1745 """
Jon Hallb1290e82014-11-18 16:17:48 -05001746 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001747 """
1748 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001749 import time
1750
Jon Hall8f89dda2015-01-22 16:03:33 -08001751 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001752
1753 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001754 main.log.report( description )
1755 main.case( description )
1756 switch = main.params[ 'kill' ][ 'switch' ]
1757 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hallb1290e82014-11-18 16:17:48 -05001758
Jon Hall6aec96b2015-01-19 14:49:31 -08001759 # TODO: Make this switch parameterizable
1760 main.step( "Kill " + switch )
1761 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001762 main.Mininet1.delSwitch( switch )
1763 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001764 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001765 time.sleep( switchSleep )
1766 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001767 # Peek at the deleted switch
1768 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001769 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001770 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001771 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001772 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001773 onpass="Kill switch succesful",
1774 onfail="Failed to kill switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001775
Jon Hall6aec96b2015-01-19 14:49:31 -08001776 def CASE12( self, main ):
1777 """
Jon Hallb1290e82014-11-18 16:17:48 -05001778 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001779 """
1780 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001781 import time
Jon Hall669173b2014-12-17 11:36:30 -08001782
Jon Hall8f89dda2015-01-22 16:03:33 -08001783 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001784 switch = main.params[ 'kill' ][ 'switch' ]
1785 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1786 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hallb1290e82014-11-18 16:17:48 -05001787 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001788 main.log.report( description )
1789 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001790
Jon Hall6aec96b2015-01-19 14:49:31 -08001791 main.step( "Add back " + switch )
1792 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001793 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001794 # TODO: New dpid or same? Ask Thomas?
1795 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001796 main.Mininet1.addLink( switch, peer )
1797 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -08001798 sw=switch.split( 's' )[ 1 ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001799 count=numControllers,
1800 ip1=ONOS1Ip,
1801 port1=ONOS1Port,
1802 ip2=ONOS2Ip,
1803 port2=ONOS2Port,
1804 ip3=ONOS3Ip,
1805 port3=ONOS3Port,
1806 ip4=ONOS4Ip,
1807 port4=ONOS4Port,
1808 ip5=ONOS5Ip,
1809 port5=ONOS5Port,
1810 ip6=ONOS6Ip,
1811 port6=ONOS6Port,
1812 ip7=ONOS7Ip,
1813 port7=ONOS7Port )
Jon Hall6aec96b2015-01-19 14:49:31 -08001814 main.log.info(
1815 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001816 str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001817 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001818 time.sleep( switchSleep )
1819 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001820 # Peek at the deleted switch
1821 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001822 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001823 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001824 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001825 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001826 onpass="add switch succesful",
1827 onfail="Failed to add switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001828
Jon Hall6aec96b2015-01-19 14:49:31 -08001829 def CASE13( self, main ):
1830 """
Jon Hallb1290e82014-11-18 16:17:48 -05001831 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001832 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001833 import os
1834 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001835 # TODO: make use of this elsewhere
1836 ips = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001837 ips.append( ONOS1Ip )
1838 ips.append( ONOS2Ip )
1839 ips.append( ONOS3Ip )
1840 ips.append( ONOS4Ip )
1841 ips.append( ONOS5Ip )
1842 ips.append( ONOS6Ip )
1843 ips.append( ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001844
1845 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001846 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001847 colors[ 'cyan' ] = '\033[96m'
1848 colors[ 'purple' ] = '\033[95m'
1849 colors[ 'blue' ] = '\033[94m'
1850 colors[ 'green' ] = '\033[92m'
1851 colors[ 'yellow' ] = '\033[93m'
1852 colors[ 'red' ] = '\033[91m'
1853 colors[ 'end' ] = '\033[0m'
Jon Hall368769f2014-11-19 15:43:35 -08001854 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001855 main.log.report( description )
1856 main.case( description )
1857 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001858 main.Mininet2.stopTcpdump()
Jon Hallb1290e82014-11-18 16:17:48 -05001859
Jon Hall6aec96b2015-01-19 14:49:31 -08001860 main.step( "Checking ONOS Logs for errors" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001861 for i in range( 7 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001862 print colors[ 'purple' ] + "Checking logs for errors on " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001863 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
1864 print main.ONOSbench.checkLogs( ips[ i ] )
Jon Hall94fd0472014-12-08 11:52:42 -08001865
Jon Hall6aec96b2015-01-19 14:49:31 -08001866 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hallb1290e82014-11-18 16:17:48 -05001867 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001868 teststationUser = main.params[ 'TESTONUSER' ]
1869 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001870 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001871 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001872 # FIXME: scp
1873 # mn files
1874 # TODO: Load these from params
1875 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001876 logFolder = "/opt/onos/log/"
1877 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001878 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001879 dstDir = "~/packet_captures/"
1880 for f in logFiles:
1881 for i in range( 7 ):
1882 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1883 logFolder + f + " " +
1884 teststationUser + "@" +
1885 teststationIP + ":" +
1886 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001887 "-ONOS" + str( i + 1 ) + "-" +
1888 f )
1889 # std*.log's
1890 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001891 logFolder = "/opt/onos/var/"
1892 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001893 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001894 dstDir = "~/packet_captures/"
1895 for f in logFiles:
1896 for i in range( 7 ):
1897 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1898 logFolder + f + " " +
1899 teststationUser + "@" +
1900 teststationIP + ":" +
1901 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001902 "-ONOS" + str( i + 1 ) + "-" +
1903 f )
1904 # sleep so scp can finish
1905 time.sleep( 10 )
1906 main.step( "Packing and rotating pcap archives" )
1907 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001908
Jon Hall6aec96b2015-01-19 14:49:31 -08001909 # TODO: actually check something here
1910 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001911 onpass="Test cleanup successful",
1912 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001913
Jon Hall6aec96b2015-01-19 14:49:31 -08001914 def CASE14( self, main ):
1915 """
Jon Hall94fd0472014-12-08 11:52:42 -08001916 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001917 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001918 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001919 # install app on onos 1
1920 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001921 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001922 # wait for election
1923 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001924 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001925 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001926 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001927 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001928 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001929 elif leader is None:
1930 # No leader elected
1931 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001932 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001933 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001934 # error in response
1935 # TODO: add check for "Command not found:" in the driver, this
1936 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001937 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001938 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001939 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001940 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001941 # error in response
1942 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001943 "Unexpected response from electionTestLeader function:'" +
1944 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001945 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001946 leaderResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001947
Jon Hall6aec96b2015-01-19 14:49:31 -08001948 # install on other nodes and check for leader.
1949 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001950 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001951 # loop through ONOScli handlers
1952 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001953 node.featureInstall( "onos-app-election" )
1954 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001955 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001956 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001957 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001958 pass
1959 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001960 # error in response
1961 # TODO: add check for "Command not found:" in the driver, this
1962 # means the app isn't loaded
1963 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001964 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001965 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001966 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001967 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001968 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001969 main.log.report( "ONOS" + str( controller ) + " sees " +
1970 str( leaderN ) +
1971 " as the leader of the election app. Leader" +
1972 " should be " +
1973 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001974 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001975 main.log.report( "Leadership election tests passed( consistent " +
1976 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001977 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001978 utilities.assert_equals(
1979 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001980 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001981 onpass="Leadership election passed",
1982 onfail="Something went wrong with Leadership election" )
Jon Hall94fd0472014-12-08 11:52:42 -08001983
Jon Hall6aec96b2015-01-19 14:49:31 -08001984 def CASE15( self, main ):
1985 """
Jon Hall669173b2014-12-17 11:36:30 -08001986 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001987 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001988 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001989 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001990 main.log.report( description )
1991 main.case( description )
1992 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001993 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001994 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001995 withdrawResult = main.FALSE
1996 if leader == ONOS1Ip:
1997 oldLeader = getattr( main, "ONOScli1" )
1998 elif leader == ONOS2Ip:
1999 oldLeader = getattr( main, "ONOScli2" )
2000 elif leader == ONOS3Ip:
2001 oldLeader = getattr( main, "ONOScli3" )
2002 elif leader == ONOS4Ip:
2003 oldLeader = getattr( main, "ONOScli4" )
2004 elif leader == ONOS5Ip:
2005 oldLeader = getattr( main, "ONOScli5" )
2006 elif leader == ONOS6Ip:
2007 oldLeader = getattr( main, "ONOScli6" )
2008 elif leader == ONOS7Ip:
2009 oldLeader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002010 elif leader is None or leader == main.FALSE:
2011 main.log.report(
2012 "Leader for the election app should be an ONOS node," +
2013 "instead got '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002014 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002015 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002016 leaderResult = main.FALSE
2017 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08002018 utilities.assert_equals(
2019 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002020 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002021 onpass="App was withdrawn from election",
2022 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08002023
Jon Hall6aec96b2015-01-19 14:49:31 -08002024 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002025 leaderList = []
2026 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002027 # loop through ONOScli handlers
2028 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002029 leaderList.append( node.electionTestLeader() )
2030 for leaderN in leaderList:
Jon Hall669173b2014-12-17 11:36:30 -08002031 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08002032 main.log.report(
2033 "ONOS" +
2034 str( controller ) +
2035 " still sees " +
2036 str( leader ) +
2037 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002038 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002039 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002040 # error in response
2041 # TODO: add check for "Command not found:" in the driver, this
2042 # means the app isn't loaded
2043 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002044 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002045 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002046 leaderResult = main.FALSE
2047 consistentLeader = main.FALSE
2048 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002049 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002050 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002051 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002052 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002053 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002054 main.log.report(
2055 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002056 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002057 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002058 str( leaderList[ n ] ) )
2059 if leaderResult:
2060 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002061 "view of leader across listeners and a new " +
2062 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002063 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002064 utilities.assert_equals(
2065 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002066 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002067 onpass="Leadership election passed",
2068 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002069
Jon Hall6aec96b2015-01-19 14:49:31 -08002070 main.step(
Jon Hall8f89dda2015-01-22 16:03:33 -08002071 "Run for election on old leader( just so everyone is in the hat )" )
2072 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08002073 utilities.assert_equals(
2074 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002075 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002076 onpass="App re-ran for election",
2077 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002078 if consistentLeader == main.TRUE:
2079 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002080 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002081 if afterRun == leaderList[ 0 ]:
2082 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002083 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002084 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002085 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002086
Jon Hall6aec96b2015-01-19 14:49:31 -08002087 utilities.assert_equals(
2088 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002089 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002090 onpass="Leadership election passed",
2091 onfail="Something went wrong with Leadership election after " +
2092 "the old leader re-ran for election" )