Run codestyle script for FUNCintent
Change-Id: Ia74ea4bde4fc06839138486870c2b9b83294abea
diff --git a/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py b/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py
old mode 100755
new mode 100644
index 3051658..f295b11
--- a/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py
+++ b/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py
@@ -4,10 +4,10 @@
Author: kelvin@onlab.us
"""
import time
-import copy
import json
import os
+
def __init__( self ):
self.default = ''
@@ -16,6 +16,7 @@
singleToMultiFailFlag = False
multiToSingleFailFlag = False
+
def installHostIntent( main,
name,
host1,
@@ -62,7 +63,6 @@
ipProto - IP protocol
tcp - TCP ports in the same order as the hosts in hostNames
"""
-
assert main, "There is no main variable"
assert host1, "You must specify host1"
assert host2, "You must specify host2"
@@ -106,7 +106,7 @@
attempts=50 ):
main.assertReturnString += 'Install Intent State Passed\n'
- #Check VLAN if test encapsulation
+ # Check VLAN if test encapsulation
if encap != "":
if EncapsulatedIntentCheck( main, tag=encap ):
main.assertReturnString += 'Encapsulation intents check Passed\n'
@@ -123,7 +123,6 @@
main.assertReturnString += 'Bandwidth Allocation check Failed\n'
return main.FALSE
-
if flowDuration( main ):
main.assertReturnString += 'Flow duration check Passed\n'
return intentId
@@ -137,6 +136,7 @@
main.assertReturnString += 'Install Intent State Failed\n'
return main.FALSE
+
def testHostIntent( main,
name,
intentId,
@@ -189,7 +189,6 @@
switches are down
"""
-
# Parameter Validity Check
assert main, "There is no main variable"
assert host1, "You must specify host1"
@@ -390,6 +389,7 @@
return testResult
+
def installPointIntent( main,
name,
senders,
@@ -441,7 +441,6 @@
be two links lower than the links before the two
switches are down
"""
-
assert main, "There is no main variable"
assert senders, "You must specify a sender"
assert recipients, "You must specify a recipient"
@@ -466,7 +465,6 @@
main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
-
ingressDevice = senders[ 0 ].get( "device" )
egressDevice = recipients[ 0 ].get( "device" )
@@ -543,6 +541,7 @@
pointIntentFailFlag = True
return main.FALSE
+
def pointIntentTcp( main,
name,
host1,
@@ -565,7 +564,6 @@
sw1="",
sw2="",
expectedLink=0 ):
-
"""
Description:
Verify add-point-intent only for TCP
@@ -615,7 +613,6 @@
be two links lower than the links before the two
switches are down
"""
-
assert main, "There is no main variable"
assert name, "variable name is empty"
assert host1 and host2, "You must specify hosts"
@@ -722,7 +719,7 @@
checkFlowsState( main )
# Run iperf to both host
- iperfTemp = main.Mininet1.iperftcp( host1, host2 ,10 )
+ iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
iperfResult = iperfResult and iperfTemp
if iperfTemp:
main.assertReturnString += 'Initial Iperf Passed\n'
@@ -838,6 +835,7 @@
return stepResult
+
def installSingleToMultiIntent( main,
name,
senders,
@@ -890,7 +888,6 @@
be two links lower than the links before the two
switches are down
"""
-
assert main, "There is no main variable"
assert senders, "You must specify a sender"
assert recipients, "You must specify a recipient"
@@ -915,7 +912,6 @@
main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
-
ingressDevice = senders[ 0 ].get( "device" )
egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
@@ -988,6 +984,7 @@
singleToMultiFailFlag = True
return main.FALSE
+
def installMultiToSingleIntent( main,
name,
senders,
@@ -1040,7 +1037,6 @@
be two links lower than the links before the two
switches are down
"""
-
assert main, "There is no main variable"
assert senders, "You must specify a sender"
assert recipients, "You must specify a recipient"
@@ -1137,6 +1133,7 @@
multiToSingleFailFlag = True
return main.FALSE
+
def testPointIntent( main,
name,
intentId,
@@ -1204,7 +1201,6 @@
switches are down
"""
-
# Parameter Validity Check
assert main, "There is no main variable"
assert senders, "You must specify a sender"
@@ -1265,11 +1261,11 @@
retValue=main.FALSE,
args=[ main ],
sleep=main.checkFlowCountSleep,
- attempts=3 ) and utilities.retry( f=checkFlowsState,
- retValue=main.FALSE,
- args=[ main ],
- sleep=main.checkFlowCountSleep,
- attempts=3 ):
+ attempts=attempts ) and utilities.retry( f=checkFlowsState,
+ retValue=main.FALSE,
+ args=[ main ],
+ sleep=main.checkFlowCountSleep,
+ attempts=attempts ):
main.assertReturnString += 'Initial Flow State Passed\n'
else:
main.assertReturnString += 'Intial Flow State Failed\n'
@@ -1292,7 +1288,7 @@
if utilities.retry( f=scapyCheckConnection,
retValue=main.FALSE,
args=( main, badSenderNames, recipientNames ),
- kwargs={ "expectFailure":True } ):
+ kwargs={ "expectFailure": True } ):
main.assertReturnString += 'Bad Sender Ping Passed\n'
else:
main.assertReturnString += 'Bad Sender Ping Failed\n'
@@ -1303,7 +1299,7 @@
if utilities.retry( f=scapyCheckConnection,
retValue=main.FALSE,
args=( main, senderNames, badRecipientNames ),
- kwargs={ "expectFailure":True } ):
+ kwargs={ "expectFailure": True } ):
main.assertReturnString += 'Bad Recipient Ping Passed\n'
else:
main.assertReturnString += 'Bad Recipient Ping Failed\n'
@@ -1352,11 +1348,11 @@
retValue=main.FALSE,
args=[ main ],
sleep=main.checkFlowCountSleep,
- attempts=attempts * 2 ) and utilities.retry( f=checkFlowsState,
+ attempts=attempts ) and utilities.retry( f=checkFlowsState,
retValue=main.FALSE,
args=[ main ],
sleep=main.checkFlowCountSleep,
- attempts=attempts * 2 ):
+ attempts=attempts ):
main.assertReturnString += 'Link Down Flow State Passed\n'
else:
main.assertReturnString += 'Link Down Flow State Failed\n'
@@ -1411,11 +1407,11 @@
retValue=main.FALSE,
args=[ main ],
sleep=main.checkFlowCountSleep,
- attempts=3 ) and utilities.retry( f=checkFlowsState,
- retValue=main.FALSE,
- args=[ main ],
- sleep=main.checkFlowCountSleep,
- attempts=3 ):
+ attempts=attempts ) and utilities.retry( f=checkFlowsState,
+ retValue=main.FALSE,
+ args=[ main ],
+ sleep=main.checkFlowCountSleep,
+ attempts=attempts ):
main.assertReturnString += 'Link Up Flow State Passed\n'
else:
main.assertReturnString += 'Link Up Flow State Failed\n'
@@ -1434,7 +1430,7 @@
if utilities.retry( f=scapyCheckConnection,
retValue=main.FALSE,
sleep=main.checkConnectionSleep,
- attempts=100,
+ attempts=attempts,
args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
else:
@@ -1453,6 +1449,7 @@
return testResult
+
def testEndPointFail( main,
name,
intentId,
@@ -1478,7 +1475,6 @@
"""
Test Multi point to single point intent Topology for Endpoint failures
"""
-
# Parameter Validity Check
assert main, "There is no main variable"
assert senders, "You must specify a sender"
@@ -1498,8 +1494,8 @@
recipientNames = [ x.get( "name" ) for x in recipients ]
isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
- connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
- connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
+ connectedSenderNames = [ x.get( "name" ) for x in senders if x.get( "name" ) not in isolatedSenderNames ]
+ connectedRecipientNames = [ x.get( "name" ) for x in recipients if x.get( "name" ) not in isolatedRecipientNames ]
for sender in senders:
if not sender.get( "device" ):
@@ -1508,7 +1504,7 @@
for recipient in recipients:
if not recipient.get( "device" ):
- main.log.warn( "Device not given for recipient {0}. Loading from " +\
+ main.log.warn( "Device not given for recipient {0}. Loading from " +
main.hostData.format( recipient.get( "name" ) ) )
recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
except( KeyError, TypeError ):
@@ -1698,7 +1694,7 @@
if utilities.retry( f=scapyCheckConnection,
retValue=main.FALSE,
attempts=attempts,
- args=( main, connectedSenderNames , connectedRecipientNames ) ):
+ args=( main, connectedSenderNames, connectedRecipientNames ) ):
main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
else:
main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
@@ -1826,10 +1822,10 @@
args=[ main ],
sleep=main.checkFlowCountSleep,
attempts=attempts ) and utilities.retry( f=checkFlowsState,
- retValue=main.FALSE,
- args=[ main ],
- sleep=main.checkFlowCountSleep,
- attempts=attempts ):
+ retValue=main.FALSE,
+ args=[ main ],
+ sleep=main.checkFlowCountSleep,
+ attempts=attempts ):
main.assertReturnString += 'Link Up Flow State Passed\n'
else:
main.assertReturnString += 'Link Up Flow State Failed\n'
@@ -1875,6 +1871,7 @@
main.log.info( "Pinging: " + str( hostList ) )
return main.Mininet1.pingallHosts( hostList )
+
def fwdPingall( main ):
"""
Use fwd app and pingall to discover all the hosts
@@ -1896,7 +1893,7 @@
# Send pingall in mininet
main.log.info( "Run Pingall" )
- pingResult = main.Mininet1.pingall( timeout = 600 )
+ pingResult = main.Mininet1.pingall( timeout=600 )
main.log.info( "Deactivating reactive forwarding app " )
deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
@@ -1908,6 +1905,7 @@
getDataResult = main.FALSE
return getDataResult
+
def confirmHostDiscovery( main ):
"""
Confirms that all ONOS nodes have discovered all scapy hosts
@@ -1937,7 +1935,8 @@
onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
for x in hostData
if len( x.get( "ipAddresses" ) ) > 0 ]
- if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
+ if not set( collections.Counter( scapyHostIPs ) ).issubset(
+ set( collections.Counter( onosHostIPs ) ) ):
main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
hostFails.append( controllerStr )
else:
@@ -1953,6 +1952,7 @@
else:
return main.TRUE
+
def sendDiscoveryArp( main, hosts=None ):
"""
Sends Discovery ARP packets from each host provided
@@ -1973,6 +1973,7 @@
host.sendPacket( packet=pkt, iface=iface )
main.log.info( "Sending ARP packet from {0}".format( host.name ) )
+
def populateHostData( main ):
"""
Populates hostsData
@@ -2008,6 +2009,7 @@
main.log.error( "TypeError while populating hostsData" )
return main.FALSE
+
def checkTopology( main, expectedLink ):
statusResult = main.TRUE
# Check onos topology
@@ -2022,6 +2024,7 @@
main.log.info( itemName + ": Topology match" )
return statusResult
+
def checkIntentState( main, intentsId ):
"""
This function will check intent state to make sure all the intents
@@ -2040,6 +2043,7 @@
intentResult = main.FALSE
return intentResult
+
def checkBandwidthAllocations( main, bandwidth ):
"""
Compare the given bandwith allocation output to the cli output on each node
@@ -2057,12 +2061,14 @@
bandwidthResult = main.FALSE
return bandwidthResult
+
def checkFlowsState( main ):
main.log.info( itemName + ": Check flows state" )
checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
return checkFlowsResult
+
def link( main, sw1, sw2, option ):
# link down
@@ -2071,6 +2077,7 @@
linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
return linkResult
+
def scapyCheckConnection( main,
senders,
recipients,
@@ -2093,7 +2100,7 @@
if not packetFilter:
packetFilter = 'ether host {}'
if useTCP:
- packetFilter += ' ip proto \\tcp tcp port {}'.format(main.params[ 'SDNIP' ][ 'dstPort' ])
+ packetFilter += ' ip proto \\tcp tcp port {}'.format( main.params[ 'SDNIP' ][ 'dstPort' ] )
if expectFailure:
timeout = 1
else:
@@ -2119,9 +2126,9 @@
continue
if vlanId:
- recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
+ recipientComp.startFilter( pktFilter=( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
else:
- recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
+ recipientComp.startFilter( pktFilter=packetFilter.format( senderComp.hostMac ) )
if not packet:
if vlanId:
@@ -2142,21 +2149,21 @@
if vlanId:
senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
else:
- senderComp.sendPacket( packet = pkt )
+ senderComp.sendPacket( packet=pkt )
if recipientComp.checkFilter( timeout ):
if expectFailure:
- main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
+ main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender, recipient ) )
connectionsFunctional = main.FALSE
else:
- main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
+ main.log.info( "Packet from {0} successfully received by {1}".format( sender, recipient ) )
connectionsFunctional = main.TRUE
else:
recipientComp.killFilter()
if expectFailure:
- main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
+ main.log.info( "As expected, packet from {0} was not received by {1}".format( sender, recipient ) )
else:
- main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
+ main.log.error( "Packet from {0} was not received by {1}".format( sender, recipient ) )
connectionsFunctional = main.FALSE
return connectionsFunctional
@@ -2166,7 +2173,6 @@
"""
Remove all intents in the intentsId
"""
-
onosSummary = []
removeIntentResult = main.TRUE
# Remove intents
@@ -2195,6 +2201,7 @@
return removeIntentResult
+
def checkFlowsCount( main ):
"""
Check flows count in each node
@@ -2212,7 +2219,7 @@
flowsCount.append( summaryJson.get( 'flows' ) )
if flowsCount:
- if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
+ if all( flows == flowsCount[ 0 ] for flows in flowsCount ):
main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
" flows in all ONOS node" )
else:
@@ -2225,6 +2232,7 @@
return main.TRUE
+
def checkLeaderChange( leaders1, leaders2 ):
"""
Checks for a change in intent partition leadership.
@@ -2250,18 +2258,19 @@
for dict1 in leaders1:
if "intent" in dict1.get( "topic", [] ):
for dict2 in leaders2:
- if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
- dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
+ if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and\
+ dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
mismatch = True
- main.log.error( "{0} changed leader from {1} to {2}".\
- format( dict1.get( "topic", "no-topic" ),\
- dict1.get( "leader", "no-leader" ),\
- dict2.get( "leader", "no-leader" ) ) )
+ main.log.error( "%s changed leader from %s to %s",
+ dict1.get( "topic", "no-topic" ),
+ dict1.get( "leader", "no-leader" ),
+ dict2.get( "leader", "no-leader" ) )
if mismatch:
return main.FALSE
else:
return main.TRUE
+
def report( main ):
"""
Report errors/warnings/exceptions
@@ -2278,26 +2287,26 @@
main.log.info( "ERROR report: \n" )
for i in range( main.numCtrls ):
main.ONOSbench.logReport( main.ONOSip[ i ],
- [ "ERROR" ],
- "d" )
+ [ "ERROR" ],
+ "d" )
main.log.info( "EXCEPTIONS report: \n" )
for i in range( main.numCtrls ):
main.ONOSbench.logReport( main.ONOSip[ i ],
- [ "Except" ],
- "d" )
+ [ "Except" ],
+ "d" )
main.log.info( "WARNING report: \n" )
for i in range( main.numCtrls ):
main.ONOSbench.logReport( main.ONOSip[ i ],
- [ "WARN" ],
- "d" )
+ [ "WARN" ],
+ "d" )
+
def flowDuration( main ):
"""
Check age of flows to see if flows are being overwritten
"""
- import time
main.log.info( "Getting current flow durations" )
flowsJson1 = main.CLIs[ 0 ].flows( noCore=True )
try:
@@ -2337,7 +2346,7 @@
def EncapsulatedIntentCheck( main, tag="" ):
"""
Check encapsulated intents
- tag: encapsulation tag (e.g. VLAN, MPLS)
+ tag: encapsulation tag ( e.g. VLAN, MPLS )
Getting added flows
Check tags on each flows
@@ -2345,7 +2354,6 @@
else failed
"""
- import json
HostJson = []
Jflows = main.CLIs[ 0 ].flows( noCore=True )
try:
@@ -2355,10 +2363,10 @@
return main.FALSE
for flow in Jflows:
- if len(flow[ "flows" ]) != 0:
+ if len( flow[ "flows" ] ) != 0:
HostJson.append( flow[ "flows" ] )
- totalflows = len( HostJson[ 0 ])
+ totalflows = len( HostJson[ 0 ] )
pop = 0
push = 0
@@ -2378,8 +2386,8 @@
else:
return main.FALSE
+
def ProtectedIntentCheck( main ):
- import json
intent = main.CLIs[ 0 ].intents( jsonFormat=False )
if "Protection" in intent:
return main.TRUE
diff --git a/TestON/tests/FUNC/FUNCintent/dependencies/startUp.py b/TestON/tests/FUNC/FUNCintent/dependencies/startUp.py
index bf2a2b6..8122586 100644
--- a/TestON/tests/FUNC/FUNCintent/dependencies/startUp.py
+++ b/TestON/tests/FUNC/FUNCintent/dependencies/startUp.py
@@ -1,16 +1,15 @@
"""
This wrapper function is use for starting up onos instance
"""
-
import time
import os
import json
+
def onosBuild( main, gitBranch ):
"""
This includes pulling ONOS and building it using maven install
"""
-
buildResult = main.FALSE
# Git checkout a branch of ONOS
@@ -18,10 +17,10 @@
# Does the git pull on the branch that was checked out
if not checkOutResult:
main.log.warn( "Failed to checked out " + gitBranch +
- " branch")
+ " branch" )
else:
main.log.info( "Successfully checked out " + gitBranch +
- " branch")
+ " branch" )
gitPullResult = main.ONOSbench.gitPull()
if gitPullResult == main.ERROR:
main.log.error( "Error pulling git branch" )
@@ -32,7 +31,3 @@
buildResult = main.ONOSbench.cleanInstall()
return buildResult
-
-
-
-
diff --git a/TestON/tests/FUNC/FUNCintent/dependencies/topo.py b/TestON/tests/FUNC/FUNCintent/dependencies/topo.py
index b44e3fc..7217d4d 100644
--- a/TestON/tests/FUNC/FUNCintent/dependencies/topo.py
+++ b/TestON/tests/FUNC/FUNCintent/dependencies/topo.py
@@ -1,11 +1,11 @@
"""
These functions can be used for topology comparisons
"""
-
import time
import os
import json
+
def getAllDevices( main ):
"""
Return a list containing the devices output from each ONOS node
@@ -13,9 +13,9 @@
devices = []
threads = []
for i in range( main.numCtrls ):
- t = main.Thread( target=main.CLIs[i].devices,
+ t = main.Thread( target=main.CLIs[ i ].devices,
name="devices-" + str( i ),
- args=[ ] )
+ args=[] )
threads.append( t )
t.start()
@@ -24,6 +24,7 @@
devices.append( t.result )
return devices
+
def getAllHosts( main ):
"""
Return a list containing the hosts output from each ONOS node
@@ -32,9 +33,9 @@
ipResult = main.TRUE
threads = []
for i in range( main.numCtrls ):
- t = main.Thread( target=main.CLIs[i].hosts,
+ t = main.Thread( target=main.CLIs[ i ].hosts,
name="hosts-" + str( i ),
- args=[ ] )
+ args=[] )
threads.append( t )
t.start()
@@ -43,6 +44,7 @@
hosts.append( t.result )
return hosts
+
def getAllPorts( main ):
"""
Return a list containing the ports output from each ONOS node
@@ -50,9 +52,9 @@
ports = []
threads = []
for i in range( main.numCtrls ):
- t = main.Thread( target=main.CLIs[i].ports,
+ t = main.Thread( target=main.CLIs[ i ].ports,
name="ports-" + str( i ),
- args=[ ] )
+ args=[] )
threads.append( t )
t.start()
@@ -61,6 +63,7 @@
ports.append( t.result )
return ports
+
def getAllLinks( main ):
"""
Return a list containing the links output from each ONOS node
@@ -68,9 +71,9 @@
links = []
threads = []
for i in range( main.numCtrls ):
- t = main.Thread( target=main.CLIs[i].links,
+ t = main.Thread( target=main.CLIs[ i ].links,
name="links-" + str( i ),
- args=[ ] )
+ args=[] )
threads.append( t )
t.start()
@@ -79,6 +82,7 @@
links.append( t.result )
return links
+
def getAllClusters( main ):
"""
Return a list containing the clusters output from each ONOS node
@@ -86,9 +90,9 @@
clusters = []
threads = []
for i in range( main.numCtrls ):
- t = main.Thread( target=main.CLIs[i].clusters,
+ t = main.Thread( target=main.CLIs[ i ].clusters,
name="clusters-" + str( i ),
- args=[ ] )
+ args=[] )
threads.append( t )
t.start()
@@ -96,5 +100,3 @@
t.join()
clusters.append( t.result )
return clusters
-
-