blob: 4fcb07409ac461c1db45630c78d3bb2db25425b5 [file] [log] [blame]
kelvin-onlab4ff9cc12015-05-05 11:14:42 -07001
2# Testing the basic functionality of ONOS Next
3# For sanity and driver functionality excercises only.
4
5import time
6import json
7
8time.sleep( 1 )
9
10class SingleFunc:
11
12 def __init__( self ):
13 self.default = ''
14
15 def CASE10( self, main ):
16 import time
17 import os
18 """
19 Startup sequence:
20 cell <name>
21 onos-verify-cell
22 onos-remove-raft-log
23 git pull
24 mvn clean install
25 onos-package
26 onos-install -f
27 onos-wait-for-start
28 """
29 #Local variables
30 cellName = main.params[ 'ENV' ][ 'cellName' ]
31 main.ONOS1ip = os.environ[ 'OC1' ]
32 main.ONOS1port = main.params[ 'CTRL' ][ 'port1' ]
33 main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] )
34 gitBranch = main.params[ 'GIT' ][ 'branch' ]
35 topology = main.params[ 'MININET' ][ 'topo' ]
36 PULLCODE = False
37 if main.params[ 'GIT' ][ 'pull' ] == 'True':
38 PULLCODE = True
39 main.case( "Setting up test environment" )
40
41 main.step( "Apply cell to environment" )
42 cellResult = main.ONOSbench.setCell( cellName )
43 verifyResult = main.ONOSbench.verifyCell()
44 stepResult = cellResult and verifyResult
45 utilities.assert_equals( expect=main.TRUE,
46 actual=stepResult,
47 onpass="Successfully applied cell to " + \
48 "environment",
49 onfail="Failed to apply cell to environment " )
50 """main.step( "Removing raft logs" )
51 removeRaftResult = main.ONOSbench.onosRemoveRaftLogs()
52 stepResult = removeRaftResult
53 utilities.assert_equals( expect=main.TRUE,
54 actual=stepResult,
55 onpass="Successfully removed raft logs",
56 onfail="Failed to remove raft logs" )
57 """
58 if PULLCODE:
59 main.step( "Git checkout and pull " + gitBranch )
60 main.ONOSbench.gitCheckout( gitBranch )
61 gitPullResult = main.ONOSbench.gitPull()
62 if gitPullResult == main.ERROR:
63 main.log.error( "Error pulling git branch" )
64 main.step( "Using mvn clean & install" )
65 cleanInstallResult = main.ONOSbench.cleanInstall()
66 stepResult = cleanInstallResult
67 utilities.assert_equals( expect=main.TRUE,
68 actual=stepResult,
69 onpass="Successfully compiled latest ONOS",
70 onfail="Failed to compile latest ONOS" )
71 else:
72 main.log.warn( "Did not pull new code so skipping mvn " +
73 "clean install" )
74
75 main.step( "Creating ONOS package" )
76 packageResult = main.ONOSbench.onosPackage()
77 stepResult = packageResult
78 utilities.assert_equals( expect=main.TRUE,
79 actual=stepResult,
80 onpass="Successfully created ONOS package",
81 onfail="Failed to create ONOS package" )
82
83 main.step( "Uninstalling ONOS package" )
84 onosUninstallResult = main.ONOSbench.onosUninstall(
85 nodeIp=main.ONOS1ip )
86 stepResult = onosUninstallResult
87 utilities.assert_equals( expect=main.TRUE,
88 actual=stepResult,
89 onpass="Successfully uninstalled ONOS package",
90 onfail="Failed to uninstall ONOS package" )
91 time.sleep( 5 )
92 main.step( "Installing ONOS package" )
93 onosInstallResult = main.ONOSbench.onosInstall( node=main.ONOS1ip )
94 stepResult = onosInstallResult
95 utilities.assert_equals( expect=main.TRUE,
96 actual=stepResult,
97 onpass="Successfully installed ONOS package",
98 onfail="Failed to install ONOS package" )
99
100 main.step( "Starting ONOS service" )
101 stopResult = main.TRUE
102 startResult = main.TRUE
103 onosIsUp = main.ONOSbench.isup()
104 if onosIsUp == main.TRUE:
105 main.log.report( "ONOS instance is up and ready" )
106 else:
107 main.log.report( "ONOS instance may not be up, stop and " +
108 "start ONOS again " )
109 stopResult = main.ONOSbench.onosStop( main.ONOS1ip )
110 startResult = main.ONOSbench.onosStart( main.ONOS1ip )
111 stepResult = onosIsUp and stopResult and startResult
112 utilities.assert_equals( expect=main.TRUE,
113 actual=stepResult,
114 onpass="ONOS service is ready",
115 onfail="ONOS service did not start properly" )
116
117 main.step( "Starting Mininet Topology" )
118 topoResult = main.Mininet1.startNet( topoFile=topology )
119 stepResult = topoResult
120 utilities.assert_equals( expect=main.TRUE,
121 actual=stepResult,
122 onpass="Successfully loaded topology",
123 onfail="Failed to load topology" )
124 # Exit if topology did not load properly
125 if not topoResult:
126 main.cleanup()
127 main.exit()
128
129 main.step( "Start ONOS cli" )
130 cliResult = main.ONOScli1.startOnosCli( ONOSIp=main.ONOS1ip )
131 stepResult = cliResult
132 utilities.assert_equals( expect=main.TRUE,
133 actual=stepResult,
134 onpass="Successfully start ONOS cli",
135 onfail="Failed to start ONOS cli" )
136
137 def CASE11( self, main ):
138 """
139 Assign mastership to controllers
140 """
kelvin-onlab5cbf9992015-05-05 14:34:07 -0700141 import re
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700142 main.log.report( "Assigning switches to controllers" )
143 main.log.case( "Assigning swithes to controllers" )
144
145 main.step( "Assigning switches to controllers" )
146 assignResult = main.TRUE
kelvin-onlab5cbf9992015-05-05 14:34:07 -0700147 for i in range( 1, ( main.numSwitch + 1 ) ):
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700148 main.Mininet1.assignSwController( sw=str( i ),
149 count=1,
kelvin-onlab5cbf9992015-05-05 14:34:07 -0700150 ip1=main.ONOS1ip,
151 port1=main.ONOS1port )
152 for i in range( 1, ( main.numSwitch + 1 ) ):
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700153 response = main.Mininet1.getSwController( "s" + str( i ) )
154 print( "Response is " + str( response ) )
kelvin-onlab5cbf9992015-05-05 14:34:07 -0700155 if re.search( "tcp:" + main.ONOS1ip, response ):
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700156 assignResult = assignResult and main.TRUE
157 else:
158 assignResult = main.FALSE
159 stepResult = assignResult
160 utilities.assert_equals( expect=main.TRUE,
161 actual=stepResult,
162 onpass="Successfully assigned switches" +
163 "to controller",
164 onfail="Failed to assign switches to " +
165 "controller" )
166
kelvin-onlab7c577e82015-05-07 10:45:16 -0700167
168 def CASE1000( self, main ):
169 """
170 Add host intents between 2 host
171 """
172 import time
173 import json
174
175 item = []
176
177 ipv4 = { 'name':'', 'host1':, 'host2': }
178
179 main.case( "Add host intents between 2 host" )
180
181 main.step(" Discover host using arping" )
182
183
184
185 main.step( "Discover host using arping" )
186 step1Result = main.TRUE
187 main.hostMACs = []
188 main.hostId = []
189 #Listing host MAC addresses
190 for i in range( 1 , 7 ):
191 main.hostMACs.append( "00:00:00:00:00:" +
192 str( hex( i )[ 2: ] ).zfill( 2 ).upper() )
193 for macs in main.hostMACs:
194 main.hostId.append( macs + "/-1" )
195 host1 = main.hostId[ 0 ]
196 host2 = main.hostId[ 1 ]
197 # Use arping to discover the hosts
198 main.LincOE2.arping( host = "h1" )
199 main.LincOE2.arping( host = "h2" )
200 time.sleep( 5 )
201 hostsDict = main.ONOS3.hosts()
202 if not len( hostsDict ):
203 step1Result = main.FALSE
204 # Adding host intent
205 utilities.assert_equals(
206 expect=main.TRUE,
207 actual=step1Result,
208 onpass="Hosts discovered",
209 onfail="Failed to discover hosts")
210
211 main.step( "Adding host intents to h1 and h2" )
212 step2Result = main.TRUE
213 intentsId = []
214 intent1 = main.ONOS3.addHostIntent( hostIdOne = host1,
215 hostIdTwo = host2 )
216 intentsId.append( intent1 )
217 time.sleep( 5 )
218 intent2 = main.ONOS3.addHostIntent( hostIdOne = host2,
219 hostIdTwo = host1 )
220 intentsId.append( intent2 )
221 # Checking intents state before pinging
222 main.log.info( "Checking intents state" )
223 time.sleep( 15 )
224 intentResult = main.ONOS3.checkIntentState( intentsId = intentsId )
225 #check intent state again if intents are not in installed state
226 if not intentResult:
227 intentResult = main.ONOS3.checkIntentState( intentsId = intentsId )
228 step2Result = intentResult
229 utilities.assert_equals( expect=main.TRUE,
230 actual=step2Result,
231 onpass="All intents are in INSTALLED state ",
232 onfail="Some of the intents are not in " +
233 "INSTALLED state " )
234
235 # pinging h1 to h2 and then ping h2 to h1
236 main.step( "Pinging h1 and h2" )
237 step3Result = main.TRUE
238 pingResult = main.TRUE
239 pingResult = main.LincOE2.pingHostOptical( src="h1", target="h2" )
240 pingResult = pingResult and main.LincOE2.pingHostOptical( src="h2",
241 target="h1" )
242 step3Result = pingResult
243 utilities.assert_equals( expect=main.TRUE,
244 actual=step3Result,
245 onpass="Pinged successfully between h1 and h2",
246 onfail="Pinged failed between h1 and h2" )
247 # Removed all added host intents
248 main.step( "Removing host intents" )
249 step4Result = main.TRUE
250 removeResult = main.TRUE
251 # Check remaining intents
252 intentsJson = json.loads( main.ONOS3.intents() )
253 main.ONOS3.removeIntent( intentId=intent1, purge=True )
254 main.ONOS3.removeIntent( intentId=intent2, purge=True )
255 for intents in intentsJson:
256 main.ONOS3.removeIntent( intentId=intents.get( 'id' ),
257 app='org.onosproject.optical',
258 purge=True )
259 print json.loads( main.ONOS3.intents() )
260 if len( json.loads( main.ONOS3.intents() ) ):
261 removeResult = main.FALSE
262 step4Result = removeResult
263 utilities.assert_equals( expect=main.TRUE,
264 actual=step4Result,
265 onpass="Successfully removed host intents",
266 onfail="Failed to remove host intents" )
267 case25Result = step1Result and step2Result and step3Result and \
268 step4Result
269 utilities.assert_equals( expect=main.TRUE,
270 actual=case25Result,
271 onpass="Add host intent successful",
272 onfail="Add host intent failed" )