blob: 6e4ae5a1649caa642e62bf1fe88f99813ca94891 [file] [log] [blame]
Jeremyfc567ca2016-02-16 15:08:25 -08001# Testing the NETCONF protocol within ONOS
2
3class FUNCnetconf:
4
5 def __init__( self ):
6 self.default = ''
7
8 def CASE1( self, main ):
9 import time
10 import imp
11 import re
12
13 """
14 - Construct tests variables
15 - GIT ( optional )
16 - Checkout ONOS master branch
17 - Pull latest ONOS code
18 - Building ONOS ( optional )
19 - Install ONOS package
20 - Build ONOS package
21 """
22
23 main.case( "Constructing test variables and building ONOS package" )
24 main.step( "Constructing test variables" )
25 main.caseExplanation = "This test case is mainly for loading " +\
26 "from params file, and pull and build the " +\
27 " latest ONOS package"
28 stepResult = main.FALSE
29
30 # Test variables
31 try:
32 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
33 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
34 gitBranch = main.params[ 'GIT' ][ 'branch' ]
35 main.dependencyPath = main.testOnDirectory + \
36 main.params[ 'DEPENDENCY' ][ 'path' ]
37 # main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
38 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
39 if main.ONOSbench.maxNodes:
40 main.maxNodes = int( main.ONOSbench.maxNodes )
41 else:
42 main.maxNodes = 0
43 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
44 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
45 wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
46 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
47 main.switchSleep = int( main.params[ 'SLEEP' ][ 'upSwitch' ] )
48 main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] )
49 main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] )
50
51 # Config file parameters
52 main.configDevicePort = main.params[ 'CONFIGURE' ][ 'cfgDevicePort' ]
53 main.configDriver = main.params[ 'CONFIGURE' ][ 'cfgDriver' ]
54 main.configApps = main.params[ 'CONFIGURE' ][ 'cfgApps' ]
55 main.configName = main.params[ 'CONFIGURE' ][ 'cfgName' ]
56 main.configPass = main.params[ 'CONFIGURE' ][ 'cfgPass' ]
57 main.configPort = main.params[ 'CONFIGURE' ][ 'cfgAppPort' ]
Jeremy Songster17147f22016-05-31 18:30:52 -070058 main.cycle = 0 # How many times FUNCintent has run through its tests
Jeremyfc567ca2016-02-16 15:08:25 -080059
60 gitPull = main.params[ 'GIT' ][ 'pull' ]
61 main.cellData = {} # for creating cell file
62 main.hostsData = {}
63 main.CLIs = []
64 main.CLIs2 = []
65 main.ONOSip = []
66 main.assertReturnString = '' # Assembled assert return string
67
68 main.ONOSip = main.ONOSbench.getOnosIps()
69 print main.ONOSip
70
71 # Assigning ONOS cli handles to a list
72 for i in range( 1, main.maxNodes + 1 ):
73 main.CLIs.append( getattr( main, 'ONOSrest' + str( i ) ) )
74 main.CLIs2.append( getattr( main, 'ONOScli' + str( i ) ) )
75
76 # -- INIT SECTION, ONLY RUNS ONCE -- #
77 main.startUp = imp.load_source( wrapperFile1,
78 main.dependencyPath +
79 wrapperFile1 +
80 ".py" )
81
82 main.netconfFunction = imp.load_source( wrapperFile2,
83 main.dependencyPath +
84 wrapperFile2 +
85 ".py" )
86
87 main.topo = imp.load_source( wrapperFile3,
88 main.dependencyPath +
89 wrapperFile3 +
90 ".py" )
91
92 # Uncomment out the following if a mininet topology is added
93 # copyResult1 = main.ONOSbench.scp( main.Mininet1,
94 # main.dependencyPath +
95 # main.topology,
96 # main.Mininet1.home + "custom/",
97 # direction="to" )
98
99 if main.CLIs and main.CLIs2:
100 stepResult = main.TRUE
101 else:
102 main.log.error( "Did not properly created list of ONOS CLI handle" )
103 stepResult = main.FALSE
104 except Exception as e:
105 main.log.exception(e)
106 main.cleanup()
107 main.exit()
108
109 utilities.assert_equals( expect=main.TRUE,
110 actual=stepResult,
111 onpass="Successfully construct " +
112 "test variables ",
113 onfail="Failed to construct test variables" )
114
115 if gitPull == 'True':
116 main.step( "Building ONOS in " + gitBranch + " branch" )
117 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
118 stepResult = onosBuildResult
119 utilities.assert_equals( expect=main.TRUE,
120 actual=stepResult,
121 onpass="Successfully compiled " +
122 "latest ONOS",
123 onfail="Failed to compile " +
124 "latest ONOS" )
125 else:
126 main.log.warn( "Did not pull new code so skipping mvn " +
127 "clean install" )
128 main.ONOSbench.getVersion( report=True )
129
130 def CASE2( self, main ):
131 """
132 - Set up cell
133 - Create cell file
134 - Set cell file
135 - Verify cell file
136 - Kill ONOS process
137 - Uninstall ONOS cluster
138 - Verify ONOS start up
139 - Install ONOS cluster
140 - Connect to cli
141 """
142
Jeremy Songster17147f22016-05-31 18:30:52 -0700143 main.cycle += 1
144
Jeremyfc567ca2016-02-16 15:08:25 -0800145 # main.scale[ 0 ] determines the current number of ONOS controller
146 main.numCtrls = int( main.scale[ 0 ] )
147
148 main.case( "Starting up " + str( main.numCtrls ) +
149 " node(s) ONOS cluster" )
150 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
151 " node(s) ONOS cluster"
152
153
154
155 #kill off all onos processes
156 main.log.info( "Safety check, killing all ONOS processes" +
157 " before initiating environment setup" )
158
159
160
161 time.sleep( main.startUpSleep )
162 main.step( "Uninstalling ONOS package" )
163 onosUninstallResult = main.TRUE
164 for ip in main.ONOSip:
165 onosUninstallResult = onosUninstallResult and \
166 main.ONOSbench.onosUninstall( nodeIp=ip )
167 stepResult = onosUninstallResult
168 utilities.assert_equals( expect=main.TRUE,
169 actual=stepResult,
170 onpass="Successfully uninstalled ONOS package",
171 onfail="Failed to uninstall ONOS package" )
172
173 for i in range( main.maxNodes ):
174 main.ONOSbench.onosDie( main.ONOSip[ i ] )
175
176 main.log.info( "NODE COUNT = " + str( main.numCtrls ) )
177
178 tempOnosIp = []
179 for i in range( main.numCtrls ):
180 tempOnosIp.append( main.ONOSip[i] )
181
182 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
183 "temp", main.Mininet1.ip_address,
184 main.apps, tempOnosIp )
185
186 main.step( "Apply cell to environment" )
187 cellResult = main.ONOSbench.setCell( "temp" )
188 verifyResult = main.ONOSbench.verifyCell()
189 stepResult = cellResult and verifyResult
190 utilities.assert_equals( expect=main.TRUE,
191 actual=stepResult,
192 onpass="Successfully applied cell to " + \
193 "environment",
194 onfail="Failed to apply cell to environment " )
195
196 main.step( "Creating ONOS package" )
197 packageResult = main.ONOSbench.onosPackage()
198 stepResult = packageResult
199 utilities.assert_equals( expect=main.TRUE,
200 actual=stepResult,
201 onpass="Successfully created ONOS package",
202 onfail="Failed to create ONOS package" )
203
204 time.sleep( main.startUpSleep )
205 main.step( "Installing ONOS package" )
206 onosInstallResult = main.TRUE
207 for i in range( main.numCtrls ):
208 onosInstallResult = onosInstallResult and \
209 main.ONOSbench.onosInstall( node=main.ONOSip[ i ], options="" )
210 stepResult = onosInstallResult
211
212 utilities.assert_equals( expect=main.TRUE,
213 actual=stepResult,
214 onpass="Successfully installed ONOS package",
215 onfail="Failed to install ONOS package" )
216
217 time.sleep( main.startUpSleep )
218 main.step( "Starting ONOS service" )
219 stopResult = main.TRUE
220 startResult = main.TRUE
221 onosIsUp = main.TRUE
222
223 for i in range( main.numCtrls ):
224 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
225 if onosIsUp == main.TRUE:
226 main.log.report( "ONOS instance is up and ready" )
227 else:
228 main.log.report( "ONOS instance may not be up, stop and " +
229 "start ONOS again " )
230 for i in range( main.numCtrls ):
231 stopResult = stopResult and \
232 main.ONOSbench.onosStop( main.ONOSip[ i ] )
233 for i in range( main.numCtrls ):
234 startResult = startResult and \
235 main.ONOSbench.onosStart( main.ONOSip[ i ] )
236 stepResult = onosIsUp and stopResult and startResult
237 utilities.assert_equals( expect=main.TRUE,
238 actual=stepResult,
239 onpass="ONOS service is ready",
240 onfail="ONOS service did not start properly" )
241
242 # Start an ONOS cli to provide functionality that is not currently
243 # supported by the Rest API remove this when Leader Checking is supported
244 # by the REST API
245
246 main.step( "Start ONOS cli" )
247 cliResult = main.TRUE
248 for i in range( main.numCtrls ):
249 cliResult = cliResult and \
250 main.CLIs2[ i ].startOnosCli( main.ONOSip[ i ] )
251 stepResult = cliResult
252 utilities.assert_equals( expect=main.TRUE,
253 actual=stepResult,
254 onpass="Successfully start ONOS cli",
255 onfail="Failed to start ONOS cli" )
256
257 # Remove the first element in main.scale list
258 main.scale.remove( main.scale[ 0 ] )
259
Jeremy Songster17147f22016-05-31 18:30:52 -0700260 def CASE19( self, main ):
261 """
262 Copy the karaf.log files after each testcase cycle
263 """
264 main.log.report( "Copy karaf logs" )
265 main.case( "Copy karaf logs" )
266 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
267 "reinstalling ONOS"
268 main.step( "Copying karaf logs" )
269 i = 0
270 for cli in main.CLIs:
271 main.node = cli
272 ip = main.ONOSip[ i ]
273 main.node.ip_address = ip
274 main.ONOSbench.scp( main.node ,
275 "/opt/onos/log/karaf.log",
276 "/tmp/karaf.log",
277 direction="from" )
278 main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
279 copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) )
280 i += 1
281
Jeremyfc567ca2016-02-16 15:08:25 -0800282 def CASE100( self, main ):
283 """
284 Start NETCONF app and OFC-Server or make sure that they are already running
285 """
286 assert main, "There is no main"
287 assert main.CLIs, "There is no main.CLIs"
288 assert main.numCtrls, "Placed the total number of switch topology in \
289 main.numCtrls"
290
291 testResult = main.FALSE
292 main.testName = "Start up NETCONF app in all nodes"
293 main.case( main.testName + " Test - " + str( main.numCtrls ) +
294 " NODE(S)" )
295 main.step( "Starting NETCONF app" )
296 main.assertReturnString = "Assertion result for starting NETCONF app"
297 testResult = main.netconfFunction.startApp( main )
298
299 utilities.assert_equals( expect=main.TRUE,
300 actual=testResult,
301 onpass=main.assertReturnString,
302 onfail=main.assertReturnString )
303
304 main.step( "Starting OFC-Server" )
305 main.assertReturnString = "Assertion result for starting OFC-Server"
306 testResult = main.netconfFunction.startOFC( main )
307
308 utilities.assert_equals( expect=main.TRUE,
309 actual=testResult,
310 onpass=main.assertReturnString,
311 onfail=main.assertReturnString )
312 time.sleep( main.startUpSleep )
313
314 def CASE200( self, main ):
315 """
316 Create or modify a Configuration file
317 -The file is built from information loaded from the .params file
318 """
319 assert main, "There is no main"
320 assert main.CLIs, "There is no main.CLIs"
321 assert main.numCtrls, "Placed the total number of switch topology in \
322 main.numCtrls"
323
324 main.testName = "Assemble the configuration"
325 main.case( main.testName + " Test - " + str( main.numCtrls ) +
326 " NODES(S)" )
327 main.step( "Assembling configuration file" )
328 main.assertReturnString = "Assertion result for assembling configuration file"
329 testResult = main.FALSE
330 testResult = main.netconfFunction.createConfig( main )
331
332 utilities.assert_equals( expect=main.TRUE,
333 actual=testResult,
334 onpass=main.assertReturnString,
335 onfail=main.assertReturnString )
336 time.sleep( main.startUpSleep )
337
338 def CASE300( self, main ):
339 """
340 Push a configuration and bring up a switch
341 """
342 assert main, "There is no main"
343 assert main.CLIs, "There is no main.CLIs"
344 assert main.numCtrls, "Placed the total number of switch topology in \
345 main.numCtrls"
346
347 main.testName = "Uploading the configuration"
348 main.case( main.testName + " Test - " + str( main.numCtrls ) +
349 " NODES(S)" )
350 main.step( "Sending the configuration file")
351 main.assertReturnString = "Assertion result for sending the configuration file"
352 testResult = main.FALSE
353
354 testResult = main.netconfFunction.sendConfig( main )
355
356 utilities.assert_equals( expect=main.TRUE,
357 actual=testResult,
358 onpass=main.assertReturnString,
359 onfail=main.assertReturnString )
360
361 time.sleep( main.switchSleep )
362
363 main.step( "Confirming the device was configured" )
364 main.assertReturnString = "Assertion result for confirming a configuration."
365 testResult = main.FALSE
366
367 testResult = main.netconfFunction.devices( main )
368
369 utilities.assert_equals( expect=main.TRUE,
370 actual=testResult,
371 onpass=main.assertReturnString,
372 onfail=main.assertReturnString )
373
374 def CASE400( self, main ):
375 """
376 Bring down a switch
377 This test case is not yet possible, but the functionality needed to
378 perform it is planned to be added
379 There is a message that is sent "Device () has closed session"
380 when the device disconnects from onos for some reason.
381 Because of the triggers for this message are not practical
382 to activate this will likely not be used to implement the test
383 case at this time
384 Possible ways to do this may include bringing down mininet then checking
385 ONOS to see if it was recongnized the device being disconnected
386 """