From 8db41f04d54526104920f3a160203ecf7ef453b0 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Thu, 7 May 2015 13:00:38 +0000 Subject: [PATCH] Allow users to run 'tox -epy34' With this commit, it is possible to successfully run 'tox -epy34', even though only a small amount of tests will actually be run. This is a required step in making Neutron compatible with Python 3, as described in the 'Porting to Python 3' specification. This commit: - fixes some broken imports, while making sure they still work with Python 3; - updates a call to gettext.install; - adds a py34 target in tox.ini. Change-Id: I91cc7a992d05ea85f7004d1c5a45a1c02cbf1c85 Blueprint: neutron-python3 --- bin/neutron-rootwrap-xen-dom0 | 2 +- neutron/__init__.py | 6 +++++- neutron/agent/l3/router_processing_queue.py | 2 +- neutron/agent/linux/utils.py | 2 +- neutron/agent/ovsdb/impl_idl.py | 2 +- neutron/agent/ovsdb/native/connection.py | 2 +- neutron/common/repos.py | 2 +- neutron/plugins/ibm/common/constants.py | 2 +- neutron/plugins/ibm/sdnve_api.py | 2 +- neutron/plugins/oneconvergence/lib/plugin_helper.py | 2 +- neutron/tests/tempest/common/glance_http.py | 2 +- neutron/tests/tempest/services/botoclients.py | 2 +- neutron/tests/unit/_test_extension_portbindings.py | 2 +- neutron/tests/unit/test_policy.py | 7 ++----- neutron/tests/unit/test_wsgi.py | 10 +++++----- tox.ini | 7 ++++++- 16 files changed, 30 insertions(+), 24 deletions(-) diff --git a/bin/neutron-rootwrap-xen-dom0 b/bin/neutron-rootwrap-xen-dom0 index a3ebb77e774..8e92d33fed1 100755 --- a/bin/neutron-rootwrap-xen-dom0 +++ b/bin/neutron-rootwrap-xen-dom0 @@ -23,7 +23,7 @@ responsible determining whether a command is safe to execute. """ from __future__ import print_function -import ConfigParser +from six.moves import configparser as ConfigParser import json import os import select diff --git a/neutron/__init__.py b/neutron/__init__.py index 710b18c4641..fa7a241e59e 100644 --- a/neutron/__init__.py +++ b/neutron/__init__.py @@ -14,6 +14,10 @@ # under the License. import gettext +import six -gettext.install('neutron', unicode=1) +if six.PY2: + gettext.install('neutron', unicode=1) +else: + gettext.install('neutron') diff --git a/neutron/agent/l3/router_processing_queue.py b/neutron/agent/l3/router_processing_queue.py index 1c8ee26b170..a46177005dc 100644 --- a/neutron/agent/l3/router_processing_queue.py +++ b/neutron/agent/l3/router_processing_queue.py @@ -14,7 +14,7 @@ # import datetime -import Queue +from six.moves import queue as Queue from oslo_utils import timeutils diff --git a/neutron/agent/linux/utils.py b/neutron/agent/linux/utils.py index 548b4cddb92..c38ed138489 100644 --- a/neutron/agent/linux/utils.py +++ b/neutron/agent/linux/utils.py @@ -16,7 +16,6 @@ import fcntl import glob import grp -import httplib import os import pwd import shlex @@ -33,6 +32,7 @@ from oslo_log import log as logging from oslo_log import loggers from oslo_rootwrap import client from oslo_utils import excutils +from six.moves import http_client as httplib from neutron.agent.common import config from neutron.common import constants diff --git a/neutron/agent/ovsdb/impl_idl.py b/neutron/agent/ovsdb/impl_idl.py index 4a737078115..45851f8d116 100644 --- a/neutron/agent/ovsdb/impl_idl.py +++ b/neutron/agent/ovsdb/impl_idl.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -import Queue +from six.moves import queue as Queue import time from oslo_config import cfg diff --git a/neutron/agent/ovsdb/native/connection.py b/neutron/agent/ovsdb/native/connection.py index ce0d21691e5..7f2b10a1566 100644 --- a/neutron/agent/ovsdb/native/connection.py +++ b/neutron/agent/ovsdb/native/connection.py @@ -13,7 +13,7 @@ # under the License. import os -import Queue +from six.moves import queue as Queue import threading import traceback diff --git a/neutron/common/repos.py b/neutron/common/repos.py index 59b8735b7f2..2bd15737e56 100644 --- a/neutron/common/repos.py +++ b/neutron/common/repos.py @@ -13,12 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import ConfigParser import importlib import os from oslo_config import cfg from oslo_log import log as logging +from six.moves import configparser as ConfigParser LOG = logging.getLogger(__name__) diff --git a/neutron/plugins/ibm/common/constants.py b/neutron/plugins/ibm/common/constants.py index 758f630f539..f296c49e21b 100644 --- a/neutron/plugins/ibm/common/constants.py +++ b/neutron/plugins/ibm/common/constants.py @@ -15,7 +15,7 @@ # under the License. -import httplib +from six.moves import http_client as httplib # Topic for info notifications between the plugin and agent INFO = 'info' diff --git a/neutron/plugins/ibm/sdnve_api.py b/neutron/plugins/ibm/sdnve_api.py index ac2e6a46186..5fe8af0665b 100644 --- a/neutron/plugins/ibm/sdnve_api.py +++ b/neutron/plugins/ibm/sdnve_api.py @@ -15,7 +15,7 @@ # under the License. -import httplib +from six.moves import http_client as httplib import urllib import httplib2 diff --git a/neutron/plugins/oneconvergence/lib/plugin_helper.py b/neutron/plugins/oneconvergence/lib/plugin_helper.py index 58b94797cfc..66fbacdd747 100644 --- a/neutron/plugins/oneconvergence/lib/plugin_helper.py +++ b/neutron/plugins/oneconvergence/lib/plugin_helper.py @@ -14,7 +14,7 @@ """Library to talk to NVSD controller.""" -import httplib +from six.moves import http_client as httplib import time from oslo_config import cfg diff --git a/neutron/tests/tempest/common/glance_http.py b/neutron/tests/tempest/common/glance_http.py index 66fc2abd453..66504773965 100644 --- a/neutron/tests/tempest/common/glance_http.py +++ b/neutron/tests/tempest/common/glance_http.py @@ -17,7 +17,7 @@ import copy import hashlib -import httplib +from six.moves import http_client as httplib import json import posixpath import re diff --git a/neutron/tests/tempest/services/botoclients.py b/neutron/tests/tempest/services/botoclients.py index 025e8e1830c..87d52663785 100644 --- a/neutron/tests/tempest/services/botoclients.py +++ b/neutron/tests/tempest/services/botoclients.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -import ConfigParser +from six.moves import configparser as ConfigParser import contextlib from tempest_lib import exceptions as lib_exc import types diff --git a/neutron/tests/unit/_test_extension_portbindings.py b/neutron/tests/unit/_test_extension_portbindings.py index d43ede72b8c..b3d82abcca7 100644 --- a/neutron/tests/unit/_test_extension_portbindings.py +++ b/neutron/tests/unit/_test_extension_portbindings.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -import httplib +from six.moves import http_client as httplib from oslo_config import cfg from webob import exc diff --git a/neutron/tests/unit/test_policy.py b/neutron/tests/unit/test_policy.py index 61b4b9b72c5..4d732d32588 100644 --- a/neutron/tests/unit/test_policy.py +++ b/neutron/tests/unit/test_policy.py @@ -15,9 +15,6 @@ """Test of Policy Engine For Neutron""" -import StringIO -import urllib2 - import mock from oslo_config import cfg from oslo_serialization import jsonutils @@ -112,7 +109,7 @@ class PolicyTestCase(base.BaseTestCase): self.assertEqual(result, True) @mock.patch.object(urlrequest, 'urlopen', - return_value=StringIO.StringIO("True")) + return_value=six.StringIO("True")) def test_enforce_http_true(self, mock_urlrequest): action = "example:get_http" target = {} @@ -124,7 +121,7 @@ class PolicyTestCase(base.BaseTestCase): def fakeurlopen(url, post_data): return six.StringIO("False") - with mock.patch.object(urllib2, 'urlopen', new=fakeurlopen): + with mock.patch.object(urlrequest, 'urlopen', new=fakeurlopen): action = "example:get_http" target = {} self.assertRaises(common_policy.PolicyNotAuthorized, diff --git a/neutron/tests/unit/test_wsgi.py b/neutron/tests/unit/test_wsgi.py index dea7712e0cb..584a66610ee 100644 --- a/neutron/tests/unit/test_wsgi.py +++ b/neutron/tests/unit/test_wsgi.py @@ -16,10 +16,10 @@ import os import socket import ssl -import urllib2 import mock from oslo_config import cfg +import six.moves.urllib.request as urlrequest import testtools import webob import webob.exc @@ -41,12 +41,12 @@ def open_no_proxy(*args, **kwargs): # introduced in python 2.7.9 under PEP-0476 # https://github.com/python/peps/blob/master/pep-0476.txt if hasattr(ssl, "_create_unverified_context"): - opener = urllib2.build_opener( - urllib2.ProxyHandler({}), - urllib2.HTTPSHandler(context=ssl._create_unverified_context()) + opener = urlrequest.build_opener( + urlrequest.ProxyHandler({}), + urlrequest.HTTPSHandler(context=ssl._create_unverified_context()) ) else: - opener = urllib2.build_opener(urllib2.ProxyHandler({})) + opener = urlrequest.build_opener(urlrequest.ProxyHandler({})) return opener.open(*args, **kwargs) diff --git a/tox.ini b/tox.ini index 6a9cc8ffb8f..05c165c3066 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,pep8 +envlist = py27,py34,pep8 minversion = 1.8 skipsdist = True @@ -96,6 +96,11 @@ commands = {posargs} [testenv:docs] commands = sphinx-build -W -b html doc/source doc/build +[testenv:py34] +commands = python -m testtools.run \ + neutron.tests.fullstack.test_l3_agent \ + neutron.tests.unit.common.test_rpc + [flake8] # E125 continuation line does not distinguish itself from next logical line # E126 continuation line over-indented for hanging indent