blob: 1b22c2fe785cdef6691efe7476c415174a94d9e0 [file] [log] [blame]
Jeremyfc567ca2016-02-16 15:08:25 -08001# Testing the NETCONF protocol within ONOS
2
Jon Hall0c3f46f2017-05-24 16:34:46 -07003
Jeremyfc567ca2016-02-16 15:08:25 -08004class FUNCnetconf:
5
6 def __init__( self ):
7 self.default = ''
8
9 def CASE1( self, main ):
10 import time
11 import imp
12 import re
13
14 """
15 - Construct tests variables
16 - GIT ( optional )
17 - Checkout ONOS master branch
18 - Pull latest ONOS code
19 - Building ONOS ( optional )
20 - Install ONOS package
21 - Build ONOS package
22 """
Jeremyfc567ca2016-02-16 15:08:25 -080023 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' ]
Jon Hall0c3f46f2017-05-24 16:34:46 -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' ]
Jon Hall0c3f46f2017-05-24 16:34:46 -070061 main.cellData = {} # for creating cell file
Jeremyfc567ca2016-02-16 15:08:25 -080062 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
Jon Hall0c3f46f2017-05-24 16:34:46 -070072 for i in range( 1, main.maxNodes + 1 ):
Jeremyfc567ca2016-02-16 15:08:25 -080073 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,
Jon Hall0c3f46f2017-05-24 16:34:46 -070083 main.dependencyPath +
84 wrapperFile2 +
85 ".py" )
Jeremyfc567ca2016-02-16 15:08:25 -080086
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:
Jon Hall0c3f46f2017-05-24 16:34:46 -0700105 main.log.exception( e )
Jeremyfc567ca2016-02-16 15:08:25 -0800106 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
Jeremyfc567ca2016-02-16 15:08:25 -0800115 main.ONOSbench.getVersion( report=True )
116
117 def CASE2( self, main ):
118 """
119 - Set up cell
120 - Create cell file
121 - Set cell file
122 - Verify cell file
123 - Kill ONOS process
124 - Uninstall ONOS cluster
125 - Verify ONOS start up
126 - Install ONOS cluster
127 - Connect to cli
128 """
Jeremy Songster17147f22016-05-31 18:30:52 -0700129 main.cycle += 1
130
Jeremyfc567ca2016-02-16 15:08:25 -0800131 # main.scale[ 0 ] determines the current number of ONOS controller
132 main.numCtrls = int( main.scale[ 0 ] )
133
134 main.case( "Starting up " + str( main.numCtrls ) +
135 " node(s) ONOS cluster" )
136 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
137 " node(s) ONOS cluster"
138
Jeremyfc567ca2016-02-16 15:08:25 -0800139 #kill off all onos processes
140 main.log.info( "Safety check, killing all ONOS processes" +
141 " before initiating environment setup" )
142
Jeremyfc567ca2016-02-16 15:08:25 -0800143 time.sleep( main.startUpSleep )
144 main.step( "Uninstalling ONOS package" )
145 onosUninstallResult = main.TRUE
146 for ip in main.ONOSip:
147 onosUninstallResult = onosUninstallResult and \
148 main.ONOSbench.onosUninstall( nodeIp=ip )
149 stepResult = onosUninstallResult
150 utilities.assert_equals( expect=main.TRUE,
151 actual=stepResult,
152 onpass="Successfully uninstalled ONOS package",
153 onfail="Failed to uninstall ONOS package" )
154
155 for i in range( main.maxNodes ):
156 main.ONOSbench.onosDie( main.ONOSip[ i ] )
157
158 main.log.info( "NODE COUNT = " + str( main.numCtrls ) )
159
160 tempOnosIp = []
161 for i in range( main.numCtrls ):
Jon Hall0c3f46f2017-05-24 16:34:46 -0700162 tempOnosIp.append( main.ONOSip[ i ] )
Jeremyfc567ca2016-02-16 15:08:25 -0800163
164 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
165 "temp", main.Mininet1.ip_address,
Devin Lim461f0872017-06-05 16:49:33 -0700166 main.apps, tempOnosIp, main.ONOScli1.user_name )
Jeremyfc567ca2016-02-16 15:08:25 -0800167
168 main.step( "Apply cell to environment" )
169 cellResult = main.ONOSbench.setCell( "temp" )
170 verifyResult = main.ONOSbench.verifyCell()
171 stepResult = cellResult and verifyResult
172 utilities.assert_equals( expect=main.TRUE,
173 actual=stepResult,
Jon Hall0c3f46f2017-05-24 16:34:46 -0700174 onpass="Successfully applied cell to " +
Jeremyfc567ca2016-02-16 15:08:25 -0800175 "environment",
176 onfail="Failed to apply cell to environment " )
177
178 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700179 packageResult = main.ONOSbench.buckBuild()
Jeremyfc567ca2016-02-16 15:08:25 -0800180 stepResult = packageResult
181 utilities.assert_equals( expect=main.TRUE,
182 actual=stepResult,
183 onpass="Successfully created ONOS package",
184 onfail="Failed to create ONOS package" )
185
186 time.sleep( main.startUpSleep )
187 main.step( "Installing ONOS package" )
188 onosInstallResult = main.TRUE
189 for i in range( main.numCtrls ):
190 onosInstallResult = onosInstallResult and \
191 main.ONOSbench.onosInstall( node=main.ONOSip[ i ], options="" )
192 stepResult = onosInstallResult
193
194 utilities.assert_equals( expect=main.TRUE,
195 actual=stepResult,
196 onpass="Successfully installed ONOS package",
197 onfail="Failed to install ONOS package" )
198
You Wangf5de25b2017-01-06 15:13:01 -0800199 main.step( "Set up ONOS secure SSH" )
200 secureSshResult = main.TRUE
201 for i in range( int( main.numCtrls ) ):
Jon Hall0c3f46f2017-05-24 16:34:46 -0700202 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] )
You Wangf5de25b2017-01-06 15:13:01 -0800203 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
204 onpass="Test step PASS",
205 onfail="Test step FAIL" )
206
Jeremyfc567ca2016-02-16 15:08:25 -0800207 time.sleep( main.startUpSleep )
208 main.step( "Starting ONOS service" )
209 stopResult = main.TRUE
210 startResult = main.TRUE
211 onosIsUp = main.TRUE
212
213 for i in range( main.numCtrls ):
214 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
215 if onosIsUp == main.TRUE:
216 main.log.report( "ONOS instance is up and ready" )
217 else:
218 main.log.report( "ONOS instance may not be up, stop and " +
219 "start ONOS again " )
220 for i in range( main.numCtrls ):
221 stopResult = stopResult and \
222 main.ONOSbench.onosStop( main.ONOSip[ i ] )
223 for i in range( main.numCtrls ):
224 startResult = startResult and \
225 main.ONOSbench.onosStart( main.ONOSip[ i ] )
226 stepResult = onosIsUp and stopResult and startResult
227 utilities.assert_equals( expect=main.TRUE,
228 actual=stepResult,
229 onpass="ONOS service is ready",
230 onfail="ONOS service did not start properly" )
231
232 # Start an ONOS cli to provide functionality that is not currently
233 # supported by the Rest API remove this when Leader Checking is supported
234 # by the REST API
235
236 main.step( "Start ONOS cli" )
237 cliResult = main.TRUE
238 for i in range( main.numCtrls ):
239 cliResult = cliResult and \
240 main.CLIs2[ i ].startOnosCli( main.ONOSip[ i ] )
241 stepResult = cliResult
242 utilities.assert_equals( expect=main.TRUE,
243 actual=stepResult,
244 onpass="Successfully start ONOS cli",
245 onfail="Failed to start ONOS cli" )
246
247 # Remove the first element in main.scale list
248 main.scale.remove( main.scale[ 0 ] )
249
Jeremy Songster17147f22016-05-31 18:30:52 -0700250 def CASE19( self, main ):
251 """
252 Copy the karaf.log files after each testcase cycle
253 """
254 main.log.report( "Copy karaf logs" )
255 main.case( "Copy karaf logs" )
256 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
257 "reinstalling ONOS"
258 main.step( "Copying karaf logs" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700259 stepResult = main.TRUE
260 scpResult = main.TRUE
261 copyResult = main.TRUE
Jeremy Songstercc5414b2016-07-11 10:59:53 -0700262 for i in range( main.numCtrls ):
Jeremy Songsterd2d687e2016-07-19 11:20:48 -0700263 main.node = main.CLIs2[ i ]
Jeremy Songster17147f22016-05-31 18:30:52 -0700264 ip = main.ONOSip[ i ]
265 main.node.ip_address = ip
Jon Hall0c3f46f2017-05-24 16:34:46 -0700266 scpResult = scpResult and main.ONOSbench.scp( main.node,
267 "/opt/onos/log/karaf.log",
268 "/tmp/karaf.log",
269 direction="from" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700270 copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
271 copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) )
272 if scpResult and copyResult:
Jon Hall0c3f46f2017-05-24 16:34:46 -0700273 stepResult = main.TRUE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700274 else:
275 stepResult = main.FALSE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700276 utilities.assert_equals( expect=main.TRUE,
277 actual=stepResult,
278 onpass="Successfully copied remote ONOS logs",
279 onfail="Failed to copy remote ONOS logs" )
Jeremy Songster17147f22016-05-31 18:30:52 -0700280
Jeremyfc567ca2016-02-16 15:08:25 -0800281 def CASE100( self, main ):
282 """
283 Start NETCONF app and OFC-Server or make sure that they are already running
284 """
285 assert main, "There is no main"
286 assert main.CLIs, "There is no main.CLIs"
287 assert main.numCtrls, "Placed the total number of switch topology in \
288 main.numCtrls"
289
290 testResult = main.FALSE
291 main.testName = "Start up NETCONF app in all nodes"
292 main.case( main.testName + " Test - " + str( main.numCtrls ) +
293 " NODE(S)" )
294 main.step( "Starting NETCONF app" )
295 main.assertReturnString = "Assertion result for starting NETCONF app"
296 testResult = main.netconfFunction.startApp( main )
297
298 utilities.assert_equals( expect=main.TRUE,
299 actual=testResult,
300 onpass=main.assertReturnString,
301 onfail=main.assertReturnString )
302
303 main.step( "Starting OFC-Server" )
304 main.assertReturnString = "Assertion result for starting OFC-Server"
305 testResult = main.netconfFunction.startOFC( 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 CASE200( self, main ):
314 """
315 Create or modify a Configuration file
316 -The file is built from information loaded from the .params file
317 """
318 assert main, "There is no main"
319 assert main.CLIs, "There is no main.CLIs"
320 assert main.numCtrls, "Placed the total number of switch topology in \
321 main.numCtrls"
322
323 main.testName = "Assemble the configuration"
324 main.case( main.testName + " Test - " + str( main.numCtrls ) +
325 " NODES(S)" )
326 main.step( "Assembling configuration file" )
327 main.assertReturnString = "Assertion result for assembling configuration file"
328 testResult = main.FALSE
329 testResult = main.netconfFunction.createConfig( main )
330
331 utilities.assert_equals( expect=main.TRUE,
332 actual=testResult,
333 onpass=main.assertReturnString,
334 onfail=main.assertReturnString )
335 time.sleep( main.startUpSleep )
336
337 def CASE300( self, main ):
338 """
339 Push a configuration and bring up a switch
340 """
341 assert main, "There is no main"
342 assert main.CLIs, "There is no main.CLIs"
343 assert main.numCtrls, "Placed the total number of switch topology in \
344 main.numCtrls"
345
346 main.testName = "Uploading the configuration"
347 main.case( main.testName + " Test - " + str( main.numCtrls ) +
348 " NODES(S)" )
Jon Hall0c3f46f2017-05-24 16:34:46 -0700349 main.step( "Sending the configuration file" )
Jeremyfc567ca2016-02-16 15:08:25 -0800350 main.assertReturnString = "Assertion result for sending the configuration file"
351 testResult = main.FALSE
352
353 testResult = main.netconfFunction.sendConfig( main )
354
355 utilities.assert_equals( expect=main.TRUE,
356 actual=testResult,
357 onpass=main.assertReturnString,
358 onfail=main.assertReturnString )
359
360 time.sleep( main.switchSleep )
361
362 main.step( "Confirming the device was configured" )
363 main.assertReturnString = "Assertion result for confirming a configuration."
364 testResult = main.FALSE
365
366 testResult = main.netconfFunction.devices( main )
367
368 utilities.assert_equals( expect=main.TRUE,
369 actual=testResult,
370 onpass=main.assertReturnString,
371 onfail=main.assertReturnString )
372
373 def CASE400( self, main ):
374 """
375 Bring down a switch
376 This test case is not yet possible, but the functionality needed to
377 perform it is planned to be added
378 There is a message that is sent "Device () has closed session"
379 when the device disconnects from onos for some reason.
380 Because of the triggers for this message are not practical
381 to activate this will likely not be used to implement the test
382 case at this time
383 Possible ways to do this may include bringing down mininet then checking
384 ONOS to see if it was recongnized the device being disconnected
385 """