Keep py3.X compatibility for urllib.urlencode

For py3.X, urllib has no attr urlencode while python 2 has.
Change urlencode to keep compatibility.

Change-Id: I48ce3271c2b6ae83b9fa7b5dcb0eb30b5534bc3d
This commit is contained in:
Yatin Kumbhare 2016-01-06 11:15:45 +05:30
parent ed35918607
commit dc36df51c0
10 changed files with 31 additions and 30 deletions

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
from six.moves.urllib import parse
from neutron_lbaas.tests.tempest.lib.common import service_client
@ -23,7 +23,7 @@ class DatabaseFlavorsClientJSON(service_client.ServiceClient):
def list_db_flavors(self, params=None):
url = 'flavors'
if params:
url += '?%s' % urllib.urlencode(params)
url += '?%s' % parse.urlencode(params)
resp, body = self.get(url)
self.expected_success(200, resp.status)

View File

@ -14,7 +14,8 @@
# under the License.
import json
import urllib
from six.moves.urllib import parse
from neutron_lbaas.tests.tempest.lib.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)

View File

@ -14,7 +14,8 @@
# under the License.
import json
import urllib
from six.moves.urllib import parse
from neutron_lbaas.tests.tempest.lib.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)

View File

@ -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)

View File

@ -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
@ -742,7 +742,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)

View File

@ -12,9 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
from oslo_serialization import jsonutils
from six.moves.urllib import parse
from neutron_lbaas.tests.tempest.lib.common import service_client
@ -28,7 +27,7 @@ class HealthMonitorsClientJSON(service_client.ServiceClient):
"""List all health monitors."""
url = 'v2.0/lbaas/healthmonitors'
if params:
url = "{0}?{1}".format(url, urllib.urlencode(params))
url = "{0}?{1}".format(url, parse.urlencode(params))
resp, body = self.get(url)
body = jsonutils.loads(body)
self.expected_success(200, resp.status)
@ -38,7 +37,7 @@ class HealthMonitorsClientJSON(service_client.ServiceClient):
"""Get health monitor details."""
url = 'v2.0/lbaas/healthmonitors/{0}'.format(health_monitor_id)
if params:
url = '{0}?{1}'.format(url, urllib.urlencode(params))
url = '{0}?{1}'.format(url, parse.urlencode(params))
resp, body = self.get(url)
body = jsonutils.loads(body)
self.expected_success(200, resp.status)

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
from six.moves.urllib import parse
from oslo_serialization import jsonutils
@ -28,7 +28,7 @@ class ListenersClientJSON(service_client.ServiceClient):
"""List all listeners."""
url = 'v2.0/lbaas/listeners'
if params:
url = '{0}?{1}'.format(url, urllib.urlencode(params))
url = '{0}?{1}'.format(url, parse.urlencode(params))
resp, body = self.get(url)
body = jsonutils.loads(body)
self.expected_success(200, resp.status)
@ -38,7 +38,7 @@ class ListenersClientJSON(service_client.ServiceClient):
"""Get listener details."""
url = 'v2.0/lbaas/listeners/{0}'.format(listener_id)
if params:
url = '{0}?{1}'.format(url, urllib.urlencode(params))
url = '{0}?{1}'.format(url, parse.urlencode(params))
resp, body = self.get(url)
body = jsonutils.loads(body)
self.expected_success(200, resp.status)

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
from six.moves.urllib import parse
from oslo_serialization import jsonutils
@ -28,7 +28,7 @@ class LoadBalancersClientJSON(service_client.ServiceClient):
"""List all load balancers."""
url = 'v2.0/lbaas/loadbalancers'
if params:
url = '{0}?{1}'.format(url, urllib.urlencode(params))
url = '{0}?{1}'.format(url, parse.urlencode(params))
resp, body = self.get(url)
body = jsonutils.loads(body)
self.expected_success(200, resp.status)
@ -38,7 +38,7 @@ class LoadBalancersClientJSON(service_client.ServiceClient):
"""Get load balancer details."""
url = 'v2.0/lbaas/loadbalancers/{0}'.format(load_balancer_id)
if params:
url = '{0}?{1}'.format(url, urllib.urlencode(params))
url = '{0}?{1}'.format(url, parse.urlencode(params))
resp, body = self.get(url)
body = jsonutils.loads(body)
self.expected_success(200, resp.status)
@ -72,7 +72,7 @@ class LoadBalancersClientJSON(service_client.ServiceClient):
"""Get a load balancer's status tree."""
url = 'v2.0/lbaas/loadbalancers/{0}/statuses'.format(load_balancer_id)
if params:
url = '{0}?{1}'.format(url, urllib.urlencode(params))
url = '{0}?{1}'.format(url, parse.urlencode(params))
resp, body = self.get(url)
body = jsonutils.loads(body)
self.expected_success(200, resp.status)
@ -82,7 +82,7 @@ class LoadBalancersClientJSON(service_client.ServiceClient):
"""Get a load balancer's stats."""
url = 'v2.0/lbaas/loadbalancers/{0}/stats'.format(load_balancer_id)
if params:
url = '{0}?{1}'.format(url, urllib.urlencode(params))
url = '{0}?{1}'.format(url, parse.urlencode(params))
resp, body = self.get(url)
body = jsonutils.loads(body)
self.expected_success(200, resp.status)

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
from six.moves.urllib import parse
from oslo_serialization import jsonutils
@ -30,7 +30,7 @@ class MembersClientJSON(service_client.ServiceClient):
"""
url = 'v2.0/lbaas/pools/{0}/members'.format(pool_id)
if params:
url = "{0}?{1}".format(url, urllib.urlencode(params))
url = "{0}?{1}".format(url, parse.urlencode(params))
resp, body = self.get(url)
body = jsonutils.loads(body)
self.expected_success(200, resp.status)
@ -39,7 +39,7 @@ class MembersClientJSON(service_client.ServiceClient):
def get_member(self, pool_id, member_id, params=None):
url = 'v2.0/lbaas/pools/{0}/members/{1}'.format(pool_id, member_id)
if params:
url = '{0}?{1}'.format(url, urllib.urlencode(params))
url = '{0}?{1}'.format(url, parse.urlencode(params))
resp, body = self.get(url)
body = jsonutils.loads(body)
self.expected_success(200, resp.status)

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
from six.moves.urllib import parse
from oslo_serialization import jsonutils
@ -28,7 +28,7 @@ class PoolsClientJSON(service_client.ServiceClient):
"""List all pools"""
url = 'v2.0/lbaas/pools'
if params:
url = '{0}?{1}'.format(url, urllib.urlencode(params))
url = '{0}?{1}'.format(url, parse.urlencode(params))
resp, body = self.get(url)
body = jsonutils.loads(body)
self.expected_success(200, resp.status)
@ -38,7 +38,7 @@ class PoolsClientJSON(service_client.ServiceClient):
"""List details of a pool"""
url = 'v2.0/lbaas/pools/{pool_id}'.format(pool_id=pool_id)
if params:
url = '{0}?{1}'.format(url, urllib.urlencode(params))
url = '{0}?{1}'.format(url, parse.urlencode(params))
resp, body = self.get(url)
body = jsonutils.loads(body)
self.expected_success(200, resp.status)