2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-01 14:55:18 +00:00

python: Fix print function compatibility.

The print statement from Python 2 is a function in Python 3.  Enable
print function support for Python 2 and convert print statements to
function calls.

Enable the H233 flake8 warning.  If the hacking plugin is installed,
this will generate warnings for print statement usage not compatible
with Python 3.

  H233 Python 3.x incompatible use of print operator

Signed-off-by: Russell Bryant <russell@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
Russell Bryant
2015-12-14 10:21:53 -05:00
parent f3068bff92
commit 8ea171aba0
9 changed files with 74 additions and 57 deletions

View File

@@ -16,6 +16,8 @@
rpcserver is an XML RPC server that allows RPC client to initiate tests
"""
from __future__ import print_function
import exceptions
import sys
import xmlrpclib
@@ -357,7 +359,7 @@ def start_rpc_server(port):
rpc_server = TestArena()
reactor.listenTCP(port, server.Site(rpc_server))
try:
print "Starting RPC server\n"
print("Starting RPC server\n")
sys.stdout.flush()
# If this server was started from ovs-test client then we must flush
# STDOUT so that client would know that server is ready to accept

View File

@@ -10,6 +10,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import math
import time
@@ -28,11 +30,11 @@ def do_udp_tests(receiver, sender, tbwidth, duration, port_sizes):
udpformat = '{0:>15} {1:>15} {2:>15} {3:>15} {4:>15}'
print ("UDP test from %s:%u to %s:%u with target bandwidth %s" %
print("UDP test from %s:%u to %s:%u with target bandwidth %s" %
(sender[0], sender[1], receiver[0], receiver[1],
util.bandwidth_to_string(tbwidth)))
print udpformat.format("Datagram Size", "Snt Datagrams", "Rcv Datagrams",
"Datagram Loss", "Bandwidth")
print(udpformat.format("Datagram Size", "Snt Datagrams", "Rcv Datagrams",
"Datagram Loss", "Bandwidth"))
for size in port_sizes:
listen_handle = NO_HANDLE
@@ -42,8 +44,8 @@ def do_udp_tests(receiver, sender, tbwidth, duration, port_sizes):
listen_handle = server1.create_udp_listener(receiver[3])
if listen_handle == NO_HANDLE:
print ("Server could not open UDP listening socket on port"
" %u. Try to restart the server.\n" % receiver[3])
print("Server could not open UDP listening socket on port"
" %u. Try to restart the server.\n" % receiver[3])
return
send_handle = server2.create_udp_sender(
(util.ip_from_cidr(receiver[2]),
@@ -61,14 +63,14 @@ def do_udp_tests(receiver, sender, tbwidth, duration, port_sizes):
snt_packets) / 100
bwidth = (rcv_packets * size) / duration
print udpformat.format(size, snt_packets, rcv_packets,
'%.2f%%' % loss, util.bandwidth_to_string(bwidth))
print(udpformat.format(size, snt_packets, rcv_packets,
'%.2f%%' % loss, util.bandwidth_to_string(bwidth)))
finally:
if listen_handle != NO_HANDLE:
server1.close_udp_listener(listen_handle)
if send_handle != NO_HANDLE:
server2.close_udp_sender(send_handle)
print "\n"
print("\n")
def do_tcp_tests(receiver, sender, duration):
@@ -77,17 +79,17 @@ def do_tcp_tests(receiver, sender, duration):
server2 = util.rpc_client(sender[0], sender[1])
tcpformat = '{0:>15} {1:>15} {2:>15}'
print "TCP test from %s:%u to %s:%u (full speed)" % (sender[0], sender[1],
receiver[0], receiver[1])
print tcpformat.format("Snt Bytes", "Rcv Bytes", "Bandwidth")
print("TCP test from %s:%u to %s:%u (full speed)" % (sender[0], sender[1],
receiver[0], receiver[1]))
print(tcpformat.format("Snt Bytes", "Rcv Bytes", "Bandwidth"))
listen_handle = NO_HANDLE
send_handle = NO_HANDLE
try:
listen_handle = server1.create_tcp_listener(receiver[3])
if listen_handle == NO_HANDLE:
print ("Server was unable to open TCP listening socket on port"
" %u. Try to restart the server.\n" % receiver[3])
print("Server was unable to open TCP listening socket on port"
" %u. Try to restart the server.\n" % receiver[3])
return
send_handle = server2.create_tcp_sender(util.ip_from_cidr(receiver[2]),
receiver[3], duration)
@@ -99,14 +101,14 @@ def do_tcp_tests(receiver, sender, duration):
bwidth = rcv_bytes / duration
print tcpformat.format(snt_bytes, rcv_bytes,
util.bandwidth_to_string(bwidth))
print(tcpformat.format(snt_bytes, rcv_bytes,
util.bandwidth_to_string(bwidth)))
finally:
if listen_handle != NO_HANDLE:
server1.close_tcp_listener(listen_handle)
if send_handle != NO_HANDLE:
server2.close_tcp_sender(send_handle)
print "\n"
print("\n")
def do_l3_tests(node1, node2, bandwidth, duration, ps, type):