blob: 8635b79c1238a4442383dce70de47e16619b5510 [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,
Flavio Castrocc38a542016-03-03 13:15:46 -0800134 tempOnosIp,
Flavio Castro4cd37c12016-03-28 07:39:16 -0700135 main.ONOSbench.user_name)
Flavio Castrocc38a542016-03-03 13:15:46 -0800136
137 main.step( "Apply cell to environment" )
138 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
147 main.step( "Creating ONOS package" )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700148 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 -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 Castro4cd37c12016-03-28 07:39:16 -0700198 main.log.case( "Logging test" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800199 #main.ONOSbench.logReport( main.ONOSip[ 0 ],
200 # [ "INFO" ],
201 # "a" )
202 #main.log.info("Error report: \n" )
203 main.ONOSbench.logReport( main.ONOSip[ 0 ],
204 [ "INFO",
205 "FOLLOWER",
206 "WARN",
207 "flow",
208 "ERROR",
209 "Except" ],
210 "s" )
211
Flavio Castrocc38a542016-03-03 13:15:46 -0800212 def CASE11( self, main ):
213 """
214 Start mininet
215 """
Flavio Castro4cd37c12016-03-28 07:39:16 -0700216 main.log.case( "Start Leaf-Spine 2x2 Mininet Topology" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800217 main.log.report( "Start Mininet topology" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800218
219 main.step( "Starting Mininet Topology" )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700220 args,topo=" "," "
221 #if main.topology:
222 # topo = main.topology.pop(0)
223 #else: main.log.error( "Topo list is empty" )
224 if main.args:
225 args = "--onos 1 " + main.args.pop(0)
226 else: main.log.error( "Argument list is empty" )
227
228 topoResult = main.Mininet1.startNet( topoFile= main.dependencyPath + main.topology, args=args )
Flavio Castrocc38a542016-03-03 13:15:46 -0800229 stepResult = topoResult
230 utilities.assert_equals( expect=main.TRUE,
231 actual=stepResult,
232 onpass="Successfully loaded topology",
233 onfail="Failed to load topology" )
234 # Exit if topology did not load properly
235 if not topoResult:
236 main.cleanup()
237 main.exit()
238 main.step("Waiting for switch initialization and configuration")
Flavio Castro4cd37c12016-03-28 07:39:16 -0700239 time.sleep( 3*main.startUpSleep)
Flavio Castrocc38a542016-03-03 13:15:46 -0800240 pa = main.Mininet1.pingall()
241 utilities.assert_equals( expect=main.TRUE, actual=pa,
242 onpass="Full connectivity successfully tested",
243 onfail="Full connectivity failed" )
244 # cleanup mininet
Flavio Castrocc38a542016-03-03 13:15:46 -0800245 main.ONOSbench.onosStop( main.ONOSip[0] )
246 main.Mininet1.stopNet()
Flavio Castrocc38a542016-03-03 13:15:46 -0800247
248
249
250
251