From 053d516ba65b1cf2dd3fdf15fc4d43c4b6c45aea Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Thu, 3 Apr 2014 12:31:30 +0200 Subject: [PATCH] Remove use of py3kcompat Replace usage of py3kcompat.urlutils by six imports. py3kcompat has been removed from oslo incubator so we should try to sync. Change-Id: I252ff2b3a5284cee6e09e70a79b7dad550335f41 --- heat/api/openstack/v1/views/views_common.py | 4 +-- heat/common/exception.py | 5 ++-- heat/common/identifier.py | 27 ++++++++++--------- heat/common/urlfetch.py | 9 ++++--- heat/engine/resources/nova_utils.py | 6 ++--- heat/engine/resources/s3.py | 5 ++-- heat/engine/resources/swift.py | 5 ++-- heat/engine/signal_responder.py | 9 ++++--- heat/tests/db/test_migrations.py | 5 ++-- ...est_api_openstack_v1_views_views_common.py | 7 ++--- heat/tests/test_urlfetch.py | 10 +++---- heat/tests/v1_1/fakes.py | 5 ++-- 12 files changed, 53 insertions(+), 44 deletions(-) diff --git a/heat/api/openstack/v1/views/views_common.py b/heat/api/openstack/v1/views/views_common.py index ab0bb037dc..e834b40347 100644 --- a/heat/api/openstack/v1/views/views_common.py +++ b/heat/api/openstack/v1/views/views_common.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from heat.openstack.common.py3kcompat import urlutils +from six.moves.urllib import parse as urlparse def get_collection_links(request, items): @@ -38,4 +38,4 @@ def _get_next_link(request, marker): params = request.params.copy() params['marker'] = marker - return "%s?%s" % (request.path_url, urlutils.urlencode(params)) + return "%s?%s" % (request.path_url, urlparse.urlencode(params)) diff --git a/heat/common/exception.py b/heat/common/exception.py index 7bc204421d..fe4542e461 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -19,9 +19,10 @@ import functools import sys +from six.moves.urllib import parse as urlparse + from heat.openstack.common.gettextutils import _ from heat.openstack.common import log as logging -from heat.openstack.common.py3kcompat import urlutils _FATAL_EXCEPTION_FORMAT_ERRORS = False @@ -32,7 +33,7 @@ logger = logging.getLogger(__name__) class RedirectException(Exception): def __init__(self, url): - self.url = urlutils.urlparse(url) + self.url = urlparse.urlparse(url) class KeystoneError(Exception): diff --git a/heat/common/identifier.py b/heat/common/identifier.py index 2a8e75682d..aa01e0bab7 100644 --- a/heat/common/identifier.py +++ b/heat/common/identifier.py @@ -14,7 +14,8 @@ import collections import re -from heat.openstack.common.py3kcompat import urlutils +from six.moves.urllib import parse as urlparse + from heat.openstack.common import strutils @@ -61,10 +62,10 @@ class HeatIdentifier(collections.Mapping): if fields[1] != 'openstack' or fields[2] != 'heat' or not path: raise ValueError(_('"%s" is not a valid Heat ARN') % arn) - return cls(urlutils.unquote(fields[4]), - urlutils.unquote(path.group(1)), - urlutils.unquote(path.group(2)), - urlutils.unquote(path.group(3))) + return cls(urlparse.unquote(fields[4]), + urlparse.unquote(path.group(1)), + urlparse.unquote(path.group(2)), + urlparse.unquote(path.group(3))) @classmethod def from_arn_url(cls, url): @@ -73,7 +74,7 @@ class HeatIdentifier(collections.Mapping): The URL is expected to contain a valid arn as part of the path ''' # Sanity check the URL - urlp = urlutils.urlparse(url) + urlp = urlparse.urlparse(url) if (urlp.scheme not in ('http', 'https') or not urlp.netloc or not urlp.path): raise ValueError(_('"%s" is not a valid URL') % url) @@ -85,7 +86,7 @@ class HeatIdentifier(collections.Mapping): raise ValueError(_('"%s" is not a valid ARN URL') % url) # the +1 is to skip the leading / url_arn = urlp.path[match.start() + 1:] - arn = urlutils.unquote(url_arn) + arn = urlparse.unquote(url_arn) return cls.from_arn(arn) def arn(self): @@ -93,21 +94,21 @@ class HeatIdentifier(collections.Mapping): Return an ARN of the form: arn:openstack:heat:::stacks// ''' - return 'arn:openstack:heat::%s:%s' % (urlutils.quote(self.tenant, ''), + return 'arn:openstack:heat::%s:%s' % (urlparse.quote(self.tenant, ''), self._tenant_path()) def arn_url_path(self): ''' Return an ARN quoted correctly for use in a URL ''' - return '/' + urlutils.quote(self.arn(), '') + return '/' + urlparse.quote(self.arn(), '') def url_path(self): ''' Return a URL-encoded path segment of a URL in the form: /stacks// ''' - return '/'.join((urlutils.quote(self.tenant, ''), self._tenant_path())) + return '/'.join((urlparse.quote(self.tenant, ''), self._tenant_path())) def _tenant_path(self): ''' @@ -116,7 +117,7 @@ class HeatIdentifier(collections.Mapping): stacks// ''' return 'stacks/%s%s' % (self.stack_path(), - urlutils.quote(strutils.safe_encode( + urlparse.quote(strutils.safe_encode( self.path))) def stack_path(self): @@ -125,8 +126,8 @@ class HeatIdentifier(collections.Mapping): in the form: / ''' - return '%s/%s' % (urlutils.quote(self.stack_name, ''), - urlutils.quote(self.stack_id, '')) + return '%s/%s' % (urlparse.quote(self.stack_name, ''), + urlparse.quote(self.stack_id, '')) def _path_components(self): '''Return a list of the path components.''' diff --git a/heat/common/urlfetch.py b/heat/common/urlfetch.py index f659b2108e..0435e20223 100644 --- a/heat/common/urlfetch.py +++ b/heat/common/urlfetch.py @@ -20,9 +20,10 @@ from oslo.config import cfg import requests from requests import exceptions +from six.moves import urllib + from heat.openstack.common.gettextutils import _ from heat.openstack.common import log as logging -from heat.openstack.common.py3kcompat import urlutils cfg.CONF.import_opt('max_template_size', 'heat.common.config') @@ -40,15 +41,15 @@ def get(url, allowed_schemes=('http', 'https')): ''' logger.info(_('Fetching data from %s') % url) - components = urlutils.urlparse(url) + components = urllib.parse.urlparse(url) if components.scheme not in allowed_schemes: raise IOError(_('Invalid URL scheme %s') % components.scheme) if components.scheme == 'file': try: - return urlutils.urlopen(url).read() - except urlutils.URLError as uex: + return urllib.request.urlopen(url).read() + except urllib.error.URLError as uex: raise IOError(_('Failed to retrieve template: %s') % str(uex)) try: diff --git a/heat/engine/resources/nova_utils.py b/heat/engine/resources/nova_utils.py index d011d0db2c..fdc2b561d3 100644 --- a/heat/engine/resources/nova_utils.py +++ b/heat/engine/resources/nova_utils.py @@ -23,13 +23,13 @@ import string from oslo.config import cfg import six +from six.moves.urllib import parse as urlparse from heat.common import exception from heat.engine import clients from heat.engine import scheduler from heat.openstack.common.gettextutils import _ from heat.openstack.common import log as logging -from heat.openstack.common.py3kcompat import urlutils from heat.openstack.common import uuidutils logger = logging.getLogger(__name__) @@ -252,8 +252,8 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers # Create a boto config which the cfntools on the host use to know # where the cfn and cw API's are to be accessed - cfn_url = urlutils.urlparse(cfg.CONF.heat_metadata_server_url) - cw_url = urlutils.urlparse(cfg.CONF.heat_watch_server_url) + cfn_url = urlparse.urlparse(cfg.CONF.heat_metadata_server_url) + cw_url = urlparse.urlparse(cfg.CONF.heat_watch_server_url) is_secure = cfg.CONF.instance_connection_is_secure vcerts = cfg.CONF.instance_connection_https_validate_certificates boto_cfg = "\n".join(["[Boto]", diff --git a/heat/engine/resources/s3.py b/heat/engine/resources/s3.py index 85dacb64c9..989de5090f 100644 --- a/heat/engine/resources/s3.py +++ b/heat/engine/resources/s3.py @@ -12,12 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. +from six.moves.urllib import parse as urlparse + from heat.engine import clients from heat.engine import constraints from heat.engine import properties from heat.engine import resource from heat.openstack.common import log as logging -from heat.openstack.common.py3kcompat import urlutils logger = logging.getLogger(__name__) @@ -152,7 +153,7 @@ class S3Bucket(resource.Resource): def _resolve_attribute(self, name): url = self.swift().get_auth()[0] - parsed = list(urlutils.urlparse(url)) + parsed = list(urlparse.urlparse(url)) if name == 'DomainName': return parsed[1].split(':')[0] elif name == 'WebsiteURL': diff --git a/heat/engine/resources/swift.py b/heat/engine/resources/swift.py index 66ba607c91..c9c314d7af 100644 --- a/heat/engine/resources/swift.py +++ b/heat/engine/resources/swift.py @@ -12,12 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. +from six.moves.urllib import parse as urlparse + from heat.common import exception from heat.engine import clients from heat.engine import properties from heat.engine import resource from heat.openstack.common import log as logging -from heat.openstack.common.py3kcompat import urlutils logger = logging.getLogger(__name__) @@ -133,7 +134,7 @@ class SwiftContainer(resource.Resource): return unicode(self.resource_id) def FnGetAtt(self, key): - parsed = list(urlutils.urlparse(self.swift().url)) + parsed = list(urlparse.urlparse(self.swift().url)) if key == 'DomainName': return parsed[1].split(':')[0] elif key == 'WebsiteURL': diff --git a/heat/engine/signal_responder.py b/heat/engine/signal_responder.py index 503d9105b5..d0953fb657 100644 --- a/heat/engine/signal_responder.py +++ b/heat/engine/signal_responder.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from six.moves.urllib import parse as urlparse + from oslo.config import cfg from keystoneclient.contrib.ec2 import utils as ec2_utils @@ -22,7 +24,6 @@ from heat.engine import stack_user from heat.openstack.common import log as logging from heat.openstack.common.gettextutils import _ -from heat.openstack.common.py3kcompat import urlutils logger = logging.getLogger(__name__) @@ -82,7 +83,7 @@ class SignalResponder(stack_user.StackUser): waitcond_url = cfg.CONF.heat_waitcondition_server_url signal_url = waitcond_url.replace('/waitcondition', signal_type) - host_url = urlutils.urlparse(signal_url) + host_url = urlparse.urlparse(signal_url) path = self.identifier().arn_url_path() @@ -90,7 +91,7 @@ class SignalResponder(stack_user.StackUser): # prcessing in the CFN API (ec2token.py) has an unquoted path, so we # need to calculate the signature with the path component unquoted, but # ensure the actual URL contains the quoted version... - unquoted_path = urlutils.unquote(host_url.path + path) + unquoted_path = urlparse.unquote(host_url.path + path) request = {'host': host_url.netloc.lower(), 'verb': SIGNAL_VERB[signal_type], 'path': unquoted_path, @@ -104,7 +105,7 @@ class SignalResponder(stack_user.StackUser): signer = ec2_utils.Ec2Signer(secret_key) request['params']['Signature'] = signer.generate(request) - qs = urlutils.urlencode(request['params']) + qs = urlparse.urlencode(request['params']) url = "%s%s?%s" % (signal_url.lower(), path, qs) diff --git a/heat/tests/db/test_migrations.py b/heat/tests/db/test_migrations.py index d6d1adb317..b44b75f415 100644 --- a/heat/tests/db/test_migrations.py +++ b/heat/tests/db/test_migrations.py @@ -30,11 +30,12 @@ import uuid from migrate.versioning import repository import sqlalchemy +from six.moves.urllib import parse as urlparse + from heat.db.sqlalchemy import migrate_repo from heat.db.sqlalchemy import migration from heat.openstack.common.db.sqlalchemy import test_migrations from heat.openstack.common import log as logging -from heat.openstack.common.py3kcompat import urlutils LOG = logging.getLogger(__name__) @@ -125,7 +126,7 @@ class TestHeatMigrations(test_migrations.BaseMigrationTestCase, for key, eng in self.engines.items(): if eng is engine: conn_string = self.test_databases[key] - conn_pieces = urlutils.urlparse(conn_string) + conn_pieces = urlparse.urlparse(conn_string) if conn_string.startswith('mysql'): break else: diff --git a/heat/tests/test_api_openstack_v1_views_views_common.py b/heat/tests/test_api_openstack_v1_views_views_common.py index 2edf20c59e..343aacae58 100644 --- a/heat/tests/test_api_openstack_v1_views_views_common.py +++ b/heat/tests/test_api_openstack_v1_views_views_common.py @@ -13,8 +13,9 @@ import mock +from six.moves.urllib import parse as urlparse + from heat.api.openstack.v1.views import views_common -from heat.openstack.common.py3kcompat import urlutils from heat.tests.common import HeatTestCase @@ -73,9 +74,9 @@ class TestViewsCommon(HeatTestCase): next_link = filter(lambda link: link['rel'] == 'next', links).pop() url = next_link['href'] - query_string = urlutils.urlparse(url).query + query_string = urlparse.urlparse(url).query params = {} - params.update(urlutils.parse_qsl(query_string)) + params.update(urlparse.parse_qsl(query_string)) self.assertEqual('2', params['limit']) self.assertEqual('bar', params['foo']) diff --git a/heat/tests/test_urlfetch.py b/heat/tests/test_urlfetch.py index 3bec3a774e..01ae49c38a 100644 --- a/heat/tests/test_urlfetch.py +++ b/heat/tests/test_urlfetch.py @@ -16,9 +16,9 @@ from oslo.config import cfg import requests from requests import exceptions from six.moves import cStringIO +from six.moves import urllib from heat.common import urlfetch -from heat.openstack.common.py3kcompat import urlutils from heat.tests.common import HeatTestCase @@ -49,8 +49,8 @@ class UrlFetchTest(HeatTestCase): data = '{ "foo": "bar" }' url = 'file:///etc/profile' - self.m.StubOutWithMock(urlutils, 'urlopen') - urlutils.urlopen(url).AndReturn(cStringIO(data)) + self.m.StubOutWithMock(urllib.request, 'urlopen') + urllib.request.urlopen(url).AndReturn(cStringIO(data)) self.m.ReplayAll() self.assertEqual(data, urlfetch.get(url, allowed_schemes=['file'])) @@ -59,8 +59,8 @@ class UrlFetchTest(HeatTestCase): def test_file_scheme_failure(self): url = 'file:///etc/profile' - self.m.StubOutWithMock(urlutils, 'urlopen') - urlutils.urlopen(url).AndRaise(urlutils.URLError('oops')) + self.m.StubOutWithMock(urllib.request, 'urlopen') + urllib.request.urlopen(url).AndRaise(urllib.error.URLError('oops')) self.m.ReplayAll() self.assertRaises(IOError, urlfetch.get, url, allowed_schemes=['file']) diff --git a/heat/tests/v1_1/fakes.py b/heat/tests/v1_1/fakes.py index 4d73aeb03a..b33055ffa5 100644 --- a/heat/tests/v1_1/fakes.py +++ b/heat/tests/v1_1/fakes.py @@ -15,10 +15,11 @@ import httplib2 +from six.moves.urllib import parse as urlparse + from novaclient import client as base_client from novaclient.v1_1 import client -from heat.openstack.common.py3kcompat import urlutils from heat.tests import fakes @@ -46,7 +47,7 @@ class FakeHTTPClient(base_client.HTTPClient): assert 'body' in kwargs # Call the method - args = urlutils.parse_qsl(urlutils.urlparse(url)[4]) + args = urlparse.parse_qsl(urlparse.urlparse(url)[4]) kwargs.update(args) munged_url = url.rsplit('?', 1)[0] munged_url = munged_url.strip('/').replace('/', '_').replace('.', '_')