blob: 300cc1d2deb53349cf9548b452f55a23571935e2 [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_1node:
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()
27 main.testSetUp.gitPulling()
suibin zhang116647a2016-05-06 16:30:09 -070028
29 def CASE1( self, main ):
30 '''
31 Set up global test variables;
32 Uninstall all running cells in test env defined in .topo file
33
34 '''
Devin Lim58046fa2017-07-05 16:55:00 -070035 try:
36 from tests.dependencies.ONOSSetup import ONOSSetup
37 except ImportError:
38 main.log.error( "ONOSSetup not found. exiting the test" )
39 main.exit()
40 try:
41 main.testSetUp
42 except ( NameError, AttributeError ):
43 main.testSetUp = ONOSSetup()
suibin zhang116647a2016-05-06 16:30:09 -070044
Devin Lim58046fa2017-07-05 16:55:00 -070045 main.testSetUp.envSetupDescription()
46 stepResult = main.FALSE
47 try:
48 main.nodeList = main.params['CASE1']['NodeList'].split(",")
49 main.onosStartupSleep = float( main.params['CASE1']['SleepTimers']['onosStartup'] )
50 main.onosCfgSleep = float( main.params['CASE1']['SleepTimers']['onosCfg'] )
51 main.mnStartupSleep = float( main.params['CASE1']['SleepTimers']['mnStartup'] )
52 main.mnCfgSleep = float( main.params['CASE1']['SleepTimers']['mnCfg'] )
53 main.numCtrls = int( main.params['CASE10']['numNodes'] )
54 stepResult = main.testSetUp.envSetup( includeGitPull=False )
55 except Exception as e:
56 main.testSetUp.envSetupException( e )
57 main.testSetUp.evnSetupConclusion( stepResult )
suibin zhang116647a2016-05-06 16:30:09 -070058
Devin Lim58046fa2017-07-05 16:55:00 -070059
suibin zhang116647a2016-05-06 16:30:09 -070060
suibin zhang116647a2016-05-06 16:30:09 -070061 def CASE2( self, main ):
62 '''
63 Report errors/warnings/exceptions
64 '''
65 main.log.info("Error report: \n" )
You Wangc669d212017-01-25 11:09:48 -080066 main.ONOSbench.logReport( main.ONOSip[0],
suibin zhang116647a2016-05-06 16:30:09 -070067 [ "INFO",
68 "FOLLOWER",
69 "WARN",
70 "flow",
71 "ERROR",
72 "Except" ],
73 "s" )
74
75 def CASE10( self, main ):
76 """
alison12f34c32016-06-10 14:39:21 -070077 Start ONOS cluster (1 node in this example) in three steps:
suibin zhang116647a2016-05-06 16:30:09 -070078 1) start a basic cluster with drivers app via ONOSDriver;
79 2) activate apps via ONOSCliDriver;
80 3) configure onos via ONOSCliDriver;
81 """
82
83 import time
Devin Lim58046fa2017-07-05 16:55:00 -070084 try:
85 from tests.dependencies.ONOSSetup import ONOSSetup
86 except ImportError:
87 main.log.error( "ONOSSetup not found. exiting the test" )
88 main.exit()
89 try:
90 main.testSetUp
91 except ( NameError, AttributeError ):
92 main.testSetUp = ONOSSetup()
You Wangc669d212017-01-25 11:09:48 -080093 main.case( "Start up " + str( main.numCtrls ) + "-node onos cluster.")
suibin zhang116647a2016-05-06 16:30:09 -070094 main.step( "Start ONOS cluster with basic (drivers) app.")
Devin Lim461f0872017-06-05 16:49:33 -070095 stepResult = main.ONOSbench.startBasicONOS( nodeList=main.ONOSip, opSleep=200,
Devin Limdc78e202017-06-09 18:30:07 -070096 onosUser=main.ONOScli1.karafUser )
suibin zhang116647a2016-05-06 16:30:09 -070097 utilities.assert_equals( expect=main.TRUE,
98 actual=stepResult,
99 onpass="Successfully started basic ONOS cluster ",
100 onfail="Failed to start basic ONOS Cluster " )
101
Devin Lim58046fa2017-07-05 16:55:00 -0700102 main.testSetUp.startOnosClis()
suibin zhang116647a2016-05-06 16:30:09 -0700103
104 main.step( "Activate onos apps.")
Devin Lim58046fa2017-07-05 16:55:00 -0700105 main.apps = main.params['CASE10'].get( 'Apps' )
106 if main.apps:
107 main.log.info( "Apps to activate: " + main.apps )
suibin zhang116647a2016-05-06 16:30:09 -0700108 activateResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700109 for a in main.apps.split(","):
suibin zhang116647a2016-05-06 16:30:09 -0700110 activateResult = activateResult & main.ONOScli1.activateApp(a)
111 # TODO: check this worked
112 time.sleep( main.onosCfgSleep ) # wait for apps to activate
113 else:
114 main.log.warn( "No configurations were specified to be changed after startup" )
115 utilities.assert_equals( expect=main.TRUE,
116 actual=activateResult,
117 onpass="Successfully set config",
118 onfail="Failed to set config" )
119
120 main.step( "Set ONOS configurations" )
121 config = main.params['CASE10'].get( 'ONOS_Configuration' )
122 if config:
123 main.log.debug( config )
124 checkResult = main.TRUE
125 for component in config:
126 for setting in config[component]:
127 value = config[component][setting]
128 check = main.ONOScli1.setCfg( component, setting, value )
129 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
130 checkResult = check and checkResult
131 utilities.assert_equals( expect=main.TRUE,
132 actual=checkResult,
133 onpass="Successfully set config",
134 onfail="Failed to set config" )
135 else:
136 main.log.warn( "No configurations were specified to be changed after startup" )
137
138 def CASE11( self, main ):
139 """
140 Start mininet and assign controllers
141 """
142 import time
143
suibin zhang116647a2016-05-06 16:30:09 -0700144 topology = main.params['CASE11']['topo']
145 main.log.report( "Start Mininet topology" )
Jon Hall6509dbf2016-06-21 17:01:17 -0700146 main.case( "Start Mininet topology" )
suibin zhang116647a2016-05-06 16:30:09 -0700147
148 main.step( "Starting Mininet Topology" )
alison12f34c32016-06-10 14:39:21 -0700149 topoResult = main.Mininet1.startNet( mnCmd=topology )
suibin zhang116647a2016-05-06 16:30:09 -0700150 stepResult = topoResult
151 utilities.assert_equals( expect=main.TRUE,
152 actual=stepResult,
153 onpass="Successfully loaded topology",
154 onfail="Failed to load topology" )
155 # Exit if topology did not load properly
156 if not topoResult:
157 main.cleanup()
158 main.exit()
159
160 main.step( "Assign switches to controllers.")
161 assignResult = main.TRUE
suibin zhang116647a2016-05-06 16:30:09 -0700162 for i in range(1, 8):
163 assignResult = assignResult & main.Mininet1.assignSwController( sw="s" + str( i ),
You Wangc669d212017-01-25 11:09:48 -0800164 ip=main.ONOSip,
suibin zhang116647a2016-05-06 16:30:09 -0700165 port='6653' )
166 time.sleep(main.mnCfgSleep)
167 utilities.assert_equals( expect=main.TRUE,
168 actual=stepResult,
169 onpass="Successfully assign switches to controllers",
170 onfail="Failed to assign switches to controllers" )
171
172
173 def CASE12( self, main ):
174 """
175 Tests using through ONOS CLI handles
176 """
177
Jon Hall6509dbf2016-06-21 17:01:17 -0700178 main.case( "Test some onos commands through CLI. ")
suibin zhang116647a2016-05-06 16:30:09 -0700179 main.log.debug( main.ONOScli1.sendline("summary") )
suibin zhangc969ddd2016-05-23 12:01:52 -0700180 main.log.debug( main.ONOScli1.sendline("devices") )
suibin zhang116647a2016-05-06 16:30:09 -0700181
182 def CASE22( self, main ):
183 """
184 Tests using ONOS REST API handles
185 """
186
187 main.case( " Sample tests using ONOS REST API handles. ")
188 main.log.debug( main.ONOSrest1.send("/devices") )
alison12f34c32016-06-10 14:39:21 -0700189 main.log.debug( main.ONOSrest1.apps() )
190
191 def CASE32( self, main ):
192 """
193 Configure fwd app from .param json string with parameter configured.
194 Check if configuration successful
195 Run pingall to check connectivity
196 Check ONOS log for warning/error/exceptions
197 """
198 main.case( "Configure onos-app-fwd and check if configuration successful. " )
199 main.step( "Install reactive forwarding app." )
200 installResults = main.ONOScli1.activateApp( "org.onosproject.fwd" )
201 utilities.assert_equals( expect=main.TRUE, actual=installResults,
202 onpass = "Configure fwd successful", onfail="Configure fwd failed" )
203 main.step( "Run pingall to check connectivity. " )
204 pingResult = main.FALSE
205 passMsg = "Reactive Pingall test passed"
206 pingResult = main.Mininet1.pingall()
207 if not pingResult:
208 main.log.warn( "First pingall failed. Trying again..." )
209 pingResult = main.Mininet1.pingall()
210 passMsg += "on the second try"
211 utilities.assert_equals( expect=main.TRUE, actual=pingResult, onpass=passMsg, onfail= "Reactive Pingall failed, " + "one or more ping pairs failed." )