Merge "Remove six.moves.http_client usage"

This commit is contained in:
Zuul 2022-02-03 09:12:25 +00:00 committed by Gerrit Code Review
commit 472c1635ca
50 changed files with 190 additions and 157 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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, {}, '')

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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