You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2016 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 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 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 21 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 22 | This file contains classes for CHOTestMonkey that are related to application event |
| 23 | Author: you@onlab.us |
| 24 | """ |
| 25 | from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event |
| 26 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 27 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 28 | class ONOSEvent( Event ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 29 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 30 | def __init__( self ): |
| 31 | Event.__init__( self ) |
| 32 | self.ONOSIndex = -1 |
| 33 | |
| 34 | def startEvent( self, args ): |
| 35 | with self.eventLock: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 36 | # main.log.info( "%s - starting event" % ( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 37 | 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 Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 47 | if index < 1 or index > int( main.Cluster.numCtrls ): |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 48 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 55 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 56 | class ONOSDown( ONOSEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 57 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 58 | def __init__( self ): |
| 59 | ONOSEvent.__init__( self ) |
| 60 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 61 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 62 | |
| 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 Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 69 | main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 70 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 79 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 80 | class ONOSUp( ONOSEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 81 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 82 | def __init__( self ): |
| 83 | ONOSEvent.__init__( self ) |
| 84 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 85 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 86 | |
| 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 Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 93 | main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 94 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 114 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 115 | class CfgEvent( Event ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 116 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 117 | 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 125 | # main.log.info( "%s - starting event" % ( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 126 | result = self.startCfgEvent( args ) |
| 127 | return result |
| 128 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 129 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 130 | class SetCfg( CfgEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 131 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 132 | def __init__( self ): |
| 133 | CfgEvent.__init__( self ) |
| 134 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 135 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 136 | |
| 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 154 | main.log.warn( "%s - No available controllers" % s( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 155 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 156 | 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] | 157 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 167 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 168 | class SetFlowObj( CfgEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 169 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 170 | def __init__( self ): |
| 171 | CfgEvent.__init__( self ) |
| 172 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 173 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 174 | |
| 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 194 | main.log.warn( "%s - No available controllers" % s( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 195 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 196 | 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] | 197 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 207 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 208 | class BalanceMasters( Event ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 209 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 210 | def __init__( self ): |
| 211 | Event.__init__( self ) |
| 212 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 213 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 214 | |
| 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 223 | main.log.warn( "%s - No available controllers" % s( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 224 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 225 | main.log.info( "Event recorded: {} {}".format( self.typeIndex, self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 226 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 234 | |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 235 | class SetFlowObjCompiler( CfgEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 236 | |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 237 | def __init__( self ): |
| 238 | CfgEvent.__init__( self ) |
| 239 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 240 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 241 | |
| 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 258 | main.log.warn( "%s - No available controllers" % s( self.typeString ) ) |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 259 | 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 |