blob: 6ac92805b69cb77f0350e7fbf71efbf6a4719168 [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 '''
Devin Lim58046fa2017-07-05 16:55:00 -070018 try:
19 from tests.dependencies.ONOSSetup import ONOSSetup
20 except ImportError:
21 main.log.error( "ONOSSetup not found. exiting the test" )
22 main.exit()
23 try:
24 main.testSetUp
25 except ( NameError, AttributeError ):
26 main.testSetUp = ONOSSetup()
suibin zhang116647a2016-05-06 16:30:09 -070027
Devin Lim58046fa2017-07-05 16:55:00 -070028 main.testSetUp.gitPulling()
suibin zhang116647a2016-05-06 16:30:09 -070029
30
31 def CASE1( self, main ):
32 '''
33 Set up global test variables;
34 Uninstall all running cells in test env defined in .topo file
35
36 '''
Devin Lim58046fa2017-07-05 16:55:00 -070037 try:
38 from tests.dependencies.ONOSSetup import ONOSSetup
39 except ImportError:
40 main.log.error( "ONOSSetup not found. exiting the test" )
41 main.exit()
42 try:
43 main.testSetUp
44 except ( NameError, AttributeError ):
45 main.testSetUp = ONOSSetup()
suibin zhang116647a2016-05-06 16:30:09 -070046
Devin Lim58046fa2017-07-05 16:55:00 -070047 main.testSetUp.envSetupDescription()
48 stepResult = main.FALSE
49 try:
50 main.nodeList = main.params['CASE1']['NodeList'].split(",")
51 main.onosStartupSleep = float(main.params['CASE1']['SleepTimers']['onosStartup'])
52 main.onosCfgSleep = float(main.params['CASE1']['SleepTimers']['onosCfg'])
53 main.mnStartupSleep = float(main.params['CASE1']['SleepTimers']['mnStartup'])
54 main.mnCfgSleep = float(main.params['CASE1']['SleepTimers']['mnCfg'])
55 main.numCtrls = int( main.params['CASE10']['numNodes'] )
56 stepResult = main.testSetUp.envSetup( includeGitPull=False )
57 except Exception as e:
58 main.testSetUp.envSetupException( e )
59 main.testSetUp.evnSetupConclusion( stepResult )
suibin zhang116647a2016-05-06 16:30:09 -070060
suibin zhang116647a2016-05-06 16:30:09 -070061
suibin zhang116647a2016-05-06 16:30:09 -070062 def CASE2( self, main ):
63 '''
64 Report errors/warnings/exceptions
65 '''
66 main.log.info("Error report: \n" )
You Wangc669d212017-01-25 11:09:48 -080067 main.ONOSbench.logReport( main.ONOSip[0],
suibin zhang116647a2016-05-06 16:30:09 -070068 [ "INFO",
69 "FOLLOWER",
70 "WARN",
71 "flow",
72 "ERROR",
73 "Except" ],
74 "s" )
75
76 def CASE10( self, main ):
77 """
78 Start ONOS cluster (3 nodes in this example) in three steps:
79 1) start a basic cluster with drivers app via ONOSDriver;
80 2) activate apps via ONOSCliDriver;
81 3) configure onos via ONOSCliDriver;
82 """
Devin Lim58046fa2017-07-05 16:55:00 -070083 try:
84 from tests.dependencies.ONOSSetup import ONOSSetup
85 except ImportError:
86 main.log.error( "ONOSSetup not found. exiting the test" )
87 main.exit()
88 try:
89 main.testSetUp
90 except ( NameError, AttributeError ):
91 main.testSetUp = ONOSSetup()
suibin zhang116647a2016-05-06 16:30:09 -070092
93 import time
94
You Wangc669d212017-01-25 11:09:48 -080095 main.case( "Start up " + str( main.numCtrls ) + "-node onos cluster.")
suibin zhang116647a2016-05-06 16:30:09 -070096 main.step( "Start ONOS cluster with basic (drivers) app.")
Devin Limdc78e202017-06-09 18:30:07 -070097 stepResult = main.ONOSbench.startBasicONOS( nodeList=main.ONOSip, opSleep=200,
98 onosUser=main.ONOScli1.karafUser )
suibin zhang116647a2016-05-06 16:30:09 -070099 utilities.assert_equals( expect=main.TRUE,
100 actual=stepResult,
101 onpass="Successfully started basic ONOS cluster ",
102 onfail="Failed to start basic ONOS Cluster " )
103
Devin Lim58046fa2017-07-05 16:55:00 -0700104 main.testSetUp.startOnosClis()
suibin zhang116647a2016-05-06 16:30:09 -0700105
106 main.step( "Activate onos apps.")
Devin Lim58046fa2017-07-05 16:55:00 -0700107 main.apps = main.params['CASE10'].get( 'Apps' )
108 if main.apps:
109 main.log.info( "Apps to activate: " + main.apps )
suibin zhang116647a2016-05-06 16:30:09 -0700110 activateResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700111 for a in main.apps.split(","):
suibin zhang116647a2016-05-06 16:30:09 -0700112 activateResult = activateResult & main.ONOScli1.activateApp(a)
113 # TODO: check this worked
114 time.sleep( main.onosCfgSleep ) # wait for apps to activate
115 else:
116 main.log.warn( "No configurations were specified to be changed after startup" )
117 utilities.assert_equals( expect=main.TRUE,
118 actual=activateResult,
119 onpass="Successfully set config",
120 onfail="Failed to set config" )
121
122 main.step( "Set ONOS configurations" )
123 config = main.params['CASE10'].get( 'ONOS_Configuration' )
124 if config:
125 main.log.debug( config )
126 checkResult = main.TRUE
127 for component in config:
128 for setting in config[component]:
129 value = config[component][setting]
130 check = main.ONOScli1.setCfg( component, setting, value )
131 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
132 checkResult = check and checkResult
133 utilities.assert_equals( expect=main.TRUE,
134 actual=checkResult,
135 onpass="Successfully set config",
136 onfail="Failed to set config" )
137 else:
138 main.log.warn( "No configurations were specified to be changed after startup" )
139
140 def CASE11( self, main ):
141 """
142 Start mininet and assign controllers
143 """
144 import time
145
suibin zhang116647a2016-05-06 16:30:09 -0700146 topology = main.params['CASE11']['topo']
147 main.log.report( "Start Mininet topology" )
Jon Hall6509dbf2016-06-21 17:01:17 -0700148 main.case( "Start Mininet topology" )
suibin zhang116647a2016-05-06 16:30:09 -0700149
150 main.step( "Starting Mininet Topology" )
alison12f34c32016-06-10 14:39:21 -0700151 topoResult = main.Mininet1.startNet(mnCmd=topology )
suibin zhang116647a2016-05-06 16:30:09 -0700152 stepResult = topoResult
153 utilities.assert_equals( expect=main.TRUE,
154 actual=stepResult,
155 onpass="Successfully loaded topology",
156 onfail="Failed to load topology" )
157 # Exit if topology did not load properly
158 if not topoResult:
159 main.cleanup()
160 main.exit()
161
162 main.step( "Assign switches to controllers.")
163 assignResult = main.TRUE
suibin zhang116647a2016-05-06 16:30:09 -0700164 for i in range(1, 8):
165 assignResult = assignResult & main.Mininet1.assignSwController( sw="s" + str( i ),
You Wangc669d212017-01-25 11:09:48 -0800166 ip=main.ONOSip,
suibin zhang116647a2016-05-06 16:30:09 -0700167 port='6653' )
168 time.sleep(main.mnCfgSleep)
169 utilities.assert_equals( expect=main.TRUE,
170 actual=stepResult,
171 onpass="Successfully assign switches to controllers",
172 onfail="Failed to assign switches to controllers" )
173
174
175 def CASE12( self, main ):
176 """
177 Tests using through ONOS CLI handles
178 """
179
Jon Hall6509dbf2016-06-21 17:01:17 -0700180 main.case( "Test some onos commands through CLI. ")
suibin zhang116647a2016-05-06 16:30:09 -0700181 main.log.debug( main.ONOScli1.sendline("summary") )
182 main.log.debug( main.ONOScli3.sendline("devices") )
183
184 def CASE22( self, main ):
185 """
186 Tests using ONOS REST API handles
187 """
188
189 main.case( " Sample tests using ONOS REST API handles. ")
190 main.log.debug( main.ONOSrest1.send("/devices") )
suibin zhangc969ddd2016-05-23 12:01:52 -0700191 main.log.debug( main.ONOSrest2.apps() )
alison12f34c32016-06-10 14:39:21 -0700192
193 def CASE32( self, main ):
194 """
195 Configure fwd app from .params json string with parameter configured
196 Check if configuration successful
197 Run pingall to check connectivity
198 Check ONOS log for warning/error/exceptions
199 """
200 main.case( "Configure onos-app-fwd and check if configuration successful. " )
201 main.step( "Install reactive forwarding app." )
202 installResults = main.ONOScli1.activateApp( "org.onosproject.fwd" )
203 utilities.assert_equals( expect=main.TRUE, actual=installResults,
204 onpass= "Configure fwd successful", onfail= "Configure fwd failed" )
205 main.step( "Run pingall to check connectivity. " )
206 pingResult = main.FALSE
207 passMsg = "Reactive Pingall test passed"
208 pingResult = main.Mininet1.pingall()
209 if not pingResult:
210 main.log.warn("First pingall failed. Trying again...")
211 pingResult = main.Mininet1.pingall()
212 passMsg += "on the second try"
213 utilities.assert_equals( expect=main.TRUE, actual=pingResult, onpass=passMsg, onfail= "Reactive Pingall failed, " + "one or more ping pairs failed" )