blob: 45ed07d051d15ad712de54677364808f5bd555a1 [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
25 main.case( "Constructing test variables and building ONOS package" )
26 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' ]
33 gitBranch = main.params[ 'GIT' ][ 'branch' ]
34 main.dependencyPath = main.testOnDirectory + \
35 main.params[ 'DEPENDENCY' ][ 'path' ]
36 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
37 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
38 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
39 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
40 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
41 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
42 gitPull = main.params[ 'GIT' ][ 'pull' ]
43 main.cellData = {} # for creating cell file
44 main.CLIs = []
45 main.ONOSip = []
46
47 main.ONOSip = main.ONOSbench.getOnosIps()
48
49 # Assigning ONOS cli handles to a list
50 for i in range( 1, main.maxNodes + 1 ):
51 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
52
53 # -- INIT SECTION, ONLY RUNS ONCE -- #
54 main.startUp = imp.load_source( wrapperFile1,
55 main.dependencyPath +
56 wrapperFile1 +
57 ".py" )
58
59 copyResult1 = main.ONOSbench.scp( main.Mininet1,
60 main.dependencyPath +
61 main.topology,
62 main.Mininet1.home,
63 direction="to" )
64 if main.CLIs:
65 stepResult = main.TRUE
66 else:
67 main.log.error( "Did not properly created list of ONOS CLI handle" )
68 stepResult = main.FALSE
69
70 utilities.assert_equals( expect=main.TRUE,
71 actual=stepResult,
72 onpass="Successfully construct " +
73 "test variables ",
74 onfail="Failed to construct test variables" )
75
76 if gitPull == 'True':
77 main.step( "Building ONOS in " + gitBranch + " branch" )
78 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
79 stepResult = onosBuildResult
80 utilities.assert_equals( expect=main.TRUE,
81 actual=stepResult,
82 onpass="Successfully compiled " +
83 "latest ONOS",
84 onfail="Failed to compile " +
85 "latest ONOS" )
86 else:
87 main.log.warn( "Did not pull new code so skipping mvn " +
88 "clean install" )
89
90 def CASE2( self, main ):
91 """
92 - Set up cell
93 - Create cell file
94 - Set cell file
95 - Verify cell file
96 - Kill ONOS process
97 - Uninstall ONOS cluster
98 - Verify ONOS start up
99 - Install ONOS cluster
100 - Connect to cli
101 """
102
103 # main.scale[ 0 ] determines the current number of ONOS controller
104 main.numCtrls = int( main.scale[ 0 ] )
105
106 main.case( "Starting up " + str( main.numCtrls ) +
107 " node(s) ONOS cluster" )
108
109 #kill off all onos processes
110 main.log.info( "Safety check, killing all ONOS processes" +
111 " before initiating environment setup" )
112
113 for i in range( main.maxNodes ):
114 main.ONOSbench.onosDie( main.ONOSip[ i ] )
115
116 print "NODE COUNT = ", main.numCtrls
117
118 tempOnosIp = []
119 for i in range( main.numCtrls ):
120 tempOnosIp.append( main.ONOSip[i] )
121
122 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
123 "temp",
124 main.Mininet1.ip_address,
125 main.apps,
126 tempOnosIp,
127 main.ONOSbench.user_name)
128
129 main.step( "Apply cell to environment" )
130 cellResult = main.ONOSbench.setCell( "temp" )
131 verifyResult = main.ONOSbench.verifyCell()
132 stepResult = cellResult and verifyResult
133 utilities.assert_equals( expect=main.TRUE,
134 actual=stepResult,
135 onpass="Successfully applied cell to " + \
136 "environment",
137 onfail="Failed to apply cell to environment " )
138
139 main.step( "Creating ONOS package" )
140 main.ONOSbench.handle.sendline( "cp ~/TestON/tests/USECASE_SegmentRouting/2x2.json ~/onos/tools/package/config/network-cfg.json")
141 packageResult = main.ONOSbench.onosPackage()
142 stepResult = packageResult
143 utilities.assert_equals( expect=main.TRUE,
144 actual=stepResult,
145 onpass="Successfully created ONOS package",
146 onfail="Failed to create ONOS package" )
147
148 time.sleep( main.startUpSleep )
149 main.step( "Installing ONOS package" )
150 onosInstallResult = main.TRUE
151 for i in range( main.numCtrls ):
152 onosInstallResult = onosInstallResult and \
153 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
154 stepResult = onosInstallResult
155 utilities.assert_equals( expect=main.TRUE,
156 actual=stepResult,
157 onpass="Successfully installed ONOS package",
158 onfail="Failed to install ONOS package" )
159
160 main.step( "Starting ONOS service" )
161 stopResult = main.TRUE
162 startResult = main.TRUE
163 onosIsUp = main.TRUE
164
165 for i in range( main.numCtrls ):
166 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
167 if onosIsUp == main.TRUE:
168 main.log.report( "ONOS instance is up and ready" )
169 else:
170 main.log.report( "ONOS instance may not be up, stop and " +
171 "start ONOS again " )
172 for i in range( main.numCtrls ):
173 stopResult = stopResult and \
174 main.ONOSbench.onosStop( main.ONOSip[ i ] )
175 for i in range( main.numCtrls ):
176 startResult = startResult and \
177 main.ONOSbench.onosStart( main.ONOSip[ i ] )
178 stepResult = onosIsUp and stopResult and startResult
179 utilities.assert_equals( expect=main.TRUE,
180 actual=stepResult,
181 onpass="ONOS service is ready",
182 onfail="ONOS service did not start properly" )
183 time.sleep( main.startUpSleep )
184
185 def CASE9( self, main ):
186 '''
187 Report errors/warnings/exceptions
188 '''
189 #main.ONOSbench.logReport( main.ONOSip[ 0 ],
190 # [ "INFO" ],
191 # "a" )
192 #main.log.info("Error report: \n" )
193 main.ONOSbench.logReport( main.ONOSip[ 0 ],
194 [ "INFO",
195 "FOLLOWER",
196 "WARN",
197 "flow",
198 "ERROR",
199 "Except" ],
200 "s" )
201
202
203 def CASE11( self, main ):
204 """
205 Start mininet
206 """
207 main.log.report( "Start Mininet topology" )
208 main.log.case( "Start Mininet topology" )
209
210 main.step( "Starting Mininet Topology" )
211 topoResult = main.Mininet1.startNet( topoFile= main.dependencyPath + main.topology, args="--onos 1" )
212 stepResult = topoResult
213 utilities.assert_equals( expect=main.TRUE,
214 actual=stepResult,
215 onpass="Successfully loaded topology",
216 onfail="Failed to load topology" )
217 # Exit if topology did not load properly
218 if not topoResult:
219 main.cleanup()
220 main.exit()
221 main.step("Waiting for switch initialization and configuration")
222 time.sleep( main.startUpSleep )
223 pa = main.Mininet1.pingall()
224 utilities.assert_equals( expect=main.TRUE, actual=pa,
225 onpass="Full connectivity successfully tested",
226 onfail="Full connectivity failed" )
227 # cleanup mininet
228 main.CLIs[0].logout()
229 main.ONOSbench.onosStop( main.ONOSip[0] )
230 main.Mininet1.stopNet()
231 main.Mininet1.disconnect()
232
233
234
235
236