Merge "Port replicator to Python 3"

This commit is contained in:
Jenkins 2015-10-05 14:12:28 +00:00 committed by Gerrit Code Review
commit 557564ca94
4 changed files with 17 additions and 14 deletions

@ -25,6 +25,7 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import encodeutils
import six
from six.moves import http_client
import six.moves.urllib.parse as urlparse
from webob import exc
@ -373,7 +374,11 @@ def replication_dump(options, args):
LOG.info(_LI('Storing: %s') % image['id'])
# Dump glance information
with open(data_path, 'w') as f:
if six.PY3:
f = open(data_path, 'w', encoding='utf-8')
else:
f = open(data_path, 'w')
with f:
f.write(jsonutils.dumps(image))
if image['status'] == 'active' and not options.metaonly:

@ -77,8 +77,7 @@ class FakeHTTPConnection(object):
if not url.startswith('/'):
url = '/' + url
url = unit_test_utils.sort_url_by_qs_keys(url)
hkeys = in_headers.keys()
hkeys.sort()
hkeys = sorted(in_headers.keys())
hashable = (method, url, in_body, ' '.join(hkeys))
flat_headers = []
@ -90,8 +89,7 @@ class FakeHTTPConnection(object):
def request(self, method, url, body, headers):
self.count += 1
url = unit_test_utils.sort_url_by_qs_keys(url)
hkeys = headers.keys()
hkeys.sort()
hkeys = sorted(headers.keys())
hashable = (method, url, body, ' '.join(hkeys))
if hashable not in self.reqs:
@ -245,7 +243,7 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
class FakeHttpResponse(object):
def __init__(self, headers, data):
self.headers = headers
self.data = six.StringIO(data)
self.data = six.BytesIO(data)
def getheaders(self):
return self.headers
@ -284,7 +282,7 @@ class FakeImageService(object):
return FAKEIMAGES
def get_image(self, id):
return FakeHttpResponse({}, 'data')
return FakeHttpResponse({}, b'data')
def get_image_meta(self, id):
for img in FAKEIMAGES:

@ -13,12 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
import glance_store as store
from oslo_config import cfg
from oslo_log import log as logging
import six.moves.urllib.parse as urlparse
from six.moves import urllib
from glance.common import exception
from glance.common import store_utils
@ -50,17 +49,17 @@ def sort_url_by_qs_keys(url):
# non-deterministic ordering of the query string causing problems with unit
# tests.
parsed = urlparse.urlparse(url)
queries = urlparse.parse_qsl(parsed.query, True)
parsed = urllib.parse.urlparse(url)
queries = urllib.parse.parse_qsl(parsed.query, True)
sorted_query = sorted(queries, key=lambda x: x[0])
encoded_sorted_query = urllib.urlencode(sorted_query, True)
encoded_sorted_query = urllib.parse.urlencode(sorted_query, True)
url_parts = (parsed.scheme, parsed.netloc, parsed.path,
parsed.params, encoded_sorted_query,
parsed.fragment)
return urlparse.urlunparse(url_parts)
return urllib.parse.urlunparse(url_parts)
def get_fake_request(path='', method='POST', is_admin=False, user=USER1,
@ -150,7 +149,7 @@ class FakeStoreUtils(object):
self.safe_delete_from_backend(context, image_id, location)
def validate_external_location(self, uri):
if uri and urlparse.urlparse(uri).scheme:
if uri and urllib.parse.urlparse(uri).scheme:
return store_utils.validate_external_location(uri)
else:
return True

@ -36,6 +36,7 @@ commands =
glance.tests.unit.test_db_metadef \
glance.tests.unit.test_domain \
glance.tests.unit.test_domain_proxy \
glance.tests.unit.test_glance_replicator \
glance.tests.unit.test_image_cache \
glance.tests.unit.test_image_cache_client \
glance.tests.unit.test_jsonpatchmixin \