blob: 7ec23af99eb7a7be33332ba9a1ac532d850a7977 [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
30 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
31 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
32 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Flavio Castro4cd37c12016-03-28 07:39:16 -070033 main.diff = ( main.params[ 'ENV' ][ 'diffApps' ] ).split(";")
Flavio Castrocc38a542016-03-03 13:15:46 -080034 gitBranch = main.params[ 'GIT' ][ 'branch' ]
35 main.dependencyPath = main.testOnDirectory + \
36 main.params[ 'DEPENDENCY' ][ 'path' ]
37 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
Flavio Castro4cd37c12016-03-28 07:39:16 -070038 #main.json = ["4x4"]
39 main.json = ["2x2", "2x2"]
40 main.args = [" ", " "]
41 #main.args = [" --spine 4 --leaf 4 "]
Flavio Castrocc38a542016-03-03 13:15:46 -080042 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
43 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
44 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
45 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
46 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
47 gitPull = main.params[ 'GIT' ][ 'pull' ]
48 main.cellData = {} # for creating cell file
49 main.CLIs = []
50 main.ONOSip = []
51
52 main.ONOSip = main.ONOSbench.getOnosIps()
53
54 # Assigning ONOS cli handles to a list
55 for i in range( 1, main.maxNodes + 1 ):
56 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
57
58 # -- INIT SECTION, ONLY RUNS ONCE -- #
59 main.startUp = imp.load_source( wrapperFile1,
60 main.dependencyPath +
61 wrapperFile1 +
62 ".py" )
63
64 copyResult1 = main.ONOSbench.scp( main.Mininet1,
65 main.dependencyPath +
66 main.topology,
67 main.Mininet1.home,
68 direction="to" )
69 if main.CLIs:
70 stepResult = main.TRUE
71 else:
72 main.log.error( "Did not properly created list of ONOS CLI handle" )
73 stepResult = main.FALSE
74
75 utilities.assert_equals( expect=main.TRUE,
76 actual=stepResult,
77 onpass="Successfully construct " +
78 "test variables ",
79 onfail="Failed to construct test variables" )
80
81 if gitPull == 'True':
82 main.step( "Building ONOS in " + gitBranch + " branch" )
83 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
84 stepResult = onosBuildResult
85 utilities.assert_equals( expect=main.TRUE,
86 actual=stepResult,
87 onpass="Successfully compiled " +
88 "latest ONOS",
89 onfail="Failed to compile " +
90 "latest ONOS" )
91 else:
92 main.log.warn( "Did not pull new code so skipping mvn " +
93 "clean install" )
Flavio Castro4cd37c12016-03-28 07:39:16 -070094
Flavio Castrocc38a542016-03-03 13:15:46 -080095 def CASE2( self, main ):
96 """
97 - Set up cell
98 - Create cell file
99 - Set cell file
100 - Verify cell file
101 - Kill ONOS process
102 - Uninstall ONOS cluster
103 - Verify ONOS start up
104 - Install ONOS cluster
105 - Connect to cli
106 """
107
108 # main.scale[ 0 ] determines the current number of ONOS controller
109 main.numCtrls = int( main.scale[ 0 ] )
110
Flavio Castro4cd37c12016-03-28 07:39:16 -0700111 main.case( "Package and start ONOS")
Flavio Castrocc38a542016-03-03 13:15:46 -0800112
113 #kill off all onos processes
114 main.log.info( "Safety check, killing all ONOS processes" +
115 " before initiating environment setup" )
116
117 for i in range( main.maxNodes ):
118 main.ONOSbench.onosDie( main.ONOSip[ i ] )
119
120 print "NODE COUNT = ", main.numCtrls
121
122 tempOnosIp = []
123 for i in range( main.numCtrls ):
124 tempOnosIp.append( main.ONOSip[i] )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700125 apps=main.apps
126 if main.diff:
127 apps = main.apps+","+main.diff.pop(0)
128 else: main.log.error( "App list is empty" )
Jon Hall5c526d12016-03-08 08:54:46 -0800129 onosUser = main.params[ 'ENV' ][ 'cellUser' ]
Flavio Castrocc38a542016-03-03 13:15:46 -0800130 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
131 "temp",
132 main.Mininet1.ip_address,
Flavio Castro4cd37c12016-03-28 07:39:16 -0700133 apps,
Jon Hall503aa472016-04-05 10:52:29 -0700134 tempOnosIp )
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 Castro4cd37c12016-03-28 07:39:16 -0700147 main.ONOSbench.handle.sendline( "cp ~/OnosSystemTest/TestON/tests/USECASE_SegmentRouting/"+main.json.pop(0)+".json ~/onos/tools/package/config/network-cfg.json")
Flavio Castrocc38a542016-03-03 13:15:46 -0800148 packageResult = main.ONOSbench.onosPackage()
149 stepResult = packageResult
150 utilities.assert_equals( expect=main.TRUE,
151 actual=stepResult,
152 onpass="Successfully created ONOS package",
153 onfail="Failed to create ONOS package" )
154
155 time.sleep( main.startUpSleep )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700156
Flavio Castrocc38a542016-03-03 13:15:46 -0800157 main.step( "Installing ONOS package" )
158 onosInstallResult = main.TRUE
159 for i in range( main.numCtrls ):
160 onosInstallResult = onosInstallResult and \
161 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
162 stepResult = onosInstallResult
163 utilities.assert_equals( expect=main.TRUE,
164 actual=stepResult,
165 onpass="Successfully installed ONOS package",
166 onfail="Failed to install ONOS package" )
167
168 main.step( "Starting ONOS service" )
169 stopResult = main.TRUE
170 startResult = main.TRUE
171 onosIsUp = main.TRUE
172
173 for i in range( main.numCtrls ):
174 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
175 if onosIsUp == main.TRUE:
176 main.log.report( "ONOS instance is up and ready" )
177 else:
178 main.log.report( "ONOS instance may not be up, stop and " +
179 "start ONOS again " )
180 for i in range( main.numCtrls ):
181 stopResult = stopResult and \
182 main.ONOSbench.onosStop( main.ONOSip[ i ] )
183 for i in range( main.numCtrls ):
184 startResult = startResult and \
185 main.ONOSbench.onosStart( main.ONOSip[ i ] )
186 stepResult = onosIsUp and stopResult and startResult
187 utilities.assert_equals( expect=main.TRUE,
188 actual=stepResult,
189 onpass="ONOS service is ready",
190 onfail="ONOS service did not start properly" )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700191 time.sleep( 2*main.startUpSleep )
Flavio Castrocc38a542016-03-03 13:15:46 -0800192
193 def CASE9( self, main ):
194 '''
195 Report errors/warnings/exceptions
196 '''
Flavio Castro4cd37c12016-03-28 07:39:16 -0700197 main.log.case( "Logging test" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800198 #main.ONOSbench.logReport( main.ONOSip[ 0 ],
199 # [ "INFO" ],
200 # "a" )
201 #main.log.info("Error report: \n" )
202 main.ONOSbench.logReport( main.ONOSip[ 0 ],
203 [ "INFO",
204 "FOLLOWER",
205 "WARN",
206 "flow",
207 "ERROR",
208 "Except" ],
209 "s" )
210
Flavio Castrocc38a542016-03-03 13:15:46 -0800211 def CASE11( self, main ):
212 """
213 Start mininet
214 """
Flavio Castro4cd37c12016-03-28 07:39:16 -0700215 main.log.case( "Start Leaf-Spine 2x2 Mininet Topology" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800216 main.log.report( "Start Mininet topology" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800217
218 main.step( "Starting Mininet Topology" )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700219 args,topo=" "," "
220 #if main.topology:
221 # topo = main.topology.pop(0)
222 #else: main.log.error( "Topo list is empty" )
223 if main.args:
224 args = "--onos 1 " + main.args.pop(0)
225 else: main.log.error( "Argument list is empty" )
226
227 topoResult = main.Mininet1.startNet( topoFile= main.dependencyPath + main.topology, args=args )
Flavio Castrocc38a542016-03-03 13:15:46 -0800228 stepResult = topoResult
229 utilities.assert_equals( expect=main.TRUE,
230 actual=stepResult,
231 onpass="Successfully loaded topology",
232 onfail="Failed to load topology" )
233 # Exit if topology did not load properly
234 if not topoResult:
235 main.cleanup()
236 main.exit()
237 main.step("Waiting for switch initialization and configuration")
Flavio Castro4cd37c12016-03-28 07:39:16 -0700238 time.sleep( 3*main.startUpSleep)
Flavio Castrocc38a542016-03-03 13:15:46 -0800239 pa = main.Mininet1.pingall()
240 utilities.assert_equals( expect=main.TRUE, actual=pa,
241 onpass="Full connectivity successfully tested",
242 onfail="Full connectivity failed" )
243 # cleanup mininet
Flavio Castrocc38a542016-03-03 13:15:46 -0800244 main.ONOSbench.onosStop( main.ONOSip[0] )
245 main.Mininet1.stopNet()
Flavio Castrocc38a542016-03-03 13:15:46 -0800246
247
248
249
250