You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 2 | Copyright 2016 Open Networking Foundation (ONF) |
| 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 |
| 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 Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 23 | This file contains classes for CHOTestMonkey that are related to application event |
| 24 | Author: you@onlab.us |
| 25 | """ |
| 26 | from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event |
| 27 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 28 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 29 | class ONOSEvent( Event ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 30 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 31 | def __init__( self ): |
| 32 | Event.__init__( self ) |
| 33 | self.ONOSIndex = -1 |
| 34 | |
| 35 | def startEvent( self, args ): |
| 36 | with self.eventLock: |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 37 | #main.log.info( "%s - starting event" % ( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 38 | 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 Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 48 | if index < 1 or index > int( main.Cluster.numCtrls ): |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 49 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 56 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 57 | class ONOSDown( ONOSEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 58 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 59 | def __init__( self ): |
| 60 | ONOSEvent.__init__( self ) |
| 61 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 62 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 63 | |
| 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 Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 70 | main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 71 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 80 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 81 | class ONOSUp( ONOSEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 82 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 83 | def __init__( self ): |
| 84 | ONOSEvent.__init__( self ) |
| 85 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 86 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 87 | |
| 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 Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 94 | main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 95 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 115 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 116 | class CfgEvent( Event ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 117 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 118 | 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 Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 126 | #main.log.info( "%s - starting event" % ( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 127 | result = self.startCfgEvent( args ) |
| 128 | return result |
| 129 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 130 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 131 | class SetCfg( CfgEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 132 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 133 | def __init__( self ): |
| 134 | CfgEvent.__init__( self ) |
| 135 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 136 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 137 | |
| 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 155 | main.log.warn( "%s - No available controllers" % s( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 156 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 157 | 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] | 158 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 168 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 169 | class SetFlowObj( CfgEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 170 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 171 | def __init__( self ): |
| 172 | CfgEvent.__init__( self ) |
| 173 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 174 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 175 | |
| 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 195 | main.log.warn( "%s - No available controllers" % s( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 196 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 197 | 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] | 198 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 208 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 209 | class BalanceMasters( Event ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 210 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 211 | def __init__( self ): |
| 212 | Event.__init__( self ) |
| 213 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 214 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 215 | |
| 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 224 | main.log.warn( "%s - No available controllers" % s( self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 225 | return EventStates().ABORT |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 226 | main.log.info( "Event recorded: {} {}".format( self.typeIndex, self.typeString ) ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 227 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 235 | |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 236 | class SetFlowObjCompiler( CfgEvent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 237 | |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 238 | def __init__( self ): |
| 239 | CfgEvent.__init__( self ) |
| 240 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 241 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 242 | |
| 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 259 | main.log.warn( "%s - No available controllers" % s( self.typeString ) ) |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 260 | 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 |