blob: ba9a3cc680b0bb633ba28b203a2cbfa061a23eef [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
suibin zhang116647a2016-05-06 16:30:09 -070040 else:
41 main.log.warn( "Skipped pulling onos and Skipped building ONOS" )
42
43
44 def CASE1( self, main ):
45 '''
46 Set up global test variables;
47 Uninstall all running cells in test env defined in .topo file
48
49 '''
50
51 main.case( "Constructing global test variables and clean cluster env." )
52
53 main.step( "Constructing test variables" )
54 main.branch = main.ONOSbench.getBranchName()
55 main.log.info( "Running onos branch: " + main.branch )
56 main.commitNum = main.ONOSbench.getVersion().split(' ')[1]
57 main.log.info( "Running onos commit Number: " + main.commitNum)
58 main.nodeList = main.params['CASE1']['NodeList'].split(",")
59 main.onosStartupSleep = float( main.params['CASE1']['SleepTimers']['onosStartup'] )
60 main.onosCfgSleep = float( main.params['CASE1']['SleepTimers']['onosCfg'] )
61 main.mnStartupSleep = float( main.params['CASE1']['SleepTimers']['mnStartup'] )
62 main.mnCfgSleep = float( main.params['CASE1']['SleepTimers']['mnCfg'] )
You Wangc669d212017-01-25 11:09:48 -080063 main.numCtrls = int( main.params['CASE10']['numNodes'] )
64 main.AllONOSip = main.ONOSbench.getOnosIps()
65 main.ONOSip = []
66 for i in range( main.numCtrls ):
67 main.ONOSip.append( main.AllONOSip[i] )
suibin zhang116647a2016-05-06 16:30:09 -070068 utilities.assert_equals( expect=main.TRUE,
69 actual=main.TRUE,
70 onpass="Successfully construct " +
71 "test variables ",
72 onfail="Failed to construct test variables" )
73
suibin zhang116647a2016-05-06 16:30:09 -070074 def CASE2( self, main ):
75 '''
76 Report errors/warnings/exceptions
77 '''
78 main.log.info("Error report: \n" )
You Wangc669d212017-01-25 11:09:48 -080079 main.ONOSbench.logReport( main.ONOSip[0],
suibin zhang116647a2016-05-06 16:30:09 -070080 [ "INFO",
81 "FOLLOWER",
82 "WARN",
83 "flow",
84 "ERROR",
85 "Except" ],
86 "s" )
87
88 def CASE10( self, main ):
89 """
90 Start ONOS cluster (3 nodes in this example) in three steps:
91 1) start a basic cluster with drivers app via ONOSDriver;
92 2) activate apps via ONOSCliDriver;
93 3) configure onos via ONOSCliDriver;
94 """
95
96 import time
97
You Wangc669d212017-01-25 11:09:48 -080098 main.case( "Start up " + str( main.numCtrls ) + "-node onos cluster.")
suibin zhang116647a2016-05-06 16:30:09 -070099 main.step( "Start ONOS cluster with basic (drivers) app.")
You Wangc669d212017-01-25 11:09:48 -0800100 stepResult = main.ONOSbench.startBasicONOS( nodeList=main.ONOSip, opSleep=200 )
suibin zhang116647a2016-05-06 16:30:09 -0700101 utilities.assert_equals( expect=main.TRUE,
102 actual=stepResult,
103 onpass="Successfully started basic ONOS cluster ",
104 onfail="Failed to start basic ONOS Cluster " )
105
106 main.step( "Establishing Handles on ONOS CLIs.")
107 cliResult = main.TRUE
You Wangc669d212017-01-25 11:09:48 -0800108 for n in range( 1, main.numCtrls + 1 ):
suibin zhang116647a2016-05-06 16:30:09 -0700109 handle = "main.ONOScli" + str( n )
You Wangc669d212017-01-25 11:09:48 -0800110 cliResult = cliResult & ( eval( handle ).startOnosCli( main.ONOSip[ n-1 ] ) )
suibin zhang116647a2016-05-06 16:30:09 -0700111 utilities.assert_equals( expect=main.TRUE,
112 actual=cliResult,
113 onpass="Successfully started onos cli's ",
114 onfail="Failed to start onos cli's " )
115
116 main.step( "Activate onos apps.")
117 apps = main.params['CASE10'].get( 'Apps' )
118 if apps:
119 main.log.info( "Apps to activate: " + apps )
120 activateResult = main.TRUE
121 for a in apps.split(","):
122 activateResult = activateResult & main.ONOScli1.activateApp(a)
123 # TODO: check this worked
124 time.sleep( main.onosCfgSleep ) # wait for apps to activate
125 else:
126 main.log.warn( "No configurations were specified to be changed after startup" )
127 utilities.assert_equals( expect=main.TRUE,
128 actual=activateResult,
129 onpass="Successfully set config",
130 onfail="Failed to set config" )
131
132 main.step( "Set ONOS configurations" )
133 config = main.params['CASE10'].get( 'ONOS_Configuration' )
134 if config:
135 main.log.debug( config )
136 checkResult = main.TRUE
137 for component in config:
138 for setting in config[component]:
139 value = config[component][setting]
140 check = main.ONOScli1.setCfg( component, setting, value )
141 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
142 checkResult = check and checkResult
143 utilities.assert_equals( expect=main.TRUE,
144 actual=checkResult,
145 onpass="Successfully set config",
146 onfail="Failed to set config" )
147 else:
148 main.log.warn( "No configurations were specified to be changed after startup" )
149
150 def CASE11( self, main ):
151 """
152 Start mininet and assign controllers
153 """
154 import time
155
suibin zhang116647a2016-05-06 16:30:09 -0700156 topology = main.params['CASE11']['topo']
157 main.log.report( "Start Mininet topology" )
Jon Hall6509dbf2016-06-21 17:01:17 -0700158 main.case( "Start Mininet topology" )
suibin zhang116647a2016-05-06 16:30:09 -0700159
160 main.step( "Starting Mininet Topology" )
alison12f34c32016-06-10 14:39:21 -0700161 topoResult = main.Mininet1.startNet(mnCmd=topology )
suibin zhang116647a2016-05-06 16:30:09 -0700162 stepResult = topoResult
163 utilities.assert_equals( expect=main.TRUE,
164 actual=stepResult,
165 onpass="Successfully loaded topology",
166 onfail="Failed to load topology" )
167 # Exit if topology did not load properly
168 if not topoResult:
169 main.cleanup()
170 main.exit()
171
172 main.step( "Assign switches to controllers.")
173 assignResult = main.TRUE
suibin zhang116647a2016-05-06 16:30:09 -0700174 for i in range(1, 8):
175 assignResult = assignResult & main.Mininet1.assignSwController( sw="s" + str( i ),
You Wangc669d212017-01-25 11:09:48 -0800176 ip=main.ONOSip,
suibin zhang116647a2016-05-06 16:30:09 -0700177 port='6653' )
178 time.sleep(main.mnCfgSleep)
179 utilities.assert_equals( expect=main.TRUE,
180 actual=stepResult,
181 onpass="Successfully assign switches to controllers",
182 onfail="Failed to assign switches to controllers" )
183
184
185 def CASE12( self, main ):
186 """
187 Tests using through ONOS CLI handles
188 """
189
Jon Hall6509dbf2016-06-21 17:01:17 -0700190 main.case( "Test some onos commands through CLI. ")
suibin zhang116647a2016-05-06 16:30:09 -0700191 main.log.debug( main.ONOScli1.sendline("summary") )
192 main.log.debug( main.ONOScli3.sendline("devices") )
193
194 def CASE22( self, main ):
195 """
196 Tests using ONOS REST API handles
197 """
198
199 main.case( " Sample tests using ONOS REST API handles. ")
200 main.log.debug( main.ONOSrest1.send("/devices") )
suibin zhangc969ddd2016-05-23 12:01:52 -0700201 main.log.debug( main.ONOSrest2.apps() )
alison12f34c32016-06-10 14:39:21 -0700202
203 def CASE32( self, main ):
204 """
205 Configure fwd app from .params json string with parameter configured
206 Check if configuration successful
207 Run pingall to check connectivity
208 Check ONOS log for warning/error/exceptions
209 """
210 main.case( "Configure onos-app-fwd and check if configuration successful. " )
211 main.step( "Install reactive forwarding app." )
212 installResults = main.ONOScli1.activateApp( "org.onosproject.fwd" )
213 utilities.assert_equals( expect=main.TRUE, actual=installResults,
214 onpass= "Configure fwd successful", onfail= "Configure fwd failed" )
215 main.step( "Run pingall to check connectivity. " )
216 pingResult = main.FALSE
217 passMsg = "Reactive Pingall test passed"
218 pingResult = main.Mininet1.pingall()
219 if not pingResult:
220 main.log.warn("First pingall failed. Trying again...")
221 pingResult = main.Mininet1.pingall()
222 passMsg += "on the second try"
223 utilities.assert_equals( expect=main.TRUE, actual=pingResult, onpass=passMsg, onfail= "Reactive Pingall failed, " + "one or more ping pairs failed" )