blob: fc03203a74eb50924c7efa1d180e320f010df9af [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2016 Open Networking Foundation (ONF)
3
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
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 Wangdb927a52016-02-26 11:03:28 -080023This file contains classes for CHOTestMonkey that are related to check event
24Author: you@onlab.us
25"""
26from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event
27
Jon Hall2bb3e212017-05-24 17:07:25 -070028
You Wangdb927a52016-02-26 11:03:28 -080029class CheckEvent( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -070030
You Wangdb927a52016-02-26 11:03:28 -080031 def __init__( self ):
32 Event.__init__( self )
33
34 def startCheckEvent( self ):
35 return EventStates().PASS
36
37 def startEvent( self, args ):
38 with self.eventLock:
You Wang52163202016-07-14 16:37:15 -070039 main.log.info( "Event recorded: {} {}".format( self.typeIndex, self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -080040 result = self.startCheckEvent()
41 return result
42
Jon Hall2bb3e212017-05-24 17:07:25 -070043
You Wangdb927a52016-02-26 11:03:28 -080044class IntentCheck( CheckEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070045
You Wangdb927a52016-02-26 11:03:28 -080046 def __init__( self ):
47 CheckEvent.__init__( self )
48 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
49 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
50
51 def startCheckEvent( self, args=None ):
52 checkResult = EventStates().PASS
You Wang58aa11e2016-05-17 10:35:44 -070053 intentDict = {}
You Wangdb927a52016-02-26 11:03:28 -080054 for intent in main.intents:
You Wang58aa11e2016-05-17 10:35:44 -070055 intentDict[ intent.id ] = intent.expectedState
You Wangdb927a52016-02-26 11:03:28 -080056 for controller in main.controllers:
57 if controller.isUp():
58 with controller.CLILock:
You Wang58aa11e2016-05-17 10:35:44 -070059 intentState = controller.CLI.compareIntent( intentDict )
You Wangdb927a52016-02-26 11:03:28 -080060 if not intentState:
You Wang58aa11e2016-05-17 10:35:44 -070061 main.log.warn( "Intent Check - not all intent ids and states match that on ONOS%s" % ( controller.index ) )
You Wangdb927a52016-02-26 11:03:28 -080062 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 )
You Wangdb927a52016-02-26 11:03:28 -0800155 #if not topoState:
156 # 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
258 elif not c.isUp() and ipToState[ c.ip ] == 'INACTIVE':
259 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 Wangdb927a52016-02-26 11:03:28 -0800267 return checkResult
268
Jon Hall2bb3e212017-05-24 17:07:25 -0700269
You Wangdb927a52016-02-26 11:03:28 -0800270class TrafficCheck( CheckEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700271
You Wangdb927a52016-02-26 11:03:28 -0800272 def __init__( self ):
273 CheckEvent.__init__( self )
274 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700275 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800276
277 def startCheckEvent( self, args=None ):
278 checkResult = EventStates().PASS
279 pool = []
280 wait = int( main.params[ 'EVENT' ][ 'TrafficCheck' ][ 'pingWait' ] )
281 timeout = int( main.params[ 'EVENT' ][ 'TrafficCheck' ][ 'pingTimeout' ] )
282 dstIPv4List = {}
283 dstIPv6List = {}
284 upHosts = []
285 for host in main.hosts:
286 if host.isUp():
287 upHosts.append( host )
288 for host in upHosts:
289 dstIPv4List[ host.index ] = []
290 dstIPv6List[ host.index ] = []
291 for correspondent in host.correspondents:
Jon Hall2bb3e212017-05-24 17:07:25 -0700292 if correspondent not in upHosts:
You Wangdb927a52016-02-26 11:03:28 -0800293 continue
294 for ipAddress in correspondent.ipAddresses:
295 if ipAddress.startswith( str( main.params[ 'TEST' ][ 'ipv6Prefix' ] ) ):
296 dstIPv6List[ host.index ].append( ipAddress )
297 elif ipAddress.startswith( str( main.params[ 'TEST' ][ 'ipv4Prefix' ] ) ):
298 dstIPv4List[ host.index ].append( ipAddress )
299 thread = main.Thread( target=host.handle.pingHostSetAlternative,
300 threadID=main.threadID,
301 name="pingHostSetAlternative",
302 args=[ dstIPv4List[ host.index ], 1 ] )
303 pool.append( thread )
304 thread.start()
305 with main.variableLock:
306 main.threadID += 1
307 for thread in pool:
308 thread.join( 10 )
309 if not thread.result:
310 checkResult = EventStates().FAIL
311 main.log.warn( "Traffic Check - ping failed" )
312
313 if not main.enableIPv6:
314 return checkResult
315 # Check ipv6 ping
316 for host in upHosts:
317 thread = main.Thread( target=host.handle.pingHostSetAlternative,
318 threadID=main.threadID,
319 name="pingHostSetAlternative",
320 args=[ dstIPv6List[ host.index ], 1, True ] )
321 pool.append( thread )
322 thread.start()
323 with main.variableLock:
324 main.threadID += 1
325 for thread in pool:
326 thread.join( 10 )
327 if not thread.result:
328 checkResult = EventStates().FAIL
329 main.log.warn( "Traffic Check - ping6 failed" )
330 return checkResult
Devin Limf0822182017-09-12 14:52:57 -0700331
332class RaftLogSizeCheck( CheckEvent ):
333
334 def __init__( self ):
335 CheckEvent.__init__( self )
336 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
337 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
338
339 def startCheckEvent( self, args=None ):
340 checkResult = EventStates().PASS
341 main.log.info( "Starting checking Raft Log size" )
342 if not main.Cluster.checkPartitionSize():
343 checkResult = EventStates().FAIL
344 main.log.warn( "Raft Log Size Check - Raft log grew too big" )
345
346 return checkResult