blob: 778b5b1d69be691324a10ab51b860950a2101b1d [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 network event
23Author: you@onlab.us
24"""
25from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event
26from tests.CHOTestMonkey.dependencies.elements.NetworkElement import NetworkElement, Device, Host, Link
You Wangad483c82019-03-13 15:25:44 -070027import time
You Wangdb927a52016-02-26 11:03:28 -080028
Jon Hall2bb3e212017-05-24 17:07:25 -070029
You Wangdb927a52016-02-26 11:03:28 -080030class LinkEvent( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -070031
You Wangdb927a52016-02-26 11:03:28 -080032 def __init__( self ):
33 Event.__init__( self )
34 self.linkA = None
35 self.linkB = None
36
37 def startLinkEvent( self ):
38 return EventStates().PASS
39
40 def startEvent( self, args ):
41 """
Jon Hall2bb3e212017-05-24 17:07:25 -070042 args are the names of the two link ends, e.g. [ 's1', 's2' ]
You Wangdb927a52016-02-26 11:03:28 -080043 """
44 with self.eventLock:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070045 # main.log.info( "%s - starting event" % ( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -080046 if len( args ) < 2:
47 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
48 return EventStates().ABORT
49 elif len( args ) > 2:
50 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
51 return EventStates().ABORT
52 if args[ 0 ] == 'random' or args[ 1 ] == 'random':
You Wangdb927a52016-02-26 11:03:28 -080053 if self.typeIndex == EventType().NETWORK_LINK_DOWN:
You Wangc61aaa22019-02-01 15:49:48 -080054 with main.networkLock:
55 linkRandom = main.Network.getLinkRandom( excludeNodes=main.excludeNodes,
56 skipLinks=main.skipLinks )
Jon Hall2bb3e212017-05-24 17:07:25 -070057 if linkRandom is None:
You Wang221db322016-06-03 15:45:52 -070058 main.log.warn( "No link available, aborting event" )
59 return EventStates().ABORT
60 args[ 0 ] = linkRandom[ 0 ]
61 args[ 1 ] = linkRandom[ 1 ]
You Wangdb927a52016-02-26 11:03:28 -080062 elif self.typeIndex == EventType().NETWORK_LINK_UP:
You Wang221db322016-06-03 15:45:52 -070063 import random
You Wangdb927a52016-02-26 11:03:28 -080064 with main.variableLock:
65 downLinks = []
66 for link in main.links:
67 if link.isDown():
68 downLinks.append( link )
69 if len( downLinks ) == 0:
70 main.log.warn( "None of the links are in 'down' state, aborting event" )
71 return EventStates().ABORT
72 linkList = random.sample( downLinks, 1 )
73 self.linkA = linkList[ 0 ]
74 self.linkB = linkList[ 0 ].backwardLink
75 elif args[ 0 ] == args[ 1 ]:
76 main.log.warn( "%s - invalid arguments: %s" % ( self.typeString, args ) )
77 return EventStates().ABORT
Jon Hall2bb3e212017-05-24 17:07:25 -070078 if self.linkA is None or self.linkB is None:
You Wangdb927a52016-02-26 11:03:28 -080079 for link in main.links:
80 if link.deviceA.name == args[ 0 ] and link.deviceB.name == args[ 1 ]:
81 self.linkA = link
82 elif link.deviceA.name == args[ 1 ] and link.deviceB.name == args[ 0 ]:
83 self.linkB = link
Jon Hall2bb3e212017-05-24 17:07:25 -070084 if self.linkA is not None and self.linkB is not None:
You Wangdb927a52016-02-26 11:03:28 -080085 break
Jon Hall2bb3e212017-05-24 17:07:25 -070086 if self.linkA is None or self.linkB is None:
You Wangdb927a52016-02-26 11:03:28 -080087 main.log.warn( "Bidirectional link %s - %s does not exist: " % ( args[ 0 ], args[ 1 ] ) )
88 return EventStates().ABORT
89 main.log.debug( "%s - %s" % ( self.typeString, self.linkA ) )
90 return self.startLinkEvent()
91
Jon Hall2bb3e212017-05-24 17:07:25 -070092
You Wangdb927a52016-02-26 11:03:28 -080093class LinkDown( LinkEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070094
You Wangdb927a52016-02-26 11:03:28 -080095 """
96 Generate a link down event giving the two ends of the link
97 """
98 def __init__( self ):
99 LinkEvent.__init__( self )
100 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
101 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
102
103 def startLinkEvent( self ):
104 # TODO: do we need to handle a unidirectional link?
Jon Hall2bb3e212017-05-24 17:07:25 -0700105 assert self.linkA is not None and self.linkB is not None
You Wangdb927a52016-02-26 11:03:28 -0800106 with main.variableLock:
107 if self.linkA.isDown() or self.linkB.isDown():
108 main.log.warn( "Link Down - link already down" )
109 return EventStates().ABORT
110 elif self.linkA.isRemoved() or self.linkB.isRemoved():
111 main.log.warn( "Link Down - link has been removed" )
112 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700113 main.log.info( "Event recorded: {} {} {} {}".format( self.typeIndex, self.typeString, self.linkA.deviceA.name, self.linkA.deviceB.name ) )
You Wangc61aaa22019-02-01 15:49:48 -0800114 with main.networkLock:
Jon Hall2bb3e212017-05-24 17:07:25 -0700115 """
You Wangc61aaa22019-02-01 15:49:48 -0800116 result = main.Network.link( END1=self.linkA.deviceA.name,
117 END2=self.linkA.deviceB.name,
118 OPTION="down" )
Jon Hall2bb3e212017-05-24 17:07:25 -0700119 """
You Wangc61aaa22019-02-01 15:49:48 -0800120 result = main.Network.delLink( self.linkA.deviceA.name,
121 self.linkA.deviceB.name )
You Wangdb927a52016-02-26 11:03:28 -0800122 if not result:
123 main.log.warn( "%s - failed to bring down link" % ( self.typeString ) )
124 return EventStates().FAIL
125 with main.variableLock:
126 self.linkA.bringDown()
127 self.linkB.bringDown()
128 return EventStates().PASS
129
Jon Hall2bb3e212017-05-24 17:07:25 -0700130
You Wangdb927a52016-02-26 11:03:28 -0800131class LinkUp( LinkEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700132
You Wangdb927a52016-02-26 11:03:28 -0800133 """
134 Generate a link up event giving the two ends of the link
135 """
136 def __init__( self ):
137 LinkEvent.__init__( self )
138 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
139 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
140
141 def startLinkEvent( self ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700142 assert self.linkA is not None and self.linkB is not None
You Wangdb927a52016-02-26 11:03:28 -0800143 with main.variableLock:
144 if self.linkA.isUp() or self.linkB.isUp():
145 main.log.warn( "Link Up - link already up" )
146 return EventStates().ABORT
147 if self.linkA.isRemoved() or self.linkB.isRemoved():
148 main.log.warn( "Link Up - link has been removed" )
149 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700150 main.log.info( "Event recorded: {} {} {} {}".format( self.typeIndex, self.typeString, self.linkA.deviceA.name, self.linkA.deviceB.name ) )
You Wangc61aaa22019-02-01 15:49:48 -0800151 with main.networkLock:
Jon Hall2bb3e212017-05-24 17:07:25 -0700152 """
You Wangc61aaa22019-02-01 15:49:48 -0800153 result = main.Network.link( END1=self.linkA.deviceA.name,
154 END2=self.linkA.deviceB.name,
155 OPTION="up" )
Jon Hall2bb3e212017-05-24 17:07:25 -0700156 """
You Wangc61aaa22019-02-01 15:49:48 -0800157 result = main.Network.addLink( self.linkA.deviceA.name,
158 self.linkA.deviceB.name )
You Wangdb927a52016-02-26 11:03:28 -0800159 if not result:
160 main.log.warn( "%s - failed to bring up link" % ( self.typeString ) )
161 return EventStates().FAIL
162 with main.variableLock:
163 self.linkA.bringUp()
164 self.linkB.bringUp()
165 return EventStates().PASS
166
Jon Hall2bb3e212017-05-24 17:07:25 -0700167
You Wangdb927a52016-02-26 11:03:28 -0800168class DeviceEvent( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700169
You Wangdb927a52016-02-26 11:03:28 -0800170 def __init__( self ):
171 Event.__init__( self )
172 self.device = None
173
174 def startDeviceEvent( self ):
175 return EventStates().PASS
176
177 def startEvent( self, args ):
178 """
179 args are the names of the device, e.g. 's1'
180 """
181 with self.eventLock:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700182 # main.log.info( "%s - starting event" % ( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800183 if len( args ) < 1:
184 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
185 return EventStates().ABORT
186 elif len( args ) > 1:
187 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
188 return EventStates().ABORT
189 if args[ 0 ] == 'random':
190 import random
191 if self.typeIndex == EventType().NETWORK_DEVICE_DOWN:
You Wangc61aaa22019-02-01 15:49:48 -0800192 with main.networkLock:
193 switchRandom = main.Network.getSwitchRandom( excludeNodes=main.excludeNodes,
194 skipSwitches=main.skipSwitches )
Jon Hall2bb3e212017-05-24 17:07:25 -0700195 if switchRandom is None:
You Wang221db322016-06-03 15:45:52 -0700196 main.log.warn( "No switch available, aborting event" )
197 return EventStates().ABORT
198 args[ 0 ] = switchRandom
You Wangdb927a52016-02-26 11:03:28 -0800199 elif self.typeIndex == EventType().NETWORK_DEVICE_UP:
200 with main.variableLock:
201 removedDevices = []
202 for device in main.devices:
203 if device.isRemoved():
204 removedDevices.append( device )
205 if len( removedDevices ) == 0:
206 main.log.warn( "None of the devices are removed, aborting event" )
207 return EventStates().ABORT
208 deviceList = random.sample( removedDevices, 1 )
209 self.device = deviceList[ 0 ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700210 if self.device is None:
You Wangdb927a52016-02-26 11:03:28 -0800211 for device in main.devices:
212 if device.name == args[ 0 ]:
213 self.device = device
Jon Hall2bb3e212017-05-24 17:07:25 -0700214 if self.device is None:
You Wangdb927a52016-02-26 11:03:28 -0800215 main.log.warn( "Device %s does not exist: " % ( args[ 0 ] ) )
216 return EventStates().ABORT
217 main.log.debug( "%s - %s" % ( self.typeString, self.device ) )
218 return self.startDeviceEvent()
219
Jon Hall2bb3e212017-05-24 17:07:25 -0700220
You Wangdb927a52016-02-26 11:03:28 -0800221class DeviceDown( DeviceEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700222
You Wangdb927a52016-02-26 11:03:28 -0800223 """
Jon Hall2bb3e212017-05-24 17:07:25 -0700224 Generate a device down event ( which actually removes this device for now ) giving its name
You Wangdb927a52016-02-26 11:03:28 -0800225 """
226 def __init__( self ):
227 DeviceEvent.__init__( self )
228 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
229 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
230
231 def startDeviceEvent( self ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700232 assert self.device is not None
You Wangdb927a52016-02-26 11:03:28 -0800233 with main.variableLock:
234 if self.device.isRemoved():
235 main.log.warn( "Device Down - device has been removed" )
236 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700237 main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.device.name ) )
You Wang9fc5ce42019-01-23 15:10:08 -0800238 result = main.TRUE
You Wangc61aaa22019-02-01 15:49:48 -0800239 with main.networkLock:
You Wang9fc5ce42019-01-23 15:10:08 -0800240 # Disable ports toward dual-homed hosts
241 for host, port in self.device.hosts.items():
242 if host.isDualHomed:
243 main.log.info( "Disable port {}/{} which connects to a dual-homed host before bringing down this device".format( self.device.dpid, port ) )
244 result = result and main.Cluster.active( 0 ).CLI.portstate( dpid=self.device.dpid, port=port, state="disable" )
You Wangc61aaa22019-02-01 15:49:48 -0800245 # result = main.Network.delSwitch( self.device.name )
246 result = result and main.Network.switch( SW=self.device.name, OPTION="stop" )
You Wangdb927a52016-02-26 11:03:28 -0800247 if not result:
248 main.log.warn( "%s - failed to bring down device" % ( self.typeString ) )
249 return EventStates().FAIL
250 with main.variableLock:
251 self.device.setRemoved()
252 for link in self.device.outgoingLinks:
253 link.setRemoved()
254 link.backwardLink.setRemoved()
255 for host in self.device.hosts:
256 host.setRemoved()
You Wang2b687c02016-05-13 17:01:31 -0700257 for intent in main.intents:
258 if intent.deviceA == self.device or intent.deviceB == self.device:
259 intent.setFailed()
You Wangdb927a52016-02-26 11:03:28 -0800260 return EventStates().PASS
261
Jon Hall2bb3e212017-05-24 17:07:25 -0700262
You Wangdb927a52016-02-26 11:03:28 -0800263class DeviceUp( DeviceEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700264
You Wangdb927a52016-02-26 11:03:28 -0800265 """
Jon Hall2bb3e212017-05-24 17:07:25 -0700266 Generate a device up event ( which re-adds this device in case the device is removed ) giving its name
You Wangdb927a52016-02-26 11:03:28 -0800267 """
268 def __init__( self ):
269 DeviceEvent.__init__( self )
270 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
271 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
272
273 def startDeviceEvent( self ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700274 assert self.device is not None
You Wangdb927a52016-02-26 11:03:28 -0800275 with main.variableLock:
276 if self.device.isUp():
277 main.log.warn( "Device Up - device already up" )
278 return EventStates().ABORT
279 # Re-add the device
You Wang52163202016-07-14 16:37:15 -0700280 main.log.info( "Event recorded: {} {} {}".format( self.typeIndex, self.typeString, self.device.name ) )
You Wangc61aaa22019-02-01 15:49:48 -0800281 if hasattr( main, 'Mininet1' ):
282 with main.networkLock:
283 # result = main.Network.addSwitch( self.device.name, dpid=self.device.dpid[ 3: ] )
284 result = main.Network.switch( SW=self.device.name, OPTION='start' )
285 if not result:
286 main.log.warn( "%s - failed to re-add device" % ( self.typeString ) )
287 return EventStates().FAIL
288 # Re-assign mastership for the device
289 with main.networkLock:
290 result = main.Network.assignSwController( sw=self.device.name, ip=main.Cluster.getIps() )
291 if not result:
292 main.log.warn( "%s - failed to assign device to controller" % ( self.typeString ) )
293 return EventStates().FAIL
You Wangdb927a52016-02-26 11:03:28 -0800294 with main.variableLock:
295 self.device.bringUp()
You Wangdb927a52016-02-26 11:03:28 -0800296 for link in self.device.outgoingLinks:
297 neighbor = link.deviceB
298 # Skip bringing up any link that connecting this device to a removed neighbor
299 if neighbor.isRemoved():
300 continue
You Wangc61aaa22019-02-01 15:49:48 -0800301 # FIXME: remove this temporary hack for CORD-3240
302 if neighbor.name == 's225':
You Wangad483c82019-03-13 15:25:44 -0700303 time.sleep( 5 )
You Wangc61aaa22019-02-01 15:49:48 -0800304 main.NetworkBench.switches[ 's225' ].setPortSpeed( index=link.portB )
You Wang9fc5ce42019-01-23 15:10:08 -0800305 # Bring down again any link that was brought down before the device was down
306 if int( link.portB ) in link.deviceB.downPorts:
307 with main.variableLock:
308 link.bringDown()
309 link.backwardLink.bringDown()
You Wangdb927a52016-02-26 11:03:28 -0800310 else:
You Wang9fc5ce42019-01-23 15:10:08 -0800311 with main.variableLock:
312 link.bringUp()
313 link.backwardLink.bringUp()
314 # Re-discover hosts
315 if self.device.hosts:
You Wangc61aaa22019-02-01 15:49:48 -0800316 main.Network.discoverHosts( hostList=[ host.name for host in self.device.hosts ] )
You Wang9fc5ce42019-01-23 15:10:08 -0800317 for host in self.device.hosts:
You Wangdb927a52016-02-26 11:03:28 -0800318 with main.variableLock:
319 host.bringUp()
You Wang9fc5ce42019-01-23 15:10:08 -0800320 self.device.downPorts = []
321 return EventStates().PASS
322
323
324class PortEvent( Event ):
325
326 def __init__( self ):
327 Event.__init__( self )
328 self.device = None
329 self.port = None
330 self.link = None
331
332 def startPortEvent( self ):
333 return EventStates().PASS
334
335 def startEvent( self, args ):
336 """
337 args are the device name and port number, e.g. [ 's1', '5' ]
338 """
339 with self.eventLock:
340 # main.log.info( "%s - starting event" % ( self.typeString ) )
341 if len( args ) < 2:
342 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
343 return EventStates().ABORT
344 elif len( args ) > 2:
345 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
346 return EventStates().ABORT
347 if args[ 0 ] == 'random' or args[ 1 ] == 'random':
348 if self.typeIndex == EventType().NETWORK_PORT_DOWN:
You Wangc61aaa22019-02-01 15:49:48 -0800349 with main.networkLock:
350 linkRandom = main.Network.getLinkRandom( excludeNodes=main.excludeNodes,
351 skipLinks=main.skipLinks )
You Wang9fc5ce42019-01-23 15:10:08 -0800352 if linkRandom is None:
353 main.log.warn( "No link available, aborting event" )
354 return EventStates().ABORT
355 for link in main.links:
356 if link.deviceA.name == linkRandom[ 0 ] and link.deviceB.name == linkRandom[ 1 ]:
357 self.device = link.deviceA
358 self.port = int( link.portA )
359 if not self.device:
360 main.log.warn( "Failed to get a radnom device port, aborting event" )
361 return EventStates().ABORT
362 elif self.typeIndex == EventType().NETWORK_PORT_UP:
363 import random
364 with main.variableLock:
365 downPorts = {}
366 for link in main.links:
367 if link.isDown():
368 if int( link.portA ) in link.deviceA.downPorts:
369 downPorts[ link.deviceA ] = link.portA
370 if len( downPorts ) == 0:
371 main.log.warn( "None of the links are in 'down' state, aborting event" )
372 return EventStates().ABORT
373 deviceList = random.sample( downPorts, 1 )
374 self.device = deviceList[ 0 ]
375 self.port = int( downPorts[ self.device ] )
376 if self.device is None:
377 for device in main.devices:
378 if device.name == args[ 0 ]:
379 self.device = device
380 if self.device is None:
381 main.log.warn( "Device %s does not exist: " % ( args[ 0 ] ) )
382 return EventStates().ABORT
383 if self.port is None:
384 try:
385 self.port = int( args[ 1 ] )
386 except Exception:
387 main.log.warn( "Device port is not a number: {}".format( args[ 1 ] ) )
388 return EventStates().ABORT
389 if self.link is None:
390 for link in main.links:
391 if link.deviceA.name == self.device.name and int( link.portA ) == self.port:
392 self.link = link
393 if self.link is None:
394 main.log.warn( "There's no link on device {} port {}".format( self.device.name, self.port ) )
395 return EventStates().ABORT
396 main.log.debug( "%s - %s:%s" % ( self.typeString, self.device, self.port ) )
397 return self.startPortEvent()
398
399
400class PortDown( PortEvent ):
401
402 """
403 Generate a port down event giving the device name and port number
404 """
405 def __init__( self ):
406 PortEvent.__init__( self )
407 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
408 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
409
410 def startPortEvent( self ):
411 assert self.device is not None and self.port is not None and self.link is not None
412 if self.link.isDown():
413 main.log.warn( "port Down - link already down" )
414 return EventStates().ABORT
415 elif self.link.isRemoved():
416 main.log.warn( "port Down - link has been removed" )
417 return EventStates().ABORT
418 main.log.info( "Event recorded: {} {} {} {}".format( self.typeIndex, self.typeString, self.device.name, self.port ) )
You Wangc61aaa22019-02-01 15:49:48 -0800419 with main.networkLock:
You Wang9fc5ce42019-01-23 15:10:08 -0800420 result = main.Cluster.active( 0 ).CLI.portstate( dpid=self.device.dpid, port=self.port, state="disable" )
421 if not result:
422 main.log.warn( "%s - failed to bring down port" % ( self.typeString ) )
423 return EventStates().FAIL
424 with main.variableLock:
425 self.device.downPorts.append( self.port )
426 self.link.bringDown()
427 self.link.backwardLink.bringDown()
428 return EventStates().PASS
429
430
431class PortUp( PortEvent ):
432
433 """
434 Generate a port up event giving the device name and port number
435 """
436 def __init__( self ):
437 PortEvent.__init__( self )
438 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
439 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
440
441 def startPortEvent( self ):
442 assert self.device is not None and self.port is not None and self.link is not None
443 if self.link.isUp():
444 main.log.warn( "port up - link already up" )
445 return EventStates().ABORT
446 elif self.link.isRemoved():
447 main.log.warn( "port up - link has been removed" )
448 return EventStates().ABORT
449 main.log.info( "Event recorded: {} {} {} {}".format( self.typeIndex, self.typeString, self.device.name, self.port ) )
You Wangc61aaa22019-02-01 15:49:48 -0800450 with main.networkLock:
You Wang9fc5ce42019-01-23 15:10:08 -0800451 result = main.Cluster.active( 0 ).CLI.portstate( dpid=self.device.dpid, port=self.port, state="enable" )
452 if not result:
453 main.log.warn( "%s - failed to bring up port " % ( self.typeString ) )
454 return EventStates().FAIL
You Wangc61aaa22019-02-01 15:49:48 -0800455 # FIXME: remove this temporary hack for CORD-3240
456 if self.link.deviceB.name == 's225':
457 main.NetworkBench.switches[ 's225' ].setPortSpeed( index=self.link.portB )
You Wang9fc5ce42019-01-23 15:10:08 -0800458 with main.variableLock:
459 self.device.downPorts.remove( self.port )
460 self.link.bringUp()
461 self.link.backwardLink.bringUp()
You Wangdb927a52016-02-26 11:03:28 -0800462 return EventStates().PASS