blob: 00c58c5a4e3cfaa7d862d094114b4d497a87d16c [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070021"""
You Wangdb927a52016-02-26 11:03:28 -080022This file contains classes for CHOTestMonkey that are related to application event
23Author: you@onlab.us
24"""
25from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event
26
Jon Hall2bb3e212017-05-24 17:07:25 -070027
You Wangdb927a52016-02-26 11:03:28 -080028class ONOSEvent( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -070029
You Wangdb927a52016-02-26 11:03:28 -080030 def __init__( self ):
31 Event.__init__( self )
32 self.ONOSIndex = -1
33
34 def startEvent( self, args ):
35 with self.eventLock:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070036 # main.log.info( "%s - starting event" % ( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -080037 result = EventStates().PASS
38 if self.typeIndex == EventType().ONOS_ONOS_DOWN or self.typeIndex == EventType().ONOS_ONOS_UP:
39 if len( args ) < 1:
40 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
41 result = EventStates().ABORT
42 elif len( args ) > 1:
43 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
44 result = EventStates().ABORT
45 else:
46 index = int( args[ 0 ] )
Devin Lim142b5342017-07-20 15:22:39 -070047 if index < 1 or index > int( main.Cluster.numCtrls ):
You Wangdb927a52016-02-26 11:03:28 -080048 main.log.warn( "%s - invalid argument: %s" % ( self.typeString, index ) )
49 result = EventStates().ABORT
50 else:
51 self.ONOSIndex = index
52 result = self.startONOSEvent()
53 return result
54
Jon Hall2bb3e212017-05-24 17:07:25 -070055
You Wangdb927a52016-02-26 11:03:28 -080056class ONOSDown( ONOSEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070057
You Wangdb927a52016-02-26 11:03:28 -080058 def __init__( self ):
59 ONOSEvent.__init__( self )
60 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -070061 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -080062
63 def startONOSEvent( self ):
64 assert self.ONOSIndex != -1
65 with main.variableLock:
66 if not main.controllers[ self.ONOSIndex - 1 ].isUp():
67 main.log.warn( "ONOS Down - ONOS already down" )
68 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -070069 main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) )
You Wangdb927a52016-02-26 11:03:28 -080070 with main.ONOSbenchLock:
You Wang7d14d642019-01-23 15:10:08 -080071 result = main.ONOSbench.onosDie( main.controllers[ self.ONOSIndex - 1 ].ip )
You Wangdb927a52016-02-26 11:03:28 -080072 if not result:
73 main.log.warn( "%s - failed to bring down ONOS" % ( self.typeString ) )
74 return EventStates().FAIL
75 with main.variableLock:
76 main.controllers[ self.ONOSIndex - 1 ].bringDown()
77 return EventStates().PASS
78
Jon Hall2bb3e212017-05-24 17:07:25 -070079
You Wangdb927a52016-02-26 11:03:28 -080080class ONOSUp( ONOSEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070081
You Wangdb927a52016-02-26 11:03:28 -080082 def __init__( self ):
83 ONOSEvent.__init__( self )
84 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -070085 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -080086
87 def startONOSEvent( self ):
88 assert self.ONOSIndex != -1
89 with main.variableLock:
90 if main.controllers[ self.ONOSIndex - 1 ].isUp():
91 main.log.warn( "ONOS Up - ONOS already up" )
92 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -070093 main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) )
You Wangdb927a52016-02-26 11:03:28 -080094 with main.ONOSbenchLock:
95 startResult = main.ONOSbench.onosStart( main.controllers[ self.ONOSIndex - 1 ].ip )
96 if not startResult:
97 main.log.warn( "%s - failed to bring up ONOS" % ( self.typeString ) )
98 return EventStates().FAIL
99 else:
100 ONOSState = main.ONOSbench.isup( main.controllers[ self.ONOSIndex - 1 ].ip )
101 if not ONOSState:
102 main.log.warn( "%s - ONOS is not up" % ( self.typeString ) )
103 return EventStates().FAIL
104 else:
105 cliResult = main.controllers[ self.ONOSIndex - 1 ].startCLI()
106 if not cliResult:
107 main.log.warn( "%s - failed to start ONOS cli" % ( self.typeString ) )
108 return EventStates().FAIL
109 else:
110 with main.variableLock:
111 main.controllers[ self.ONOSIndex - 1 ].bringUp()
112 return EventStates().PASS
113
Jon Hall2bb3e212017-05-24 17:07:25 -0700114
You Wangdb927a52016-02-26 11:03:28 -0800115class CfgEvent( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700116
You Wangdb927a52016-02-26 11:03:28 -0800117 def __init__( self ):
118 Event.__init__( self )
119 self.component = ''
120 self.propName = ''
121 self.value = ''
122
123 def startEvent( self, args ):
124 with self.eventLock:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700125 # main.log.info( "%s - starting event" % ( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800126 result = self.startCfgEvent( args )
127 return result
128
Jon Hall2bb3e212017-05-24 17:07:25 -0700129
You Wangdb927a52016-02-26 11:03:28 -0800130class SetCfg( CfgEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700131
You Wangdb927a52016-02-26 11:03:28 -0800132 def __init__( self ):
133 CfgEvent.__init__( self )
134 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700135 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800136
137 def startCfgEvent( self, args ):
138 if len( args ) < 3:
139 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
140 return EventStates().ABORT
141 elif len( args ) > 3:
142 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
143 return EventStates().ABORT
144 else:
145 self.component = str( args[ 0 ] )
146 self.propName = str( args[ 1 ] )
147 self.value = str( args[ 2 ] )
148 assert self.component != '' and self.propName != '' and self.value != ''
149 index = -1
150 for controller in main.controllers:
151 if controller.isUp():
152 index = controller.index
153 if index == -1:
Jon Hall2bb3e212017-05-24 17:07:25 -0700154 main.log.warn( "%s - No available controllers" % s( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800155 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700156 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) )
You Wangdb927a52016-02-26 11:03:28 -0800157 controller = main.controllers[ index - 1 ]
158 with controller.CLILock:
159 result = controller.CLI.setCfg( component=self.component,
160 propName=self.propName,
161 value=self.value )
162 if not result:
163 main.log.warn( "%s - failed to set configuration" % ( self.typeString ) )
164 return EventStates().FAIL
165 return EventStates().PASS
166
Jon Hall2bb3e212017-05-24 17:07:25 -0700167
You Wangdb927a52016-02-26 11:03:28 -0800168class SetFlowObj( CfgEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700169
You Wangdb927a52016-02-26 11:03:28 -0800170 def __init__( self ):
171 CfgEvent.__init__( self )
172 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700173 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800174
175 def startCfgEvent( self, args ):
176 if len( args ) < 1:
177 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
178 return EventStates().ABORT
179 elif len( args ) > 1:
180 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
181 return EventStates().ABORT
182 elif args[ 0 ] != 'true' and args[ 0 ] != 'false':
183 main.log.warn( "%s - Invalid arguments: %s" % ( self.typeString, args ) )
184 return EventStates().ABORT
185 else:
186 self.component = 'org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator'
187 self.propName = 'useFlowObjectives'
188 self.value = str( args[ 0 ] )
189 index = -1
190 for controller in main.controllers:
191 if controller.isUp():
192 index = controller.index
193 if index == -1:
Jon Hall2bb3e212017-05-24 17:07:25 -0700194 main.log.warn( "%s - No available controllers" % s( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800195 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700196 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) )
You Wangdb927a52016-02-26 11:03:28 -0800197 controller = main.controllers[ index - 1 ]
198 with controller.CLILock:
199 result = controller.CLI.setCfg( component=self.component,
200 propName=self.propName,
201 value=self.value )
202 if not result:
203 main.log.warn( "%s - failed to set configuration" % ( self.typeString ) )
204 return EventStates().FAIL
You Wangb1665b52019-02-01 15:49:48 -0800205 main.flowObj = True if self.value == 'true' else False
You Wangdb927a52016-02-26 11:03:28 -0800206 return EventStates().PASS
207
Jon Hall2bb3e212017-05-24 17:07:25 -0700208
You Wangdb927a52016-02-26 11:03:28 -0800209class BalanceMasters( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700210
You Wangdb927a52016-02-26 11:03:28 -0800211 def __init__( self ):
212 Event.__init__( self )
213 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700214 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800215
216 def startEvent( self, args=None ):
217 with self.eventLock:
218 main.log.info( "%s - starting event" % ( self.typeString ) )
219 index = -1
220 for controller in main.controllers:
221 if controller.isUp():
222 index = controller.index
223 if index == -1:
Jon Hall2bb3e212017-05-24 17:07:25 -0700224 main.log.warn( "%s - No available controllers" % s( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800225 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700226 main.log.info( "Event recorded: {} {}".format( self.typeIndex, self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800227 controller = main.controllers[ index - 1 ]
228 with controller.CLILock:
229 result = controller.CLI.balanceMasters()
230 if not result:
231 main.log.warn( "%s - failed to balance masters" % ( self.typeString ) )
232 return EventStates().FAIL
233 return EventStates().PASS
234
Jon Hall2bb3e212017-05-24 17:07:25 -0700235
You Wang106d0fa2017-05-15 17:22:15 -0700236class SetFlowObjCompiler( CfgEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700237
You Wang106d0fa2017-05-15 17:22:15 -0700238 def __init__( self ):
239 CfgEvent.__init__( self )
240 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700241 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wang106d0fa2017-05-15 17:22:15 -0700242
243 def startCfgEvent( self, args ):
244 if len( args ) < 1:
245 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
246 return EventStates().ABORT
247 elif len( args ) > 1:
248 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
249 return EventStates().ABORT
250 else:
251 self.component = 'org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator'
252 self.propName = 'defaultFlowObjectiveCompiler'
253 self.value = str( args[ 0 ] )
254 index = -1
255 for controller in main.controllers:
256 if controller.isUp():
257 index = controller.index
258 if index == -1:
Jon Hall2bb3e212017-05-24 17:07:25 -0700259 main.log.warn( "%s - No available controllers" % s( self.typeString ) )
You Wang106d0fa2017-05-15 17:22:15 -0700260 return EventStates().ABORT
261 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) )
262 controller = main.controllers[ index - 1 ]
263 with controller.CLILock:
264 result = controller.CLI.setCfg( component=self.component,
265 propName=self.propName,
266 value=self.value )
267 if not result:
268 main.log.warn( "%s - failed to set configuration" % ( self.typeString ) )
269 return EventStates().FAIL
270 return EventStates().PASS