]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Allow users to run 'tox -epy34'
authorCyril Roelandt <cyril.roelandt@enovance.com>
Thu, 7 May 2015 13:00:38 +0000 (13:00 +0000)
committerCyril Roelandt <cyril.roelandt@enovance.com>
Mon, 11 May 2015 14:09:51 +0000 (16:09 +0200)
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

16 files changed:
bin/neutron-rootwrap-xen-dom0
neutron/__init__.py
neutron/agent/l3/router_processing_queue.py
neutron/agent/linux/utils.py
neutron/agent/ovsdb/impl_idl.py
neutron/agent/ovsdb/native/connection.py
neutron/common/repos.py
neutron/plugins/ibm/common/constants.py
neutron/plugins/ibm/sdnve_api.py
neutron/plugins/oneconvergence/lib/plugin_helper.py
neutron/tests/tempest/common/glance_http.py
neutron/tests/tempest/services/botoclients.py
neutron/tests/unit/_test_extension_portbindings.py
neutron/tests/unit/test_policy.py
neutron/tests/unit/test_wsgi.py
tox.ini

index a3ebb77e7741fa490074eecf3aa670b9ee17e083..8e92d33fed1ed7e2215dcf475f326fcf2352049f 100755 (executable)
@@ -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
index 710b18c464114e5a14425819bed11b26cce6962a..fa7a241e59e65ed8293f467d9ca48eebeaaeb1ca 100644 (file)
 #    under the License.
 
 import gettext
+import six
 
 
-gettext.install('neutron', unicode=1)
+if six.PY2:
+    gettext.install('neutron', unicode=1)
+else:
+    gettext.install('neutron')
index 1c8ee26b17030156b0a3ced793de0764844f6f10..a46177005dc7b27242b28974d7eaca949c3d6a1a 100644 (file)
@@ -14,7 +14,7 @@
 #
 
 import datetime
-import Queue
+from six.moves import queue as Queue
 
 from oslo_utils import timeutils
 
index 548b4cddb92cc0de15b812cab913972f389f018b..c38ed138489cb116007b8fdbc398a6ffb5302536 100644 (file)
@@ -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
index 4a73707811543cd1046bac44c6346ad3c943d38b..45851f8d116aa00696a6d6c751fd3510a204b733 100644 (file)
@@ -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
index ce0d21691e53e772bc4b1bd7d260994f29903981..7f2b10a1566d7970545fd4890b2d29587eccc441 100644 (file)
@@ -13,7 +13,7 @@
 #    under the License.
 
 import os
-import Queue
+from six.moves import queue as Queue
 import threading
 import traceback
 
index 59b8735b7f26f8daa92d1407dcbf9dc26c5a9f2c..2bd15737e56f2417b958a518642d54b600ec19b9 100644 (file)
 # 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__)
 
index 758f630f539b97cf1ed571596aec1295570cd642..f296c49e21b6fe5817ec0da9e5202363b8c9a2d5 100644 (file)
@@ -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'
index ac2e6a46186644d0db0cb6c872ea11c1b6473000..5fe8af0665b7d778461147193838a0ddf8b20479 100644 (file)
@@ -15,7 +15,7 @@
 #    under the License.
 
 
-import httplib
+from six.moves import http_client as httplib
 import urllib
 
 import httplib2
index 58b94797cfc120af1c1721ebff9e308594a08794..66fbacdd7476f0dc0e2258d2709c7230f52b37cd 100644 (file)
@@ -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
index 66fc2abd4538a7633de459513a1d6a903a4e7e1d..66504773965835845d770cad1020331e4cc0cd76 100644 (file)
@@ -17,7 +17,7 @@
 
 import copy
 import hashlib
-import httplib
+from six.moves import http_client as httplib
 import json
 import posixpath
 import re
index 025e8e1830c0945f789c6468d9dd21056d4afcac..87d526637859ab5f3087825c5579a1fd0963aeff 100644 (file)
@@ -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
index d43ede72b8cc5ef8d3e1fcc20441b36ca9990cae..b3d82abcca7ab9a076437623f76a77c353c3f9ce 100644 (file)
@@ -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
index 61b4b9b72c559ef363042bf6207d73f54784f5aa..4d732d32588a860e8f605ae52550a345de0de429 100644 (file)
@@ -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,
index dea7712e0cb74f555e3d5db677edbafb191b9dbe..584a66610eea0307d0294003ceec0663f9bd07aa 100644 (file)
 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 6a9cc8ffb8f8540fb3c53a7346da36e34a182bf0..05c165c30667176062730603c277558804341b30 100644 (file)
--- 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