blob: b6184daa6a5d51ea298518181b845b77d3eaa1c8 [file] [log] [blame]
cameron@onlab.us966d1be2015-05-15 14:54:09 -07001
kelvin-onlabc2b79102015-07-14 11:41:20 -07002# This is a sample template that starts up ONOS cluster, this template
3# is used as a starting script for creating functionality and performance test
cameron@onlab.us966d1be2015-05-15 14:54:09 -07004
Jon Hallf57a5ef2015-07-07 17:56:16 -07005class SAMPstartTemplate:
cameron@onlab.us966d1be2015-05-15 14:54:09 -07006
7 def __init__( self ):
8 self.default = ''
9
kelvin-onlaba4074292015-07-09 15:19:49 -070010 def CASE1( self, main ):
cameron@onlab.us966d1be2015-05-15 14:54:09 -070011 import time
12 import os
kelvin-onlabbf456822015-06-22 16:53:06 -070013 import imp
Jon Hallf632d202015-07-30 15:45:11 -070014 import re
cameron@onlab.us966d1be2015-05-15 14:54:09 -070015
kelvin-onlaba4074292015-07-09 15:19:49 -070016 """
17 - Construct tests variables
18 - GIT ( optional )
19 - Checkout ONOS master branch
20 - Pull latest ONOS code
21 - Building ONOS ( optional )
22 - Install ONOS package
23 - Build ONOS package
24 """
25
26 main.case( "Constructing test variables and building ONOS package" )
27 main.step( "Constructing test variables" )
28 stepResult = main.FALSE
29
30 # Test variables
Jon Hallf632d202015-07-30 15:45:11 -070031 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
kelvin-onlaba4074292015-07-09 15:19:49 -070032 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
33 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
cameron@onlab.us966d1be2015-05-15 14:54:09 -070034 gitBranch = main.params[ 'GIT' ][ 'branch' ]
kelvin-onlaba4074292015-07-09 15:19:49 -070035 main.dependencyPath = main.testOnDirectory + \
36 main.params[ 'DEPENDENCY' ][ 'path' ]
37 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
38 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
39 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
40 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
41 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
42 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
43 gitPull = main.params[ 'GIT' ][ 'pull' ]
44 main.cellData = {} # for creating cell file
cameron@onlab.us966d1be2015-05-15 14:54:09 -070045 main.CLIs = []
kelvin-onlaba4074292015-07-09 15:19:49 -070046 main.ONOSip = []
47
48 main.ONOSip = main.ONOSbench.getOnosIps()
49 print main.ONOSip
50
51 # Assigning ONOS cli handles to a list
52 for i in range( 1, main.maxNodes + 1 ):
cameron@onlab.us966d1be2015-05-15 14:54:09 -070053 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
54
55 # -- INIT SECTION, ONLY RUNS ONCE -- #
kelvin-onlaba4074292015-07-09 15:19:49 -070056 main.startUp = imp.load_source( wrapperFile1,
57 main.dependencyPath +
58 wrapperFile1 +
59 ".py" )
cameron@onlab.us966d1be2015-05-15 14:54:09 -070060
kelvin-onlabd9e23de2015-08-06 10:34:44 -070061 copyResult1 = main.ONOSbench.scp( main.Mininet1,
62 main.dependencyPath +
63 main.topology,
64 main.Mininet1.home,
65 direction="to" )
kelvin-onlaba4074292015-07-09 15:19:49 -070066 if main.CLIs:
67 stepResult = main.TRUE
68 else:
69 main.log.error( "Did not properly created list of ONOS CLI handle" )
70 stepResult = main.FALSE
cameron@onlab.us966d1be2015-05-15 14:54:09 -070071
kelvin-onlaba4074292015-07-09 15:19:49 -070072 utilities.assert_equals( expect=main.TRUE,
73 actual=stepResult,
74 onpass="Successfully construct " +
75 "test variables ",
76 onfail="Failed to construct test variables" )
cameron@onlab.us966d1be2015-05-15 14:54:09 -070077
kelvin-onlaba4074292015-07-09 15:19:49 -070078 if gitPull == 'True':
79 main.step( "Building ONOS in " + gitBranch + " branch" )
80 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
81 stepResult = onosBuildResult
82 utilities.assert_equals( expect=main.TRUE,
83 actual=stepResult,
84 onpass="Successfully compiled " +
85 "latest ONOS",
86 onfail="Failed to compile " +
87 "latest ONOS" )
88 else:
89 main.log.warn( "Did not pull new code so skipping mvn " +
90 "clean install" )
kelvin-onlabbf456822015-06-22 16:53:06 -070091
kelvin-onlaba4074292015-07-09 15:19:49 -070092 def CASE2( self, main ):
93 """
94 - Set up cell
95 - Create cell file
96 - Set cell file
97 - Verify cell file
98 - Kill ONOS process
99 - Uninstall ONOS cluster
100 - Verify ONOS start up
101 - Install ONOS cluster
102 - Connect to cli
103 """
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700104
kelvin-onlaba4074292015-07-09 15:19:49 -0700105 # main.scale[ 0 ] determines the current number of ONOS controller
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700106 main.numCtrls = int( main.scale[ 0 ] )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700107
kelvin-onlaba4074292015-07-09 15:19:49 -0700108 main.case( "Starting up " + str( main.numCtrls ) +
109 " node(s) ONOS cluster" )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700110
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700111 #kill off all onos processes
112 main.log.info( "Safety check, killing all ONOS processes" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800113 " before initiating environment setup" )
kelvin-onlaba4074292015-07-09 15:19:49 -0700114
115 for i in range( main.maxNodes ):
116 main.ONOSbench.onosDie( main.ONOSip[ i ] )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700117
118 print "NODE COUNT = ", main.numCtrls
kelvin-onlaba4074292015-07-09 15:19:49 -0700119
120 tempOnosIp = []
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700121 for i in range( main.numCtrls ):
kelvin-onlaba4074292015-07-09 15:19:49 -0700122 tempOnosIp.append( main.ONOSip[i] )
123
kelvin-onlabd9e23de2015-08-06 10:34:44 -0700124 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
125 "temp",
126 main.Mininet1.ip_address,
127 main.apps,
128 tempOnosIp )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700129
130 main.step( "Apply cell to environment" )
kelvin-onlaba4074292015-07-09 15:19:49 -0700131 cellResult = main.ONOSbench.setCell( "temp" )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700132 verifyResult = main.ONOSbench.verifyCell()
133 stepResult = cellResult and verifyResult
134 utilities.assert_equals( expect=main.TRUE,
135 actual=stepResult,
136 onpass="Successfully applied cell to " + \
137 "environment",
138 onfail="Failed to apply cell to environment " )
139
140 main.step( "Creating ONOS package" )
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
kelvin-onlaba4074292015-07-09 15:19:49 -0700148 time.sleep( main.startUpSleep )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700149 main.step( "Uninstalling ONOS package" )
150 onosUninstallResult = main.TRUE
151 for i in range( main.numCtrls ):
152 onosUninstallResult = onosUninstallResult and \
153 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
154 stepResult = onosUninstallResult
155 utilities.assert_equals( expect=main.TRUE,
156 actual=stepResult,
157 onpass="Successfully uninstalled ONOS package",
158 onfail="Failed to uninstall ONOS package" )
kelvin-onlaba4074292015-07-09 15:19:49 -0700159
160 time.sleep( main.startUpSleep )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700161 main.step( "Installing ONOS package" )
162 onosInstallResult = main.TRUE
163 for i in range( main.numCtrls ):
164 onosInstallResult = onosInstallResult and \
165 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
166 stepResult = onosInstallResult
167 utilities.assert_equals( expect=main.TRUE,
168 actual=stepResult,
169 onpass="Successfully installed ONOS package",
170 onfail="Failed to install ONOS package" )
171
kelvin-onlaba4074292015-07-09 15:19:49 -0700172 time.sleep( main.startUpSleep )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700173 main.step( "Starting ONOS service" )
174 stopResult = main.TRUE
175 startResult = main.TRUE
176 onosIsUp = main.TRUE
kelvin-onlaba4074292015-07-09 15:19:49 -0700177
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700178 for i in range( main.numCtrls ):
179 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
180 if onosIsUp == main.TRUE:
181 main.log.report( "ONOS instance is up and ready" )
182 else:
183 main.log.report( "ONOS instance may not be up, stop and " +
184 "start ONOS again " )
185 for i in range( main.numCtrls ):
186 stopResult = stopResult and \
187 main.ONOSbench.onosStop( main.ONOSip[ i ] )
188 for i in range( main.numCtrls ):
189 startResult = startResult and \
190 main.ONOSbench.onosStart( main.ONOSip[ i ] )
191 stepResult = onosIsUp and stopResult and startResult
192 utilities.assert_equals( expect=main.TRUE,
193 actual=stepResult,
194 onpass="ONOS service is ready",
195 onfail="ONOS service did not start properly" )
kelvin-onlabbf456822015-06-22 16:53:06 -0700196
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700197 main.step( "Start ONOS cli" )
198 cliResult = main.TRUE
199 for i in range( main.numCtrls ):
200 cliResult = cliResult and \
kelvin-onlabbf456822015-06-22 16:53:06 -0700201 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700202 stepResult = cliResult
203 utilities.assert_equals( expect=main.TRUE,
204 actual=stepResult,
205 onpass="Successfully start ONOS cli",
206 onfail="Failed to start ONOS cli" )
kelvin-onlabbf456822015-06-22 16:53:06 -0700207
kelvin-onlaba4074292015-07-09 15:19:49 -0700208 # Remove the first element in main.scale list
209 main.scale.remove( main.scale[ 0 ] )
210
kelvin-onlabbf456822015-06-22 16:53:06 -0700211 def CASE9( self, main ):
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700212 '''
kelvin-onlabbf456822015-06-22 16:53:06 -0700213 Report errors/warnings/exceptions
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700214 '''
kelvin-onlabbf456822015-06-22 16:53:06 -0700215 main.log.info("Error report: \n" )
kelvin-onlaba4074292015-07-09 15:19:49 -0700216 main.ONOSbench.logReport( main.ONOSip[ 0 ],
kelvin-onlabbf456822015-06-22 16:53:06 -0700217 [ "INFO",
218 "FOLLOWER",
219 "WARN",
220 "flow",
221 "ERROR",
222 "Except" ],
223 "s" )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700224
225 def CASE11( self, main ):
226 """
227 Start mininet
228 """
229 main.log.report( "Start Mininet topology" )
230 main.log.case( "Start Mininet topology" )
231
232 main.step( "Starting Mininet Topology" )
Jon Hallc6793552016-01-19 14:18:37 -0800233 topoResult = main.Mininet1.startNet( topoFile=main.dependencyPath + main.topology )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700234 stepResult = topoResult
235 utilities.assert_equals( expect=main.TRUE,
236 actual=stepResult,
237 onpass="Successfully loaded topology",
238 onfail="Failed to load topology" )
239 # Exit if topology did not load properly
240 if not topoResult:
241 main.cleanup()
242 main.exit()
243
kelvin-onlaba4074292015-07-09 15:19:49 -0700244 def CASE12( self, main ):
245 """
246 Test random ONOS command
247 """
248
249 main.CLIs[ 0 ].startOnosCli( main.ONOSip[ 0 ] )
250 print main.CLIs[ 0 ].leaders()
251