You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
| 2 | This file contains classes for CHOTestMonkey that are related to application event |
| 3 | Author: you@onlab.us |
| 4 | """ |
| 5 | from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event |
| 6 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 7 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 8 | class ONOSEvent( Event ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 9 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 10 | def __init__( self ): |
| 11 | Event.__init__( self ) |
| 12 | self.ONOSIndex = -1 |
| 13 | |
| 14 | def startEvent( self, args ): |
| 15 | with self.eventLock: |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 16 | #main.log.info( "%s - starting event" % ( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 17 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 35 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 36 | class ONOSDown( ONOSEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 37 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 38 | def __init__( self ): |
| 39 | ONOSEvent.__init__( self ) |
| 40 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 41 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 42 | |
| 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 Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 49 | main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 50 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 59 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 60 | class ONOSUp( ONOSEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 61 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 62 | def __init__( self ): |
| 63 | ONOSEvent.__init__( self ) |
| 64 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 65 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 66 | |
| 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 Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 73 | main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 74 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 94 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 95 | class CfgEvent( Event ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 96 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 97 | 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 Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 105 | #main.log.info( "%s - starting event" % ( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 106 | result = self.startCfgEvent( args ) |
| 107 | return result |
| 108 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 109 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 110 | class SetCfg( CfgEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 111 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 112 | def __init__( self ): |
| 113 | CfgEvent.__init__( self ) |
| 114 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 115 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 116 | |
| 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 134 | main.log.warn( "%s - No available controllers" % s( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 135 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 136 | main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 137 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 147 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 148 | class SetFlowObj( CfgEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 149 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 150 | def __init__( self ): |
| 151 | CfgEvent.__init__( self ) |
| 152 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 153 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 154 | |
| 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 174 | main.log.warn( "%s - No available controllers" % s( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 175 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 176 | main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 177 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 187 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 188 | class BalanceMasters( Event ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 189 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 190 | def __init__( self ): |
| 191 | Event.__init__( self ) |
| 192 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 193 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 194 | |
| 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 203 | main.log.warn( "%s - No available controllers" % s( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 204 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 205 | main.log.info( "Event recorded: {} {}".format( self.typeIndex, self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 206 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 214 | |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 215 | class SetFlowObjCompiler( CfgEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 216 | |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 217 | def __init__( self ): |
| 218 | CfgEvent.__init__( self ) |
| 219 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 220 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 221 | |
| 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 238 | main.log.warn( "%s - No available controllers" % s( self.typeString ) ) |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 239 | 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 |