blob: e8b7281cb1fa0d44a9c16890c99356455ce4c436 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2016 Open Networking Foundation (ONF)
3
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
11 (at your option) any later version.
12
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"""
21
22"""
You Wangdb927a52016-02-26 11:03:28 -080023This file contains classes for CHOTestMonkey that are related to application event
24Author: you@onlab.us
25"""
26from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event
27
Jon Hall2bb3e212017-05-24 17:07:25 -070028
You Wangdb927a52016-02-26 11:03:28 -080029class ONOSEvent( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -070030
You Wangdb927a52016-02-26 11:03:28 -080031 def __init__( self ):
32 Event.__init__( self )
33 self.ONOSIndex = -1
34
35 def startEvent( self, args ):
36 with self.eventLock:
You Wang52163202016-07-14 16:37:15 -070037 #main.log.info( "%s - starting event" % ( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -080038 result = EventStates().PASS
39 if self.typeIndex == EventType().ONOS_ONOS_DOWN or self.typeIndex == EventType().ONOS_ONOS_UP:
40 if len( args ) < 1:
41 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
42 result = EventStates().ABORT
43 elif len( args ) > 1:
44 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
45 result = EventStates().ABORT
46 else:
47 index = int( args[ 0 ] )
Devin Lim142b5342017-07-20 15:22:39 -070048 if index < 1 or index > int( main.Cluster.numCtrls ):
You Wangdb927a52016-02-26 11:03:28 -080049 main.log.warn( "%s - invalid argument: %s" % ( self.typeString, index ) )
50 result = EventStates().ABORT
51 else:
52 self.ONOSIndex = index
53 result = self.startONOSEvent()
54 return result
55
Jon Hall2bb3e212017-05-24 17:07:25 -070056
You Wangdb927a52016-02-26 11:03:28 -080057class ONOSDown( ONOSEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070058
You Wangdb927a52016-02-26 11:03:28 -080059 def __init__( self ):
60 ONOSEvent.__init__( self )
61 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -070062 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -080063
64 def startONOSEvent( self ):
65 assert self.ONOSIndex != -1
66 with main.variableLock:
67 if not main.controllers[ self.ONOSIndex - 1 ].isUp():
68 main.log.warn( "ONOS Down - ONOS already down" )
69 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -070070 main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) )
You Wangdb927a52016-02-26 11:03:28 -080071 with main.ONOSbenchLock:
72 result = main.ONOSbench.onosStop( main.controllers[ self.ONOSIndex - 1 ].ip )
73 if not result:
74 main.log.warn( "%s - failed to bring down ONOS" % ( self.typeString ) )
75 return EventStates().FAIL
76 with main.variableLock:
77 main.controllers[ self.ONOSIndex - 1 ].bringDown()
78 return EventStates().PASS
79
Jon Hall2bb3e212017-05-24 17:07:25 -070080
You Wangdb927a52016-02-26 11:03:28 -080081class ONOSUp( ONOSEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070082
You Wangdb927a52016-02-26 11:03:28 -080083 def __init__( self ):
84 ONOSEvent.__init__( self )
85 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -070086 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -080087
88 def startONOSEvent( self ):
89 assert self.ONOSIndex != -1
90 with main.variableLock:
91 if main.controllers[ self.ONOSIndex - 1 ].isUp():
92 main.log.warn( "ONOS Up - ONOS already up" )
93 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -070094 main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) )
You Wangdb927a52016-02-26 11:03:28 -080095 with main.ONOSbenchLock:
96 startResult = main.ONOSbench.onosStart( main.controllers[ self.ONOSIndex - 1 ].ip )
97 if not startResult:
98 main.log.warn( "%s - failed to bring up ONOS" % ( self.typeString ) )
99 return EventStates().FAIL
100 else:
101 ONOSState = main.ONOSbench.isup( main.controllers[ self.ONOSIndex - 1 ].ip )
102 if not ONOSState:
103 main.log.warn( "%s - ONOS is not up" % ( self.typeString ) )
104 return EventStates().FAIL
105 else:
106 cliResult = main.controllers[ self.ONOSIndex - 1 ].startCLI()
107 if not cliResult:
108 main.log.warn( "%s - failed to start ONOS cli" % ( self.typeString ) )
109 return EventStates().FAIL
110 else:
111 with main.variableLock:
112 main.controllers[ self.ONOSIndex - 1 ].bringUp()
113 return EventStates().PASS
114
Jon Hall2bb3e212017-05-24 17:07:25 -0700115
You Wangdb927a52016-02-26 11:03:28 -0800116class CfgEvent( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700117
You Wangdb927a52016-02-26 11:03:28 -0800118 def __init__( self ):
119 Event.__init__( self )
120 self.component = ''
121 self.propName = ''
122 self.value = ''
123
124 def startEvent( self, args ):
125 with self.eventLock:
You Wang52163202016-07-14 16:37:15 -0700126 #main.log.info( "%s - starting event" % ( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800127 result = self.startCfgEvent( args )
128 return result
129
Jon Hall2bb3e212017-05-24 17:07:25 -0700130
You Wangdb927a52016-02-26 11:03:28 -0800131class SetCfg( CfgEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700132
You Wangdb927a52016-02-26 11:03:28 -0800133 def __init__( self ):
134 CfgEvent.__init__( self )
135 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700136 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800137
138 def startCfgEvent( self, args ):
139 if len( args ) < 3:
140 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
141 return EventStates().ABORT
142 elif len( args ) > 3:
143 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
144 return EventStates().ABORT
145 else:
146 self.component = str( args[ 0 ] )
147 self.propName = str( args[ 1 ] )
148 self.value = str( args[ 2 ] )
149 assert self.component != '' and self.propName != '' and self.value != ''
150 index = -1
151 for controller in main.controllers:
152 if controller.isUp():
153 index = controller.index
154 if index == -1:
Jon Hall2bb3e212017-05-24 17:07:25 -0700155 main.log.warn( "%s - No available controllers" % s( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800156 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700157 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) )
You Wangdb927a52016-02-26 11:03:28 -0800158 controller = main.controllers[ index - 1 ]
159 with controller.CLILock:
160 result = controller.CLI.setCfg( component=self.component,
161 propName=self.propName,
162 value=self.value )
163 if not result:
164 main.log.warn( "%s - failed to set configuration" % ( self.typeString ) )
165 return EventStates().FAIL
166 return EventStates().PASS
167
Jon Hall2bb3e212017-05-24 17:07:25 -0700168
You Wangdb927a52016-02-26 11:03:28 -0800169class SetFlowObj( CfgEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700170
You Wangdb927a52016-02-26 11:03:28 -0800171 def __init__( self ):
172 CfgEvent.__init__( self )
173 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700174 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800175
176 def startCfgEvent( self, args ):
177 if len( args ) < 1:
178 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
179 return EventStates().ABORT
180 elif len( args ) > 1:
181 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
182 return EventStates().ABORT
183 elif args[ 0 ] != 'true' and args[ 0 ] != 'false':
184 main.log.warn( "%s - Invalid arguments: %s" % ( self.typeString, args ) )
185 return EventStates().ABORT
186 else:
187 self.component = 'org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator'
188 self.propName = 'useFlowObjectives'
189 self.value = str( args[ 0 ] )
190 index = -1
191 for controller in main.controllers:
192 if controller.isUp():
193 index = controller.index
194 if index == -1:
Jon Hall2bb3e212017-05-24 17:07:25 -0700195 main.log.warn( "%s - No available controllers" % s( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800196 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700197 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) )
You Wangdb927a52016-02-26 11:03:28 -0800198 controller = main.controllers[ index - 1 ]
199 with controller.CLILock:
200 result = controller.CLI.setCfg( component=self.component,
201 propName=self.propName,
202 value=self.value )
203 if not result:
204 main.log.warn( "%s - failed to set configuration" % ( self.typeString ) )
205 return EventStates().FAIL
206 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