blob: 96d24a9f3c13924b8fdcdc68c214ce77353e0f2e [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
cameron@onlab.us966d1be2015-05-15 14:54:09 -070014
kelvin-onlaba4074292015-07-09 15:19:49 -070015 """
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 = os.path.dirname( os.getcwd ( ) )
31 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
32 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
cameron@onlab.us966d1be2015-05-15 14:54:09 -070033 gitBranch = main.params[ 'GIT' ][ 'branch' ]
kelvin-onlaba4074292015-07-09 15:19:49 -070034 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
cameron@onlab.us966d1be2015-05-15 14:54:09 -070044 main.CLIs = []
kelvin-onlaba4074292015-07-09 15:19:49 -070045 main.ONOSip = []
46
47 main.ONOSip = main.ONOSbench.getOnosIps()
48 print main.ONOSip
49
50 # Assigning ONOS cli handles to a list
51 for i in range( 1, main.maxNodes + 1 ):
cameron@onlab.us966d1be2015-05-15 14:54:09 -070052 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
53
54 # -- INIT SECTION, ONLY RUNS ONCE -- #
kelvin-onlaba4074292015-07-09 15:19:49 -070055 main.startUp = imp.load_source( wrapperFile1,
56 main.dependencyPath +
57 wrapperFile1 +
58 ".py" )
cameron@onlab.us966d1be2015-05-15 14:54:09 -070059
kelvin-onlaba4074292015-07-09 15:19:49 -070060 copyResult = main.ONOSbench.copyMininetFile( main.topology,
61 main.dependencyPath,
62 main.Mininet1.user_name,
63 main.Mininet1.ip_address )
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
cameron@onlab.us966d1be2015-05-15 14:54:09 -070069
kelvin-onlaba4074292015-07-09 15:19:49 -070070 utilities.assert_equals( expect=main.TRUE,
71 actual=stepResult,
72 onpass="Successfully construct " +
73 "test variables ",
74 onfail="Failed to construct test variables" )
cameron@onlab.us966d1be2015-05-15 14:54:09 -070075
kelvin-onlaba4074292015-07-09 15:19:49 -070076 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" )
kelvin-onlabbf456822015-06-22 16:53:06 -070089
kelvin-onlaba4074292015-07-09 15:19:49 -070090 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 """
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700102
kelvin-onlaba4074292015-07-09 15:19:49 -0700103 # main.scale[ 0 ] determines the current number of ONOS controller
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700104 main.numCtrls = int( main.scale[ 0 ] )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700105
kelvin-onlaba4074292015-07-09 15:19:49 -0700106 main.case( "Starting up " + str( main.numCtrls ) +
107 " node(s) ONOS cluster" )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700108
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700109 #kill off all onos processes
110 main.log.info( "Safety check, killing all ONOS processes" +
111 " before initiating enviornment setup" )
kelvin-onlaba4074292015-07-09 15:19:49 -0700112
113 for i in range( main.maxNodes ):
114 main.ONOSbench.onosDie( main.ONOSip[ i ] )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700115
116 print "NODE COUNT = ", main.numCtrls
kelvin-onlaba4074292015-07-09 15:19:49 -0700117
118 tempOnosIp = []
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700119 for i in range( main.numCtrls ):
kelvin-onlaba4074292015-07-09 15:19:49 -0700120 tempOnosIp.append( main.ONOSip[i] )
121
122 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp", main.Mininet1.ip_address, main.apps, tempOnosIp )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700123
124 main.step( "Apply cell to environment" )
kelvin-onlaba4074292015-07-09 15:19:49 -0700125 cellResult = main.ONOSbench.setCell( "temp" )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700126 verifyResult = main.ONOSbench.verifyCell()
127 stepResult = cellResult and verifyResult
128 utilities.assert_equals( expect=main.TRUE,
129 actual=stepResult,
130 onpass="Successfully applied cell to " + \
131 "environment",
132 onfail="Failed to apply cell to environment " )
133
134 main.step( "Creating ONOS package" )
135 packageResult = main.ONOSbench.onosPackage()
136 stepResult = packageResult
137 utilities.assert_equals( expect=main.TRUE,
138 actual=stepResult,
139 onpass="Successfully created ONOS package",
140 onfail="Failed to create ONOS package" )
141
kelvin-onlaba4074292015-07-09 15:19:49 -0700142 time.sleep( main.startUpSleep )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700143 main.step( "Uninstalling ONOS package" )
144 onosUninstallResult = main.TRUE
145 for i in range( main.numCtrls ):
146 onosUninstallResult = onosUninstallResult and \
147 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
148 stepResult = onosUninstallResult
149 utilities.assert_equals( expect=main.TRUE,
150 actual=stepResult,
151 onpass="Successfully uninstalled ONOS package",
152 onfail="Failed to uninstall ONOS package" )
kelvin-onlaba4074292015-07-09 15:19:49 -0700153
154 time.sleep( main.startUpSleep )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700155 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
kelvin-onlaba4074292015-07-09 15:19:49 -0700166 time.sleep( main.startUpSleep )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700167 main.step( "Starting ONOS service" )
168 stopResult = main.TRUE
169 startResult = main.TRUE
170 onosIsUp = main.TRUE
kelvin-onlaba4074292015-07-09 15:19:49 -0700171
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700172 for i in range( main.numCtrls ):
173 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
174 if onosIsUp == main.TRUE:
175 main.log.report( "ONOS instance is up and ready" )
176 else:
177 main.log.report( "ONOS instance may not be up, stop and " +
178 "start ONOS again " )
179 for i in range( main.numCtrls ):
180 stopResult = stopResult and \
181 main.ONOSbench.onosStop( main.ONOSip[ i ] )
182 for i in range( main.numCtrls ):
183 startResult = startResult and \
184 main.ONOSbench.onosStart( main.ONOSip[ i ] )
185 stepResult = onosIsUp and stopResult and startResult
186 utilities.assert_equals( expect=main.TRUE,
187 actual=stepResult,
188 onpass="ONOS service is ready",
189 onfail="ONOS service did not start properly" )
kelvin-onlabbf456822015-06-22 16:53:06 -0700190
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700191 main.step( "Start ONOS cli" )
192 cliResult = main.TRUE
193 for i in range( main.numCtrls ):
194 cliResult = cliResult and \
kelvin-onlabbf456822015-06-22 16:53:06 -0700195 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700196 stepResult = cliResult
197 utilities.assert_equals( expect=main.TRUE,
198 actual=stepResult,
199 onpass="Successfully start ONOS cli",
200 onfail="Failed to start ONOS cli" )
kelvin-onlabbf456822015-06-22 16:53:06 -0700201
kelvin-onlaba4074292015-07-09 15:19:49 -0700202 # Remove the first element in main.scale list
203 main.scale.remove( main.scale[ 0 ] )
204
kelvin-onlabbf456822015-06-22 16:53:06 -0700205 def CASE9( self, main ):
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700206 '''
kelvin-onlabbf456822015-06-22 16:53:06 -0700207 Report errors/warnings/exceptions
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700208 '''
kelvin-onlabbf456822015-06-22 16:53:06 -0700209 main.log.info("Error report: \n" )
kelvin-onlaba4074292015-07-09 15:19:49 -0700210 main.ONOSbench.logReport( main.ONOSip[ 0 ],
kelvin-onlabbf456822015-06-22 16:53:06 -0700211 [ "INFO",
212 "FOLLOWER",
213 "WARN",
214 "flow",
215 "ERROR",
216 "Except" ],
217 "s" )
cameron@onlab.us966d1be2015-05-15 14:54:09 -0700218
219 def CASE11( self, main ):
220 """
221 Start mininet
222 """
223 main.log.report( "Start Mininet topology" )
224 main.log.case( "Start Mininet topology" )
225
226 main.step( "Starting Mininet Topology" )
227 topoResult = main.Mininet1.startNet( topoFile=topology )
228 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
kelvin-onlaba4074292015-07-09 15:19:49 -0700238 def CASE12( self, main ):
239 """
240 Test random ONOS command
241 """
242
243 main.CLIs[ 0 ].startOnosCli( main.ONOSip[ 0 ] )
244 print main.CLIs[ 0 ].leaders()
245