blob: 28960d2d5c3b9fe96464c57877337b1c48b08641 [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
7class 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 Wang52163202016-07-14 16:37:15 -070014 #main.log.info( "%s - starting event" % ( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -080015 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
33class 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 Wang52163202016-07-14 16:37:15 -070045 main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) )
You Wangdb927a52016-02-26 11:03:28 -080046 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
55class 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 Wang52163202016-07-14 16:37:15 -070067 main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.ONOSIndex ) )
You Wangdb927a52016-02-26 11:03:28 -080068 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
88class 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 Wang52163202016-07-14 16:37:15 -070097 #main.log.info( "%s - starting event" % ( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -080098 result = self.startCfgEvent( args )
99 return result
100
101class 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 Wang52163202016-07-14 16:37:15 -0700126 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) )
You Wangdb927a52016-02-26 11:03:28 -0800127 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
137class 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 Wang52163202016-07-14 16:37:15 -0700164 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.component, self.propName, self.value ) )
You Wangdb927a52016-02-26 11:03:28 -0800165 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
175class 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 Wang52163202016-07-14 16:37:15 -0700191 main.log.info( "Event recorded: {} {}".format( self.typeIndex, self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800192 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