1
2
3
4
6
9
11 import time
12 import os
13 import imp
14 import re
15
16 """
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
31 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
32 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
33 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
34 gitBranch = main.params[ 'GIT' ][ 'branch' ]
35 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 = {}
45 main.CLIs = []
46 main.ONOSip = []
47
48 main.ONOSip = main.ONOSbench.getOnosIps()
49 print main.ONOSip
50
51
52 for i in range( 1, main.maxNodes + 1 ):
53 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
54
55
56 main.startUp = imp.load_source( wrapperFile1,
57 main.dependencyPath +
58 wrapperFile1 +
59 ".py" )
60
61 copyResult = main.ONOSbench.copyMininetFile( main.topology,
62 main.dependencyPath,
63 main.Mininet1.user_name,
64 main.Mininet1.ip_address )
65 if main.CLIs:
66 stepResult = main.TRUE
67 else:
68 main.log.error( "Did not properly created list of ONOS CLI handle" )
69 stepResult = main.FALSE
70
71 utilities.assert_equals( expect=main.TRUE,
72 actual=stepResult,
73 onpass="Successfully construct " +
74 "test variables ",
75 onfail="Failed to construct test variables" )
76
77 if gitPull == 'True':
78 main.step( "Building ONOS in " + gitBranch + " branch" )
79 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
80 stepResult = onosBuildResult
81 utilities.assert_equals( expect=main.TRUE,
82 actual=stepResult,
83 onpass="Successfully compiled " +
84 "latest ONOS",
85 onfail="Failed to compile " +
86 "latest ONOS" )
87 else:
88 main.log.warn( "Did not pull new code so skipping mvn " +
89 "clean install" )
90
92 """
93 - Set up cell
94 - Create cell file
95 - Set cell file
96 - Verify cell file
97 - Kill ONOS process
98 - Uninstall ONOS cluster
99 - Verify ONOS start up
100 - Install ONOS cluster
101 - Connect to cli
102 """
103
104
105 main.numCtrls = int( main.scale[ 0 ] )
106
107 main.case( "Starting up " + str( main.numCtrls ) +
108 " node(s) ONOS cluster" )
109
110
111 main.log.info( "Safety check, killing all ONOS processes" +
112 " before initiating enviornment setup" )
113
114 for i in range( main.maxNodes ):
115 main.ONOSbench.onosDie( main.ONOSip[ i ] )
116
117 print "NODE COUNT = ", main.numCtrls
118
119 tempOnosIp = []
120 for i in range( main.numCtrls ):
121 tempOnosIp.append( main.ONOSip[i] )
122
123 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp", main.Mininet1.ip_address, main.apps, tempOnosIp )
124
125 main.step( "Apply cell to environment" )
126 cellResult = main.ONOSbench.setCell( "temp" )
127 verifyResult = main.ONOSbench.verifyCell()
128 stepResult = cellResult and verifyResult
129 utilities.assert_equals( expect=main.TRUE,
130 actual=stepResult,
131 onpass="Successfully applied cell to " + \
132 "environment",
133 onfail="Failed to apply cell to environment " )
134
135 main.step( "Creating ONOS package" )
136 packageResult = main.ONOSbench.onosPackage()
137 stepResult = packageResult
138 utilities.assert_equals( expect=main.TRUE,
139 actual=stepResult,
140 onpass="Successfully created ONOS package",
141 onfail="Failed to create ONOS package" )
142
143 time.sleep( main.startUpSleep )
144 main.step( "Uninstalling ONOS package" )
145 onosUninstallResult = main.TRUE
146 for i in range( main.numCtrls ):
147 onosUninstallResult = onosUninstallResult and \
148 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
149 stepResult = onosUninstallResult
150 utilities.assert_equals( expect=main.TRUE,
151 actual=stepResult,
152 onpass="Successfully uninstalled ONOS package",
153 onfail="Failed to uninstall ONOS package" )
154
155 time.sleep( main.startUpSleep )
156 main.step( "Installing ONOS package" )
157 onosInstallResult = main.TRUE
158 for i in range( main.numCtrls ):
159 onosInstallResult = onosInstallResult and \
160 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
161 stepResult = onosInstallResult
162 utilities.assert_equals( expect=main.TRUE,
163 actual=stepResult,
164 onpass="Successfully installed ONOS package",
165 onfail="Failed to install ONOS package" )
166
167 time.sleep( main.startUpSleep )
168 main.step( "Starting ONOS service" )
169 stopResult = main.TRUE
170 startResult = main.TRUE
171 onosIsUp = main.TRUE
172
173 for i in range( main.numCtrls ):
174 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
175 if onosIsUp == main.TRUE:
176 main.log.report( "ONOS instance is up and ready" )
177 else:
178 main.log.report( "ONOS instance may not be up, stop and " +
179 "start ONOS again " )
180 for i in range( main.numCtrls ):
181 stopResult = stopResult and \
182 main.ONOSbench.onosStop( main.ONOSip[ i ] )
183 for i in range( main.numCtrls ):
184 startResult = startResult and \
185 main.ONOSbench.onosStart( main.ONOSip[ i ] )
186 stepResult = onosIsUp and stopResult and startResult
187 utilities.assert_equals( expect=main.TRUE,
188 actual=stepResult,
189 onpass="ONOS service is ready",
190 onfail="ONOS service did not start properly" )
191
192 main.step( "Start ONOS cli" )
193 cliResult = main.TRUE
194 for i in range( main.numCtrls ):
195 cliResult = cliResult and \
196 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
197 stepResult = cliResult
198 utilities.assert_equals( expect=main.TRUE,
199 actual=stepResult,
200 onpass="Successfully start ONOS cli",
201 onfail="Failed to start ONOS cli" )
202
203
204 main.scale.remove( main.scale[ 0 ] )
205
206 - def CASE9( self, main ):
207 '''
208 Report errors/warnings/exceptions
209 '''
210 main.log.info("Error report: \n" )
211 main.ONOSbench.logReport( main.ONOSip[ 0 ],
212 [ "INFO",
213 "FOLLOWER",
214 "WARN",
215 "flow",
216 "ERROR",
217 "Except" ],
218 "s" )
219
221 """
222 Start mininet
223 """
224 main.log.report( "Start Mininet topology" )
225 main.log.case( "Start Mininet topology" )
226
227 main.step( "Starting Mininet Topology" )
228 topoResult = main.Mininet1.startNet( topoFile=topology )
229 stepResult = topoResult
230 utilities.assert_equals( expect=main.TRUE,
231 actual=stepResult,
232 onpass="Successfully loaded topology",
233 onfail="Failed to load topology" )
234
235 if not topoResult:
236 main.cleanup()
237 main.exit()
238
240 """
241 Test random ONOS command
242 """
243
244 main.CLIs[ 0 ].startOnosCli( main.ONOSip[ 0 ] )
245 print main.CLIs[ 0 ].leaders()
246