blob: 3bbca7d89de2536ecc6aa062e71decf4a68dfcde [file] [log] [blame]
Flavio Castro0a05b8d2016-06-16 17:26:51 -07001import os
2import imp
3import time
4
5from core import utilities
6
7
8class Testcaselib:
9 @staticmethod
10 def initTest( main ):
11 """
12 - Construct tests variables
13 - GIT ( optional )
14 - Checkout ONOS master branch
15 - Pull latest ONOS code
16 - Building ONOS ( optional )
17 - Install ONOS package
18 - Build ONOS package
19 """
20 main.case( "Constructing test variables and building ONOS" )
21 main.step( "Constructing test variables" )
22 # Test variables
23 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
24 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
25 main.diff = main.params[ 'ENV' ][ 'diffApps' ]
26 gitBranch = main.params[ 'GIT' ][ 'branch' ]
27 main.path = os.path.dirname( main.testFile )
28 main.dependencyPath = main.path +"/../dependencies/"
29 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
30 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
31 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
32 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
33 #main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
34 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
35 main.cellData = {} # for creating cell file
36 main.CLIs = []
37 main.ONOSip = []
38
39 # Assigning ONOS cli handles to a list
40 for i in range( 1, main.maxNodes + 1 ):
41 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
42 main.ONOSip.append( main.CLIs[i-1].ip_address )
43 # -- INIT SECTION, ONLY RUNS ONCE -- #
44 main.startUp = imp.load_source( wrapperFile1,
45 main.dependencyPath +
46 wrapperFile1 +
47 ".py" )
48
49 copyResult1 = main.ONOSbench.scp( main.Mininet1,
50 main.dependencyPath +
51 main.topology,
52 main.Mininet1.home,
53 direction="to" )
54 if main.CLIs:
55 stepResult = main.TRUE
56 else:
57 main.log.error( "Did not properly created list of ONOS CLI handle" )
58 stepResult = main.FALSE
59
60 utilities.assert_equals( expect=main.TRUE,
61 actual=stepResult,
62 onpass="Successfully construct " +
63 "test variables ",
64 onfail="Failed to construct test variables" )
65
66 @staticmethod
67 def installOnos( main ):
68 """
69 - Set up cell
70 - Create cell file
71 - Set cell file
72 - Verify cell file
73 - Kill ONOS process
74 - Uninstall ONOS cluster
75 - Verify ONOS start up
76 - Install ONOS cluster
77 - Connect to cli
78 """
79 # main.scale[ 0 ] determines the current number of ONOS controller
80 apps=main.apps
81 if main.diff:
82 apps = main.apps + "," + main.diff
83 else: main.log.error( "App list is empty" )
84 main.case( "Package and start ONOS using apps:" + apps)
85 print "NODE COUNT = ", main.numCtrls
86 print main.ONOSip
87 tempOnosIp = []
88 for i in range( main.numCtrls ):
89 tempOnosIp.append( main.ONOSip[i] )
90 onosUser = main.params[ 'ENV' ][ 'cellUser' ]
91 main.step("Create and Apply cell file")
92 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
93 "temp",
94 main.Mininet1.ip_address,
95 apps,
96 tempOnosIp,
97 onosUser )
98 cellResult = main.ONOSbench.setCell( "temp" )
99 verifyResult = main.ONOSbench.verifyCell()
100 stepResult = cellResult and verifyResult
101 utilities.assert_equals( expect=main.TRUE,
102 actual=stepResult,
103 onpass="Successfully applied cell to " + \
104 "environment",
105 onfail="Failed to apply cell to environment " )
106 #kill off all onos processes
107 main.log.info( "Safety check, killing all ONOS processes" +
108 " before initiating environment setup" )
109 for i in range( main.maxNodes ):
110 main.ONOSbench.onosDie( main.ONOSip[ i ] )
111 main.step( "Create and Install ONOS package" )
112 main.ONOSbench.handle.sendline( "cp "+main.dependencyPath+"/"+main.cfgName+".json ~/onos/tools/package/config/network-cfg.json")
113 packageResult = main.ONOSbench.onosPackage()
114
115 onosInstallResult = main.TRUE
116 for i in range( main.numCtrls ):
117 onosInstallResult = onosInstallResult and \
118 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
119 stepResult = onosInstallResult
120 utilities.assert_equals( expect=main.TRUE,
121 actual=stepResult,
122 onpass="Successfully installed ONOS package",
123 onfail="Failed to install ONOS package" )
124 main.step( "Starting ONOS service" )
125 stopResult,startResult, onosIsUp= main.TRUE, main.TRUE, main.TRUE,
126 for i in range( main.numCtrls ):
127 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
128 if onosIsUp == main.TRUE:
129 main.log.report( "ONOS instance is up and ready" )
130 else:
131 main.log.report( "ONOS instance may not be up, stop and " +
132 "start ONOS again " )
133 for i in range( main.numCtrls ):
134 stopResult = stopResult and \
135 main.ONOSbench.onosStop( main.ONOSip[ i ] )
136 for i in range( main.numCtrls ):
137 startResult = startResult and \
138 main.ONOSbench.onosStart( main.ONOSip[ i ] )
139 stepResult = onosIsUp and stopResult and startResult
140
141 utilities.assert_equals( expect=main.TRUE,
142 actual=stepResult,
143 onpass="ONOS service is ready",
144 onfail="ONOS service did not start properly" )
145 main.step( "Checking if ONOS CLI is ready" )
146 for i in range( main.numCtrls ):
147 main.CLIs[i].startCellCli()
148 cliResult = main.CLIs[i].startOnosCli( main.ONOSip[ i ],
149 commandlineTimeout=60, onosStartTimeout=100 )
150 utilities.assert_equals( expect=main.TRUE,
151 actual=cliResult,
152 onpass="ONOS CLI is ready",
153 onfail="ONOS CLI is not ready" )
154 main.active=0
155 for i in range( 10 ):
156 ready = True
157 output = main.CLIs[main.active].summary()
158 if not output:
159 ready = False
160 if ready:
161 break
162 time.sleep( 10 )
163 utilities.assert_equals( expect=True, actual=ready,
164 onpass="ONOS summary command succeded",
165 onfail="ONOS summary command failed" )
166
167 if not ready:
168 main.log.error( "ONOS startup failed!" )
169 main.cleanup()
170 main.exit()
171
172 for i in range( main.numCtrls ):
173 main.CLIs[i].logSet( "DEBUG", "org.onosproject.segmentrouting" )
174 main.CLIs[i].logSet( "DEBUG", "org.onosproject.driver.pipeline" )
175 main.CLIs[i].logSet( "DEBUG", "org.onosproject.store.group.impl" )
176 main.CLIs[i].logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
177
178 @staticmethod
179 def startMininet( main, topology, args="" ):
180 main.step( "Starting Mininet Topology" )
181 arg = "--onos %d %s" % (main.numCtrls, args)
182 main.topology=topology
183 topoResult = main.Mininet1.startNet( topoFile= main.dependencyPath + main.topology, args=arg )
184 stepResult = topoResult
185 utilities.assert_equals( expect=main.TRUE,
186 actual=stepResult,
187 onpass="Successfully loaded topology",
188 onfail="Failed to load topology" )
189 # Exit if topology did not load properly
190 if not topoResult:
191 main.cleanup()
192 main.exit()
193
194 @staticmethod
195 def checkFlows( main, flowCount ):
196 main.step(" Check whether the flow count is bigger than %s" % flowCount)
197 count = utilities.retry( main.CLIs[main.active].checkFlowCount,
198 main.FALSE,
199 kwargs={'min':flowCount},
200 attempts=10,
201 sleep=10 )
202 utilities.assertEquals( \
203 expect=True,
204 actual=(count>0),
205 onpass="Flow count looks correct: "+str(count),
206 onfail="Flow count looks wrong: "+str(count) )
207
208 main.step( "Check whether all flow status are ADDED" )
209 flowCheck = utilities.retry( main.CLIs[main.active].checkFlowsState,
210 main.FALSE,
211 kwargs={'isPENDING':False},
212 attempts=10,
213 sleep=10)
214 utilities.assertEquals( \
215 expect=main.TRUE,
216 actual=flowCheck,
217 onpass="Flow status is correct!",
218 onfail="Flow status is wrong!" )
219 main.ONOSbench.dumpFlows( main.ONOSip[main.active],
220 main.logdir, "flowsBefore" + main.cfgName)
221 main.ONOSbench.dumpGroups( main.ONOSip[0],
222 main.logdir, "groupsBefore" + main.cfgName)
223
224 @staticmethod
225 def pingAll( main, tag=""):
226 main.log.report( "Check full connectivity" )
227 main.step("Check full connectivity %s" %tag)
228 pa = main.Mininet1.pingall()
229 utilities.assert_equals( expect=main.TRUE, actual=pa,
230 onpass="Full connectivity successfully tested",
231 onfail="Full connectivity failed" )
232 ##FIXME choose valid onos instead of 0
233 main.ONOSbench.dumpFlows( main.ONOSip[main.active],
234 main.logdir, "flowsOn" + tag)
235 main.ONOSbench.dumpGroups( main.ONOSip[main.active],
236 main.logdir, "groupsOn" + tag)
237
238 @staticmethod
239 def killLink( main, end1, end2, switches, links ):
240 """
241 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
242 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
243 Kill a link and verify ONOS can see the proper link change
244 """
245 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
246 main.step( "Kill link between %s and %s" %(end1, end2))
247 LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
248 main.log.info( "Waiting %s seconds for link up to be discovered" % (main.linkSleep) )
249 # TODO Maybe parameterize number of expected links
250 time.sleep( main.linkSleep )
251 ##FIXME CLI for active node instead of 0
252 topology = utilities.retry( main.CLIs[main.active].checkStatus,
253 main.FALSE,
254 kwargs={'numoswitch':switches, 'numolink':links},
255 attempts=10,
256 sleep=main.linkSleep)
257 result = topology & LinkDown
258 utilities.assert_equals( expect=main.TRUE, actual=result,
259 onpass="Link down successful",
260 onfail="Failed to turn off link?" )
261
262 @staticmethod
263 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches, links ):
264 """
265 Params:
266 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
267 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
268 port1, port2: respective port of the end switchs that connects to the link, ex.:'1'
269 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
270 Kill a link and verify ONOS can see the proper link change
271 """
272 main.step( "Restore link between %s and %s" %( end1, end2 ) )
273 result = False
274 count=0
275 while True:
276 count+=0
277 main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
278 main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
279 main.log.info( "Waiting %s seconds for link up to be discovered" % (main.linkSleep) )
280 time.sleep( main.linkSleep )
281 main.CLIs[main.active].portstate( dpid=dpid1, port=port1 )
282 main.CLIs[main.active].portstate( dpid=dpid2, port=port2 )
283 time.sleep( main.linkSleep )
284
285 result = main.CLIs[main.active].checkStatus( numoswitch=switches, numolink=links )
286 if count>5 or result:
287 break
288 utilities.assert_equals( expect=main.TRUE, actual=result,
289 onpass="Link up successful",
290 onfail="Failed to bring link up" )
291
292 @staticmethod
293 def killSwitch( main, switch, switches, links ):
294 """
295 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
296 Kill a switch and verify ONOS can see the proper change
297 """
298 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
299 main.step( "Kill " + switch )
300 main.log.info( "Stopping" + switch )
301 main.Mininet1.switch( SW=switch, OPTION="stop" )
302 main.log.info( "Waiting %s seconds for switch down to be discovered" % ( main.switchSleep ) )
303 time.sleep( main.switchSleep )
304 topology = utilities.retry( main.CLIs[main.active].checkStatus,
305 main.FALSE,
306 kwargs={'numoswitch':switches, 'numolink':links},
307 attempts=10,
308 sleep=main.switchSleep)
309 utilities.assert_equals( expect=main.TRUE, actual=topology,
310 onpass="Kill switch successful",
311 onfail="Failed to kill switch?" )
312
313 @staticmethod
314 def recoverSwitch( main, switch, switches, links ):
315 """
316 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
317 Recover a switch and verify ONOS can see the proper change
318 """
319 main.step( "Recovering " + switch )
320 main.log.info( "Starting" + switch )
321 main.Mininet1.switch( SW=switch, OPTION="start")
322 main.log.info( "Waiting %s seconds for switch up to be discovered" %(main.switchSleep))
323 time.sleep( main.switchSleep )
324 topology = utilities.retry( main.CLIs[main.active].checkStatus,
325 main.FALSE,
326 kwargs={'numoswitch':switches, 'numolink':links},
327 attempts=10,
328 sleep=main.switchSleep)
329 utilities.assert_equals( expect=main.TRUE, actual=topology,
330 onpass="Switch recovery successful",
331 onfail="Failed to recover switch?" )
332
333 @staticmethod
334 def cleanup( main ):
335 """
336 Stop Onos-cluster.
337 Stops Mininet
338 Copies ONOS log
339 """
340 main.Mininet1.stopNet()
341 main.ONOSbench.scp( main.ONOScli1 ,"/opt/onos/log/karaf.log",
342 "/tmp/karaf.log", direction="from" )
343 main.ONOSbench.cpLogsToDir("/tmp/karaf.log",main.logdir,
344 copyFileName="karaf.log."+main.cfgName)
345 for i in range(main.numCtrls):
346 main.ONOSbench.onosStop( main.ONOSip[i] )