Run codecheck script on CHOTestMonkey
Change-Id: I11047f1b4c6ecd8273695c230d3a4a99475a6db6
diff --git a/TestON/tests/CHOTestMonkey/dependencies/events/AppEvent.py b/TestON/tests/CHOTestMonkey/dependencies/events/AppEvent.py
index 4283ff6..2661a07 100644
--- a/TestON/tests/CHOTestMonkey/dependencies/events/AppEvent.py
+++ b/TestON/tests/CHOTestMonkey/dependencies/events/AppEvent.py
@@ -5,7 +5,9 @@
from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event
from tests.CHOTestMonkey.dependencies.elements.ONOSElement import HostIntent, PointIntent
+
class IntentEvent( Event ):
+
def __init__( self ):
Event.__init__( self )
# The index of the ONOS CLI that is going to run the command
@@ -19,7 +21,7 @@
candidates = [ host for host in main.hosts if host not in hostA.correspondents and host != hostA ]
if len( candidates ) == 0:
return None
- hostB = random.sample( candidates, 1 )[0]
+ hostB = random.sample( candidates, 1 )[ 0 ]
return hostB
def getRandomHostPair( self, connected=True ):
@@ -28,11 +30,11 @@
with main.variableLock:
for host in main.hosts:
correspondent = self.getRandomCorrespondent( host, connected=connected )
- if correspondent != None:
+ if correspondent is not None:
candidateDict[ host ] = correspondent
if candidateDict == {}:
return None
- hostA = random.sample( candidateDict.keys(), 1 )[0]
+ hostA = random.sample( candidateDict.keys(), 1 )[ 0 ]
hostB = candidateDict[ hostA ]
return [ hostA, hostB ]
@@ -52,7 +54,9 @@
intent = random.sample( intents, 1 )[ 0 ]
return intent
+
class HostIntentEvent( IntentEvent ):
+
def __init__( self ):
IntentEvent.__init__( self )
self.hostA = None
@@ -75,14 +79,14 @@
if args[ 0 ] == 'random' or args[ 1 ] == 'random':
if self.typeIndex == EventType().APP_INTENT_HOST_ADD:
hostPairRandom = self.getRandomHostPair( connected=False )
- if hostPairRandom == None:
+ if hostPairRandom is None:
main.log.warn( "All host pairs are connected, aborting event" )
return EventStates().ABORT
self.hostA = hostPairRandom[ 0 ]
self.hostB = hostPairRandom[ 1 ]
elif self.typeIndex == EventType().APP_INTENT_HOST_DEL:
intent = self.getRandomIntentByType( 'INTENT_HOST' )
- if intent == None:
+ if intent is None:
main.log.warn( "No host intent for deletion, aborting event" )
return EventStates().ABORT
self.hostA = intent.hostA
@@ -96,12 +100,12 @@
self.hostA = host
elif host.name == args[ 1 ]:
self.hostB = host
- if self.hostA != None and self.hostB != None:
+ if self.hostA is not None and self.hostB is not None:
break
- if self.hostA == None:
+ if self.hostA is None:
main.log.warn( "Host %s does not exist: " % ( args[ 0 ] ) )
return EventStates().ABORT
- if self.hostB == None:
+ if self.hostB is None:
main.log.warn( "Host %s does not exist: " % ( args[ 1 ] ) )
return EventStates().ABORT
index = int( args[ 2 ] )
@@ -117,32 +121,34 @@
main.log.warn( "Caught exception, aborting event" )
return EventStates().ABORT
+
class AddHostIntent( HostIntentEvent ):
+
"""
- Add a host-to-host intent (bidirectional)
+ Add a host-to-host intent ( bidirectional )
"""
def __init__( self ):
HostIntentEvent.__init__( self )
self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
- self.typeIndex= int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
+ self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
def startHostIntentEvent( self ):
try:
- assert self.hostA != None and self.hostB != None
+ assert self.hostA is not None and self.hostB is not None
# Check whether there already exists some intent for the host pair
# For now we should avoid installing overlapping intents
for intent in main.intents:
if not intent.type == 'INTENT_HOST':
continue
if intent.hostA == self.hostA and intent.hostB == self.hostB or\
- intent.hostB == self.hostA and intent.hostA == self.hostB:
+ intent.hostB == self.hostA and intent.hostA == self.hostB:
main.log.warn( self.typeString + " - find an exiting intent for the host pair, abort installation" )
return EventStates().ABORT
main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.hostA.name, self.hostB.name, self.CLIIndex ) )
controller = main.controllers[ self.CLIIndex - 1 ]
with controller.CLILock:
id = controller.CLI.addHostIntent( self.hostA.id, self.hostB.id )
- if id == None:
+ if id is None:
main.log.warn( self.typeString + " - add host intent failed" )
return EventStates().FAIL
with main.variableLock:
@@ -157,34 +163,36 @@
main.log.warn( "Caught exception, aborting event" )
return EventStates().ABORT
+
class DelHostIntent( HostIntentEvent ):
+
"""
- Delete a host-to-host intent (bidirectional)
+ Delete a host-to-host intent ( bidirectional )
"""
def __init__( self ):
HostIntentEvent.__init__( self )
self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
- self.typeIndex= int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
+ self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
def startHostIntentEvent( self ):
try:
- assert self.hostA != None and self.hostB != None
+ assert self.hostA is not None and self.hostB is not None
targetIntent = None
for intent in main.intents:
if not intent.type == 'INTENT_HOST':
continue
if intent.hostA == self.hostA and intent.hostB == self.hostB or\
- intent.hostB == self.hostA and intent.hostA == self.hostB:
+ intent.hostB == self.hostA and intent.hostA == self.hostB:
targetIntent = intent
break
- if targetIntent == None:
+ if targetIntent is None:
main.log.warn( self.typeString + " - intent does not exist" )
return EventStates().FAIL
main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.hostA.name, self.hostB.name, self.CLIIndex ) )
controller = main.controllers[ self.CLIIndex - 1 ]
with controller.CLILock:
result = controller.CLI.removeIntent( targetIntent.id, purge=True )
- if result == None or result == main.FALSE:
+ if result is None or result == main.FALSE:
main.log.warn( self.typeString + " - delete host intent failed" )
return EventStates().FAIL
with main.variableLock:
@@ -195,7 +203,9 @@
main.log.warn( "Caught exception, aborting event" )
return EventStates().ABORT
+
class PointIntentEvent( IntentEvent ):
+
def __init__( self ):
IntentEvent.__init__( self )
self.deviceA = None
@@ -218,14 +228,14 @@
if args[ 0 ] == 'random' or args[ 1 ] == 'random':
if self.typeIndex == EventType().APP_INTENT_POINT_ADD:
hostPairRandom = self.getRandomHostPair( connected=False )
- if hostPairRandom == None:
+ if hostPairRandom is None:
main.log.warn( "All host pairs are connected, aborting event" )
return EventStates().ABORT
self.deviceA = hostPairRandom[ 0 ].device
self.deviceB = hostPairRandom[ 1 ].device
elif self.typeIndex == EventType().APP_INTENT_POINT_DEL:
intent = self.getRandomIntentByType( 'INTENT_POINT' )
- if intent == None:
+ if intent is None:
main.log.warn( "No point intent for deletion, aborting event" )
return EventStates().ABORT
self.deviceA = intent.deviceA
@@ -239,12 +249,12 @@
self.deviceA = device
elif device.name == args[ 1 ]:
self.deviceB = device
- if self.deviceA != None and self.deviceB != None:
+ if self.deviceA is not None and self.deviceB is not None:
break
- if self.deviceA == None:
+ if self.deviceA is None:
main.log.warn( "Device %s does not exist: " % ( args[ 0 ] ) )
return EventStates().ABORT
- if self.deviceB == None:
+ if self.deviceB is None:
main.log.warn( "Device %s does not exist: " % ( args[ 1 ] ) )
return EventStates().ABORT
index = int( args[ 2 ] )
@@ -270,18 +280,20 @@
main.log.warn( "Caught exception, aborting event" )
return EventStates().ABORT
+
class AddPointIntent( PointIntentEvent ):
+
"""
Add a point-to-point intent
"""
def __init__( self ):
PointIntentEvent.__init__( self )
self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
- self.typeIndex= int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
+ self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
def startPointIntentEvent( self ):
try:
- assert self.deviceA != None and self.deviceB != None
+ assert self.deviceA is not None and self.deviceB is not None
controller = main.controllers[ self.CLIIndex - 1 ]
# TODO: support multiple hosts under one device
# Check whether there already exists some intent for the device pair
@@ -302,7 +314,7 @@
if len( self.deviceB.hosts ) > 0:
dstMAC = self.deviceB.hosts[ 0 ].mac
id = controller.CLI.addPointIntent( self.deviceA.dpid, self.deviceB.dpid, 1, 1, '', srcMAC, dstMAC )
- if id == None:
+ if id is None:
main.log.warn( self.typeString + " - add point intent failed" )
return EventStates().FAIL
with main.variableLock:
@@ -317,18 +329,20 @@
main.log.warn( "Caught exception, aborting event" )
return EventStates().ABORT
+
class DelPointIntent( PointIntentEvent ):
+
"""
Delete a point-to-point intent
"""
def __init__( self ):
PointIntentEvent.__init__( self )
self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
- self.typeIndex= int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
+ self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
def startPointIntentEvent( self ):
try:
- assert self.deviceA != None and self.deviceB != None
+ assert self.deviceA is not None and self.deviceB is not None
targetIntent = None
for intent in main.intents:
if not intent.type == 'INTENT_POINT':
@@ -336,14 +350,14 @@
if intent.deviceA == self.deviceA and intent.deviceB == self.deviceB:
targetIntent = intent
break
- if targetIntent == None:
+ if targetIntent is None:
main.log.warn( self.typeString + " - intent does not exist" )
return EventStates().FAIL
main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.deviceA.name, self.deviceB.name, self.CLIIndex ) )
controller = main.controllers[ self.CLIIndex - 1 ]
with controller.CLILock:
result = controller.CLI.removeIntent( targetIntent.id, purge=True )
- if result == None or result == main.FALSE:
+ if result is None or result == main.FALSE:
main.log.warn( self.typeString + " - delete point intent failed" )
return EventStates().FAIL
with main.variableLock: