blob: ddd1cd85d4dd8083209cf985187b4fd7af9fd792 [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' ]
58
59 gitPull = main.params[ 'GIT' ][ 'pull' ]
60 main.cellData = {} # for creating cell file
61 main.hostsData = {}
62 main.CLIs = []
63 main.CLIs2 = []
64 main.ONOSip = []
65 main.assertReturnString = '' # Assembled assert return string
66
67 main.ONOSip = main.ONOSbench.getOnosIps()
68 print main.ONOSip
69
70 # Assigning ONOS cli handles to a list
71 for i in range( 1, main.maxNodes + 1 ):
72 main.CLIs.append( getattr( main, 'ONOSrest' + str( i ) ) )
73 main.CLIs2.append( getattr( main, 'ONOScli' + str( i ) ) )
74
75 # -- INIT SECTION, ONLY RUNS ONCE -- #
76 main.startUp = imp.load_source( wrapperFile1,
77 main.dependencyPath +
78 wrapperFile1 +
79 ".py" )
80
81 main.netconfFunction = imp.load_source( wrapperFile2,
82 main.dependencyPath +
83 wrapperFile2 +
84 ".py" )
85
86 main.topo = imp.load_source( wrapperFile3,
87 main.dependencyPath +
88 wrapperFile3 +
89 ".py" )
90
91 # Uncomment out the following if a mininet topology is added
92 # copyResult1 = main.ONOSbench.scp( main.Mininet1,
93 # main.dependencyPath +
94 # main.topology,
95 # main.Mininet1.home + "custom/",
96 # direction="to" )
97
98 if main.CLIs and main.CLIs2:
99 stepResult = main.TRUE
100 else:
101 main.log.error( "Did not properly created list of ONOS CLI handle" )
102 stepResult = main.FALSE
103 except Exception as e:
104 main.log.exception(e)
105 main.cleanup()
106 main.exit()
107
108 utilities.assert_equals( expect=main.TRUE,
109 actual=stepResult,
110 onpass="Successfully construct " +
111 "test variables ",
112 onfail="Failed to construct test variables" )
113
114 if gitPull == 'True':
115 main.step( "Building ONOS in " + gitBranch + " branch" )
116 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
117 stepResult = onosBuildResult
118 utilities.assert_equals( expect=main.TRUE,
119 actual=stepResult,
120 onpass="Successfully compiled " +
121 "latest ONOS",
122 onfail="Failed to compile " +
123 "latest ONOS" )
124 else:
125 main.log.warn( "Did not pull new code so skipping mvn " +
126 "clean install" )
127 main.ONOSbench.getVersion( report=True )
128
129 def CASE2( self, main ):
130 """
131 - Set up cell
132 - Create cell file
133 - Set cell file
134 - Verify cell file
135 - Kill ONOS process
136 - Uninstall ONOS cluster
137 - Verify ONOS start up
138 - Install ONOS cluster
139 - Connect to cli
140 """
141
142 # main.scale[ 0 ] determines the current number of ONOS controller
143 main.numCtrls = int( main.scale[ 0 ] )
144
145 main.case( "Starting up " + str( main.numCtrls ) +
146 " node(s) ONOS cluster" )
147 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
148 " node(s) ONOS cluster"
149
150
151
152 #kill off all onos processes
153 main.log.info( "Safety check, killing all ONOS processes" +
154 " before initiating environment setup" )
155
156
157
158 time.sleep( main.startUpSleep )
159 main.step( "Uninstalling ONOS package" )
160 onosUninstallResult = main.TRUE
161 for ip in main.ONOSip:
162 onosUninstallResult = onosUninstallResult and \
163 main.ONOSbench.onosUninstall( nodeIp=ip )
164 stepResult = onosUninstallResult
165 utilities.assert_equals( expect=main.TRUE,
166 actual=stepResult,
167 onpass="Successfully uninstalled ONOS package",
168 onfail="Failed to uninstall ONOS package" )
169
170 for i in range( main.maxNodes ):
171 main.ONOSbench.onosDie( main.ONOSip[ i ] )
172
173 main.log.info( "NODE COUNT = " + str( main.numCtrls ) )
174
175 tempOnosIp = []
176 for i in range( main.numCtrls ):
177 tempOnosIp.append( main.ONOSip[i] )
178
179 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
180 "temp", main.Mininet1.ip_address,
181 main.apps, tempOnosIp )
182
183 main.step( "Apply cell to environment" )
184 cellResult = main.ONOSbench.setCell( "temp" )
185 verifyResult = main.ONOSbench.verifyCell()
186 stepResult = cellResult and verifyResult
187 utilities.assert_equals( expect=main.TRUE,
188 actual=stepResult,
189 onpass="Successfully applied cell to " + \
190 "environment",
191 onfail="Failed to apply cell to environment " )
192
193 main.step( "Creating ONOS package" )
194 packageResult = main.ONOSbench.onosPackage()
195 stepResult = packageResult
196 utilities.assert_equals( expect=main.TRUE,
197 actual=stepResult,
198 onpass="Successfully created ONOS package",
199 onfail="Failed to create ONOS package" )
200
201 time.sleep( main.startUpSleep )
202 main.step( "Installing ONOS package" )
203 onosInstallResult = main.TRUE
204 for i in range( main.numCtrls ):
205 onosInstallResult = onosInstallResult and \
206 main.ONOSbench.onosInstall( node=main.ONOSip[ i ], options="" )
207 stepResult = onosInstallResult
208
209 utilities.assert_equals( expect=main.TRUE,
210 actual=stepResult,
211 onpass="Successfully installed ONOS package",
212 onfail="Failed to install ONOS package" )
213
214 time.sleep( main.startUpSleep )
215 main.step( "Starting ONOS service" )
216 stopResult = main.TRUE
217 startResult = main.TRUE
218 onosIsUp = main.TRUE
219
220 for i in range( main.numCtrls ):
221 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
222 if onosIsUp == main.TRUE:
223 main.log.report( "ONOS instance is up and ready" )
224 else:
225 main.log.report( "ONOS instance may not be up, stop and " +
226 "start ONOS again " )
227 for i in range( main.numCtrls ):
228 stopResult = stopResult and \
229 main.ONOSbench.onosStop( main.ONOSip[ i ] )
230 for i in range( main.numCtrls ):
231 startResult = startResult and \
232 main.ONOSbench.onosStart( main.ONOSip[ i ] )
233 stepResult = onosIsUp and stopResult and startResult
234 utilities.assert_equals( expect=main.TRUE,
235 actual=stepResult,
236 onpass="ONOS service is ready",
237 onfail="ONOS service did not start properly" )
238
239 # Start an ONOS cli to provide functionality that is not currently
240 # supported by the Rest API remove this when Leader Checking is supported
241 # by the REST API
242
243 main.step( "Start ONOS cli" )
244 cliResult = main.TRUE
245 for i in range( main.numCtrls ):
246 cliResult = cliResult and \
247 main.CLIs2[ i ].startOnosCli( main.ONOSip[ i ] )
248 stepResult = cliResult
249 utilities.assert_equals( expect=main.TRUE,
250 actual=stepResult,
251 onpass="Successfully start ONOS cli",
252 onfail="Failed to start ONOS cli" )
253
254 # Remove the first element in main.scale list
255 main.scale.remove( main.scale[ 0 ] )
256
257 def CASE100( self, main ):
258 """
259 Start NETCONF app and OFC-Server or make sure that they are already running
260 """
261 assert main, "There is no main"
262 assert main.CLIs, "There is no main.CLIs"
263 assert main.numCtrls, "Placed the total number of switch topology in \
264 main.numCtrls"
265
266 testResult = main.FALSE
267 main.testName = "Start up NETCONF app in all nodes"
268 main.case( main.testName + " Test - " + str( main.numCtrls ) +
269 " NODE(S)" )
270 main.step( "Starting NETCONF app" )
271 main.assertReturnString = "Assertion result for starting NETCONF app"
272 testResult = main.netconfFunction.startApp( main )
273
274 utilities.assert_equals( expect=main.TRUE,
275 actual=testResult,
276 onpass=main.assertReturnString,
277 onfail=main.assertReturnString )
278
279 main.step( "Starting OFC-Server" )
280 main.assertReturnString = "Assertion result for starting OFC-Server"
281 testResult = main.netconfFunction.startOFC( main )
282
283 utilities.assert_equals( expect=main.TRUE,
284 actual=testResult,
285 onpass=main.assertReturnString,
286 onfail=main.assertReturnString )
287 time.sleep( main.startUpSleep )
288
289 def CASE200( self, main ):
290 """
291 Create or modify a Configuration file
292 -The file is built from information loaded from the .params file
293 """
294 assert main, "There is no main"
295 assert main.CLIs, "There is no main.CLIs"
296 assert main.numCtrls, "Placed the total number of switch topology in \
297 main.numCtrls"
298
299 main.testName = "Assemble the configuration"
300 main.case( main.testName + " Test - " + str( main.numCtrls ) +
301 " NODES(S)" )
302 main.step( "Assembling configuration file" )
303 main.assertReturnString = "Assertion result for assembling configuration file"
304 testResult = main.FALSE
305 testResult = main.netconfFunction.createConfig( main )
306
307 utilities.assert_equals( expect=main.TRUE,
308 actual=testResult,
309 onpass=main.assertReturnString,
310 onfail=main.assertReturnString )
311 time.sleep( main.startUpSleep )
312
313 def CASE300( self, main ):
314 """
315 Push a configuration and bring up a switch
316 """
317 assert main, "There is no main"
318 assert main.CLIs, "There is no main.CLIs"
319 assert main.numCtrls, "Placed the total number of switch topology in \
320 main.numCtrls"
321
322 main.testName = "Uploading the configuration"
323 main.case( main.testName + " Test - " + str( main.numCtrls ) +
324 " NODES(S)" )
325 main.step( "Sending the configuration file")
326 main.assertReturnString = "Assertion result for sending the configuration file"
327 testResult = main.FALSE
328
329 testResult = main.netconfFunction.sendConfig( main )
330
331 utilities.assert_equals( expect=main.TRUE,
332 actual=testResult,
333 onpass=main.assertReturnString,
334 onfail=main.assertReturnString )
335
336 time.sleep( main.switchSleep )
337
338 main.step( "Confirming the device was configured" )
339 main.assertReturnString = "Assertion result for confirming a configuration."
340 testResult = main.FALSE
341
342 testResult = main.netconfFunction.devices( main )
343
344 utilities.assert_equals( expect=main.TRUE,
345 actual=testResult,
346 onpass=main.assertReturnString,
347 onfail=main.assertReturnString )
348
349 def CASE400( self, main ):
350 """
351 Bring down a switch
352 This test case is not yet possible, but the functionality needed to
353 perform it is planned to be added
354 There is a message that is sent "Device () has closed session"
355 when the device disconnects from onos for some reason.
356 Because of the triggers for this message are not practical
357 to activate this will likely not be used to implement the test
358 case at this time
359 Possible ways to do this may include bringing down mininet then checking
360 ONOS to see if it was recongnized the device being disconnected
361 """