blob: 16300668eac1d1ec15a2dc11911e25a4330fd971 [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:
71 result = main.ONOSbench.onosStop( main.controllers[ self.ONOSIndex - 1 ].ip )
72 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
205 return EventStates().PASS
206
Jon Hall2bb3e212017-05-24 17:07:25 -0700207
You Wangdb927a52016-02-26 11:03:28 -0800208class BalanceMasters( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700209
You Wangdb927a52016-02-26 11:03:28 -0800210 def __init__( self ):
211 Event.__init__( self )
212 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700213 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800214
215 def startEvent( self, args=None ):
216 with self.eventLock:
217 main.log.info( "%s - starting event" % ( self.typeString ) )
218 index = -1
219 for controller in main.controllers:
220 if controller.isUp():
221 index = controller.index
222 if index == -1:
Jon Hall2bb3e212017-05-24 17:07:25 -0700223 main.log.warn( "%s - No available controllers" % s( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800224 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700225 main.log.info( "Event recorded: {} {}".format( self.typeIndex, self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800226 controller = main.controllers[ index - 1 ]
227 with controller.CLILock:
228 result = controller.CLI.balanceMasters()
229 if not result:
230 main.log.warn( "%s - failed to balance masters" % ( self.typeString ) )
231 return EventStates().FAIL
232 return EventStates().PASS
233
Jon Hall2bb3e212017-05-24 17:07:25 -0700234
You Wang106d0fa2017-05-15 17:22:15 -0700235class SetFlowObjCompiler( CfgEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700236
You Wang106d0fa2017-05-15 17:22:15 -0700237 def __init__( self ):
238 CfgEvent.__init__( self )
239 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700240 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wang106d0fa2017-05-15 17:22:15 -0700241
242 def startCfgEvent( self, args ):
243 if len( args ) < 1:
244 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
245 return EventStates().ABORT
246 elif len( args ) > 1:
247 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
248 return EventStates().ABORT
249 else:
250 self.component = 'org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator'
251 self.propName = 'defaultFlowObjectiveCompiler'
252 self.value = str( args[ 0 ] )
253 index = -1
254 for controller in main.controllers:
255 if controller.isUp():
256 index = controller.index
257 if index == -1:
Jon Hall2bb3e212017-05-24 17:07:25 -0700258 main.log.warn( "%s - No available controllers" % s( self.typeString ) )
You Wang106d0fa2017-05-15 17:22:15 -0700259 return EventStates().ABORT
260 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) )
261 controller = main.controllers[ index - 1 ]
262 with controller.CLILock:
263 result = controller.CLI.setCfg( component=self.component,
264 propName=self.propName,
265 value=self.value )
266 if not result:
267 main.log.warn( "%s - failed to set configuration" % ( self.typeString ) )
268 return EventStates().FAIL
269 return EventStates().PASS