Fix imports of xmlrpclib to be compatible with Python 3. Python 2 had xmlrpclib (client) and SimpleXMLRPCServer (server). In Python 3, these have been renamed to xmlrpc.client and xmlrpc.server.
The solution implemented here is to use the six library. It may seem excessive for this particular issue, but the six library provides helpers for Python 2 and 3 compatibility for many different issues. This is just the first of many uses of the six library. Signed-off-by: Russell Bryant <russ...@ovn.org> --- INSTALL.md | 2 +- m4/openvswitch.m4 | 6 ++++++ python/ovstest/rpcserver.py | 5 +++-- python/ovstest/util.py | 6 ++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index bf756f2..4f619fa 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -48,7 +48,7 @@ you will need the following software: privileges. If libcap-ng is installed, then Open vSwitch will automatically build with support for it. - - Python 2.7. + - Python 2.7. You must also have the Python six library. On Linux, you may choose to compile the kernel module that comes with the Open vSwitch distribution or to use the kernel module built into diff --git a/m4/openvswitch.m4 b/m4/openvswitch.m4 index 6d4e5da..0149c30 100644 --- a/m4/openvswitch.m4 +++ b/m4/openvswitch.m4 @@ -341,6 +341,12 @@ else: fi done done + if test $ovs_cv_python != no; then + if test -x "$ovs_cv_python" && ! "$ovs_cv_python" -c 'import six' >/dev/null 2>&1; then + ovs_cv_python=no + AC_MSG_WARN([Missing Python six library.]) + fi + fi fi]) AC_SUBST([HAVE_PYTHON]) AM_MISSING_PROG([PYTHON], [python]) diff --git a/python/ovstest/rpcserver.py b/python/ovstest/rpcserver.py index 80fc5dc..7abf13c 100644 --- a/python/ovstest/rpcserver.py +++ b/python/ovstest/rpcserver.py @@ -20,8 +20,8 @@ from __future__ import print_function import exceptions import sys -import xmlrpclib +import six.moves.xmlrpc_client from twisted.internet import reactor from twisted.internet.error import CannotListenError from twisted.web import xmlrpc @@ -108,7 +108,8 @@ class TestArena(xmlrpc.XMLRPC): Returns the ovs-test server IP address that the other ovs-test server with the given ip will see. """ - server1 = xmlrpclib.Server("http://%s:%u/" % (his_ip, his_port)) + server1 = six.moves.xmlrpc_client.Server("http://%s:%u/" % + (his_ip, his_port)) return server1.get_my_address() def xmlrpc_create_udp_listener(self, port): diff --git a/python/ovstest/util.py b/python/ovstest/util.py index 16c012e..a522195 100644 --- a/python/ovstest/util.py +++ b/python/ovstest/util.py @@ -25,7 +25,8 @@ import struct import signal import subprocess import re -import xmlrpclib + +import six.moves.xmlrpc_client def str_ip(ip_address): @@ -167,7 +168,8 @@ def get_interface_from_routing_decision(ip): def rpc_client(ip, port): - return xmlrpclib.Server("http://%s:%u/" % (ip, port), allow_none=True) + return six.moves.xmlrpc_client.Server("http://%s:%u/" % (ip, port), + allow_none=True) def sigint_intercept(): -- 2.5.0 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev