From 1e5ef92f6af7b1a7c9d9221110a1e0accf2b4405 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Wed, 1 Jul 2015 19:16:43 +0000 Subject: [PATCH] Python3: do not use urllib.urlencode It has been moved in Python3. Use six.moves to have code that works with both Python 2 and 3. Change-Id: I5f286b1f784b3b7bb37852b00169a6c1227eb74b Blueprint: neutron-python3 --- neutron/api/api_common.py | 6 +++--- neutron/plugins/ibm/sdnve_api.py | 4 ++-- .../tempest/services/identity/v3/json/identity_client.py | 7 ++++--- .../tempest/services/identity/v3/json/region_client.py | 5 +++-- .../tests/tempest/services/network/json/network_client.py | 6 +++--- neutron/tests/tempest/test.py | 4 ++-- tox.ini | 6 ++++++ 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/neutron/api/api_common.py b/neutron/api/api_common.py index 7c062cd6d65..778c40794da 100644 --- a/neutron/api/api_common.py +++ b/neutron/api/api_common.py @@ -14,11 +14,11 @@ # under the License. import functools -import urllib from oslo_config import cfg from oslo_log import log as logging import six +from six.moves.urllib import parse from webob import exc from neutron.common import constants @@ -60,7 +60,7 @@ def get_previous_link(request, items, id_key): marker = items[0][id_key] params['marker'] = marker params['page_reverse'] = True - return "%s?%s" % (request.path_url, urllib.urlencode(params)) + return "%s?%s" % (request.path_url, parse.urlencode(params)) def get_next_link(request, items, id_key): @@ -70,7 +70,7 @@ def get_next_link(request, items, id_key): marker = items[-1][id_key] params['marker'] = marker params.pop('page_reverse', None) - return "%s?%s" % (request.path_url, urllib.urlencode(params)) + return "%s?%s" % (request.path_url, parse.urlencode(params)) def get_limit_and_marker(request): diff --git a/neutron/plugins/ibm/sdnve_api.py b/neutron/plugins/ibm/sdnve_api.py index 5fe8af0665b..63546d30394 100644 --- a/neutron/plugins/ibm/sdnve_api.py +++ b/neutron/plugins/ibm/sdnve_api.py @@ -16,12 +16,12 @@ from six.moves import http_client as httplib -import urllib import httplib2 from keystoneclient.v2_0 import client as keyclient from oslo_config import cfg from oslo_log import log as logging +from six.moves.urllib import parse from neutron.api.v2 import attributes from neutron.common import utils @@ -158,7 +158,7 @@ class RequestHandler(object): serverurl = SDNVE_URL % (controller_ip, self.port, self.base_url) myurl = serverurl + url if params and isinstance(params, dict): - myurl += '?' + urllib.urlencode(params, doseq=1) + myurl += '?' + parse.urlencode(params, doseq=1) try: LOG.debug("Sending request to SDN-VE. url: " diff --git a/neutron/tests/tempest/services/identity/v3/json/identity_client.py b/neutron/tests/tempest/services/identity/v3/json/identity_client.py index f8dd4f75e03..a7db46a5785 100644 --- a/neutron/tests/tempest/services/identity/v3/json/identity_client.py +++ b/neutron/tests/tempest/services/identity/v3/json/identity_client.py @@ -14,7 +14,8 @@ # under the License. import json -import urllib + +from six.moves.urllib import parse from neutron.tests.tempest.common import service_client @@ -95,7 +96,7 @@ class IdentityV3ClientJSON(service_client.ServiceClient): """Get the list of users.""" url = 'users' if params: - url += '?%s' % urllib.urlencode(params) + url += '?%s' % parse.urlencode(params) resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) @@ -134,7 +135,7 @@ class IdentityV3ClientJSON(service_client.ServiceClient): def list_projects(self, params=None): url = "projects" if params: - url += '?%s' % urllib.urlencode(params) + url += '?%s' % parse.urlencode(params) resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) diff --git a/neutron/tests/tempest/services/identity/v3/json/region_client.py b/neutron/tests/tempest/services/identity/v3/json/region_client.py index e173aa51961..d2fa53b7561 100644 --- a/neutron/tests/tempest/services/identity/v3/json/region_client.py +++ b/neutron/tests/tempest/services/identity/v3/json/region_client.py @@ -14,7 +14,8 @@ # under the License. import json -import urllib + +from six.moves.urllib import parse from neutron.tests.tempest.common import service_client @@ -64,7 +65,7 @@ class RegionClientJSON(service_client.ServiceClient): """List regions.""" url = 'regions' if params: - url += '?%s' % urllib.urlencode(params) + url += '?%s' % parse.urlencode(params) resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) diff --git a/neutron/tests/tempest/services/network/json/network_client.py b/neutron/tests/tempest/services/network/json/network_client.py index 82271f71aa9..54f264c82f1 100644 --- a/neutron/tests/tempest/services/network/json/network_client.py +++ b/neutron/tests/tempest/services/network/json/network_client.py @@ -12,8 +12,8 @@ import json import time -import urllib +from six.moves.urllib import parse from tempest_lib.common.utils import misc from tempest_lib import exceptions as lib_exc @@ -98,7 +98,7 @@ class NetworkClientJSON(service_client.ServiceClient): def _list(**filters): uri = self.get_uri(plural_name) if filters: - uri += '?' + urllib.urlencode(filters, doseq=1) + uri += '?' + parse.urlencode(filters, doseq=1) resp, body = self.get(uri) result = {plural_name: self.deserialize_list(body)} self.expected_success(200, resp.status) @@ -124,7 +124,7 @@ class NetworkClientJSON(service_client.ServiceClient): plural = self.pluralize(resource_name) uri = '%s/%s' % (self.get_uri(plural), resource_id) if fields: - uri += '?' + urllib.urlencode(fields, doseq=1) + uri += '?' + parse.urlencode(fields, doseq=1) resp, body = self.get(uri) body = self.deserialize_single(body) self.expected_success(200, resp.status) diff --git a/neutron/tests/tempest/test.py b/neutron/tests/tempest/test.py index 4bb196038ac..d95174bd886 100644 --- a/neutron/tests/tempest/test.py +++ b/neutron/tests/tempest/test.py @@ -20,13 +20,13 @@ import os import re import sys import time -import urllib import uuid import fixtures from oslo_log import log as logging from oslo_utils import importutils import six +from six.moves.urllib import parse import testscenarios import testtools @@ -590,7 +590,7 @@ class NegativeAutoTest(BaseTestCase): if not json_dict: return url, None elif method in ["GET", "HEAD", "PUT", "DELETE"]: - return "%s?%s" % (url, urllib.urlencode(json_dict)), None + return "%s?%s" % (url, parse.urlencode(json_dict)), None else: return url, json.dumps(json_dict) diff --git a/tox.ini b/tox.ini index 12f2b91fbf3..e9716d7f049 100644 --- a/tox.ini +++ b/tox.ini @@ -117,6 +117,7 @@ commands = python -m testtools.run \ neutron.tests.unit.plugins.oneconvergence.test_nvsd_agent \ neutron.tests.unit.plugins.oneconvergence.test_plugin_helper \ neutron.tests.unit.plugins.oneconvergence.test_nvsdlib \ + neutron.tests.unit.plugins.ibm.test_sdnve_agent \ neutron.tests.unit.plugins.ibm.test_sdnve_api \ neutron.tests.unit.plugins.ml2.test_db \ neutron.tests.unit.plugins.ml2.test_driver_context \ @@ -131,6 +132,7 @@ commands = python -m testtools.run \ neutron.tests.unit.plugins.ml2.drivers.mech_fake_agent \ neutron.tests.unit.plugins.ml2.drivers.test_type_vxlan \ neutron.tests.unit.plugins.ml2.drivers.test_type_gre \ + neutron.tests.unit.plugins.ml2.drivers.test_helpers \ neutron.tests.unit.plugins.ml2.drivers.arista.test_mechanism_arista \ neutron.tests.unit.plugins.ml2.drivers.test_type_local \ neutron.tests.unit.plugins.ml2.drivers.mechanism_logger \ @@ -138,12 +140,14 @@ commands = python -m testtools.run \ neutron.tests.unit.plugins.ml2.drivers.cisco.apic.base \ neutron.tests.unit.plugins.ml2.drivers.cisco.apic.test_apic_topology \ neutron.tests.unit.plugins.ml2.drivers.test_type_flat \ + neutron.tests.unit.plugins.ml2.drivers.test_type_vlan \ neutron.tests.unit.plugins.ml2.drivers.mechanism_test \ neutron.tests.unit.plugins.ml2.drivers.l2pop.rpc_manager.l2population_rpc_base \ neutron.tests.unit.plugins.ml2.extensions.fake_extension \ neutron.tests.unit.plugins.ml2.drivers.l2pop.rpc_manager.test_l2population_rpc \ neutron.tests.unit.plugins.cisco.n1kv.fake_client \ neutron.tests.unit.plugins.cisco.test_network_db \ + neutron.tests.unit.scheduler.test_dhcp_agent_scheduler \ neutron.tests.unit.db.test_l3_dvr_db \ neutron.tests.unit.db.test_migration \ neutron.tests.unit.db.test_agents_db \ @@ -177,8 +181,10 @@ commands = python -m testtools.run \ neutron.tests.unit.agent.linux.test_ipset_manager \ neutron.tests.unit.agent.linux.test_iptables_firewall \ neutron.tests.unit.agent.linux.test_ebtables_manager \ + neutron.tests.unit.agent.linux.test_iptables_firewall \ neutron.tests.unit.agent.linux.test_ebtables_driver \ neutron.tests.unit.agent.linux.test_polling \ + neutron.tests.unit.agent.linux.test_ip_lib \ neutron.tests.unit.agent.linux.test_ip_monitor \ neutron.tests.unit.agent.linux.test_iptables_manager \ neutron.tests.unit.agent.linux.test_external_process \