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
This commit is contained in:
parent
62ccf394c2
commit
8db41f04d5
@ -23,7 +23,7 @@ responsible determining whether a command is safe to execute.
|
|||||||
"""
|
"""
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import ConfigParser
|
from six.moves import configparser as ConfigParser
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import select
|
import select
|
||||||
|
@ -14,6 +14,10 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
|
import six
|
||||||
|
|
||||||
|
|
||||||
gettext.install('neutron', unicode=1)
|
if six.PY2:
|
||||||
|
gettext.install('neutron', unicode=1)
|
||||||
|
else:
|
||||||
|
gettext.install('neutron')
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import Queue
|
from six.moves import queue as Queue
|
||||||
|
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
import fcntl
|
import fcntl
|
||||||
import glob
|
import glob
|
||||||
import grp
|
import grp
|
||||||
import httplib
|
|
||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
import shlex
|
import shlex
|
||||||
@ -33,6 +32,7 @@ from oslo_log import log as logging
|
|||||||
from oslo_log import loggers
|
from oslo_log import loggers
|
||||||
from oslo_rootwrap import client
|
from oslo_rootwrap import client
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
|
from six.moves import http_client as httplib
|
||||||
|
|
||||||
from neutron.agent.common import config
|
from neutron.agent.common import config
|
||||||
from neutron.common import constants
|
from neutron.common import constants
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import Queue
|
from six.moves import queue as Queue
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import Queue
|
from six.moves import queue as Queue
|
||||||
import threading
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import ConfigParser
|
|
||||||
import importlib
|
import importlib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from six.moves import configparser as ConfigParser
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
import httplib
|
from six.moves import http_client as httplib
|
||||||
|
|
||||||
# Topic for info notifications between the plugin and agent
|
# Topic for info notifications between the plugin and agent
|
||||||
INFO = 'info'
|
INFO = 'info'
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
import httplib
|
from six.moves import http_client as httplib
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
import httplib2
|
import httplib2
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
"""Library to talk to NVSD controller."""
|
"""Library to talk to NVSD controller."""
|
||||||
|
|
||||||
import httplib
|
from six.moves import http_client as httplib
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
import hashlib
|
import hashlib
|
||||||
import httplib
|
from six.moves import http_client as httplib
|
||||||
import json
|
import json
|
||||||
import posixpath
|
import posixpath
|
||||||
import re
|
import re
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import ConfigParser
|
from six.moves import configparser as ConfigParser
|
||||||
import contextlib
|
import contextlib
|
||||||
from tempest_lib import exceptions as lib_exc
|
from tempest_lib import exceptions as lib_exc
|
||||||
import types
|
import types
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httplib
|
from six.moves import http_client as httplib
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from webob import exc
|
from webob import exc
|
||||||
|
@ -15,9 +15,6 @@
|
|||||||
|
|
||||||
"""Test of Policy Engine For Neutron"""
|
"""Test of Policy Engine For Neutron"""
|
||||||
|
|
||||||
import StringIO
|
|
||||||
import urllib2
|
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
@ -112,7 +109,7 @@ class PolicyTestCase(base.BaseTestCase):
|
|||||||
self.assertEqual(result, True)
|
self.assertEqual(result, True)
|
||||||
|
|
||||||
@mock.patch.object(urlrequest, 'urlopen',
|
@mock.patch.object(urlrequest, 'urlopen',
|
||||||
return_value=StringIO.StringIO("True"))
|
return_value=six.StringIO("True"))
|
||||||
def test_enforce_http_true(self, mock_urlrequest):
|
def test_enforce_http_true(self, mock_urlrequest):
|
||||||
action = "example:get_http"
|
action = "example:get_http"
|
||||||
target = {}
|
target = {}
|
||||||
@ -124,7 +121,7 @@ class PolicyTestCase(base.BaseTestCase):
|
|||||||
def fakeurlopen(url, post_data):
|
def fakeurlopen(url, post_data):
|
||||||
return six.StringIO("False")
|
return six.StringIO("False")
|
||||||
|
|
||||||
with mock.patch.object(urllib2, 'urlopen', new=fakeurlopen):
|
with mock.patch.object(urlrequest, 'urlopen', new=fakeurlopen):
|
||||||
action = "example:get_http"
|
action = "example:get_http"
|
||||||
target = {}
|
target = {}
|
||||||
self.assertRaises(common_policy.PolicyNotAuthorized,
|
self.assertRaises(common_policy.PolicyNotAuthorized,
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
import urllib2
|
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
import six.moves.urllib.request as urlrequest
|
||||||
import testtools
|
import testtools
|
||||||
import webob
|
import webob
|
||||||
import webob.exc
|
import webob.exc
|
||||||
@ -41,12 +41,12 @@ def open_no_proxy(*args, **kwargs):
|
|||||||
# introduced in python 2.7.9 under PEP-0476
|
# introduced in python 2.7.9 under PEP-0476
|
||||||
# https://github.com/python/peps/blob/master/pep-0476.txt
|
# https://github.com/python/peps/blob/master/pep-0476.txt
|
||||||
if hasattr(ssl, "_create_unverified_context"):
|
if hasattr(ssl, "_create_unverified_context"):
|
||||||
opener = urllib2.build_opener(
|
opener = urlrequest.build_opener(
|
||||||
urllib2.ProxyHandler({}),
|
urlrequest.ProxyHandler({}),
|
||||||
urllib2.HTTPSHandler(context=ssl._create_unverified_context())
|
urlrequest.HTTPSHandler(context=ssl._create_unverified_context())
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
opener = urllib2.build_opener(urllib2.ProxyHandler({}))
|
opener = urlrequest.build_opener(urlrequest.ProxyHandler({}))
|
||||||
return opener.open(*args, **kwargs)
|
return opener.open(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
7
tox.ini
7
tox.ini
@ -1,5 +1,5 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist = py27,pep8
|
envlist = py27,py34,pep8
|
||||||
minversion = 1.8
|
minversion = 1.8
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
|
|
||||||
@ -96,6 +96,11 @@ commands = {posargs}
|
|||||||
[testenv:docs]
|
[testenv:docs]
|
||||||
commands = sphinx-build -W -b html doc/source doc/build
|
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]
|
[flake8]
|
||||||
# E125 continuation line does not distinguish itself from next logical line
|
# E125 continuation line does not distinguish itself from next logical line
|
||||||
# E126 continuation line over-indented for hanging indent
|
# E126 continuation line over-indented for hanging indent
|
||||||
|
Loading…
x
Reference in New Issue
Block a user