[ovs-dev] [PATCH 11/55] python: Fix print function compatibility.
Russell Bryant
russell at ovn.org
Mon Dec 21 20:47:11 UTC 2015
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.
Signed-off-by: Russell Bryant <russell at ovn.org>
---
python/ovstest/rpcserver.py | 4 +++-
python/ovstest/tests.py | 36 +++++++++++++++++++-----------------
2 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/python/ovstest/rpcserver.py b/python/ovstest/rpcserver.py
index 5c92014..434344e 100644
--- a/python/ovstest/rpcserver.py
+++ b/python/ovstest/rpcserver.py
@@ -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
diff --git a/python/ovstest/tests.py b/python/ovstest/tests.py
index 26befef..63d761f 100644
--- a/python/ovstest/tests.py
+++ b/python/ovstest/tests.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
import math
import time
@@ -16,11 +18,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")
+ util.bandwidth_to_string(tbwidth))))
+ print(udpformat.format("Datagram Size", "Snt Datagrams", "Rcv Datagrams",
+ "Datagram Loss", "Bandwidth"))
for size in port_sizes:
listen_handle = NO_HANDLE
@@ -30,8 +32,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]),
@@ -49,14 +51,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):
@@ -65,17 +67,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)
@@ -87,14 +89,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):
--
2.5.0
More information about the dev
mailing list