blob: 31678fe3d0bf93a92aa38acb2eea271bd96a5566 [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' ]
Jon Hall53c5e662016-04-13 16:06:56 -070034 main.dependencyPath = os.path.dirname( main.testFile ) + "/dependencies/"
Flavio Castrocc38a542016-03-03 13:15:46 -080035 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
Flavio Castro4cd37c12016-03-28 07:39:16 -070036 #main.json = ["4x4"]
37 main.json = ["2x2", "2x2"]
38 main.args = [" ", " "]
39 #main.args = [" --spine 4 --leaf 4 "]
Flavio Castrocc38a542016-03-03 13:15:46 -080040 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
41 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
42 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
43 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
44 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
45 gitPull = main.params[ 'GIT' ][ 'pull' ]
46 main.cellData = {} # for creating cell file
47 main.CLIs = []
48 main.ONOSip = []
49
50 main.ONOSip = main.ONOSbench.getOnosIps()
51
52 # Assigning ONOS cli handles to a list
53 for i in range( 1, main.maxNodes + 1 ):
54 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
55
56 # -- INIT SECTION, ONLY RUNS ONCE -- #
57 main.startUp = imp.load_source( wrapperFile1,
58 main.dependencyPath +
59 wrapperFile1 +
60 ".py" )
61
62 copyResult1 = main.ONOSbench.scp( main.Mininet1,
63 main.dependencyPath +
64 main.topology,
65 main.Mininet1.home,
66 direction="to" )
67 if main.CLIs:
68 stepResult = main.TRUE
69 else:
70 main.log.error( "Did not properly created list of ONOS CLI handle" )
71 stepResult = main.FALSE
72
73 utilities.assert_equals( expect=main.TRUE,
74 actual=stepResult,
75 onpass="Successfully construct " +
76 "test variables ",
77 onfail="Failed to construct test variables" )
78
79 if gitPull == 'True':
80 main.step( "Building ONOS in " + gitBranch + " branch" )
81 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
82 stepResult = onosBuildResult
83 utilities.assert_equals( expect=main.TRUE,
84 actual=stepResult,
85 onpass="Successfully compiled " +
86 "latest ONOS",
87 onfail="Failed to compile " +
88 "latest ONOS" )
89 else:
90 main.log.warn( "Did not pull new code so skipping mvn " +
91 "clean install" )
Flavio Castro4cd37c12016-03-28 07:39:16 -070092
Flavio Castrocc38a542016-03-03 13:15:46 -080093 def CASE2( self, main ):
94 """
95 - Set up cell
96 - Create cell file
97 - Set cell file
98 - Verify cell file
99 - Kill ONOS process
100 - Uninstall ONOS cluster
101 - Verify ONOS start up
102 - Install ONOS cluster
103 - Connect to cli
104 """
105
106 # main.scale[ 0 ] determines the current number of ONOS controller
107 main.numCtrls = int( main.scale[ 0 ] )
108
Flavio Castro4cd37c12016-03-28 07:39:16 -0700109 main.case( "Package and start ONOS")
Flavio Castrocc38a542016-03-03 13:15:46 -0800110
111 #kill off all onos processes
112 main.log.info( "Safety check, killing all ONOS processes" +
113 " before initiating environment setup" )
114
115 for i in range( main.maxNodes ):
116 main.ONOSbench.onosDie( main.ONOSip[ i ] )
117
118 print "NODE COUNT = ", main.numCtrls
119
120 tempOnosIp = []
121 for i in range( main.numCtrls ):
122 tempOnosIp.append( main.ONOSip[i] )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700123 apps=main.apps
124 if main.diff:
125 apps = main.apps+","+main.diff.pop(0)
126 else: main.log.error( "App list is empty" )
Jon Hall5c526d12016-03-08 08:54:46 -0800127 onosUser = main.params[ 'ENV' ][ 'cellUser' ]
Flavio Castrocc38a542016-03-03 13:15:46 -0800128 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
129 "temp",
130 main.Mininet1.ip_address,
Flavio Castro4cd37c12016-03-28 07:39:16 -0700131 apps,
Jon Hall503aa472016-04-05 10:52:29 -0700132 tempOnosIp )
Flavio Castrocc38a542016-03-03 13:15:46 -0800133
134 main.step( "Apply cell to environment" )
135 cellResult = main.ONOSbench.setCell( "temp" )
136 verifyResult = main.ONOSbench.verifyCell()
137 stepResult = cellResult and verifyResult
138 utilities.assert_equals( expect=main.TRUE,
139 actual=stepResult,
140 onpass="Successfully applied cell to " + \
141 "environment",
142 onfail="Failed to apply cell to environment " )
143
144 main.step( "Creating ONOS package" )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700145 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 -0800146 packageResult = main.ONOSbench.onosPackage()
147 stepResult = packageResult
148 utilities.assert_equals( expect=main.TRUE,
149 actual=stepResult,
150 onpass="Successfully created ONOS package",
151 onfail="Failed to create ONOS package" )
152
153 time.sleep( main.startUpSleep )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700154
Flavio Castrocc38a542016-03-03 13:15:46 -0800155 main.step( "Installing ONOS package" )
156 onosInstallResult = main.TRUE
157 for i in range( main.numCtrls ):
158 onosInstallResult = onosInstallResult and \
159 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
160 stepResult = onosInstallResult
161 utilities.assert_equals( expect=main.TRUE,
162 actual=stepResult,
163 onpass="Successfully installed ONOS package",
164 onfail="Failed to install ONOS package" )
165
166 main.step( "Starting ONOS service" )
167 stopResult = main.TRUE
168 startResult = main.TRUE
169 onosIsUp = main.TRUE
170
171 for i in range( main.numCtrls ):
172 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
173 if onosIsUp == main.TRUE:
174 main.log.report( "ONOS instance is up and ready" )
175 else:
176 main.log.report( "ONOS instance may not be up, stop and " +
177 "start ONOS again " )
178 for i in range( main.numCtrls ):
179 stopResult = stopResult and \
180 main.ONOSbench.onosStop( main.ONOSip[ i ] )
181 for i in range( main.numCtrls ):
182 startResult = startResult and \
183 main.ONOSbench.onosStart( main.ONOSip[ i ] )
184 stepResult = onosIsUp and stopResult and startResult
185 utilities.assert_equals( expect=main.TRUE,
186 actual=stepResult,
187 onpass="ONOS service is ready",
188 onfail="ONOS service did not start properly" )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700189 time.sleep( 2*main.startUpSleep )
Flavio Castrocc38a542016-03-03 13:15:46 -0800190
191 def CASE9( self, main ):
192 '''
193 Report errors/warnings/exceptions
194 '''
Flavio Castro4cd37c12016-03-28 07:39:16 -0700195 main.log.case( "Logging test" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800196 #main.ONOSbench.logReport( main.ONOSip[ 0 ],
197 # [ "INFO" ],
198 # "a" )
199 #main.log.info("Error report: \n" )
200 main.ONOSbench.logReport( main.ONOSip[ 0 ],
201 [ "INFO",
202 "FOLLOWER",
203 "WARN",
204 "flow",
205 "ERROR",
206 "Except" ],
207 "s" )
208
Flavio Castrocc38a542016-03-03 13:15:46 -0800209 def CASE11( self, main ):
210 """
211 Start mininet
212 """
Flavio Castro4cd37c12016-03-28 07:39:16 -0700213 main.log.case( "Start Leaf-Spine 2x2 Mininet Topology" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800214 main.log.report( "Start Mininet topology" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800215
216 main.step( "Starting Mininet Topology" )
Flavio Castro4cd37c12016-03-28 07:39:16 -0700217 args,topo=" "," "
218 #if main.topology:
219 # topo = main.topology.pop(0)
220 #else: main.log.error( "Topo list is empty" )
221 if main.args:
222 args = "--onos 1 " + main.args.pop(0)
223 else: main.log.error( "Argument list is empty" )
224
225 topoResult = main.Mininet1.startNet( topoFile= main.dependencyPath + main.topology, args=args )
Flavio Castrocc38a542016-03-03 13:15:46 -0800226 stepResult = topoResult
227 utilities.assert_equals( expect=main.TRUE,
228 actual=stepResult,
229 onpass="Successfully loaded topology",
230 onfail="Failed to load topology" )
231 # Exit if topology did not load properly
232 if not topoResult:
233 main.cleanup()
234 main.exit()
235 main.step("Waiting for switch initialization and configuration")
Flavio Castro4cd37c12016-03-28 07:39:16 -0700236 time.sleep( 3*main.startUpSleep)
Flavio Castrocc38a542016-03-03 13:15:46 -0800237 pa = main.Mininet1.pingall()
238 utilities.assert_equals( expect=main.TRUE, actual=pa,
239 onpass="Full connectivity successfully tested",
240 onfail="Full connectivity failed" )
241 # cleanup mininet
Flavio Castrocc38a542016-03-03 13:15:46 -0800242 main.ONOSbench.onosStop( main.ONOSip[0] )
243 main.Mininet1.stopNet()
Flavio Castrocc38a542016-03-03 13:15:46 -0800244
245
246
247
248