blob: f2c7062c410d12c1e4baea1e05878bd4b2c0c961 [file] [log] [blame]
kelvin-onlaba0ce3222015-01-27 17:25:15 -08001"""
2Description: This test is an example of a simple single node ONOS test
3
4List of test cases:
5CASE1: Compile ONOS and push it to the test machine
6CASE2: Assign mastership to controller
7CASE3: Pingall
8"""
9class Ping2topoExample:
10
11 def __init__( self ):
12 self.default = ''
13
14 def CASE1( self, main ):
15 """
16 CASE1 is to compile ONOS and push it to the test machines
17
18 Startup sequence:
19 git pull
20 mvn clean install
21 onos-package
22 cell <name>
23 onos-verify-cell
24 onos-install -f
25 onos-wait-for-start
26 """
27 desc = "Testing ping all function on two topology in one test run"
28 main.log.report( desc )
29 main.case( "Setting up test environment" )
30
31 # load some vairables from the params file
32 PULLCODE = False
33 if main.params[ 'Git' ] == 'True':
34 PULLCODE = True
35 cellName = main.params[ 'ENV' ][ 'cellName' ]
36
37 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
38
39 main.step( "Applying cell variable to environment" )
40 cellResult = main.ONOSbench.setCell( cellName )
41 verifyResult = main.ONOSbench.verifyCell()
42
43 main.log.report( "Uninstalling ONOS" )
44 main.ONOSbench.onosUninstall( ONOS1Ip )
45
46 cleanInstallResult = main.TRUE
47 gitPullResult = main.TRUE
48
49 main.step( "Compiling the latest version of ONOS" )
50 if PULLCODE:
51 main.step( "Git checkout and pull master" )
52 main.ONOSbench.gitCheckout( "master" )
53 gitPullResult = main.ONOSbench.gitPull()
54
55 main.step( "Using mvn clean & install" )
56 cleanInstallResult = main.TRUE
57 if gitPullResult == main.TRUE:
58 cleanInstallResult = main.ONOSbench.cleanInstall()
59 else:
60 main.log.warn( "Did not pull new code so skipping mvn " +
61 "clean install" )
62 main.ONOSbench.getVersion( report=True )
63
64 cellResult = main.ONOSbench.setCell( cellName )
65 verifyResult = main.ONOSbench.verifyCell()
66 main.step( "Creating ONOS package" )
67 packageResult = main.ONOSbench.onosPackage()
68
69 main.step( "Installing ONOS package" )
70 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
71 node=ONOS1Ip )
72
73 main.step( "Checking if ONOS is up yet" )
74 for i in range( 2 ):
75 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
76 if onos1Isup:
77 break
78 if not onos1Isup:
79 main.log.report( "ONOS1 didn't start!" )
80
81 # TODO: if it becomes an issue, we can retry this step a few times
82
83 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
84
85 case1Result = ( cleanInstallResult and packageResult and
86 cellResult and verifyResult and
87 onos1InstallResult and
88 onos1Isup and cliResult )
89
90 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
91 onpass="Test startup successful",
92 onfail="Test startup NOT successful" )
93
94 if case1Result == main.FALSE:
95 main.cleanup()
96 main.exit()
97
98 main.step( "Starting Mininet CLI..." )
99 netIsUp = main.Mininet1.startNet()
100 if netIsUp:
101 main.log.info("Mininet CLI is up")
102 else:
103 main.log.info("Mininet CLI is down")
104
105 def CASE2( self, main ):
106 """
107 Assign mastership to controller
108 """
109 import re
110
111 main.log.report( "Assigning switches to controller" )
112 main.case( "Assigning Controller" )
113 main.step( "Assign switches to controller" )
114
115 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
116 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
117
118 for i in range( 1, 14 ):
119 main.Mininet1.assignSwController(
120 sw=str( i ),
121 ip1=ONOS1Ip,
122 port1=ONOS1Port )
123
124 mastershipCheck = main.TRUE
125 for i in range( 1, 14 ):
126 response = main.Mininet1.getSwController( "s" + str( i ) )
127 try:
128 main.log.info( str( response ) )
129 except:
130 main.log.info( repr( response ) )
131 if re.search( "tcp:" + ONOS1Ip, response ):
132 mastershipCheck = mastershipCheck and main.TRUE
133 else:
134 mastershipCheck = main.FALSE
135 if mastershipCheck == main.TRUE:
136 main.log.report( "Switch mastership assigned correctly" )
137 utilities.assert_equals(
138 expect=main.TRUE,
139 actual=mastershipCheck,
140 onpass="Switch mastership assigned correctly",
141 onfail="Switches not assigned correctly to controllers" )
142
143 def CASE3( self, main ):
144 """
145 Assign intents
146 """
147 import time
148
149 main.log.report( "Run Pingall" )
150 main.case( "Run Pingall" )
151
152 # install onos-app-fwd
153 main.log.info( "Install reactive forwarding app" )
154 main.ONOScli1.featureInstall( "onos-app-fwd" )
155
156 # REACTIVE FWD test
157 pingResult = main.FALSE
158 time1 = time.time()
159 pingResult = main.Mininet1.pingall()
160 time2 = time.time()
161 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
162
163 # uninstall onos-app-fwd
164 main.log.info( "Uninstall reactive forwarding app" )
165 main.ONOScli1.featureUninstall( "onos-app-fwd" )
166
167 utilities.assert_equals( expect=main.TRUE, actual=pingResult,
168 onpass="All hosts are reachable",
169 onfail="Some pings failed" )
170
171 def CASE4( self, main):
172 """
173 Stop mininet and start a new one using different topology
174 """
175 main.log.info( "Stopping Mininet..." )
176 main.Mininet1.stopNet()
177
178 main.log.info( "Starting Mininet..." )
179 topoFile = main.params[ 'TOPO1' ][ 'file' ]
180 args = main.params[ 'TOPO1' ][ 'args' ]
181
182 isMnUp = main.FALSE
183 isMnUp = main.Mininet1.startNet(topoFile = topoFile, args = args)
184 utilities.assert_equals(
185 expect=main.TRUE,
186 actual=isMnUp,
187 onpass="New mininet topology is up and runing",
188 onfail="New mininet topology failed to run" )
189
190
191
192 def CASE5( self, main ):
193 """
194 Assign mastership to controller
195 """
196 import re
197
198 main.log.report( "Assigning switches to controller" )
199 main.case( "Assigning Controller" )
200 main.step( "Assign switches to controller" )
201
202 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
203 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
204
205 for i in range( 1, 25 ):
206 main.Mininet1.assignSwController(
207 sw=str( i ),
208 ip1=ONOS1Ip,
209 port1=ONOS1Port )
210
211 mastershipCheck = main.TRUE
212 for i in range( 1, 25 ):
213 response = main.Mininet1.getSwController( "s" + str( i ) )
214 try:
215 main.log.info( str( response ) )
216 except:
217 main.log.info( repr( response ) )
218 if re.search( "tcp:" + ONOS1Ip, response ):
219 mastershipCheck = mastershipCheck and main.TRUE
220 else:
221 mastershipCheck = main.FALSE
222 if mastershipCheck == main.TRUE:
223 main.log.report( "Switch mastership assigned correctly" )
224 utilities.assert_equals(
225 expect=main.TRUE,
226 actual=mastershipCheck,
227 onpass="Switch mastership assigned correctly",
228 onfail="Switches not assigned correctly to controllers" )