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 | |
| 7 | class ONOSEvent( Event ): |
| 8 | def __init__( self ): |
| 9 | Event.__init__( self ) |
| 10 | self.ONOSIndex = -1 |
| 11 | |
| 12 | def startEvent( self, args ): |
| 13 | with self.eventLock: |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 14 | #main.log.info( "%s - starting event" % ( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 15 | result = EventStates().PASS |
| 16 | if self.typeIndex == EventType().ONOS_ONOS_DOWN or self.typeIndex == EventType().ONOS_ONOS_UP: |
| 17 | if len( args ) < 1: |
| 18 | main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) ) |
| 19 | result = EventStates().ABORT |
| 20 | elif len( args ) > 1: |
| 21 | main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) ) |
| 22 | result = EventStates().ABORT |
| 23 | else: |
| 24 | index = int( args[ 0 ] ) |
| 25 | if index < 1 or index > int( main.numCtrls ): |
| 26 | main.log.warn( "%s - invalid argument: %s" % ( self.typeString, index ) ) |
| 27 | result = EventStates().ABORT |
| 28 | else: |
| 29 | self.ONOSIndex = index |
| 30 | result = self.startONOSEvent() |
| 31 | return result |
| 32 | |
| 33 | class ONOSDown( ONOSEvent ): |
| 34 | def __init__( self ): |
| 35 | ONOSEvent.__init__( self ) |
| 36 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 37 | self.typeIndex= int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 38 | |
| 39 | def startONOSEvent( self ): |
| 40 | assert self.ONOSIndex != -1 |
| 41 | with main.variableLock: |
| 42 | if not main.controllers[ self.ONOSIndex - 1 ].isUp(): |
| 43 | main.log.warn( "ONOS Down - ONOS already down" ) |
| 44 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 45 | main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 46 | with main.ONOSbenchLock: |
| 47 | result = main.ONOSbench.onosStop( main.controllers[ self.ONOSIndex - 1 ].ip ) |
| 48 | if not result: |
| 49 | main.log.warn( "%s - failed to bring down ONOS" % ( self.typeString ) ) |
| 50 | return EventStates().FAIL |
| 51 | with main.variableLock: |
| 52 | main.controllers[ self.ONOSIndex - 1 ].bringDown() |
| 53 | return EventStates().PASS |
| 54 | |
| 55 | class ONOSUp( ONOSEvent ): |
| 56 | def __init__( self ): |
| 57 | ONOSEvent.__init__( self ) |
| 58 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 59 | self.typeIndex= int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 60 | |
| 61 | def startONOSEvent( self ): |
| 62 | assert self.ONOSIndex != -1 |
| 63 | with main.variableLock: |
| 64 | if main.controllers[ self.ONOSIndex - 1 ].isUp(): |
| 65 | main.log.warn( "ONOS Up - ONOS already up" ) |
| 66 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 67 | main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 68 | with main.ONOSbenchLock: |
| 69 | startResult = main.ONOSbench.onosStart( main.controllers[ self.ONOSIndex - 1 ].ip ) |
| 70 | if not startResult: |
| 71 | main.log.warn( "%s - failed to bring up ONOS" % ( self.typeString ) ) |
| 72 | return EventStates().FAIL |
| 73 | else: |
| 74 | ONOSState = main.ONOSbench.isup( main.controllers[ self.ONOSIndex - 1 ].ip ) |
| 75 | if not ONOSState: |
| 76 | main.log.warn( "%s - ONOS is not up" % ( self.typeString ) ) |
| 77 | return EventStates().FAIL |
| 78 | else: |
| 79 | cliResult = main.controllers[ self.ONOSIndex - 1 ].startCLI() |
| 80 | if not cliResult: |
| 81 | main.log.warn( "%s - failed to start ONOS cli" % ( self.typeString ) ) |
| 82 | return EventStates().FAIL |
| 83 | else: |
| 84 | with main.variableLock: |
| 85 | main.controllers[ self.ONOSIndex - 1 ].bringUp() |
| 86 | return EventStates().PASS |
| 87 | |
| 88 | class CfgEvent( Event ): |
| 89 | def __init__( self ): |
| 90 | Event.__init__( self ) |
| 91 | self.component = '' |
| 92 | self.propName = '' |
| 93 | self.value = '' |
| 94 | |
| 95 | def startEvent( self, args ): |
| 96 | with self.eventLock: |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 97 | #main.log.info( "%s - starting event" % ( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 98 | result = self.startCfgEvent( args ) |
| 99 | return result |
| 100 | |
| 101 | class SetCfg( CfgEvent ): |
| 102 | def __init__( self ): |
| 103 | CfgEvent.__init__( self ) |
| 104 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 105 | self.typeIndex= int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 106 | |
| 107 | def startCfgEvent( self, args ): |
| 108 | if len( args ) < 3: |
| 109 | main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) ) |
| 110 | return EventStates().ABORT |
| 111 | elif len( args ) > 3: |
| 112 | main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) ) |
| 113 | return EventStates().ABORT |
| 114 | else: |
| 115 | self.component = str( args[ 0 ] ) |
| 116 | self.propName = str( args[ 1 ] ) |
| 117 | self.value = str( args[ 2 ] ) |
| 118 | assert self.component != '' and self.propName != '' and self.value != '' |
| 119 | index = -1 |
| 120 | for controller in main.controllers: |
| 121 | if controller.isUp(): |
| 122 | index = controller.index |
| 123 | if index == -1: |
| 124 | main.log.warn( "%s - No available controllers" %s ( self.typeString ) ) |
| 125 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 126 | 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] | 127 | controller = main.controllers[ index - 1 ] |
| 128 | with controller.CLILock: |
| 129 | result = controller.CLI.setCfg( component=self.component, |
| 130 | propName=self.propName, |
| 131 | value=self.value ) |
| 132 | if not result: |
| 133 | main.log.warn( "%s - failed to set configuration" % ( self.typeString ) ) |
| 134 | return EventStates().FAIL |
| 135 | return EventStates().PASS |
| 136 | |
| 137 | class SetFlowObj( CfgEvent ): |
| 138 | def __init__( self ): |
| 139 | CfgEvent.__init__( self ) |
| 140 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 141 | self.typeIndex= int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 142 | |
| 143 | def startCfgEvent( self, args ): |
| 144 | if len( args ) < 1: |
| 145 | main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) ) |
| 146 | return EventStates().ABORT |
| 147 | elif len( args ) > 1: |
| 148 | main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) ) |
| 149 | return EventStates().ABORT |
| 150 | elif args[ 0 ] != 'true' and args[ 0 ] != 'false': |
| 151 | main.log.warn( "%s - Invalid arguments: %s" % ( self.typeString, args ) ) |
| 152 | return EventStates().ABORT |
| 153 | else: |
| 154 | self.component = 'org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator' |
| 155 | self.propName = 'useFlowObjectives' |
| 156 | self.value = str( args[ 0 ] ) |
| 157 | index = -1 |
| 158 | for controller in main.controllers: |
| 159 | if controller.isUp(): |
| 160 | index = controller.index |
| 161 | if index == -1: |
| 162 | main.log.warn( "%s - No available controllers" %s ( self.typeString ) ) |
| 163 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 164 | 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] | 165 | controller = main.controllers[ index - 1 ] |
| 166 | with controller.CLILock: |
| 167 | result = controller.CLI.setCfg( component=self.component, |
| 168 | propName=self.propName, |
| 169 | value=self.value ) |
| 170 | if not result: |
| 171 | main.log.warn( "%s - failed to set configuration" % ( self.typeString ) ) |
| 172 | return EventStates().FAIL |
| 173 | return EventStates().PASS |
| 174 | |
| 175 | class BalanceMasters( Event ): |
| 176 | def __init__( self ): |
| 177 | Event.__init__( self ) |
| 178 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 179 | self.typeIndex= int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 180 | |
| 181 | def startEvent( self, args=None ): |
| 182 | with self.eventLock: |
| 183 | main.log.info( "%s - starting event" % ( self.typeString ) ) |
| 184 | index = -1 |
| 185 | for controller in main.controllers: |
| 186 | if controller.isUp(): |
| 187 | index = controller.index |
| 188 | if index == -1: |
| 189 | main.log.warn( "%s - No available controllers" %s ( self.typeString ) ) |
| 190 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 191 | main.log.info( "Event recorded: {} {}".format( self.typeIndex, self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 192 | controller = main.controllers[ index - 1 ] |
| 193 | with controller.CLILock: |
| 194 | result = controller.CLI.balanceMasters() |
| 195 | if not result: |
| 196 | main.log.warn( "%s - failed to balance masters" % ( self.typeString ) ) |
| 197 | return EventStates().FAIL |
| 198 | return EventStates().PASS |
| 199 | |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 200 | class SetFlowObjCompiler( CfgEvent ): |
| 201 | def __init__( self ): |
| 202 | CfgEvent.__init__( self ) |
| 203 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 204 | self.typeIndex= int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 205 | |
| 206 | def startCfgEvent( self, args ): |
| 207 | if len( args ) < 1: |
| 208 | main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) ) |
| 209 | return EventStates().ABORT |
| 210 | elif len( args ) > 1: |
| 211 | main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) ) |
| 212 | return EventStates().ABORT |
| 213 | else: |
| 214 | self.component = 'org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator' |
| 215 | self.propName = 'defaultFlowObjectiveCompiler' |
| 216 | self.value = str( args[ 0 ] ) |
| 217 | index = -1 |
| 218 | for controller in main.controllers: |
| 219 | if controller.isUp(): |
| 220 | index = controller.index |
| 221 | if index == -1: |
| 222 | main.log.warn( "%s - No available controllers" %s ( self.typeString ) ) |
| 223 | return EventStates().ABORT |
| 224 | main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) ) |
| 225 | controller = main.controllers[ index - 1 ] |
| 226 | with controller.CLILock: |
| 227 | result = controller.CLI.setCfg( component=self.component, |
| 228 | propName=self.propName, |
| 229 | value=self.value ) |
| 230 | if not result: |
| 231 | main.log.warn( "%s - failed to set configuration" % ( self.typeString ) ) |
| 232 | return EventStates().FAIL |
| 233 | return EventStates().PASS |
| 234 | |