From 9679ffc46349134082f31b2d67214a567f7e8f32 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 21 Dec 2021 13:09:22 +0000 Subject: [PATCH] Remove six.moves.http_client usage This is a rather beefy change due to the number of usages of this import. The changes are trivial though. Change-Id: I7badeeaca438b0291f4ed86670e7f217e6372c61 Signed-off-by: Stephen Finucane --- glance/api/middleware/cache.py | 2 +- glance/api/v2/image_actions.py | 4 +- glance/api/v2/image_members.py | 2 +- glance/api/v2/image_tags.py | 3 +- glance/api/v2/images.py | 2 +- glance/api/v2/metadef_namespaces.py | 3 +- glance/api/v2/metadef_objects.py | 3 +- glance/api/v2/metadef_properties.py | 3 +- glance/api/v2/metadef_resource_types.py | 3 +- glance/api/v2/metadef_tags.py | 3 +- glance/api/v2/tasks.py | 2 +- glance/api/versions.py | 5 +- glance/cmd/replicator.py | 13 ++-- glance/common/auth.py | 3 +- glance/common/client.py | 44 ++++++------- glance/tests/functional/ft_utils.py | 2 +- .../tests/functional/serial/test_scrubber.py | 30 ++++----- glance/tests/functional/store_utils.py | 21 ++++--- glance/tests/functional/test_api.py | 3 +- .../tests/functional/test_cache_middleware.py | 2 +- .../functional/test_client_exceptions.py | 4 +- .../tests/functional/test_client_redirects.py | 4 +- .../tests/functional/test_cors_middleware.py | 11 ++-- .../functional/test_healthcheck_middleware.py | 6 +- glance/tests/functional/test_logging.py | 2 +- glance/tests/functional/test_reload.py | 2 +- glance/tests/functional/test_wsgi.py | 2 +- glance/tests/functional/v2/test_images.py | 2 +- .../functional/v2/test_metadef_namespaces.py | 3 +- .../functional/v2/test_metadef_objects.py | 3 +- .../functional/v2/test_metadef_properties.py | 3 +- .../v2/test_metadef_resourcetypes.py | 3 +- .../tests/functional/v2/test_metadef_tags.py | 3 +- glance/tests/functional/v2/test_schemas.py | 3 +- glance/tests/functional/v2/test_tasks.py | 2 +- .../v2/test_property_quota_violations.py | 17 +++--- glance/tests/integration/v2/test_tasks_api.py | 61 ++++++++++--------- glance/tests/unit/common/test_client.py | 14 ++--- glance/tests/unit/common/test_exception.py | 3 +- glance/tests/unit/common/test_wsgi.py | 2 +- glance/tests/unit/test_auth.py | 3 +- glance/tests/unit/test_cache_middleware.py | 3 +- glance/tests/unit/test_glance_replicator.py | 2 +- glance/tests/unit/test_versions.py | 3 +- .../tests/unit/v2/test_image_data_resource.py | 2 +- .../unit/v2/test_image_members_resource.py | 2 +- .../tests/unit/v2/test_image_tags_resource.py | 3 +- glance/tests/unit/v2/test_images_resource.py | 2 +- glance/tests/unit/v2/test_tasks_resource.py | 2 +- glance/tests/utils.py | 22 +++---- 50 files changed, 190 insertions(+), 157 deletions(-) diff --git a/glance/api/middleware/cache.py b/glance/api/middleware/cache.py index 066cec90db..5d3f8a99d1 100644 --- a/glance/api/middleware/cache.py +++ b/glance/api/middleware/cache.py @@ -22,11 +22,11 @@ When subsequent requests for the same image file are received, the local cached copy of the image file is returned. """ +import http.client as http import re import six from oslo_log import log as logging -from six.moves import http_client as http import webob from glance.api.common import size_checked_iter diff --git a/glance/api/v2/image_actions.py b/glance/api/v2/image_actions.py index 383e6e5d41..d3e80fe393 100644 --- a/glance/api/v2/image_actions.py +++ b/glance/api/v2/image_actions.py @@ -12,9 +12,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + +import http.client as http + import glance_store from oslo_log import log as logging -from six.moves import http_client as http import webob.exc from glance.api import policy diff --git a/glance/api/v2/image_members.py b/glance/api/v2/image_members.py index f5b0e9b273..2f195fb695 100644 --- a/glance/api/v2/image_members.py +++ b/glance/api/v2/image_members.py @@ -14,13 +14,13 @@ # under the License. import copy +import http.client as http import glance_store from oslo_config import cfg from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils -from six.moves import http_client as http import webob from glance.api import policy diff --git a/glance/api/v2/image_tags.py b/glance/api/v2/image_tags.py index 6b9d4e4a8e..dc374486e5 100644 --- a/glance/api/v2/image_tags.py +++ b/glance/api/v2/image_tags.py @@ -12,10 +12,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import http.client as http + import glance_store from oslo_log import log as logging from oslo_utils import encodeutils -from six.moves import http_client as http import webob.exc from glance.api import policy diff --git a/glance/api/v2/images.py b/glance/api/v2/images.py index d9dedb4233..1bc996af61 100644 --- a/glance/api/v2/images.py +++ b/glance/api/v2/images.py @@ -14,6 +14,7 @@ import datetime import hashlib +import http.client as http import os import re @@ -27,7 +28,6 @@ from oslo_serialization import jsonutils as json from oslo_utils import encodeutils from oslo_utils import timeutils as oslo_timeutils import requests -from six.moves import http_client as http import six.moves.urllib.parse as urlparse import webob.exc diff --git a/glance/api/v2/metadef_namespaces.py b/glance/api/v2/metadef_namespaces.py index 4542af5ba4..4feef91c72 100644 --- a/glance/api/v2/metadef_namespaces.py +++ b/glance/api/v2/metadef_namespaces.py @@ -13,11 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +import http.client as http + from oslo_config import cfg from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils -from six.moves import http_client as http import six.moves.urllib.parse as urlparse import webob.exc from wsme.rest import json diff --git a/glance/api/v2/metadef_objects.py b/glance/api/v2/metadef_objects.py index e6dcc13cc6..7b009c41ce 100644 --- a/glance/api/v2/metadef_objects.py +++ b/glance/api/v2/metadef_objects.py @@ -13,10 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import http.client as http + from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils -from six.moves import http_client as http import webob.exc from wsme.rest import json diff --git a/glance/api/v2/metadef_properties.py b/glance/api/v2/metadef_properties.py index 30607392f9..ac9f8b65ca 100644 --- a/glance/api/v2/metadef_properties.py +++ b/glance/api/v2/metadef_properties.py @@ -13,10 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import http.client as http + from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils -from six.moves import http_client as http import webob.exc from wsme.rest import json diff --git a/glance/api/v2/metadef_resource_types.py b/glance/api/v2/metadef_resource_types.py index 13add66a9a..36c8204e80 100644 --- a/glance/api/v2/metadef_resource_types.py +++ b/glance/api/v2/metadef_resource_types.py @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import http.client as http + from oslo_log import log as logging from oslo_serialization import jsonutils -from six.moves import http_client as http import webob.exc from wsme.rest import json diff --git a/glance/api/v2/metadef_tags.py b/glance/api/v2/metadef_tags.py index 8c3514eecb..190a7af816 100644 --- a/glance/api/v2/metadef_tags.py +++ b/glance/api/v2/metadef_tags.py @@ -13,10 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import http.client as http + from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils -from six.moves import http_client as http import webob.exc from wsme.rest import json diff --git a/glance/api/v2/tasks.py b/glance/api/v2/tasks.py index 9dcc5a0580..21998adfc6 100644 --- a/glance/api/v2/tasks.py +++ b/glance/api/v2/tasks.py @@ -15,6 +15,7 @@ # under the License. import copy +import http.client as http import debtcollector import glance_store @@ -24,7 +25,6 @@ import oslo_serialization.jsonutils as json from oslo_utils import encodeutils from oslo_utils import uuidutils import six -from six.moves import http_client as http import six.moves.urllib.parse as urlparse import webob.exc diff --git a/glance/api/versions.py b/glance/api/versions.py index 211cbc7bf7..d1c45163c4 100644 --- a/glance/api/versions.py +++ b/glance/api/versions.py @@ -13,10 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client + from oslo_config import cfg from oslo_log import log as logging from oslo_serialization import jsonutils -from six.moves import http_client from six.moves import urllib import webob.dec @@ -99,7 +100,7 @@ class Controller(object): build_version_object(2.0, 'v2', 'SUPPORTED'), ]) - status = explicit and http_client.OK or http_client.MULTIPLE_CHOICES + status = explicit and http.client.OK or http.client.MULTIPLE_CHOICES response = webob.Response(request=req, status=status, content_type='application/json') diff --git a/glance/cmd/replicator.py b/glance/cmd/replicator.py index 8aef036449..af4ed5bcf8 100644 --- a/glance/cmd/replicator.py +++ b/glance/cmd/replicator.py @@ -16,6 +16,7 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http import os import sys @@ -25,7 +26,6 @@ from oslo_serialization import jsonutils from oslo_utils import encodeutils from oslo_utils import uuidutils import six -from six.moves import http_client as http import six.moves.urllib.parse as urlparse from webob import exc @@ -117,8 +117,9 @@ class ImageService(object): def __init__(self, conn, auth_token): """Initialize the ImageService. - conn: a http_client.HTTPConnection to the glance server - auth_token: authentication token to pass in the x-auth-token header + :param conn: a http.client.HTTPConnection to the glance server + :param auth_token: authentication token to pass in the x-auth-token + header """ self.auth_token = auth_token self.conn = conn @@ -133,7 +134,7 @@ class ImageService(object): body: body to send with the request ignore_result_body: the body of the result will be ignored - Returns: a http_client response object + :returns: A http.client response object """ if self.auth_token: headers.setdefault('x-auth-token', self.auth_token) @@ -178,7 +179,7 @@ class ImageService(object): if ignore_result_body: # NOTE: because we are pipelining requests through a single HTTP - # connection, http_client requires that we read the response body + # connection, http.client requires that we read the response body # before we can make another request. If the caller knows they # don't care about the body, they can ask us to do that for them. response.read() @@ -211,7 +212,7 @@ class ImageService(object): image_uuid: the id of an image - Returns: a http_client Response object where the body is the image. + :returns: a http.client Response object where the body is the image. """ url = '/v1/images/%s' % image_uuid return self._http_request('GET', url, {}, '') diff --git a/glance/common/auth.py b/glance/common/auth.py index 1823742e72..c583b5fb26 100644 --- a/glance/common/auth.py +++ b/glance/common/auth.py @@ -31,10 +31,11 @@ Keystone (an identity management system). http://service_endpoint/ """ +import http.client as http + import httplib2 from keystoneclient import service_catalog as ks_service_catalog from oslo_serialization import jsonutils -from six.moves import http_client as http import six.moves.urllib.parse as urlparse from glance.common import exception diff --git a/glance/common/client.py b/glance/common/client.py index bf1066077a..04a0ca8b09 100644 --- a/glance/common/client.py +++ b/glance/common/client.py @@ -21,6 +21,7 @@ import collections.abc import copy import errno import functools +import http.client import os import re @@ -43,7 +44,6 @@ from oslo_log import log as logging from oslo_utils import encodeutils from oslo_utils import netutils import six -from six.moves import http_client import six.moves.urllib.parse as urlparse from glance.common import auth @@ -92,7 +92,7 @@ def handle_redirects(func): return wrapped -class HTTPSClientAuthConnection(http_client.HTTPSConnection): +class HTTPSClientAuthConnection(http.client.HTTPSConnection): """ Class to make a HTTPS connection, with support for full client-based SSL Authentication @@ -103,7 +103,7 @@ class HTTPSClientAuthConnection(http_client.HTTPSConnection): def __init__(self, host, port, key_file, cert_file, ca_file, timeout=None, insecure=False): - http_client.HTTPSConnection.__init__(self, host, port, + http.client.HTTPSConnection.__init__(self, host, port, key_file=key_file, cert_file=cert_file) self.key_file = key_file @@ -150,18 +150,18 @@ class BaseClient(object): '/etc/ssl/cert.pem') OK_RESPONSE_CODES = ( - http_client.OK, - http_client.CREATED, - http_client.ACCEPTED, - http_client.NO_CONTENT, + http.client.OK, + http.client.CREATED, + http.client.ACCEPTED, + http.client.NO_CONTENT, ) REDIRECT_RESPONSE_CODES = ( - http_client.MOVED_PERMANENTLY, - http_client.FOUND, - http_client.SEE_OTHER, - http_client.USE_PROXY, - http_client.TEMPORARY_REDIRECT, + http.client.MOVED_PERMANENTLY, + http.client.FOUND, + http.client.SEE_OTHER, + http.client.USE_PROXY, + http.client.TEMPORARY_REDIRECT, ) def __init__(self, host, port=None, timeout=None, use_ssl=False, @@ -328,7 +328,7 @@ class BaseClient(object): if self.use_ssl: return HTTPSClientAuthConnection else: - return http_client.HTTPConnection + return http.client.HTTPConnection def _authenticate(self, force_reauth=False): """ @@ -522,24 +522,24 @@ class BaseClient(object): return res elif status_code in self.REDIRECT_RESPONSE_CODES: raise exception.RedirectException(res.getheader('Location')) - elif status_code == http_client.UNAUTHORIZED: + elif status_code == http.client.UNAUTHORIZED: raise exception.NotAuthenticated(read_body(res)) - elif status_code == http_client.FORBIDDEN: + elif status_code == http.client.FORBIDDEN: raise exception.Forbidden(read_body(res)) - elif status_code == http_client.NOT_FOUND: + elif status_code == http.client.NOT_FOUND: raise exception.NotFound(read_body(res)) - elif status_code == http_client.CONFLICT: + elif status_code == http.client.CONFLICT: raise exception.Duplicate(read_body(res)) - elif status_code == http_client.BAD_REQUEST: + elif status_code == http.client.BAD_REQUEST: raise exception.Invalid(read_body(res)) - elif status_code == http_client.MULTIPLE_CHOICES: + elif status_code == http.client.MULTIPLE_CHOICES: raise exception.MultipleChoices(body=read_body(res)) - elif status_code == http_client.REQUEST_ENTITY_TOO_LARGE: + elif status_code == http.client.REQUEST_ENTITY_TOO_LARGE: raise exception.LimitExceeded(retry=_retry(res), body=read_body(res)) - elif status_code == http_client.INTERNAL_SERVER_ERROR: + elif status_code == http.client.INTERNAL_SERVER_ERROR: raise exception.ServerError() - elif status_code == http_client.SERVICE_UNAVAILABLE: + elif status_code == http.client.SERVICE_UNAVAILABLE: raise exception.ServiceUnavailable(retry=_retry(res)) else: raise exception.UnexpectedStatus(status=status_code, diff --git a/glance/tests/functional/ft_utils.py b/glance/tests/functional/ft_utils.py index 0804a00a40..e9c7d0961e 100644 --- a/glance/tests/functional/ft_utils.py +++ b/glance/tests/functional/ft_utils.py @@ -13,12 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http import time from oslo_serialization import jsonutils from oslo_utils import timeutils import requests -from six.moves import http_client as http def verify_image_hashes_and_status( diff --git a/glance/tests/functional/serial/test_scrubber.py b/glance/tests/functional/serial/test_scrubber.py index 785952fb34..3674ff7d2d 100644 --- a/glance/tests/functional/serial/test_scrubber.py +++ b/glance/tests/functional/serial/test_scrubber.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client import os import sys import time @@ -21,7 +22,6 @@ import httplib2 from oslo_config import cfg from oslo_serialization import jsonutils from oslo_utils.fixture import uuidsentinel as uuids -from six.moves import http_client from glance import context import glance.db as db_api @@ -99,14 +99,14 @@ class TestScrubber(functional.FunctionalTest): metadata_encryption_key='', **kwargs) path = "http://%s:%d/v2/images" % ("127.0.0.1", self.api_port) response, content = self._send_create_image_http_request(path) - self.assertEqual(http_client.CREATED, response.status) + self.assertEqual(http.client.CREATED, response.status) image = jsonutils.loads(content) self.assertEqual('queued', image['status']) file_path = "%s/%s/file" % (path, image['id']) response, content = self._send_upload_image_http_request(file_path, body='XXX') - self.assertEqual(http_client.NO_CONTENT, response.status) + self.assertEqual(http.client.NO_CONTENT, response.status) path = "%s/%s" % (path, image['id']) response, content = self._send_http_request(path, 'GET') @@ -114,7 +114,7 @@ class TestScrubber(functional.FunctionalTest): self.assertEqual('active', image['status']) response, content = self._send_http_request(path, 'DELETE') - self.assertEqual(http_client.NO_CONTENT, response.status) + self.assertEqual(http.client.NO_CONTENT, response.status) image = self._get_pending_delete_image(image['id']) self.assertEqual('pending_delete', image['status']) @@ -134,14 +134,14 @@ class TestScrubber(functional.FunctionalTest): metadata_encryption_key='', **kwargs) path = "http://%s:%d/v2/images" % ("127.0.0.1", self.api_port) response, content = self._send_create_image_http_request(path) - self.assertEqual(http_client.CREATED, response.status) + self.assertEqual(http.client.CREATED, response.status) image = jsonutils.loads(content) self.assertEqual('queued', image['status']) file_path = "%s/%s/file" % (path, image['id']) response, content = self._send_upload_image_http_request(file_path, body='XXX') - self.assertEqual(http_client.NO_CONTENT, response.status) + self.assertEqual(http.client.NO_CONTENT, response.status) path = "%s/%s" % (path, image['id']) response, content = self._send_http_request(path, 'GET') @@ -149,7 +149,7 @@ class TestScrubber(functional.FunctionalTest): self.assertEqual('active', image['status']) response, content = self._send_http_request(path, 'DELETE') - self.assertEqual(http_client.NO_CONTENT, response.status) + self.assertEqual(http.client.NO_CONTENT, response.status) image = self._get_pending_delete_image(image['id']) self.assertEqual('pending_delete', image['status']) @@ -187,14 +187,14 @@ class TestScrubber(functional.FunctionalTest): # add an image path = "http://%s:%d/v2/images" % ("127.0.0.1", self.api_port) response, content = self._send_create_image_http_request(path) - self.assertEqual(http_client.CREATED, response.status) + self.assertEqual(http.client.CREATED, response.status) image = jsonutils.loads(content) self.assertEqual('queued', image['status']) file_path = "%s/%s/file" % (path, image['id']) response, content = self._send_upload_image_http_request(file_path, body='XXX') - self.assertEqual(http_client.NO_CONTENT, response.status) + self.assertEqual(http.client.NO_CONTENT, response.status) path = "%s/%s" % (path, image['id']) response, content = self._send_http_request(path, 'GET') @@ -202,7 +202,7 @@ class TestScrubber(functional.FunctionalTest): self.assertEqual('active', image['status']) # delete the image response, content = self._send_http_request(path, 'DELETE') - self.assertEqual(http_client.NO_CONTENT, response.status) + self.assertEqual(http.client.NO_CONTENT, response.status) # ensure the image is marked pending delete. image = self._get_pending_delete_image(image['id']) self.assertEqual('pending_delete', image['status']) @@ -259,14 +259,14 @@ class TestScrubber(functional.FunctionalTest): metadata_encryption_key='', **kwargs) path = "http://%s:%d/v2/images" % ("127.0.0.1", self.api_port) response, content = self._send_create_image_http_request(path) - self.assertEqual(http_client.CREATED, response.status) + self.assertEqual(http.client.CREATED, response.status) image = jsonutils.loads(content) self.assertEqual('queued', image['status']) file_path = "%s/%s/file" % (path, image['id']) response, content = self._send_upload_image_http_request(file_path, body='XXX') - self.assertEqual(http_client.NO_CONTENT, response.status) + self.assertEqual(http.client.NO_CONTENT, response.status) path = "%s/%s" % (path, image['id']) response, content = self._send_http_request(path, 'GET') @@ -274,7 +274,7 @@ class TestScrubber(functional.FunctionalTest): self.assertEqual('active', image['status']) response, content = self._send_http_request(path, 'DELETE') - self.assertEqual(http_client.NO_CONTENT, response.status) + self.assertEqual(http.client.NO_CONTENT, response.status) image = self._get_pending_delete_image(image['id']) self.assertEqual('pending_delete', image['status']) @@ -301,14 +301,14 @@ class TestScrubber(functional.FunctionalTest): path = "http://%s:%d/v2/images" % ("127.0.0.1", self.api_port) response, content = self._send_create_image_http_request(path) - self.assertEqual(http_client.CREATED, response.status) + self.assertEqual(http.client.CREATED, response.status) image = jsonutils.loads(content) self.assertEqual('queued', image['status']) file_path = "%s/%s/file" % (path, image['id']) response, content = self._send_upload_image_http_request(file_path, body='XXX') - self.assertEqual(http_client.NO_CONTENT, response.status) + self.assertEqual(http.client.NO_CONTENT, response.status) path = "%s/%s" % (path, image['id']) response, content = self._send_http_request(path, 'GET') diff --git a/glance/tests/functional/store_utils.py b/glance/tests/functional/store_utils.py index fd3275b1c4..b3c84541e6 100644 --- a/glance/tests/functional/store_utils.py +++ b/glance/tests/functional/store_utils.py @@ -18,29 +18,30 @@ Utility methods to set testcases up for Swift tests. """ +import http.client +import http.server import threading from oslo_utils import units -from six.moves import BaseHTTPServer -from six.moves import http_client as http - FIVE_KB = 5 * units.Ki -class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler): +class RemoteImageHandler(http.server.BaseHTTPRequestHandler): def do_HEAD(self): """ Respond to an image HEAD request fake metadata """ if 'images' in self.path: - self.send_response(http.OK) + self.send_response(http.client.OK) self.send_header('Content-Type', 'application/octet-stream') self.send_header('Content-Length', FIVE_KB) self.end_headers() return else: - self.send_error(http.NOT_FOUND, 'File Not Found: %s' % self.path) + self.send_error( + http.client.NOT_FOUND, 'File Not Found: %s' % self.path, + ) return def do_GET(self): @@ -48,7 +49,7 @@ class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler): Respond to an image GET request with fake image content. """ if 'images' in self.path: - self.send_response(http.OK) + self.send_response(http.client.OK) self.send_header('Content-Type', 'application/octet-stream') self.send_header('Content-Length', FIVE_KB) self.end_headers() @@ -57,7 +58,9 @@ class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler): self.wfile.close() return else: - self.send_error(http.NOT_FOUND, 'File Not Found: %s' % self.path) + self.send_error( + http.client.NOT_FOUND, 'File Not Found: %s' % self.path, + ) return def log_message(self, format, *args): @@ -68,7 +71,7 @@ class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler): def setup_http(test): - server_class = BaseHTTPServer.HTTPServer + server_class = http.server.HTTPServer remote_server = server_class(('127.0.0.1', 0), RemoteImageHandler) remote_ip, remote_port = remote_server.server_address diff --git a/glance/tests/functional/test_api.py b/glance/tests/functional/test_api.py index 407fe7e672..fa5608d64e 100644 --- a/glance/tests/functional/test_api.py +++ b/glance/tests/functional/test_api.py @@ -15,9 +15,10 @@ """Version-independent api tests""" +import http.client as http_client + import httplib2 from oslo_serialization import jsonutils -from six.moves import http_client from glance.tests import functional from glance.tests.unit import test_versions as tv diff --git a/glance/tests/functional/test_cache_middleware.py b/glance/tests/functional/test_cache_middleware.py index d87d886db0..ea6f5fa9ee 100644 --- a/glance/tests/functional/test_cache_middleware.py +++ b/glance/tests/functional/test_cache_middleware.py @@ -20,6 +20,7 @@ but that is really not relevant, as the image cache is transparent to the backend store. """ +import http.client as http_client import os import shutil @@ -27,7 +28,6 @@ import httplib2 from oslo_serialization import jsonutils from oslo_utils.fixture import uuidsentinel as uuids from oslo_utils import units -from six.moves import http_client from glance.tests import functional from glance.tests.utils import skip_if_disabled diff --git a/glance/tests/functional/test_client_exceptions.py b/glance/tests/functional/test_client_exceptions.py index f8f5f15460..3274d26512 100644 --- a/glance/tests/functional/test_client_exceptions.py +++ b/glance/tests/functional/test_client_exceptions.py @@ -15,9 +15,11 @@ # under the License. """Functional test asserting strongly typed exceptions from glance client""" + +import http.client as http_client + import eventlet.patcher import httplib2 -from six.moves import http_client import webob.dec import webob.exc diff --git a/glance/tests/functional/test_client_redirects.py b/glance/tests/functional/test_client_redirects.py index 2a71f4c983..957a151b83 100644 --- a/glance/tests/functional/test_client_redirects.py +++ b/glance/tests/functional/test_client_redirects.py @@ -14,8 +14,10 @@ # under the License. """Functional test cases testing glance client redirect-following.""" + +import http.client as http + import eventlet.patcher -from six.moves import http_client as http import webob.dec import webob.exc diff --git a/glance/tests/functional/test_cors_middleware.py b/glance/tests/functional/test_cors_middleware.py index 3421cdb019..e380f77f8e 100644 --- a/glance/tests/functional/test_cors_middleware.py +++ b/glance/tests/functional/test_cors_middleware.py @@ -14,9 +14,10 @@ """Tests cors middleware.""" +import http.client + import httplib2 from oslo_utils.fixture import uuidsentinel as uuids -from six.moves import http_client from glance.tests import functional @@ -59,7 +60,7 @@ class TestCORSMiddleware(functional.FunctionalTest): 'Access-Control-Request-Method': 'GET' })) - self.assertEqual(http_client.OK, r_headers.status) + self.assertEqual(http.client.OK, r_headers.status) self.assertIn('access-control-allow-origin', r_headers) self.assertEqual('http://valid.example.com', r_headers['access-control-allow-origin']) @@ -73,7 +74,7 @@ class TestCORSMiddleware(functional.FunctionalTest): 'Access-Control-Request-Method': 'GET' })) - self.assertEqual(http_client.OK, r_headers.status) + self.assertEqual(http.client.OK, r_headers.status) self.assertNotIn('access-control-allow-origin', r_headers) def test_valid_cors_get_request(self): @@ -84,7 +85,7 @@ class TestCORSMiddleware(functional.FunctionalTest): 'Origin': 'http://valid.example.com' })) - self.assertEqual(http_client.OK, r_headers.status) + self.assertEqual(http.client.OK, r_headers.status) self.assertIn('access-control-allow-origin', r_headers) self.assertEqual('http://valid.example.com', r_headers['access-control-allow-origin']) @@ -97,5 +98,5 @@ class TestCORSMiddleware(functional.FunctionalTest): 'Origin': 'http://invalid.example.com' })) - self.assertEqual(http_client.OK, r_headers.status) + self.assertEqual(http.client.OK, r_headers.status) self.assertNotIn('access-control-allow-origin', r_headers) diff --git a/glance/tests/functional/test_healthcheck_middleware.py b/glance/tests/functional/test_healthcheck_middleware.py index 656cd40bc7..03324656cd 100644 --- a/glance/tests/functional/test_healthcheck_middleware.py +++ b/glance/tests/functional/test_healthcheck_middleware.py @@ -15,10 +15,10 @@ """Tests healthcheck middleware.""" +import http.client import tempfile import httplib2 -from six.moves import http_client from glance.tests import functional from glance.tests import utils @@ -38,7 +38,7 @@ class HealthcheckMiddlewareTest(functional.FunctionalTest): response, content = self.request() self.assertEqual(b'OK', content) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) self.stop_servers() @@ -50,6 +50,6 @@ class HealthcheckMiddlewareTest(functional.FunctionalTest): response, content = self.request() self.assertEqual(b'DISABLED BY FILE', content) - self.assertEqual(http_client.SERVICE_UNAVAILABLE, response.status) + self.assertEqual(http.client.SERVICE_UNAVAILABLE, response.status) self.stop_servers() diff --git a/glance/tests/functional/test_logging.py b/glance/tests/functional/test_logging.py index 29c806a25b..5879e698ed 100644 --- a/glance/tests/functional/test_logging.py +++ b/glance/tests/functional/test_logging.py @@ -15,11 +15,11 @@ """Functional test case that tests logging output""" +import http.client as http import os import stat import httplib2 -from six.moves import http_client as http from glance.tests import functional diff --git a/glance/tests/functional/test_reload.py b/glance/tests/functional/test_reload.py index 957dc367a9..eacb1dc7b1 100644 --- a/glance/tests/functional/test_reload.py +++ b/glance/tests/functional/test_reload.py @@ -13,13 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http import os import re import time import psutil import requests -from six.moves import http_client as http from glance.tests import functional from glance.tests.utils import execute diff --git a/glance/tests/functional/test_wsgi.py b/glance/tests/functional/test_wsgi.py index b75a19a58a..d54fefa56c 100644 --- a/glance/tests/functional/test_wsgi.py +++ b/glance/tests/functional/test_wsgi.py @@ -15,8 +15,8 @@ """Tests for `glance.wsgi`.""" +import http.client as http import os -from six.moves import http_client as http import socket import time diff --git a/glance/tests/functional/v2/test_images.py b/glance/tests/functional/v2/test_images.py index 25b94aa488..0740dbf56b 100644 --- a/glance/tests/functional/v2/test_images.py +++ b/glance/tests/functional/v2/test_images.py @@ -14,6 +14,7 @@ # under the License. import hashlib +import http.client as http import os import subprocess import tempfile @@ -26,7 +27,6 @@ from oslo_serialization import jsonutils from oslo_utils.secretutils import md5 from oslo_utils import units import requests -from six.moves import http_client as http from six.moves import urllib from glance.quota import keystone as ks_quota diff --git a/glance/tests/functional/v2/test_metadef_namespaces.py b/glance/tests/functional/v2/test_metadef_namespaces.py index ddf4ff0910..cecbc00630 100644 --- a/glance/tests/functional/v2/test_metadef_namespaces.py +++ b/glance/tests/functional/v2/test_metadef_namespaces.py @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import http.client as http + from oslo_serialization import jsonutils import requests -from six.moves import http_client as http from glance.tests.functional.v2 import metadef_base diff --git a/glance/tests/functional/v2/test_metadef_objects.py b/glance/tests/functional/v2/test_metadef_objects.py index 4fa8d6ef6f..3e45017aa9 100644 --- a/glance/tests/functional/v2/test_metadef_objects.py +++ b/glance/tests/functional/v2/test_metadef_objects.py @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import http.client as http + from oslo_serialization import jsonutils import requests -from six.moves import http_client as http from glance.tests.functional.v2 import metadef_base diff --git a/glance/tests/functional/v2/test_metadef_properties.py b/glance/tests/functional/v2/test_metadef_properties.py index 3bf5889ffd..4328e5a812 100644 --- a/glance/tests/functional/v2/test_metadef_properties.py +++ b/glance/tests/functional/v2/test_metadef_properties.py @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import http.client as http + from oslo_serialization import jsonutils import requests -from six.moves import http_client as http from glance.tests.functional.v2 import metadef_base diff --git a/glance/tests/functional/v2/test_metadef_resourcetypes.py b/glance/tests/functional/v2/test_metadef_resourcetypes.py index b3d86340f6..26e085f305 100644 --- a/glance/tests/functional/v2/test_metadef_resourcetypes.py +++ b/glance/tests/functional/v2/test_metadef_resourcetypes.py @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import http.client as http + from oslo_serialization import jsonutils import requests -from six.moves import http_client as http from glance.tests.functional.v2 import metadef_base diff --git a/glance/tests/functional/v2/test_metadef_tags.py b/glance/tests/functional/v2/test_metadef_tags.py index 73fde458c1..3c91ebbc27 100644 --- a/glance/tests/functional/v2/test_metadef_tags.py +++ b/glance/tests/functional/v2/test_metadef_tags.py @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import http.client as http + from oslo_serialization import jsonutils import requests -from six.moves import http_client as http from glance.tests.functional.v2 import metadef_base diff --git a/glance/tests/functional/v2/test_schemas.py b/glance/tests/functional/v2/test_schemas.py index 106c3f8fdf..3c2d27eff0 100644 --- a/glance/tests/functional/v2/test_schemas.py +++ b/glance/tests/functional/v2/test_schemas.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http + from oslo_serialization import jsonutils import requests -from six.moves import http_client as http from glance.tests import functional diff --git a/glance/tests/functional/v2/test_tasks.py b/glance/tests/functional/v2/test_tasks.py index 971735a61c..2168c65413 100644 --- a/glance/tests/functional/v2/test_tasks.py +++ b/glance/tests/functional/v2/test_tasks.py @@ -14,11 +14,11 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http import uuid from oslo_serialization import jsonutils import requests -from six.moves import http_client as http from glance.tests import functional diff --git a/glance/tests/integration/v2/test_property_quota_violations.py b/glance/tests/integration/v2/test_property_quota_violations.py index 3c4d64e891..f3e7aeb700 100644 --- a/glance/tests/integration/v2/test_property_quota_violations.py +++ b/glance/tests/integration/v2/test_property_quota_violations.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client + from oslo_config import cfg from oslo_serialization import jsonutils -from six.moves import http_client from glance.tests.integration.v2 import base @@ -41,7 +42,7 @@ class TestPropertyQuotaViolations(base.ApiTest): def _get(self, image_id=""): path = ('/v2/images/%s' % image_id).rstrip('/') rsp, content = self.http.request(path, 'GET', headers=self._headers()) - self.assertEqual(http_client.OK, rsp.status) + self.assertEqual(http.client.OK, rsp.status) content = jsonutils.loads(content) return content @@ -50,7 +51,7 @@ class TestPropertyQuotaViolations(base.ApiTest): headers = self._headers({'content-type': 'application/json'}) rsp, content = self.http.request(path, 'POST', headers=headers, body=jsonutils.dumps(body)) - self.assertEqual(http_client.CREATED, rsp.status) + self.assertEqual(http.client.CREATED, rsp.status) return jsonutils.loads(content) def _patch(self, image_id, body, expected_status): @@ -89,16 +90,16 @@ class TestPropertyQuotaViolations(base.ApiTest): patch_body = [{'op': 'replace', 'path': '/k_4', 'value': 'v_4.new'}] image = jsonutils.loads(self._patch(image_id, patch_body, - http_client.OK)) + http.client.OK)) self.assertEqual('v_4.new', image['k_4']) patch_body = [{'op': 'remove', 'path': '/k_7'}] image = jsonutils.loads(self._patch(image_id, patch_body, - http_client.OK)) + http.client.OK)) self.assertNotIn('k_7', image) patch_body = [{'op': 'add', 'path': '/k_100', 'value': 'v_100'}] - self._patch(image_id, patch_body, http_client.REQUEST_ENTITY_TOO_LARGE) + self._patch(image_id, patch_body, http.client.REQUEST_ENTITY_TOO_LARGE) image = self._get(image_id) self.assertNotIn('k_100', image) @@ -106,7 +107,7 @@ class TestPropertyQuotaViolations(base.ApiTest): {'op': 'remove', 'path': '/k_5'}, {'op': 'add', 'path': '/k_100', 'value': 'v_100'}, ] - self._patch(image_id, patch_body, http_client.REQUEST_ENTITY_TOO_LARGE) + self._patch(image_id, patch_body, http.client.REQUEST_ENTITY_TOO_LARGE) image = self._get(image_id) self.assertNotIn('k_100', image) self.assertIn('k_5', image) @@ -119,7 +120,7 @@ class TestPropertyQuotaViolations(base.ApiTest): to_rm = ['k_%d' % i for i in range(orig_property_quota) if i != 7] patch_body.extend([{'op': 'remove', 'path': '/%s' % k} for k in to_rm]) image = jsonutils.loads(self._patch(image_id, patch_body, - http_client.OK)) + http.client.OK)) self.assertEqual('v_99', image['k_99']) self.assertEqual('v_100', image['k_100']) for k in to_rm: diff --git a/glance/tests/integration/v2/test_tasks_api.py b/glance/tests/integration/v2/test_tasks_api.py index 7185a48379..5ad73ce392 100644 --- a/glance/tests/integration/v2/test_tasks_api.py +++ b/glance/tests/integration/v2/test_tasks_api.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client + import eventlet from oslo_serialization import jsonutils as json -from six.moves import http_client from glance.api.v2 import tasks from glance.common import timeutils @@ -73,7 +74,7 @@ class TestTasksApi(base.ApiTest): headers=minimal_task_headers()) content_dict = json.loads(content) - self.assertEqual(http_client.OK, res.status) + self.assertEqual(http.client.OK, res.status) res_tasks = content_dict['tasks'] if len(res_tasks) != 0: for task in res_tasks: @@ -104,7 +105,7 @@ class TestTasksApi(base.ApiTest): headers=headers, body=body_content) - self.assertEqual(http_client.CREATED, response.status) + self.assertEqual(http.client.CREATED, response.status) task = json.loads(content) task_id = task['id'] @@ -126,7 +127,7 @@ class TestTasksApi(base.ApiTest): headers=minimal_task_headers()) content_dict = json.loads(content) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) self.assertFalse(content_dict['tasks']) # 1. GET /tasks/{task_id} @@ -136,7 +137,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.NOT_FOUND, response.status) + self.assertEqual(http.client.NOT_FOUND, response.status) # 2. POST /tasks # Create a new task @@ -149,7 +150,7 @@ class TestTasksApi(base.ApiTest): path = "/v2/tasks/%s" % task_id response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) # NOTE(sabari): wait for all task executions to finish before checking # task status. @@ -161,7 +162,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) self.assertIsNotNone(content) data = json.loads(content) @@ -184,7 +185,7 @@ class TestTasksApi(base.ApiTest): path = "/v2/schemas/task" response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) schema = tasks.get_task_schema() expected_schema = schema.minimal() @@ -197,7 +198,7 @@ class TestTasksApi(base.ApiTest): path = "/v2/schemas/tasks" response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) schema = tasks.get_collection_schema() expected_schema = schema.minimal() @@ -220,7 +221,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request( path, 'POST', headers=minimal_task_headers(task_owner), body=body_content) - self.assertEqual(http_client.CREATED, response.status) + self.assertEqual(http.client.CREATED, response.status) data = json.loads(content) task_id = data['id'] @@ -241,7 +242,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request( path, 'POST', headers=minimal_task_headers(task_owner), body=body_content) - self.assertEqual(http_client.BAD_REQUEST, response.status) + self.assertEqual(http.client.BAD_REQUEST, response.status) # 1. POST /tasks # Create a new task with invalid input for type 'import' @@ -254,7 +255,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request( path, 'POST', headers=minimal_task_headers(task_owner), body=body_content) - self.assertEqual(http_client.BAD_REQUEST, response.status) + self.assertEqual(http.client.BAD_REQUEST, response.status) # NOTE(nikhil): wait for all task executions to finish before exiting # else there is a risk of running into deadlock @@ -268,7 +269,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) content_dict = json.loads(content) self.assertFalse(content_dict['tasks']) @@ -290,7 +291,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) content_dict = json.loads(content) self.assertEqual(2, len(content_dict['tasks'])) @@ -303,7 +304,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) content_dict = json.loads(content) self.assertEqual(1, len(content_dict['tasks'])) @@ -316,7 +317,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) content_dict = json.loads(content) self.assertEqual(1, len(content_dict['tasks'])) @@ -329,7 +330,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) content_dict = json.loads(content) self.assertEqual(2, len(content_dict['tasks'])) @@ -351,7 +352,7 @@ class TestTasksApi(base.ApiTest): path = "/v2/tasks" response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) tasks = json.loads(content) self.assertFalse(tasks['tasks']) @@ -374,7 +375,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) tasks = json.loads(content)['tasks'] @@ -387,7 +388,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) actual_tasks = json.loads(content)['tasks'] @@ -402,7 +403,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) actual_tasks = json.loads(content)['tasks'] @@ -417,7 +418,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) actual_tasks = json.loads(content)['tasks'] @@ -434,7 +435,7 @@ class TestTasksApi(base.ApiTest): path = "/v2/tasks" response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) tasks = json.loads(content) self.assertFalse(tasks['tasks']) @@ -458,7 +459,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) actual_tasks = json.loads(content)['tasks'] @@ -473,7 +474,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) expected_task_owners = [TENANT1, TENANT2, TENANT3] expected_task_owners.sort() @@ -489,7 +490,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) actual_tasks = json.loads(content)['tasks'] self.assertEqual(2, len(actual_tasks)) @@ -505,7 +506,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) actual_tasks = json.loads(content)['tasks'] @@ -526,7 +527,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request( path, 'POST', headers=minimal_task_headers(task_owner), body=body_content) - self.assertEqual(http_client.CREATED, response.status) + self.assertEqual(http.client.CREATED, response.status) data = json.loads(content) task_id = data['id'] @@ -537,7 +538,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'DELETE', headers=minimal_task_headers()) - self.assertEqual(http_client.METHOD_NOT_ALLOWED, response.status) + self.assertEqual(http.client.METHOD_NOT_ALLOWED, response.status) self.assertEqual('GET', response.webob_resp.headers.get('Allow')) self.assertEqual(('GET',), response.webob_resp.allow) self.assertEqual(('GET',), response.allow) @@ -548,7 +549,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(http_client.OK, response.status) + self.assertEqual(http.client.OK, response.status) self.assertIsNotNone(content) # NOTE(nikhil): wait for all task executions to finish before exiting diff --git a/glance/tests/unit/common/test_client.py b/glance/tests/unit/common/test_client.py index c834dd1517..650a33fc21 100644 --- a/glance/tests/unit/common/test_client.py +++ b/glance/tests/unit/common/test_client.py @@ -13,9 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client from unittest import mock -from six.moves import http_client import testtools from glance.common import auth @@ -41,11 +41,11 @@ class TestClient(testtools.TestCase): with mock.patch.object(auth, 'get_plugin_from_strategy'): self.client.make_auth_plugin(creds, insecure) - @mock.patch.object(http_client.HTTPConnection, "getresponse") - @mock.patch.object(http_client.HTTPConnection, "request") + @mock.patch.object(http.client.HTTPConnection, "getresponse") + @mock.patch.object(http.client.HTTPConnection, "request") def test_http_encoding_headers(self, _mock_req, _mock_resp): # Lets fake the response - # returned by http_client + # returned by http.client fake = utils.FakeHTTPResponse(data=b"Ok") _mock_resp.return_value = fake @@ -54,11 +54,11 @@ class TestClient(testtools.TestCase): headers=headers) self.assertEqual(fake, resp) - @mock.patch.object(http_client.HTTPConnection, "getresponse") - @mock.patch.object(http_client.HTTPConnection, "request") + @mock.patch.object(http.client.HTTPConnection, "getresponse") + @mock.patch.object(http.client.HTTPConnection, "request") def test_http_encoding_params(self, _mock_req, _mock_resp): # Lets fake the response - # returned by http_client + # returned by http.client fake = utils.FakeHTTPResponse(data=b"Ok") _mock_resp.return_value = fake diff --git a/glance/tests/unit/common/test_exception.py b/glance/tests/unit/common/test_exception.py index eea548728b..1d26dc7114 100644 --- a/glance/tests/unit/common/test_exception.py +++ b/glance/tests/unit/common/test_exception.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http + from oslo_utils import encodeutils -from six.moves import http_client as http from glance.common import exception from glance.tests import utils as test_utils diff --git a/glance/tests/unit/common/test_wsgi.py b/glance/tests/unit/common/test_wsgi.py index 92933c368f..fb4e101c7e 100644 --- a/glance/tests/unit/common/test_wsgi.py +++ b/glance/tests/unit/common/test_wsgi.py @@ -17,6 +17,7 @@ import datetime import gettext +import http.client as http import os import socket from unittest import mock @@ -28,7 +29,6 @@ from oslo_concurrency import processutils from oslo_serialization import jsonutils import routes import six -from six.moves import http_client as http import webob from glance.api.v2 import router as router_v2 diff --git a/glance/tests/unit/test_auth.py b/glance/tests/unit/test_auth.py index afd49f9303..04cfc2be78 100644 --- a/glance/tests/unit/test_auth.py +++ b/glance/tests/unit/test_auth.py @@ -14,8 +14,9 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http + from oslo_serialization import jsonutils -from six.moves import http_client as http import webob from glance.api import authorization diff --git a/glance/tests/unit/test_cache_middleware.py b/glance/tests/unit/test_cache_middleware.py index 8ca3e8f445..034edc4b1a 100644 --- a/glance/tests/unit/test_cache_middleware.py +++ b/glance/tests/unit/test_cache_middleware.py @@ -12,11 +12,12 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + +import http.client as http from unittest.mock import patch from oslo_policy import policy from oslo_utils.fixture import uuidsentinel as uuids -from six.moves import http_client as http import testtools import webob diff --git a/glance/tests/unit/test_glance_replicator.py b/glance/tests/unit/test_glance_replicator.py index 8a3071068e..a894760c2c 100644 --- a/glance/tests/unit/test_glance_replicator.py +++ b/glance/tests/unit/test_glance_replicator.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http import io from unittest import mock @@ -23,7 +24,6 @@ import uuid import fixtures from oslo_serialization import jsonutils from six import moves -from six.moves import http_client as http import webob from glance.cmd import replicator as glance_replicator diff --git a/glance/tests/unit/test_versions.py b/glance/tests/unit/test_versions.py index 1dd115feae..e296bc7b6d 100644 --- a/glance/tests/unit/test_versions.py +++ b/glance/tests/unit/test_versions.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http + import ddt -from six.moves import http_client as http import webob from oslo_serialization import jsonutils diff --git a/glance/tests/unit/v2/test_image_data_resource.py b/glance/tests/unit/v2/test_image_data_resource.py index dcf52b0b27..b3f5291646 100644 --- a/glance/tests/unit/v2/test_image_data_resource.py +++ b/glance/tests/unit/v2/test_image_data_resource.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http import io from unittest import mock import uuid @@ -21,7 +22,6 @@ from cursive import exception as cursive_exception import glance_store from glance_store._drivers import filesystem from oslo_config import cfg -from six.moves import http_client as http import webob import glance.api.policy diff --git a/glance/tests/unit/v2/test_image_members_resource.py b/glance/tests/unit/v2/test_image_members_resource.py index 13cd8754e6..f9aad85476 100644 --- a/glance/tests/unit/v2/test_image_members_resource.py +++ b/glance/tests/unit/v2/test_image_members_resource.py @@ -14,11 +14,11 @@ # under the License. import datetime +import http.client as http import glance_store from oslo_config import cfg from oslo_serialization import jsonutils -from six.moves import http_client as http import webob import glance.api.v2.image_members diff --git a/glance/tests/unit/v2/test_image_tags_resource.py b/glance/tests/unit/v2/test_image_tags_resource.py index c61207d46a..51dd5898d5 100644 --- a/glance/tests/unit/v2/test_image_tags_resource.py +++ b/glance/tests/unit/v2/test_image_tags_resource.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -from six.moves import http_client as http +import http.client as http + import webob import glance.api.v2.image_tags diff --git a/glance/tests/unit/v2/test_images_resource.py b/glance/tests/unit/v2/test_images_resource.py index 109625b5e1..4be56b2883 100644 --- a/glance/tests/unit/v2/test_images_resource.py +++ b/glance/tests/unit/v2/test_images_resource.py @@ -15,6 +15,7 @@ import datetime import hashlib +import http.client as http import os import requests from unittest import mock @@ -26,7 +27,6 @@ from oslo_config import cfg from oslo_serialization import jsonutils from oslo_utils import fixture import six -from six.moves import http_client as http import testtools import webob import webob.exc diff --git a/glance/tests/unit/v2/test_tasks_resource.py b/glance/tests/unit/v2/test_tasks_resource.py index eb2beff1ff..754612b11f 100644 --- a/glance/tests/unit/v2/test_tasks_resource.py +++ b/glance/tests/unit/v2/test_tasks_resource.py @@ -15,12 +15,12 @@ # under the License. import datetime +import http.client as http from unittest import mock import uuid from oslo_config import cfg from oslo_serialization import jsonutils -from six.moves import http_client as http import webob import glance.api.v2.tasks diff --git a/glance/tests/utils.py b/glance/tests/utils.py index 0f0c186d50..0c67a4d681 100644 --- a/glance/tests/utils.py +++ b/glance/tests/utils.py @@ -17,6 +17,8 @@ import errno import functools +import http.client +import http.server import io import os import shlex @@ -36,8 +38,6 @@ from oslo_log.fixture import logging_error as log_fixture from oslo_log import log from oslo_utils import timeutils from oslo_utils import units -from six.moves import BaseHTTPServer -from six.moves import http_client as http import testtools import webob @@ -546,9 +546,9 @@ def minimal_add_command(port, name, suffix='', public=True): def start_http_server(image_id, image_data): def _get_http_handler_class(fixture): - class StaticHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): + class StaticHTTPRequestHandler(http.server.BaseHTTPRequestHandler): def do_GET(self): - self.send_response(http.OK) + self.send_response(http.client.OK) self.send_header('Content-Length', str(len(fixture))) self.end_headers() self.wfile.write(fixture.encode('latin-1')) @@ -558,9 +558,9 @@ def start_http_server(image_id, image_data): # reserve non_existing_image_path for the cases where we expect # 404 from the server if 'non_existing_image_path' in self.path: - self.send_response(http.NOT_FOUND) + self.send_response(http.client.NOT_FOUND) else: - self.send_response(http.OK) + self.send_response(http.client.OK) self.send_header('Content-Length', str(len(fixture))) self.end_headers() return @@ -574,7 +574,7 @@ def start_http_server(image_id, image_data): server_address = ('127.0.0.1', 0) handler_class = _get_http_handler_class(image_data) - httpd = BaseHTTPServer.HTTPServer(server_address, handler_class) + httpd = http.server.HTTPServer(server_address, handler_class) port = httpd.socket.getsockname()[1] thread = threading.Thread(target=httpd.serve_forever) @@ -616,7 +616,7 @@ class FakeAuthMiddleware(wsgi.Middleware): class FakeHTTPResponse(object): - def __init__(self, status=http.OK, headers=None, data=None, + def __init__(self, status=http.client.OK, headers=None, data=None, *args, **kwargs): data = data or b'I am a teapot, short and stout\n' self.data = io.BytesIO(data) @@ -708,10 +708,10 @@ def is_sqlite_version_prior_to(major, minor): def start_standalone_http_server(): def _get_http_handler_class(): - class StaticHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): + class StaticHTTPRequestHandler(http.server.BaseHTTPRequestHandler): def do_GET(self): data = b"Hello World!!!" - self.send_response(http.OK) + self.send_response(http.client.OK) self.send_header('Content-Length', str(len(data))) self.end_headers() self.wfile.write(data) @@ -721,7 +721,7 @@ def start_standalone_http_server(): server_address = ('127.0.0.1', 0) handler_class = _get_http_handler_class() - httpd = BaseHTTPServer.HTTPServer(server_address, handler_class) + httpd = http.server.HTTPServer(server_address, handler_class) port = httpd.socket.getsockname()[1] thread = threading.Thread(target=httpd.serve_forever)