blob: c95e232864fbd799d19b319119c1485873aeb773 [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 Castro4cd37c12016-03-28 07:39:16 -070032 main.diff = ( main.params[ 'ENV' ][ 'diffApps' ] ).split(";")
Flavio Castrocc38a542016-03-03 13:15:46 -080033 gitBranch = main.params[ 'GIT' ][ 'branch' ]
Flavio Castro7b4d7262016-04-19 11:59:02 -070034 main.path = os.path.dirname( main.testFile )
35 main.dependencyPath = main.path + "/dependencies/"
Flavio Castrocc38a542016-03-03 13:15:46 -080036 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
Flavio Castro4cd37c12016-03-28 07:39:16 -070037 #main.json = ["4x4"]
38 main.json = ["2x2", "2x2"]
39 main.args = [" ", " "]
40 #main.args = [" --spine 4 --leaf 4 "]
Flavio Castrocc38a542016-03-03 13:15:46 -080041 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
42 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
43 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
44 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
45 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
46 gitPull = main.params[ 'GIT' ][ 'pull' ]
47 main.cellData = {} # for creating cell file
48 main.CLIs = []
49 main.ONOSip = []
50
51 main.ONOSip = main.ONOSbench.getOnosIps()
52
53 # Assigning ONOS cli handles to a list
54 for i in range( 1, main.maxNodes + 1 ):
55 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
56
57 # -- INIT SECTION, ONLY RUNS ONCE -- #
58 main.startUp = imp.load_source( wrapperFile1,
59 main.dependencyPath +
60 wrapperFile1 +
61 ".py" )
62
63 copyResult1 = main.ONOSbench.scp( main.Mininet1,
64 main.dependencyPath +
65 main.topology,
66 main.Mininet1.home,
67 direction="to" )
68 if main.CLIs:
69 stepResult = main.TRUE
70 else:
71 main.log.error( "Did not properly created list of ONOS CLI handle" )
72 stepResult = main.FALSE
73
74 utilities.assert_equals( expect=main.TRUE,
75 actual=stepResult,
76 onpass="Successfully construct " +
77 "test variables ",
78 onfail="Failed to construct test variables" )
79
80 if gitPull == 'True':
81 main.step( "Building ONOS in " + gitBranch + " branch" )
82 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
83 stepResult = onosBuildResult
84 utilities.assert_equals( expect=main.TRUE,
85 actual=stepResult,
86 onpass="Successfully compiled " +
87 "latest ONOS",
88 onfail="Failed to compile " +
89 "latest ONOS" )
90 else:
91 main.log.warn( "Did not pull new code so skipping mvn " +
92 "clean install" )
Flavio Castro4cd37c12016-03-28 07:39:16 -070093
Flavio Castrocc38a542016-03-03 13:15:46 -080094 def CASE2( self, main ):
95 """
96 - Set up cell
97 - Create cell file
98 - Set cell file
99 - Verify cell file
100 - Kill ONOS process
101 - Uninstall ONOS cluster
102 - Verify ONOS start up
103 - Install ONOS cluster
104 - Connect to cli
105 """
106
107 # main.scale[ 0 ] determines the current number of ONOS controller
108 main.numCtrls = int( main.scale[ 0 ] )
Flavio Castro7b4d7262016-04-19 11:59:02 -0700109 apps=main.apps
110 if main.diff:
111 apps = main.apps+","+main.diff.pop(0)
112 else: main.log.error( "App list is empty" )
113 main.case( "Package and start ONOS using apps:" + apps)
Flavio Castrocc38a542016-03-03 13:15:46 -0800114
115 #kill off all onos processes
116 main.log.info( "Safety check, killing all ONOS processes" +
117 " before initiating environment setup" )
118
119 for i in range( main.maxNodes ):
120 main.ONOSbench.onosDie( main.ONOSip[ i ] )
121
122 print "NODE COUNT = ", main.numCtrls
123
124 tempOnosIp = []
125 for i in range( main.numCtrls ):
126 tempOnosIp.append( main.ONOSip[i] )
Jon Hall5c526d12016-03-08 08:54:46 -0800127 onosUser = main.params[ 'ENV' ][ 'cellUser' ]
Flavio Castro7b4d7262016-04-19 11:59:02 -0700128 main.step("Creating cell file")
Flavio Castrocc38a542016-03-03 13:15:46 -0800129 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
130 "temp",
131 main.Mininet1.ip_address,
Flavio Castro4cd37c12016-03-28 07:39:16 -0700132 apps,
Flavio Castro7b4d7262016-04-19 11:59:02 -0700133 tempOnosIp,
134 onosUser )
Flavio Castrocc38a542016-03-03 13:15:46 -0800135
136 main.step( "Apply cell to environment" )
137 cellResult = main.ONOSbench.setCell( "temp" )
138 verifyResult = main.ONOSbench.verifyCell()
139 stepResult = cellResult and verifyResult
140 utilities.assert_equals( expect=main.TRUE,
141 actual=stepResult,
142 onpass="Successfully applied cell to " + \
143 "environment",
144 onfail="Failed to apply cell to environment " )
145
146 main.step( "Creating ONOS package" )
Flavio Castro7b4d7262016-04-19 11:59:02 -0700147 main.jsonFile=main.json.pop(0)
148 main.ONOSbench.handle.sendline( "cp "+main.path+"/"+main.jsonFile+".json ~/onos/tools/package/config/network-cfg.json")
Flavio Castrocc38a542016-03-03 13:15:46 -0800149 packageResult = main.ONOSbench.onosPackage()
150 stepResult = packageResult
151 utilities.assert_equals( expect=main.TRUE,
152 actual=stepResult,
153 onpass="Successfully created ONOS package",
154 onfail="Failed to create ONOS package" )
155
156 time.sleep( main.startUpSleep )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700157
Flavio Castrocc38a542016-03-03 13:15:46 -0800158 main.step( "Installing ONOS package" )
159 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
188 utilities.assert_equals( expect=main.TRUE,
189 actual=stepResult,
190 onpass="ONOS service is ready",
191 onfail="ONOS service did not start properly" )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700192 time.sleep( 2*main.startUpSleep )
Flavio Castrocc38a542016-03-03 13:15:46 -0800193
194 def CASE9( self, main ):
195 '''
196 Report errors/warnings/exceptions
197 '''
Flavio Castro7b4d7262016-04-19 11:59:02 -0700198 main.case( "Logging test for " + main.jsonFile )
199 if len(main.json) > 0 :
200 main.ONOSbench.cpLogsToDir("/opt/onos/log/karaf.log",main.logdir,
201 copyFileName="karaf.log."+main.jsonFile+str(len(main.json)))
Flavio Castrocc38a542016-03-03 13:15:46 -0800202 #main.ONOSbench.logReport( main.ONOSip[ 0 ],
203 # [ "INFO" ],
204 # "a" )
205 #main.log.info("Error report: \n" )
206 main.ONOSbench.logReport( main.ONOSip[ 0 ],
207 [ "INFO",
208 "FOLLOWER",
209 "WARN",
210 "flow",
211 "ERROR",
212 "Except" ],
213 "s" )
214
Flavio Castrocc38a542016-03-03 13:15:46 -0800215 def CASE11( self, main ):
216 """
217 Start mininet
218 """
Flavio Castro7b4d7262016-04-19 11:59:02 -0700219 main.case( "Start Leaf-Spine "+main.jsonFile+" Mininet Topology" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800220 main.log.report( "Start Mininet topology" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800221
222 main.step( "Starting Mininet Topology" )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700223 args,topo=" "," "
224 #if main.topology:
225 # topo = main.topology.pop(0)
226 #else: main.log.error( "Topo list is empty" )
227 if main.args:
228 args = "--onos 1 " + main.args.pop(0)
229 else: main.log.error( "Argument list is empty" )
230
231 topoResult = main.Mininet1.startNet( topoFile= main.dependencyPath + main.topology, args=args )
Flavio Castrocc38a542016-03-03 13:15:46 -0800232 stepResult = topoResult
233 utilities.assert_equals( expect=main.TRUE,
234 actual=stepResult,
235 onpass="Successfully loaded topology",
236 onfail="Failed to load topology" )
237 # Exit if topology did not load properly
238 if not topoResult:
239 main.cleanup()
240 main.exit()
241 main.step("Waiting for switch initialization and configuration")
Flavio Castro4cd37c12016-03-28 07:39:16 -0700242 time.sleep( 3*main.startUpSleep)
Flavio Castrocc38a542016-03-03 13:15:46 -0800243 pa = main.Mininet1.pingall()
244 utilities.assert_equals( expect=main.TRUE, actual=pa,
245 onpass="Full connectivity successfully tested",
246 onfail="Full connectivity failed" )
247 # cleanup mininet
Flavio Castrocc38a542016-03-03 13:15:46 -0800248 main.ONOSbench.onosStop( main.ONOSip[0] )
249 main.Mininet1.stopNet()
Flavio Castrocc38a542016-03-03 13:15:46 -0800250
251
252
253
254