blob: 7361c8f412c8480f6d55ddbe5fc9bbe8bb27b39f [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or 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 Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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 Ronquillob27ce4c2017-07-17 12:41:28 -070021"""
You Wangdb927a52016-02-26 11:03:28 -080022This file contains classes for CHOTestMonkey that are related to check event
23Author: you@onlab.us
24"""
25from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event
26
Jon Hall2bb3e212017-05-24 17:07:25 -070027
You Wangdb927a52016-02-26 11:03:28 -080028class CheckEvent( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -070029
You Wangdb927a52016-02-26 11:03:28 -080030 def __init__( self ):
31 Event.__init__( self )
32
33 def startCheckEvent( self ):
34 return EventStates().PASS
35
36 def startEvent( self, args ):
37 with self.eventLock:
You Wang52163202016-07-14 16:37:15 -070038 main.log.info( "Event recorded: {} {}".format( self.typeIndex, self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -080039 result = self.startCheckEvent()
40 return result
41
Jon Hall2bb3e212017-05-24 17:07:25 -070042
You Wangdb927a52016-02-26 11:03:28 -080043class IntentCheck( CheckEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070044
You Wangdb927a52016-02-26 11:03:28 -080045 def __init__( self ):
46 CheckEvent.__init__( self )
47 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
48 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
49
50 def startCheckEvent( self, args=None ):
51 checkResult = EventStates().PASS
You Wang58aa11e2016-05-17 10:35:44 -070052 intentDict = {}
You Wangdb927a52016-02-26 11:03:28 -080053 for intent in main.intents:
You Wang58aa11e2016-05-17 10:35:44 -070054 intentDict[ intent.id ] = intent.expectedState
You Wangdb927a52016-02-26 11:03:28 -080055 for controller in main.controllers:
56 if controller.isUp():
57 with controller.CLILock:
You Wang58aa11e2016-05-17 10:35:44 -070058 intentState = controller.CLI.compareIntent( intentDict )
You Wangdb927a52016-02-26 11:03:28 -080059 if not intentState:
You Wang58aa11e2016-05-17 10:35:44 -070060 main.log.warn( "Intent Check - not all intent ids and states match that on ONOS%s" % ( controller.index ) )
You Wange8c2b042019-01-22 15:07:25 -080061 # FIXME: ONOS leaves intents as WITHDRAWN state occasionally and we don't consider that as a FAIL for now
62 # checkResult = EventStates().FAIL
You Wang58aa11e2016-05-17 10:35:44 -070063 return checkResult
64
Jon Hall2bb3e212017-05-24 17:07:25 -070065
You Wang58aa11e2016-05-17 10:35:44 -070066class FlowCheck( CheckEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070067
You Wang58aa11e2016-05-17 10:35:44 -070068 def __init__( self ):
69 CheckEvent.__init__( self )
70 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
71 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
72
73 def startCheckEvent( self, args=None ):
74 import json
75 checkResult = EventStates().PASS
You Wang3c276252016-09-21 15:21:36 -070076 if main.enableIPv6:
You Wang62e1cf62016-09-22 17:13:03 -070077 coreFlowNum = int( main.params[ 'EVENT' ][ 'FlowCheck' ][ 'coreFlowNum6' ] )
You Wang3c276252016-09-21 15:21:36 -070078 else:
You Wang62e1cf62016-09-22 17:13:03 -070079 coreFlowNum = int( main.params[ 'EVENT' ][ 'FlowCheck' ][ 'coreFlowNum' ] )
You Wang58aa11e2016-05-17 10:35:44 -070080 for controller in main.controllers:
81 if controller.isUp():
82 with controller.CLILock:
You Wang3c276252016-09-21 15:21:36 -070083 # Check core flow number
84 for device in main.devices:
85 if device.isRemoved():
86 continue
87 coreFlowNumOnos = controller.CLI.flowAddedCount( device.dpid, core=True )
Jon Hall2bb3e212017-05-24 17:07:25 -070088 if coreFlowNumOnos is None:
You Wang3c276252016-09-21 15:21:36 -070089 main.log.warn( "Flow Check - error when trying to get flow number of %s on ONOS%s" % ( device.dpid, controller.index ) )
90 checkResult = EventStates().FAIL
91 else:
92 coreFlowNumOnos = int( coreFlowNumOnos )
93 if coreFlowNumOnos != coreFlowNum:
94 main.log.warn( "Flow Check - core flow number of %s on ONOS%s is %s" % ( device.dpid, controller.index, coreFlowNumOnos ) )
95 checkResult = EventStates().FAIL
96 # Get flows for comparison
You Wang58aa11e2016-05-17 10:35:44 -070097 flows = controller.CLI.flows()
98 try:
99 flows = json.loads( flows )
100 except ( TypeError, ValueError ):
101 main.log.exception( "Flow Check - Object not as expected: {!r}".format( flows ) )
102 return EventStates().FAIL
103 # Compare flow IDs in ONOS and Mininet
104 flowIDList = []
105 for item in flows:
106 for flow in item[ "flows" ]:
107 flowIDList.append( hex( int( flow[ 'id' ] ) ) )
108 main.log.info( "Flow Check - current flow number on ONOS%s: %s" % ( controller.index, len( flowIDList ) ) )
109 switchList = []
110 for device in main.devices:
111 switchList.append( device.name )
112 with main.mininetLock:
113 flowCompareResult = main.Mininet1.checkFlowId( switchList, flowIDList, debug=False )
114 if not flowCompareResult:
115 main.log.warn( "Flow Check - flows on ONOS%s do not match that in Mininet" % ( controller.index ) )
116 checkResult = EventStates().FAIL
117 # Check flow state
118 flowState = controller.CLI.checkFlowsState( isPENDING=False )
119 if not flowState:
120 main.log.warn( "Flow Check - not all flows are in ADDED state on ONOS%s" % ( controller.index ) )
121 checkResult = EventStates().FAIL
You Wangdb927a52016-02-26 11:03:28 -0800122 return checkResult
123
Jon Hall2bb3e212017-05-24 17:07:25 -0700124
You Wangdb927a52016-02-26 11:03:28 -0800125class TopoCheck( CheckEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700126
You Wangdb927a52016-02-26 11:03:28 -0800127 def __init__( self ):
128 CheckEvent.__init__( self )
129 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
130 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
131
132 def startCheckEvent( self, args=None ):
133 import json
134 checkResult = EventStates().PASS
135 upLinkNum = 0
136 upDeviceNum = 0
137 upHostNum = 0
138 with main.variableLock:
139 for link in main.links:
140 if not link.isDown() and not link.isRemoved():
141 upLinkNum += 1
142 for device in main.devices:
143 if not device.isDown() and not device.isRemoved():
144 upDeviceNum += 1
145 for host in main.hosts:
146 if not host.isDown() and not host.isRemoved():
147 upHostNum += 1
148 clusterNum = 1
You Wang221db322016-06-03 15:45:52 -0700149 with main.mininetLock:
150 graphDictMininet = main.Mininet1.getGraphDict( useId=True )
You Wangdb927a52016-02-26 11:03:28 -0800151 for controller in main.controllers:
152 if controller.isUp():
153 with controller.CLILock:
Flavio Castro82ee2f62016-06-07 15:04:12 -0700154 topoState = controller.CLI.checkStatus( upDeviceNum, upLinkNum )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700155 # if not topoState:
You Wangdb927a52016-02-26 11:03:28 -0800156 # main.log.warn( "Topo Check - link or device number discoverd by ONOS%s is incorrect" % ( controller.index ) )
157 # checkResult = EventStates().FAIL
You Wang221db322016-06-03 15:45:52 -0700158 # Compare ONOS and Mininet topologies
159 graphDictONOS = controller.CLI.getGraphDict()
160 compareResult = main.graph.compareGraphs( graphDictONOS, graphDictMininet )
161 if not compareResult:
162 checkResult = EventStates().FAIL
163 main.log.warn( "Topo Check - ONOS and Mininet topologies do not match" )
You Wang58aa11e2016-05-17 10:35:44 -0700164 try:
You Wang221db322016-06-03 15:45:52 -0700165 # Check links
You Wang58aa11e2016-05-17 10:35:44 -0700166 links = controller.CLI.links()
167 links = json.loads( links )
168 if not len( links ) == upLinkNum:
169 checkResult = EventStates().FAIL
170 main.log.warn( "Topo Check - link number discoverd by ONOS%s is incorrect: %s expected and %s actual" % ( controller.index, upLinkNum, len( links ) ) )
171 # Check devices
172 devices = controller.CLI.devices()
173 devices = json.loads( devices )
174 availableDeviceNum = 0
175 for device in devices:
Jon Hall2bb3e212017-05-24 17:07:25 -0700176 if device[ 'available' ]:
You Wang58aa11e2016-05-17 10:35:44 -0700177 availableDeviceNum += 1
178 if not availableDeviceNum == upDeviceNum:
179 checkResult = EventStates().FAIL
180 main.log.warn( "Topo Check - device number discoverd by ONOS%s is incorrect: %s expected and %s actual" % ( controller.index, upDeviceNum, availableDeviceNum ) )
181 # Check hosts
182 hosts = controller.CLI.hosts()
183 hosts = json.loads( hosts )
184 if not len( hosts ) == upHostNum:
185 checkResult = EventStates().FAIL
186 main.log.warn( "Topo Check - host number discoverd by ONOS%s is incorrect: %s expected and %s actual" % ( controller.index, upHostNum, len( hosts ) ) )
187 # Check clusters
188 clusters = controller.CLI.clusters()
189 clusters = json.loads( clusters )
190 if not len( clusters ) == clusterNum:
191 checkResult = EventStates().FAIL
192 main.log.warn( "Topo Check - cluster number discoverd by ONOS%s is incorrect: %s expected and %s actual" % ( controller.index, clusterNum, len( clusters ) ) )
193 except ( TypeError, ValueError ):
194 main.log.exception( "Flow Check - Object not as expected" )
195 return EventStates().FAIL
You Wangdb927a52016-02-26 11:03:28 -0800196 return checkResult
197
Jon Hall2bb3e212017-05-24 17:07:25 -0700198
You Wangdb927a52016-02-26 11:03:28 -0800199class ONOSCheck( CheckEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700200
You Wangdb927a52016-02-26 11:03:28 -0800201 def __init__( self ):
202 CheckEvent.__init__( self )
203 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700204 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800205
206 def startCheckEvent( self, args=None ):
207 import json
208 checkResult = EventStates().PASS
209 topics = []
210 # TODO: Other topics?
211 for i in range( 14 ):
Jon Hall8dafdcc2016-09-16 10:21:25 -0700212 topics.append( "work-partition-" + str( i ) )
You Wangdb927a52016-02-26 11:03:28 -0800213 dpidToAvailability = {}
214 dpidToMaster = {}
215 for device in main.devices:
216 if device.isDown() or device.isRemoved():
217 dpidToAvailability[ device.dpid ] = False
218 else:
219 dpidToAvailability[ device.dpid ] = True
220 dpidToMaster[ device.dpid ] = 'unknown'
221 # Check mastership, leaders and node states on each controller node
222 for controller in main.controllers:
223 if controller.isUp():
224 # Check mastership
You Wang58aa11e2016-05-17 10:35:44 -0700225 try:
226 with controller.CLILock:
227 roles = controller.CLI.roles()
228 roles = json.loads( roles )
229 for device in roles:
230 dpid = device[ 'id' ]
231 if dpidToMaster[ dpid ] == 'unknown':
232 dpidToMaster[ dpid ] = device[ 'master' ]
233 elif dpidToMaster[ dpid ] != device[ 'master' ]:
234 checkResult = EventStates().FAIL
235 main.log.warn( "ONOS Check - Mastership of %s on ONOS%s is inconsistent with that on ONOS1" % ( dpid, controller.index ) )
236 if dpidToAvailability[ dpid ] and device[ 'master' ] == "none":
237 checkResult = EventStates().FAIL
238 main.log.warn( "ONOS Check - Device %s has no master on ONOS%s" % ( dpid, controller.index ) )
239 # Check leaders
240 with controller.CLILock:
241 leaders = controller.CLI.leaders()
242 leaders = json.loads( leaders )
Jon Hall2bb3e212017-05-24 17:07:25 -0700243 ONOSTopics = [ j[ 'topic' ] for j in leaders ]
You Wang58aa11e2016-05-17 10:35:44 -0700244 for topic in topics:
245 if topic not in ONOSTopics:
246 checkResult = EventStates().FAIL
247 main.log.warn( "ONOS Check - Topic %s not in leaders on ONOS%s" % ( topic, controller.index ) )
248 # Check node state
249 with controller.CLILock:
250 nodes = controller.CLI.nodes()
251 nodes = json.loads( nodes )
252 ipToState = {}
253 for node in nodes:
254 ipToState[ node[ 'ip' ] ] = node[ 'state' ]
255 for c in main.controllers:
256 if c.isUp() and ipToState[ c.ip ] == 'READY':
257 pass
You Wange8c2b042019-01-22 15:07:25 -0800258 elif not c.isUp() and c.ip not in ipToState.keys():
You Wang58aa11e2016-05-17 10:35:44 -0700259 pass
260 else:
261 checkResult = EventStates().FAIL
262 main.log.warn( "ONOS Check - ONOS%s shows wrong node state: ONOS%s is %s but state is %s" % ( controller.index, c.index, c.status, ipToState[ c.ip ] ) )
263 # TODO: check partitions?
264 except ( TypeError, ValueError ):
265 main.log.exception( "ONOS Check - Object not as expected" )
266 return EventStates().FAIL
You Wange8c2b042019-01-22 15:07:25 -0800267 except Exception as e:
268 main.log.exception( "ONOS Check - Uncaught Exception: {}".format( e ) )
269 return EventStates().FAIL
You Wangdb927a52016-02-26 11:03:28 -0800270 return checkResult
271
Jon Hall2bb3e212017-05-24 17:07:25 -0700272
You Wangdb927a52016-02-26 11:03:28 -0800273class TrafficCheck( CheckEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700274
You Wangdb927a52016-02-26 11:03:28 -0800275 def __init__( self ):
276 CheckEvent.__init__( self )
277 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700278 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800279
280 def startCheckEvent( self, args=None ):
281 checkResult = EventStates().PASS
282 pool = []
283 wait = int( main.params[ 'EVENT' ][ 'TrafficCheck' ][ 'pingWait' ] )
284 timeout = int( main.params[ 'EVENT' ][ 'TrafficCheck' ][ 'pingTimeout' ] )
285 dstIPv4List = {}
286 dstIPv6List = {}
287 upHosts = []
288 for host in main.hosts:
289 if host.isUp():
290 upHosts.append( host )
291 for host in upHosts:
292 dstIPv4List[ host.index ] = []
293 dstIPv6List[ host.index ] = []
294 for correspondent in host.correspondents:
Jon Hall2bb3e212017-05-24 17:07:25 -0700295 if correspondent not in upHosts:
You Wangdb927a52016-02-26 11:03:28 -0800296 continue
297 for ipAddress in correspondent.ipAddresses:
298 if ipAddress.startswith( str( main.params[ 'TEST' ][ 'ipv6Prefix' ] ) ):
299 dstIPv6List[ host.index ].append( ipAddress )
300 elif ipAddress.startswith( str( main.params[ 'TEST' ][ 'ipv4Prefix' ] ) ):
301 dstIPv4List[ host.index ].append( ipAddress )
302 thread = main.Thread( target=host.handle.pingHostSetAlternative,
303 threadID=main.threadID,
304 name="pingHostSetAlternative",
305 args=[ dstIPv4List[ host.index ], 1 ] )
306 pool.append( thread )
307 thread.start()
308 with main.variableLock:
309 main.threadID += 1
310 for thread in pool:
311 thread.join( 10 )
312 if not thread.result:
313 checkResult = EventStates().FAIL
314 main.log.warn( "Traffic Check - ping failed" )
315
316 if not main.enableIPv6:
317 return checkResult
318 # Check ipv6 ping
319 for host in upHosts:
320 thread = main.Thread( target=host.handle.pingHostSetAlternative,
321 threadID=main.threadID,
322 name="pingHostSetAlternative",
323 args=[ dstIPv6List[ host.index ], 1, True ] )
324 pool.append( thread )
325 thread.start()
326 with main.variableLock:
327 main.threadID += 1
328 for thread in pool:
329 thread.join( 10 )
330 if not thread.result:
331 checkResult = EventStates().FAIL
332 main.log.warn( "Traffic Check - ping6 failed" )
333 return checkResult
Devin Limf0822182017-09-12 14:52:57 -0700334
335class RaftLogSizeCheck( CheckEvent ):
336
337 def __init__( self ):
338 CheckEvent.__init__( self )
339 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
340 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
341
342 def startCheckEvent( self, args=None ):
343 checkResult = EventStates().PASS
344 main.log.info( "Starting checking Raft Log size" )
345 if not main.Cluster.checkPartitionSize():
346 checkResult = EventStates().FAIL
347 main.log.warn( "Raft Log Size Check - Raft log grew too big" )
348
349 return checkResult