blob: 592c8b244d48b85149784fc0eea7a747b2dddf05 [file] [log] [blame]
suibin zhang116647a2016-05-06 16:30:09 -07001
2# This is a sample template that starts up ONOS cluster, this template
3# can be use as a base script for ONOS System Testing.
4
alison12f34c32016-06-10 14:39:21 -07005class SAMPstartTemplate_3node:
suibin zhang116647a2016-05-06 16:30:09 -07006
7 def __init__( self ):
8 self.default = ''
9
10
11 def CASE0(self, main):
12 '''
alison12f34c32016-06-10 14:39:21 -070013 Pull specific ONOS branch, then Build ONOS on ONOS Bench.
suibin zhang116647a2016-05-06 16:30:09 -070014 This step is usually skipped. Because in a Jenkins driven automated
15 test env. We want Jenkins jobs to pull&build for flexibility to handle
16 different versions of ONOS.
17 '''
18 gitPull = main.params['CASE0']['gitPull']
19 gitBranch = main.params['CASE0']['gitBranch']
20
21 main.case("Pull onos branch and build onos on Teststation.")
22
23 if gitPull == 'True':
24 main.step( "Git Checkout ONOS branch: " + gitBranch)
25 stepResult = main.ONOSbench.gitCheckout( branch = gitBranch )
26 utilities.assert_equals( expect=main.TRUE,
27 actual=stepResult,
28 onpass="Successfully checkout onos branch.",
29 onfail="Failed to checkout onos branch. Exiting test..." )
30 if not stepResult: main.exit()
31
32 main.step( "Git Pull on ONOS branch:" + gitBranch)
33 stepResult = main.ONOSbench.gitPull( )
34 utilities.assert_equals( expect=main.TRUE,
35 actual=stepResult,
36 onpass="Successfully pull onos. ",
37 onfail="Failed to pull onos. Exiting test ..." )
38 if not stepResult: main.exit()
39
40 main.step( "Building ONOS branch: " + gitBranch )
41 stepResult = main.ONOSbench.cleanInstall( skipTest = True )
42 utilities.assert_equals( expect=main.TRUE,
43 actual=stepResult,
44 onpass="Successfully build onos.",
45 onfail="Failed to build onos. Exiting test..." )
46 if not stepResult: main.exit()
47
48 else:
49 main.log.warn( "Skipped pulling onos and Skipped building ONOS" )
50
51
52 def CASE1( self, main ):
53 '''
54 Set up global test variables;
55 Uninstall all running cells in test env defined in .topo file
56
57 '''
58
59 main.case( "Constructing global test variables and clean cluster env." )
60
61 main.step( "Constructing test variables" )
62 main.branch = main.ONOSbench.getBranchName()
63 main.log.info( "Running onos branch: " + main.branch )
64 main.commitNum = main.ONOSbench.getVersion().split(' ')[1]
65 main.log.info( "Running onos commit Number: " + main.commitNum)
66 main.nodeList = main.params['CASE1']['NodeList'].split(",")
67 main.onosStartupSleep = float( main.params['CASE1']['SleepTimers']['onosStartup'] )
68 main.onosCfgSleep = float( main.params['CASE1']['SleepTimers']['onosCfg'] )
69 main.mnStartupSleep = float( main.params['CASE1']['SleepTimers']['mnStartup'] )
70 main.mnCfgSleep = float( main.params['CASE1']['SleepTimers']['mnCfg'] )
71 utilities.assert_equals( expect=main.TRUE,
72 actual=main.TRUE,
73 onpass="Successfully construct " +
74 "test variables ",
75 onfail="Failed to construct test variables" )
76
77
78
79 main.step( "Uninstall all onos nodes in the env.")
80 stepResult = main.TRUE
81 for node in main.nodeList:
82 nodeResult = main.ONOSbench.onosUninstall( nodeIp = "$" + node )
83 stepResult = stepResult & nodeResult
84 utilities.assert_equals( expect=main.TRUE,
85 actual=stepResult,
86 onpass="Successfully uninstall onos on all nodes in env.",
87 onfail="Failed to uninstall onos on all nodes in env!" )
88 if not stepResult:
89 main.log.error( "Failure to clean test env. Exiting test..." )
90 main.exit()
91
92 def CASE2( self, main ):
93 '''
94 Report errors/warnings/exceptions
95 '''
96 main.log.info("Error report: \n" )
97 main.ONOSbench.logReport( main.ONOScli1.ip_address,
98 [ "INFO",
99 "FOLLOWER",
100 "WARN",
101 "flow",
102 "ERROR",
103 "Except" ],
104 "s" )
105
106 def CASE10( self, main ):
107 """
108 Start ONOS cluster (3 nodes in this example) in three steps:
109 1) start a basic cluster with drivers app via ONOSDriver;
110 2) activate apps via ONOSCliDriver;
111 3) configure onos via ONOSCliDriver;
112 """
113
114 import time
115
116 numNodes = int( main.params['CASE10']['numNodes'] )
117 main.case( "Start up " + str( numNodes ) + "-node onos cluster.")
118
119 main.step( "Start ONOS cluster with basic (drivers) app.")
120 onosClusterIPs = []
121 for n in range( 1, numNodes + 1 ):
122 handle = "main.ONOScli" + str( n )
123 onosClusterIPs.append( eval( handle ).ip_address )
124
125 stepResult = main.ONOSbench.startBasicONOS(nodeList = onosClusterIPs, opSleep = 200 )
126 utilities.assert_equals( expect=main.TRUE,
127 actual=stepResult,
128 onpass="Successfully started basic ONOS cluster ",
129 onfail="Failed to start basic ONOS Cluster " )
130
131 main.step( "Establishing Handles on ONOS CLIs.")
132 cliResult = main.TRUE
133 for n in range( 1, numNodes + 1 ):
134 handle = "main.ONOScli" + str( n )
135 cliResult = cliResult & ( eval( handle ).startCellCli() )
136 utilities.assert_equals( expect=main.TRUE,
137 actual=cliResult,
138 onpass="Successfully started onos cli's ",
139 onfail="Failed to start onos cli's " )
140
141 main.step( "Activate onos apps.")
142 apps = main.params['CASE10'].get( 'Apps' )
143 if apps:
144 main.log.info( "Apps to activate: " + apps )
145 activateResult = main.TRUE
146 for a in apps.split(","):
147 activateResult = activateResult & main.ONOScli1.activateApp(a)
148 # TODO: check this worked
149 time.sleep( main.onosCfgSleep ) # wait for apps to activate
150 else:
151 main.log.warn( "No configurations were specified to be changed after startup" )
152 utilities.assert_equals( expect=main.TRUE,
153 actual=activateResult,
154 onpass="Successfully set config",
155 onfail="Failed to set config" )
156
157 main.step( "Set ONOS configurations" )
158 config = main.params['CASE10'].get( 'ONOS_Configuration' )
159 if config:
160 main.log.debug( config )
161 checkResult = main.TRUE
162 for component in config:
163 for setting in config[component]:
164 value = config[component][setting]
165 check = main.ONOScli1.setCfg( component, setting, value )
166 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
167 checkResult = check and checkResult
168 utilities.assert_equals( expect=main.TRUE,
169 actual=checkResult,
170 onpass="Successfully set config",
171 onfail="Failed to set config" )
172 else:
173 main.log.warn( "No configurations were specified to be changed after startup" )
174
175 def CASE11( self, main ):
176 """
177 Start mininet and assign controllers
178 """
179 import time
180
suibin zhang116647a2016-05-06 16:30:09 -0700181 topology = main.params['CASE11']['topo']
182 main.log.report( "Start Mininet topology" )
183 main.log.case( "Start Mininet topology" )
184
185 main.step( "Starting Mininet Topology" )
alison12f34c32016-06-10 14:39:21 -0700186 topoResult = main.Mininet1.startNet(mnCmd=topology )
suibin zhang116647a2016-05-06 16:30:09 -0700187 stepResult = topoResult
188 utilities.assert_equals( expect=main.TRUE,
189 actual=stepResult,
190 onpass="Successfully loaded topology",
191 onfail="Failed to load topology" )
192 # Exit if topology did not load properly
193 if not topoResult:
194 main.cleanup()
195 main.exit()
196
197 main.step( "Assign switches to controllers.")
198 assignResult = main.TRUE
199 onosNodes = [ main.ONOScli1.ip_address, main.ONOScli2.ip_address, main.ONOScli3.ip_address ]
200 for i in range(1, 8):
201 assignResult = assignResult & main.Mininet1.assignSwController( sw="s" + str( i ),
202 ip=onosNodes,
203 port='6653' )
204 time.sleep(main.mnCfgSleep)
205 utilities.assert_equals( expect=main.TRUE,
206 actual=stepResult,
207 onpass="Successfully assign switches to controllers",
208 onfail="Failed to assign switches to controllers" )
209
210
211 def CASE12( self, main ):
212 """
213 Tests using through ONOS CLI handles
214 """
215
216 main.log.case( "Test some onos commands through CLI. ")
217 main.log.debug( main.ONOScli1.sendline("summary") )
218 main.log.debug( main.ONOScli3.sendline("devices") )
219
220 def CASE22( self, main ):
221 """
222 Tests using ONOS REST API handles
223 """
224
225 main.case( " Sample tests using ONOS REST API handles. ")
226 main.log.debug( main.ONOSrest1.send("/devices") )
suibin zhangc969ddd2016-05-23 12:01:52 -0700227 main.log.debug( main.ONOSrest2.apps() )
alison12f34c32016-06-10 14:39:21 -0700228
229 def CASE32( self, main ):
230 """
231 Configure fwd app from .params json string with parameter configured
232 Check if configuration successful
233 Run pingall to check connectivity
234 Check ONOS log for warning/error/exceptions
235 """
236 main.case( "Configure onos-app-fwd and check if configuration successful. " )
237 main.step( "Install reactive forwarding app." )
238 installResults = main.ONOScli1.activateApp( "org.onosproject.fwd" )
239 utilities.assert_equals( expect=main.TRUE, actual=installResults,
240 onpass= "Configure fwd successful", onfail= "Configure fwd failed" )
241 main.step( "Run pingall to check connectivity. " )
242 pingResult = main.FALSE
243 passMsg = "Reactive Pingall test passed"
244 pingResult = main.Mininet1.pingall()
245 if not pingResult:
246 main.log.warn("First pingall failed. Trying again...")
247 pingResult = main.Mininet1.pingall()
248 passMsg += "on the second try"
249 utilities.assert_equals( expect=main.TRUE, actual=pingResult, onpass=passMsg, onfail= "Reactive Pingall failed, " + "one or more ping pairs failed" )