blob: bfdff59c7035e45e25be52e5dc37d82888d3a332 [file] [log] [blame]
Flavio Castrocc38a542016-03-03 13:15:46 -08001
2# This test is to determine if the Segment Routing application is working properly
3
4class USECASE_SegmentRouting:
5
6 def __init__( self ):
7 self.default = ''
8
9 def CASE1( self, main ):
10 import time
11 import os
12 import imp
13 import re
14
15 """
16 - Construct tests variables
17 - GIT ( optional )
18 - Checkout ONOS master branch
19 - Pull latest ONOS code
20 - Building ONOS ( optional )
21 - Install ONOS package
22 - Build ONOS package
23 """
24
Flavio Castro4cd37c12016-03-28 07:39:16 -070025 main.case( "Constructing test variables and building ONOS" )
Flavio Castrocc38a542016-03-03 13:15:46 -080026 main.step( "Constructing test variables" )
27 stepResult = main.FALSE
28
29 # Test variables
Flavio Castrocc38a542016-03-03 13:15:46 -080030 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
31 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Flavio Castro96eaa2e2016-04-23 16:24:47 -070032 main.diff = []
33 main.diff.extend(( main.params[ 'ENV' ][ 'diffApps' ] ).split(";"))
34 main.diff.extend(( main.params[ 'ENV' ][ 'diffApps' ] ).split(";"))
Flavio Castrocc38a542016-03-03 13:15:46 -080035 gitBranch = main.params[ 'GIT' ][ 'branch' ]
Flavio Castro7b4d7262016-04-19 11:59:02 -070036 main.path = os.path.dirname( main.testFile )
37 main.dependencyPath = main.path + "/dependencies/"
Flavio Castrocc38a542016-03-03 13:15:46 -080038 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
Flavio Castro4cd37c12016-03-28 07:39:16 -070039 #main.json = ["4x4"]
Flavio Castro96eaa2e2016-04-23 16:24:47 -070040 main.json = ["2x2", "2x2","4x4","4x4"]
41 main.args = [" ", " ", " --spine 4 --leaf 4 ", " --spine 4 --leaf 4 "]
Flavio Castro4cd37c12016-03-28 07:39:16 -070042 #main.args = [" --spine 4 --leaf 4 "]
Flavio Castrocc38a542016-03-03 13:15:46 -080043 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
44 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
45 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
46 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
47 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
48 gitPull = main.params[ 'GIT' ][ 'pull' ]
49 main.cellData = {} # for creating cell file
50 main.CLIs = []
51 main.ONOSip = []
52
53 main.ONOSip = main.ONOSbench.getOnosIps()
54
55 # Assigning ONOS cli handles to a list
56 for i in range( 1, main.maxNodes + 1 ):
57 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
58
59 # -- INIT SECTION, ONLY RUNS ONCE -- #
60 main.startUp = imp.load_source( wrapperFile1,
61 main.dependencyPath +
62 wrapperFile1 +
63 ".py" )
64
65 copyResult1 = main.ONOSbench.scp( main.Mininet1,
66 main.dependencyPath +
67 main.topology,
68 main.Mininet1.home,
69 direction="to" )
70 if main.CLIs:
71 stepResult = main.TRUE
72 else:
73 main.log.error( "Did not properly created list of ONOS CLI handle" )
74 stepResult = main.FALSE
75
76 utilities.assert_equals( expect=main.TRUE,
77 actual=stepResult,
78 onpass="Successfully construct " +
79 "test variables ",
80 onfail="Failed to construct test variables" )
81
82 if gitPull == 'True':
83 main.step( "Building ONOS in " + gitBranch + " branch" )
84 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
85 stepResult = onosBuildResult
86 utilities.assert_equals( expect=main.TRUE,
87 actual=stepResult,
88 onpass="Successfully compiled " +
89 "latest ONOS",
90 onfail="Failed to compile " +
91 "latest ONOS" )
92 else:
93 main.log.warn( "Did not pull new code so skipping mvn " +
94 "clean install" )
Flavio Castro4cd37c12016-03-28 07:39:16 -070095
Flavio Castrocc38a542016-03-03 13:15:46 -080096 def CASE2( self, main ):
97 """
98 - Set up cell
99 - Create cell file
100 - Set cell file
101 - Verify cell file
102 - Kill ONOS process
103 - Uninstall ONOS cluster
104 - Verify ONOS start up
105 - Install ONOS cluster
106 - Connect to cli
107 """
108
109 # main.scale[ 0 ] determines the current number of ONOS controller
110 main.numCtrls = int( main.scale[ 0 ] )
Flavio Castro7b4d7262016-04-19 11:59:02 -0700111 apps=main.apps
112 if main.diff:
113 apps = main.apps+","+main.diff.pop(0)
114 else: main.log.error( "App list is empty" )
115 main.case( "Package and start ONOS using apps:" + apps)
Flavio Castrocc38a542016-03-03 13:15:46 -0800116
117 #kill off all onos processes
118 main.log.info( "Safety check, killing all ONOS processes" +
119 " before initiating environment setup" )
120
121 for i in range( main.maxNodes ):
122 main.ONOSbench.onosDie( main.ONOSip[ i ] )
123
124 print "NODE COUNT = ", main.numCtrls
125
126 tempOnosIp = []
127 for i in range( main.numCtrls ):
128 tempOnosIp.append( main.ONOSip[i] )
Jon Hall5c526d12016-03-08 08:54:46 -0800129 onosUser = main.params[ 'ENV' ][ 'cellUser' ]
Flavio Castrod2ffffa2016-04-26 15:56:56 -0700130 main.step("Create and Apply cell file")
Flavio Castrocc38a542016-03-03 13:15:46 -0800131 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
132 "temp",
133 main.Mininet1.ip_address,
Flavio Castro4cd37c12016-03-28 07:39:16 -0700134 apps,
Flavio Castro7b4d7262016-04-19 11:59:02 -0700135 tempOnosIp,
136 onosUser )
Flavio Castrocc38a542016-03-03 13:15:46 -0800137
Flavio Castrocc38a542016-03-03 13:15:46 -0800138 cellResult = main.ONOSbench.setCell( "temp" )
139 verifyResult = main.ONOSbench.verifyCell()
140 stepResult = cellResult and verifyResult
141 utilities.assert_equals( expect=main.TRUE,
142 actual=stepResult,
143 onpass="Successfully applied cell to " + \
144 "environment",
145 onfail="Failed to apply cell to environment " )
146
Flavio Castrod2ffffa2016-04-26 15:56:56 -0700147 main.step( "Create and Install ONOS package" )
Flavio Castro7b4d7262016-04-19 11:59:02 -0700148 main.jsonFile=main.json.pop(0)
149 main.ONOSbench.handle.sendline( "cp "+main.path+"/"+main.jsonFile+".json ~/onos/tools/package/config/network-cfg.json")
Flavio Castrocc38a542016-03-03 13:15:46 -0800150 packageResult = main.ONOSbench.onosPackage()
Flavio Castro96eaa2e2016-04-23 16:24:47 -0700151 #stepResult = packageResult
152 #utilities.assert_equals( expect=main.TRUE,
153 # actual=stepResult,
154 # onpass="Successfully created ONOS package",
155 # onfail="Failed to create ONOS package" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800156
Flavio Castrod2ffffa2016-04-26 15:56:56 -0700157 #time.sleep( main.startUpSleep )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700158
Flavio Castrocc38a542016-03-03 13:15:46 -0800159 onosInstallResult = main.TRUE
160 for i in range( main.numCtrls ):
161 onosInstallResult = onosInstallResult and \
162 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
163 stepResult = onosInstallResult
164 utilities.assert_equals( expect=main.TRUE,
165 actual=stepResult,
166 onpass="Successfully installed ONOS package",
167 onfail="Failed to install ONOS package" )
168
169 main.step( "Starting ONOS service" )
170 stopResult = main.TRUE
171 startResult = main.TRUE
172 onosIsUp = main.TRUE
173
174 for i in range( main.numCtrls ):
175 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
176 if onosIsUp == main.TRUE:
177 main.log.report( "ONOS instance is up and ready" )
178 else:
179 main.log.report( "ONOS instance may not be up, stop and " +
180 "start ONOS again " )
181 for i in range( main.numCtrls ):
182 stopResult = stopResult and \
183 main.ONOSbench.onosStop( main.ONOSip[ i ] )
184 for i in range( main.numCtrls ):
185 startResult = startResult and \
186 main.ONOSbench.onosStart( main.ONOSip[ i ] )
187 stepResult = onosIsUp and stopResult and startResult
Flavio Castrod2ffffa2016-04-26 15:56:56 -0700188
Flavio Castrocc38a542016-03-03 13:15:46 -0800189 utilities.assert_equals( expect=main.TRUE,
190 actual=stepResult,
191 onpass="ONOS service is ready",
192 onfail="ONOS service did not start properly" )
Flavio Castrod2ffffa2016-04-26 15:56:56 -0700193 #time.sleep( 2*main.startUpSleep )
Flavio Castrobdcfad62016-05-10 09:52:28 -0700194 #main.ONOSbench.handle.sendline( "onos-secure-ssh")
Flavio Castrod2ffffa2016-04-26 15:56:56 -0700195 main.step( "Checking if ONOS CLI is ready" )
196 cliResult = main.CLIs[0].startOnosCli( main.ONOSip[ 0 ],
197 commandlineTimeout=100, onosStartTimeout=600 )
198 utilities.assert_equals( expect=main.TRUE,
199 actual=cliResult,
200 onpass="ONOS CLI is ready",
201 onfail="ONOS CLI is not ready" )
202 for i in range( 10 ):
203 ready = True
204 output = main.CLIs[0].summary()
205 if not output:
206 ready = False
207 if ready:
208 break
209 time.sleep( 10 )
210 utilities.assert_equals( expect=True, actual=ready,
211 onpass="ONOS summary command succeded",
212 onfail="ONOS summary command failed" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800213
Flavio Castrod2ffffa2016-04-26 15:56:56 -0700214 if not ready:
215 main.log.error( "ONOS startup failed!" )
216 main.cleanup()
217 main.exit()
218
219 def CASE10( self, main ):
Flavio Castrocc38a542016-03-03 13:15:46 -0800220 '''
221 Report errors/warnings/exceptions
222 '''
Flavio Castro7b4d7262016-04-19 11:59:02 -0700223 main.case( "Logging test for " + main.jsonFile )
Flavio Castro96eaa2e2016-04-23 16:24:47 -0700224 #if len(main.json) > 0 :
225 main.ONOSbench.cpLogsToDir("/opt/onos/log/karaf.log",main.logdir,
Flavio Castro7b4d7262016-04-19 11:59:02 -0700226 copyFileName="karaf.log."+main.jsonFile+str(len(main.json)))
Flavio Castrocc38a542016-03-03 13:15:46 -0800227 #main.ONOSbench.logReport( main.ONOSip[ 0 ],
228 # [ "INFO" ],
229 # "a" )
230 #main.log.info("Error report: \n" )
231 main.ONOSbench.logReport( main.ONOSip[ 0 ],
232 [ "INFO",
233 "FOLLOWER",
234 "WARN",
235 "flow",
236 "ERROR",
237 "Except" ],
238 "s" )
239
Flavio Castrod2ffffa2016-04-26 15:56:56 -0700240 def CASE3( self, main ):
Flavio Castrocc38a542016-03-03 13:15:46 -0800241 """
242 Start mininet
243 """
Flavio Castro7b4d7262016-04-19 11:59:02 -0700244 main.case( "Start Leaf-Spine "+main.jsonFile+" Mininet Topology" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800245 main.log.report( "Start Mininet topology" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800246
247 main.step( "Starting Mininet Topology" )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700248 args,topo=" "," "
249 #if main.topology:
250 # topo = main.topology.pop(0)
251 #else: main.log.error( "Topo list is empty" )
252 if main.args:
253 args = "--onos 1 " + main.args.pop(0)
254 else: main.log.error( "Argument list is empty" )
255
256 topoResult = main.Mininet1.startNet( topoFile= main.dependencyPath + main.topology, args=args )
Flavio Castrocc38a542016-03-03 13:15:46 -0800257 stepResult = topoResult
258 utilities.assert_equals( expect=main.TRUE,
259 actual=stepResult,
260 onpass="Successfully loaded topology",
261 onfail="Failed to load topology" )
262 # Exit if topology did not load properly
263 if not topoResult:
264 main.cleanup()
265 main.exit()
Flavio Castrod2ffffa2016-04-26 15:56:56 -0700266 #main.step("Waiting for switch initialization and configuration")
267 main.step(" Check whether the flow count is bigger than 80" )
268 count = utilities.retry( main.CLIs[0].checkFlowCount,
269 main.FALSE,
270 kwargs={'min':80},
271 attempts=10 )
272 utilities.assertEquals( \
273 expect=True,
274 actual=(count>0),
275 onpass="Flow count looks correct: "+str(count),
276 onfail="Flow count looks wrong: "+str(count) )
277
278 main.step( "Check whether all flow status are ADDED" )
279 flowCheck = utilities.retry( main.CLIs[0].checkFlowsState,
280 main.FALSE,
281 kwargs={'isPENDING':False},
282 attempts=10 )
283 utilities.assertEquals( \
284 expect=main.TRUE,
285 actual=flowCheck,
286 onpass="Flow status is correct!",
287 onfail="Flow status is wrong!" )
288 main.ONOSbench.dumpFlows( main.ONOSip[0],
Flavio Castro60a41d52016-05-16 11:20:09 -0700289 main.logdir, "flowsBefore" + main.jsonFile)
Flavio Castrod2ffffa2016-04-26 15:56:56 -0700290 #time.sleep( 3*main.startUpSleep)
291
292 def CASE4( self, main ):
293 main.case( "Check full connectivity" )
294 main.log.report( "Check full connectivity" )
295
Flavio Castro60a41d52016-05-16 11:20:09 -0700296 main.step("1st Check full connectivity")
Flavio Castrocc38a542016-03-03 13:15:46 -0800297 pa = main.Mininet1.pingall()
298 utilities.assert_equals( expect=main.TRUE, actual=pa,
299 onpass="Full connectivity successfully tested",
300 onfail="Full connectivity failed" )
301 # cleanup mininet
Flavio Castrod2ffffa2016-04-26 15:56:56 -0700302 main.ONOSbench.dumpFlows( main.ONOSip[0],
Flavio Castro60a41d52016-05-16 11:20:09 -0700303 main.logdir, "flowsAfter" + main.jsonFile)
304
305 main.step("2nd Check full connectivity")
306 pa = main.Mininet1.pingall()
307 utilities.assert_equals( expect=main.TRUE, actual=pa,
308 onpass="Full connectivity successfully tested",
309 onfail="Full connectivity failed" )
310
311 main.ONOSbench.dumpFlows( main.ONOSip[0],
312 main.logdir, "flowsAfter2nd" + main.jsonFile)
313
Flavio Castrocc38a542016-03-03 13:15:46 -0800314 main.ONOSbench.onosStop( main.ONOSip[0] )
315 main.Mininet1.stopNet()
Flavio Castrocc38a542016-03-03 13:15:46 -0800316
317
318
319
320