Initial pep8 compliant drivers
diff --git a/TestON/drivers/common/cli/emulator/remotemininetdriver.py b/TestON/drivers/common/cli/emulator/remotemininetdriver.py
index a8aedea..051d4ad 100644
--- a/TestON/drivers/common/cli/emulator/remotemininetdriver.py
+++ b/TestON/drivers/common/cli/emulator/remotemininetdriver.py
@@ -32,9 +32,10 @@
class RemoteMininetDriver( Emulator ):
"""
- RemoteMininetCliDriver is the basic driver which will handle the Mininet functions
- The main different between this and the MininetCliDriver is that this one does not build the mininet.
- It assumes that there is already a mininet running on the target.
+ RemoteMininetCliDriver is the basic driver which will handle the Mininet
+ functions. The main different between this and the MininetCliDriver is that
+ this one does not build the mininet. It assumes that there is already a
+ mininet running on the target.
"""
def __init__( self ):
super( Emulator, self ).__init__()
@@ -43,9 +44,9 @@
self.flag = 0
def connect( self, **connectargs ):
- #,user_name, ip_address, pwd,options ):
- # Here the main is the TestON instance after creating all the log
- # handles.
+ """,userName, ipAddress, pwd,options ):
+ Here the main is the TestON instance after creating all the log
+ handles."""
for key in connectargs:
vars( self )[ key ] = connectargs[ key ]
@@ -53,12 +54,12 @@
self.handle = super(
RemoteMininetDriver,
self ).connect(
- user_name=self.user_name,
- ip_address=self.ip_address,
+ userName=self.userName,
+ ipAddress=self.ipAddress,
port=None,
pwd=self.pwd )
- self.ssh_handle = self.handle
+ self.sshHandle = self.handle
# Copying the readme file to process the
if self.handle:
@@ -67,32 +68,20 @@
else:
main.log.error(
"Connection failed to the host " +
- self.user_name +
+ self.userName +
"@" +
- self.ip_address )
+ self.ipAddress )
main.log.error( "Failed to connect to the Mininet" )
return main.FALSE
-#*************************************************************************
-#*************************************************************************
-# checkForLoss will determine if any of the pings had any packets lost during the course of
-# the pingLong.
-#*************************************************************************
-#*************************************************************************
-
def checkForLoss( self, pingList ):
"""
Returns main.FALSE for 0% packet loss and
Returns main.ERROR if "found multiple mininet" is found and
Returns main.TRUE else
"""
- # TODO: maybe we want to return the % loss instead? This way we can set an acceptible loss %.
- # EX: 393 packets transmitted, 380 received, 3% packet loss, time 78519ms
- # we may need to return a float to get around rounding errors
-
self.handle.sendline( "" )
self.handle.expect( "\$" )
- # Clear any output waiting in the bg from killing pings
self.handle.sendline( "" )
self.handle.expect( "\$" )
self.handle.sendline( "cat " + pingList )
@@ -110,16 +99,18 @@
def pingLong( self, **pingParams ):
"""
- Starts a continuous ping on the mininet host outputing to a file in the /tmp dir.
+ Starts a continuous ping on the mininet host outputing
+ to a file in the /tmp dir.
"""
self.handle.sendline( "" )
self.handle.expect( "\$" )
- args = utilities.parse_args(
+ args = utilities.parseArgs(
[ "SRC", "TARGET", "PINGTIME" ], **pingParams )
precmd = "sudo rm /tmp/ping." + args[ "SRC" ]
self.execute( cmd=precmd, prompt="(.*)", timeout=10 )
- command = "sudo mininet/util/m " + args[ "SRC" ] + " ping " + args[
- "TARGET" ] + " -i .2 -w " + str( args[ 'PINGTIME' ] ) + " -D > /tmp/ping." + args[ "SRC" ] + " &"
+ command = "sudo mininet/util/m " + args[ "SRC" ] + " ping " +\
+ args[ "TARGET" ] + " -i .2 -w " + str( args[ 'PINGTIME' ] ) +\
+ " -D > /tmp/ping." + args[ "SRC" ] + " &"
main.log.info( command )
self.execute( cmd=command, prompt="(.*)", timeout=10 )
self.handle.sendline( "" )
@@ -128,11 +119,12 @@
def pingstatus( self, **pingParams ):
"""
- Tails the respective ping output file and check that there is a moving "64 bytes"
+ Tails the respective ping output file and check that
+ there is a moving "64 bytes"
"""
self.handle.sendline( "" )
self.handle.expect( "\$" )
- args = utilities.parse_args( [ "SRC" ], **pingParams )
+ args = utilities.parseArgs( [ "SRC" ], **pingParams )
self.handle.sendline( "tail /tmp/ping." + args[ "SRC" ] )
self.handle.expect( "tail" )
self.handle.expect( "\$" )
@@ -195,13 +187,11 @@
Ping from one mininet host to another
Currently the only supported Params: SRC and TARGET
"""
- args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams )
- #command = args[ "SRC" ] + " ping -" + args[ "CONTROLLER" ] + " " +args [ "TARGET" ]
+ args = utilities.parseArgs( [ "SRC", "TARGET" ], **pingParams )
command = args[ "SRC" ] + " ping " + \
args[ "TARGET" ] + " -c 1 -i 1 -W 8"
try:
main.log.warn( "Sending: " + command )
- #response = self.execute( cmd=command,prompt="mininet",timeout=10 )
self.handle.sendline( command )
i = self.handle.expect( [ command, pexpect.TIMEOUT ] )
if i == 1:
@@ -222,18 +212,15 @@
main.cleanup()
main.exit()
main.log.info( self.name + ": Ping Response: " + response )
- # if utilities.assert_matches(
- # expect=',\s0\%\spacket\sloss',actual=response,onpass="No Packet
- # loss",onfail="Host is not reachable" ):
if re.search( ',\s0\%\spacket\sloss', response ):
main.log.info( self.name + ": no packets lost, host is reachable" )
- main.last_result = main.TRUE
+ main.lastResult = main.TRUE
return main.TRUE
else:
main.log.error(
self.name +
": PACKET LOST, HOST IS NOT REACHABLE" )
- main.last_result = main.FALSE
+ main.lastResult = main.FALSE
return main.FALSE
def pingHost( self, **pingParams ):
@@ -242,25 +229,22 @@
"""
self.handle.sendline( "" )
self.handle.expect( "\$" )
- args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams )
- #command = "mininet/util/m " + args[ "SRC" ] + " ping "+args [ "TARGET" ]+" -c 4 -W 1 -i .2"
+ args = utilities.parseArgs( [ "SRC", "TARGET" ], **pingParams )
command = "mininet/util/m " + \
args[ "SRC" ] + " ping " + args[ "TARGET" ] + " -c 4 -W 1 -i .2"
main.log.info( command )
response = self.execute( cmd=command, prompt="rtt", timeout=10 )
- # self.handle.sendline( "" )
- # self.handle.expect( "\$" )
- if utilities.assert_matches(
+ if utilities.assertMatches(
expect=',\s0\%\spacket\sloss',
actual=response,
onpass="No Packet loss",
onfail="Host is not reachable" ):
main.log.info( "NO PACKET LOSS, HOST IS REACHABLE" )
- main.last_result = main.TRUE
+ main.lastResult = main.TRUE
return main.TRUE
else:
main.log.error( "PACKET LOST, HOST IS NOT REACHABLE" )
- main.last_result = main.FALSE
+ main.lastResult = main.FALSE
return main.FALSE
def checknum( self, num ):
@@ -290,7 +274,7 @@
else:
main.log.error( "Connection failed to the host" )
- def start_tcpdump(
+ def startTcpdump(
self,
filename,
intf="eth0",
@@ -314,23 +298,19 @@
" &" )
self.handle.sendline( "" )
self.handle.sendline( "" )
- i = self.handle.expect(
- [ 'No\ssuch\device', 'listening\son', pexpect.TIMEOUT, "\$" ], timeout=10 )
+ i = self.handle.expect( [ 'No\ssuch\device', 'listening\son',
+ pexpect.TIMEOUT, "\$" ], timeout=10 )
main.log.warn( self.handle.before + self.handle.after )
if i == 0:
- main.log.error(
- self.name +
- ": tcpdump - No such device exists. tcpdump attempted on: " +
- intf )
+ main.log.error( self.name + ": tcpdump - No such device exists.\
+ tcpdump attempted on: " + intf )
return main.FALSE
elif i == 1:
main.log.info( self.name + ": tcpdump started on " + intf )
return main.TRUE
elif i == 2:
- main.log.error(
- self.name +
- ": tcpdump command timed out! Check interface name, given interface was: " +
- intf )
+ main.log.error( self.name + ": tcpdump command timed out!\
+ Check interface name, given interface was: " + intf )
return main.FALSE
elif i == 3:
main.log.info( self.name + ": " + self.handle.before )
@@ -345,15 +325,13 @@
main.exit()
except:
main.log.info(
- self.name +
- ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
- main.log.error( traceback.print_exc() )
- main.log.info(
- ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
+ self.name + ":" * 60 )
+ main.log.error( traceback.printExc() )
+ main.log.info( ":" * 80 )
main.cleanup()
main.exit()
- def stop_tcpdump( self ):
+ def stopTcpdump( self ):
"pkills tcpdump"
try:
self.handle.sendline( "sudo pkill tcpdump" )
@@ -367,19 +345,17 @@
main.exit()
except:
main.log.info(
- self.name +
- ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
- main.log.error( traceback.print_exc() )
- main.log.info(
- ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
+ self.name + ":" * 60 )
+ main.log.error( traceback.printExc() )
+ main.log.info( ":" * 80 )
main.cleanup()
main.exit()
- def run_optical_mn_script( self ):
+ def runOpticalMnScript( self ):
"""
This function is only meant for Packet Optical.
- It runs the python script "optical.py" to create the packet layer( mn )
- topology
+ It runs the python script "optical.py" to create the
+ packet layer( mn ) topology
"""
try:
self.handle.sendline( "" )
@@ -411,17 +387,20 @@
response = main.FALSE
return response
- def get_flowTable( self, protoVersion, sw ):
- # TODO document usage
- # TODO add option to look at cookies. ignoreing them for now
+ def getFlowTable( self, protoVersion, sw ):
+ """
+ TODO document usage
+ TODO add option to look at cookies. ignoreing them for now
+
+ print "get_flowTable(" + str( protoVersion ) +" " + str( sw ) +")"
+ NOTE: Use format to force consistent flow table output across
+ versions"""
self.handle.sendline( "cd" )
self.handle.expect( [ "\$", pexpect.EOF, pexpect.TIMEOUT ] )
- # print "get_flowTable(" + str( protoVersion ) +" " + str( sw ) +")"
- # NOTE: Use format to force consistent flow table output across
- # versions
if protoVersion == 1.0:
command = "sudo ovs-ofctl dump-flows " + sw + \
- " -F OpenFlow10-table_id | awk '{OFS=\",\" ; print $1 $3 $6 $7 $8}' | cut -d ',' -f 2- | sort -n -k1 -r"
+ " -F OpenFlow10-table_id | awk '{OFS=\",\" ; print $1 $3 $6 \
+ $7 $8}' | cut -d ',' -f 2- | sort -n -k1 -r"
self.handle.sendline( command )
self.handle.expect( [ "k1 -r", pexpect.EOF, pexpect.TIMEOUT ] )
self.handle.expect(
@@ -431,7 +410,8 @@
return response
elif protoVersion == 1.3:
command = "sudo ovs-ofctl dump-flows " + sw + \
- " -O OpenFlow13 | awk '{OFS=\",\" ; print $1 $3 $6 $7}' | cut -d ',' -f 2- | sort -n -k1 -r"
+ " -O OpenFlow13 | awk '{OFS=\",\" ; print $1 $3 $6 $7}'\
+ | cut -d ',' -f 2- | sort -n -k1 -r"
self.handle.sendline( command )
self.handle.expect( [ "k1 -r", pexpect.EOF, pexpect.TIMEOUT ] )
self.handle.expect(
@@ -445,10 +425,10 @@
str(
type( protoVersion ) ) +
") '" +
- str(protoVersion) +
+ str( protoVersion ) +
"'" )
- def flow_comp( self, flow1, flow2 ):
+ def flowComp( self, flow1, flow2 ):
if flow1 == flow2:
return main.TRUE
else:
@@ -459,27 +439,23 @@
main.log.info( flow2 )
return main.FALSE
- def setIpTablesOUTPUT(
- self,
- dst_ip,
- dst_port,
- action='add',
- packet_type='tcp',
- rule='DROP' ):
+ def setIpTablesOUTPUT( self, dstIp, dstPort, action='add',
+ packetType='tcp', rule='DROP' ):
"""
Description:
- add or remove iptables rule to DROP ( default ) packets from specific IP and PORT
+ add or remove iptables rule to DROP ( default )
+ packets from specific IP and PORT
Usage:
* specify action ( 'add' or 'remove' )
when removing, pass in the same argument as you would add. It will
delete that specific rule.
- * specify the destination ip to block with dst_ip
- * specify destination port to block to dst_port
+ * specify the destination ip to block with dstIp
+ * specify destination port to block to dstPort
* optional packet type to block ( default tcp )
* optional iptables rule ( default DROP )
WARNING:
- * This function uses root privilege iptables command which may result in
- unwanted network errors. USE WITH CAUTION
+ * This function uses root privilege iptables command which may result
+ in unwanted network errors. USE WITH CAUTION
"""
import re
import time
@@ -488,14 +464,15 @@
# The strict checking methods of this driver function is intentional
# to discourage any misuse or error of iptables, which can cause
# severe network errors
- #*************
+ # *************
- # NOTE: Sleep needed to give some time for rule to be added and registered
+ # NOTE: Sleep needed to give some time
+ # for rule to be added and registered
# to the instance
time.sleep( 5 )
- action_type = action.lower()
- if action_type != 'add' and action_type != 'remove':
+ actionType = action.lower()
+ if actionType != 'add' and actionType != 'remove':
main.log.error(
"Invalid action type. 'add' or 'remove' table rule" )
if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG':
@@ -507,27 +484,28 @@
else:
# If there is no existing rule in the iptables, we will see an
- #'iptables:'... message. We expect to see this message.
+ # 'iptables:'... message. We expect to see this message.
# Otherwise, if there IS an existing rule, we will get the prompt
# back, hence why we expect $ for remove type. We want to remove
# an already existing rule
- if action_type == 'add':
- # NOTE: "iptables:" expect is a result of return from the command
- # iptables -C ...
- # Any changes by the iptables command return string
- # will result in failure of the function. ( deemed unlikely
- # at the time of writing this function )
+ if actionType == 'add':
+ # NOTE: "iptables:" expect is a result of
+ # return from the command
+ # iptables -C ...
+ # Any changes by the iptables command return string
+ # will result in failure of the function. ( deemed unlikely
+ # at the time of writing this function )
# Check for existing rules on current input
self.handle.sendline( "" )
self.handle.expect( "\$" )
self.handle.sendline(
"sudo iptables -C OUTPUT -p " +
- str( packet_type ) +
+ str( packetType ) +
" -d " +
- str( dst_ip ) +
+ str( dstIp ) +
" --dport " +
- str( dst_port ) +
+ str( dstPort ) +
" -j " +
str( rule ) )
i = self.handle.expect( [ "iptables:", "\$" ] )
@@ -536,61 +514,61 @@
print "after: "
print self.handle.after
- elif action_type == 'remove':
+ elif actionType == 'remove':
# Check for existing rules on current input
self.handle.sendline( "" )
self.handle.expect( "\$" )
self.handle.sendline(
"sudo iptables -C OUTPUT -p " +
- str( packet_type ) +
+ str( packetType ) +
" -d " +
- str( dst_ip ) +
+ str( dstIp ) +
" --dport " +
- str( dst_port ) +
+ str( dstPort ) +
" -j " +
str( rule ) )
self.handle.expect( "\$" )
print "before: "
print self.handle.before
- actual_string = self.handle.after
- expect_string = "iptables:"
+ actualString = self.handle.after
+ expectString = "iptables:"
print "Actual String:"
- print actual_string
+ print actualString
- if re.search( expect_string, actual_string ):
- match_result = main.TRUE
+ if re.search( expectString, actualString ):
+ matchResult = main.TRUE
else:
- match_result = main.FALSE
- # If match_result is main.TRUE, it means there is no matching rule.
+ matchResult = main.FALSE
+ # If matchResult is main.TRUE, it means there is no matching rule.
- # If tables does not exist and expected prompt is returned, go ahead and
- # add iptables rule
- if match_result == main.TRUE:
+ # If tables does not exist and expected prompt is returned,
+ # go ahead and add iptables rule
+ if matchResult == main.TRUE:
# Ensure action type is add
- if action_type == 'add':
- #-A is the 'append' action of iptables
- action_add = '-A'
+ if actionType == 'add':
+ # -A is the 'append' action of iptables
+ actionAdd = '-A'
try:
self.handle.sendline( "" )
self.handle.sendline(
"sudo iptables " +
- action_add +
+ actionAdd +
" OUTPUT -p " +
- str( packet_type ) +
+ str( packetType ) +
" -d " +
- str( dst_ip ) +
+ str( dstIp ) +
" --dport " +
- str( dst_port ) +
+ str( dstPort ) +
" -j " +
str( rule ) )
- info_string = "Rules added to " + str( self.name )
- info_string += "iptable rule added to block IP: " + \
- str( dst_ip )
- info_string += "Port: " + \
- str( dst_port ) + " Rule: " + str( rule )
+ infoString = "Rules added to " + str( self.name )
+ infoString += "iptable rule added to block IP: " + \
+ str( dstIp )
+ infoString += "Port: " + \
+ str( dstPort ) + " Rule: " + str( rule )
- main.log.info( info_string )
+ main.log.info( infoString )
self.handle.expect(
[ "\$", pexpect.EOF, pexpect.TIMEOUT ] )
@@ -599,40 +577,41 @@
self.name +
": Timeout exception in setIpTables function" )
except:
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.cleanup()
main.exit()
else:
main.log.error(
"Given rule already exists, but attempted to add it" )
- # If match_result is 0, it means there IS a matching rule provided
- elif match_result == main.FALSE:
+ # If matchResult is 0, it means there IS a matching rule provided
+ elif matchResult == main.FALSE:
# Ensure action type is remove
- if action_type == 'remove':
- #-D is the 'delete' rule of iptables
- action_remove = '-D'
+ if actionType == 'remove':
+ # -D is the 'delete' rule of iptables
+ actionRemove = '-D'
try:
self.handle.sendline( "" )
# Delete a specific rule specified into the function
self.handle.sendline(
"sudo iptables " +
- action_remove +
+ actionRemove +
" OUTPUT -p " +
- str( packet_type ) +
+ str( packetType ) +
" -d " +
- str( dst_ip ) +
+ str( dstIp ) +
" --dport " +
- str( dst_port ) +
+ str( dstPort ) +
" -j " +
str( rule ) )
- info_string = "Rules removed from " + str( self.name )
- info_string += " iptables rule removed from blocking IP: " + \
- str( dst_ip )
- info_string += " Port: " + \
- str( dst_port ) + " Rule: " + str( rule )
+ infoString = "Rules removed from " + str( self.name )
+ infoString += " iptables rule removed \
+ from blocking IP: " + \
+ str( dstIp )
+ infoString += " Port: " + \
+ str( dstPort ) + " Rule: " + str( rule )
- main.log.info( info_string )
+ main.log.info( infoString )
self.handle.expect(
[ "\$", pexpect.EOF, pexpect.TIMEOUT ] )
@@ -641,12 +620,13 @@
self.name +
": Timeout exception in setIpTables function" )
except:
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.cleanup()
main.exit()
else:
main.log.error(
- "Given rule does not exist, but attempted to remove it" )
+ "Given rule does not exist,\
+ but attempted to remove it" )
else:
# NOTE: If a bad usage of this function occurs, exit the entire
# test