Remove python25 workaround from glance_http
Since we don't support python25 removing to reduce what to cover in the
unittests.
Also fix a problem with a possible NoneType in the right side of the comparison
cause an exception. Now the default value for content-type header is an empty
string.
Change-Id: I3df5ac75455e62689f08c336fc89a0437dae6945
diff --git a/tempest/common/glance_http.py b/tempest/common/glance_http.py
index b4ba933..9358851 100644
--- a/tempest/common/glance_http.py
+++ b/tempest/common/glance_http.py
@@ -19,6 +19,7 @@
import hashlib
import httplib
import json
+import OpenSSL
import posixpath
import re
from six import moves
@@ -27,14 +28,6 @@
import struct
import urlparse
-
-# Python 2.5 compat fix
-if not hasattr(urlparse, 'parse_qsl'):
- import cgi
- urlparse.parse_qsl = cgi.parse_qsl
-
-import OpenSSL
-
from tempest import exceptions as exc
from tempest.openstack.common import log as logging
@@ -50,7 +43,7 @@
self.auth_provider = auth_provider
self.filters = filters
self.endpoint = auth_provider.base_url(filters)
- endpoint_parts = self.parse_endpoint(self.endpoint)
+ endpoint_parts = urlparse.urlparse(self.endpoint)
self.endpoint_scheme = endpoint_parts.scheme
self.endpoint_hostname = endpoint_parts.hostname
self.endpoint_port = endpoint_parts.port
@@ -61,10 +54,6 @@
self.endpoint_scheme, **kwargs)
@staticmethod
- def parse_endpoint(endpoint):
- return urlparse.urlparse(endpoint)
-
- @staticmethod
def get_connection_class(scheme):
if scheme == 'https':
return VerifiedHTTPSConnection
@@ -107,7 +96,7 @@
conn = self.get_connection()
try:
- url_parts = self.parse_endpoint(url)
+ url_parts = urlparse.urlparse(url)
conn_url = posixpath.normpath(url_parts.path)
LOG.debug('Actual Path: {path}'.format(path=conn_url))
if kwargs['headers'].get('Transfer-Encoding') == 'chunked':
@@ -134,7 +123,6 @@
raise exc.TimeoutException(message)
body_iter = ResponseBodyIterator(resp)
-
# Read body into string if it isn't obviously image data
if resp.getheader('content-type', None) != 'application/octet-stream':
body_str = ''.join([body_chunk for body_chunk in body_iter])
@@ -178,7 +166,7 @@
resp, body_iter = self._http_request(url, method, **kwargs)
- if 'application/json' in resp.getheader('content-type', None):
+ if 'application/json' in resp.getheader('content-type', ''):
body = ''.join([chunk for chunk in body_iter])
try:
body = json.loads(body)