blob: d386c1b0c80e6a0359d4140576e76677535756e3 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
2This file contains classes for CHOTestMonkey that are related to application event
3Author: you@onlab.us
4"""
5from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event
6
Jon Hall2bb3e212017-05-24 17:07:25 -07007
You Wangdb927a52016-02-26 11:03:28 -08008class ONOSEvent( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -07009
You Wangdb927a52016-02-26 11:03:28 -080010 def __init__( self ):
11 Event.__init__( self )
12 self.ONOSIndex = -1
13
14 def startEvent( self, args ):
15 with self.eventLock:
You Wang52163202016-07-14 16:37:15 -070016 #main.log.info( "%s - starting event" % ( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -080017 result = EventStates().PASS
18 if self.typeIndex == EventType().ONOS_ONOS_DOWN or self.typeIndex == EventType().ONOS_ONOS_UP:
19 if len( args ) < 1:
20 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
21 result = EventStates().ABORT
22 elif len( args ) > 1:
23 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
24 result = EventStates().ABORT
25 else:
26 index = int( args[ 0 ] )
27 if index < 1 or index > int( main.numCtrls ):
28 main.log.warn( "%s - invalid argument: %s" % ( self.typeString, index ) )
29 result = EventStates().ABORT
30 else:
31 self.ONOSIndex = index
32 result = self.startONOSEvent()
33 return result
34
Jon Hall2bb3e212017-05-24 17:07:25 -070035
You Wangdb927a52016-02-26 11:03:28 -080036class ONOSDown( ONOSEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070037
You Wangdb927a52016-02-26 11:03:28 -080038 def __init__( self ):
39 ONOSEvent.__init__( self )
40 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -070041 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -080042
43 def startONOSEvent( self ):
44 assert self.ONOSIndex != -1
45 with main.variableLock:
46 if not main.controllers[ self.ONOSIndex - 1 ].isUp():
47 main.log.warn( "ONOS Down - ONOS already down" )
48 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -070049 main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) )
You Wangdb927a52016-02-26 11:03:28 -080050 with main.ONOSbenchLock:
51 result = main.ONOSbench.onosStop( main.controllers[ self.ONOSIndex - 1 ].ip )
52 if not result:
53 main.log.warn( "%s - failed to bring down ONOS" % ( self.typeString ) )
54 return EventStates().FAIL
55 with main.variableLock:
56 main.controllers[ self.ONOSIndex - 1 ].bringDown()
57 return EventStates().PASS
58
Jon Hall2bb3e212017-05-24 17:07:25 -070059
You Wangdb927a52016-02-26 11:03:28 -080060class ONOSUp( ONOSEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070061
You Wangdb927a52016-02-26 11:03:28 -080062 def __init__( self ):
63 ONOSEvent.__init__( self )
64 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -070065 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -080066
67 def startONOSEvent( self ):
68 assert self.ONOSIndex != -1
69 with main.variableLock:
70 if main.controllers[ self.ONOSIndex - 1 ].isUp():
71 main.log.warn( "ONOS Up - ONOS already up" )
72 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -070073 main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) )
You Wangdb927a52016-02-26 11:03:28 -080074 with main.ONOSbenchLock:
75 startResult = main.ONOSbench.onosStart( main.controllers[ self.ONOSIndex - 1 ].ip )
76 if not startResult:
77 main.log.warn( "%s - failed to bring up ONOS" % ( self.typeString ) )
78 return EventStates().FAIL
79 else:
80 ONOSState = main.ONOSbench.isup( main.controllers[ self.ONOSIndex - 1 ].ip )
81 if not ONOSState:
82 main.log.warn( "%s - ONOS is not up" % ( self.typeString ) )
83 return EventStates().FAIL
84 else:
85 cliResult = main.controllers[ self.ONOSIndex - 1 ].startCLI()
86 if not cliResult:
87 main.log.warn( "%s - failed to start ONOS cli" % ( self.typeString ) )
88 return EventStates().FAIL
89 else:
90 with main.variableLock:
91 main.controllers[ self.ONOSIndex - 1 ].bringUp()
92 return EventStates().PASS
93
Jon Hall2bb3e212017-05-24 17:07:25 -070094
You Wangdb927a52016-02-26 11:03:28 -080095class CfgEvent( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -070096
You Wangdb927a52016-02-26 11:03:28 -080097 def __init__( self ):
98 Event.__init__( self )
99 self.component = ''
100 self.propName = ''
101 self.value = ''
102
103 def startEvent( self, args ):
104 with self.eventLock:
You Wang52163202016-07-14 16:37:15 -0700105 #main.log.info( "%s - starting event" % ( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800106 result = self.startCfgEvent( args )
107 return result
108
Jon Hall2bb3e212017-05-24 17:07:25 -0700109
You Wangdb927a52016-02-26 11:03:28 -0800110class SetCfg( CfgEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700111
You Wangdb927a52016-02-26 11:03:28 -0800112 def __init__( self ):
113 CfgEvent.__init__( self )
114 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700115 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800116
117 def startCfgEvent( self, args ):
118 if len( args ) < 3:
119 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
120 return EventStates().ABORT
121 elif len( args ) > 3:
122 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
123 return EventStates().ABORT
124 else:
125 self.component = str( args[ 0 ] )
126 self.propName = str( args[ 1 ] )
127 self.value = str( args[ 2 ] )
128 assert self.component != '' and self.propName != '' and self.value != ''
129 index = -1
130 for controller in main.controllers:
131 if controller.isUp():
132 index = controller.index
133 if index == -1:
Jon Hall2bb3e212017-05-24 17:07:25 -0700134 main.log.warn( "%s - No available controllers" % s( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800135 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700136 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) )
You Wangdb927a52016-02-26 11:03:28 -0800137 controller = main.controllers[ index - 1 ]
138 with controller.CLILock:
139 result = controller.CLI.setCfg( component=self.component,
140 propName=self.propName,
141 value=self.value )
142 if not result:
143 main.log.warn( "%s - failed to set configuration" % ( self.typeString ) )
144 return EventStates().FAIL
145 return EventStates().PASS
146
Jon Hall2bb3e212017-05-24 17:07:25 -0700147
You Wangdb927a52016-02-26 11:03:28 -0800148class SetFlowObj( CfgEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700149
You Wangdb927a52016-02-26 11:03:28 -0800150 def __init__( self ):
151 CfgEvent.__init__( self )
152 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700153 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800154
155 def startCfgEvent( self, args ):
156 if len( args ) < 1:
157 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
158 return EventStates().ABORT
159 elif len( args ) > 1:
160 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
161 return EventStates().ABORT
162 elif args[ 0 ] != 'true' and args[ 0 ] != 'false':
163 main.log.warn( "%s - Invalid arguments: %s" % ( self.typeString, args ) )
164 return EventStates().ABORT
165 else:
166 self.component = 'org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator'
167 self.propName = 'useFlowObjectives'
168 self.value = str( args[ 0 ] )
169 index = -1
170 for controller in main.controllers:
171 if controller.isUp():
172 index = controller.index
173 if index == -1:
Jon Hall2bb3e212017-05-24 17:07:25 -0700174 main.log.warn( "%s - No available controllers" % s( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800175 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700176 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) )
You Wangdb927a52016-02-26 11:03:28 -0800177 controller = main.controllers[ index - 1 ]
178 with controller.CLILock:
179 result = controller.CLI.setCfg( component=self.component,
180 propName=self.propName,
181 value=self.value )
182 if not result:
183 main.log.warn( "%s - failed to set configuration" % ( self.typeString ) )
184 return EventStates().FAIL
185 return EventStates().PASS
186
Jon Hall2bb3e212017-05-24 17:07:25 -0700187
You Wangdb927a52016-02-26 11:03:28 -0800188class BalanceMasters( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700189
You Wangdb927a52016-02-26 11:03:28 -0800190 def __init__( self ):
191 Event.__init__( self )
192 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700193 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800194
195 def startEvent( self, args=None ):
196 with self.eventLock:
197 main.log.info( "%s - starting event" % ( self.typeString ) )
198 index = -1
199 for controller in main.controllers:
200 if controller.isUp():
201 index = controller.index
202 if index == -1:
Jon Hall2bb3e212017-05-24 17:07:25 -0700203 main.log.warn( "%s - No available controllers" % s( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800204 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700205 main.log.info( "Event recorded: {} {}".format( self.typeIndex, self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800206 controller = main.controllers[ index - 1 ]
207 with controller.CLILock:
208 result = controller.CLI.balanceMasters()
209 if not result:
210 main.log.warn( "%s - failed to balance masters" % ( self.typeString ) )
211 return EventStates().FAIL
212 return EventStates().PASS
213
Jon Hall2bb3e212017-05-24 17:07:25 -0700214
You Wang106d0fa2017-05-15 17:22:15 -0700215class SetFlowObjCompiler( CfgEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700216
You Wang106d0fa2017-05-15 17:22:15 -0700217 def __init__( self ):
218 CfgEvent.__init__( self )
219 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700220 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wang106d0fa2017-05-15 17:22:15 -0700221
222 def startCfgEvent( self, args ):
223 if len( args ) < 1:
224 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
225 return EventStates().ABORT
226 elif len( args ) > 1:
227 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
228 return EventStates().ABORT
229 else:
230 self.component = 'org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator'
231 self.propName = 'defaultFlowObjectiveCompiler'
232 self.value = str( args[ 0 ] )
233 index = -1
234 for controller in main.controllers:
235 if controller.isUp():
236 index = controller.index
237 if index == -1:
Jon Hall2bb3e212017-05-24 17:07:25 -0700238 main.log.warn( "%s - No available controllers" % s( self.typeString ) )
You Wang106d0fa2017-05-15 17:22:15 -0700239 return EventStates().ABORT
240 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) )
241 controller = main.controllers[ index - 1 ]
242 with controller.CLILock:
243 result = controller.CLI.setCfg( component=self.component,
244 propName=self.propName,
245 value=self.value )
246 if not result:
247 main.log.warn( "%s - failed to set configuration" % ( self.typeString ) )
248 return EventStates().FAIL
249 return EventStates().PASS