diff --git a/glance/api/middleware/cache.py b/glance/api/middleware/cache.py index ac9b51a193..1928982415 100644 --- a/glance/api/middleware/cache.py +++ b/glance/api/middleware/cache.py @@ -26,6 +26,7 @@ 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 @@ -260,7 +261,7 @@ class CacheFilter(wsgi.Middleware): except TypeError: return resp - if method == 'GET' and status_code == 204: + if method == 'GET' and status_code == http.NO_CONTENT: # Bugfix:1251055 - Don't cache non-existent image files. # NOTE: Both GET for an image without locations and DELETE return # 204 but DELETE should be processed. diff --git a/glance/api/v2/image_actions.py b/glance/api/v2/image_actions.py index b9c797ef5a..9f76ec994d 100644 --- a/glance/api/v2/image_actions.py +++ b/glance/api/v2/image_actions.py @@ -14,6 +14,7 @@ # under the License. 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 @@ -81,10 +82,10 @@ class ImageActionsController(object): class ResponseSerializer(wsgi.JSONResponseSerializer): def deactivate(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT def reactivate(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT def create_resource(): diff --git a/glance/api/v2/image_members.py b/glance/api/v2/image_members.py index 4219949ea6..ad7f2e9ddb 100644 --- a/glance/api/v2/image_members.py +++ b/glance/api/v2/image_members.py @@ -20,6 +20,7 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils import six +from six.moves import http_client as http import webob from glance.api import policy @@ -234,7 +235,7 @@ class ImageMembersController(object): member = self._lookup_member(req, image, member_id) try: member_repo.remove(member) - return webob.Response(body='', status=204) + return webob.Response(body='', status=http.NO_CONTENT) except exception.Forbidden: msg = _("Not allowed to delete members for image %s.") % image_id LOG.warning(msg) diff --git a/glance/api/v2/image_tags.py b/glance/api/v2/image_tags.py index 10ce967c3f..5d37f22414 100644 --- a/glance/api/v2/image_tags.py +++ b/glance/api/v2/image_tags.py @@ -15,6 +15,7 @@ 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 @@ -89,10 +90,10 @@ class Controller(object): class ResponseSerializer(wsgi.JSONResponseSerializer): def update(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT def delete(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT class RequestDeserializer(wsgi.JSONRequestDeserializer): diff --git a/glance/api/v2/images.py b/glance/api/v2/images.py index 72cc39fa2b..cd52476545 100644 --- a/glance/api/v2/images.py +++ b/glance/api/v2/images.py @@ -21,6 +21,7 @@ from oslo_log import log as logging from oslo_serialization import jsonutils as json from oslo_utils import encodeutils import six +from six.moves import http_client as http import six.moves.urllib.parse as urlparse import webob.exc @@ -795,7 +796,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): raise webob.exc.HTTPForbidden(explanation=e.msg) def create(self, response, image): - response.status_int = 201 + response.status_int = http.CREATED self.show(response, image) response.location = self._get_image_href(image) @@ -831,7 +832,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): response.content_type = 'application/json' def delete(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT def get_base_properties(): diff --git a/glance/api/v2/metadef_namespaces.py b/glance/api/v2/metadef_namespaces.py index d379238e5c..c801b918a6 100644 --- a/glance/api/v2/metadef_namespaces.py +++ b/glance/api/v2/metadef_namespaces.py @@ -18,6 +18,7 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils import six +from six.moves import http_client as http import six.moves.urllib.parse as urlparse import webob.exc from wsme.rest import json @@ -510,7 +511,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): def create(self, response, namespace): ns_json = json.tojson(Namespace, namespace) - response = self.__render(ns_json, response, 201) + response = self.__render(ns_json, response, http.CREATED) response.location = get_namespace_href(namespace) def show(self, response, namespace): @@ -535,16 +536,16 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): def update(self, response, namespace): ns_json = json.tojson(Namespace, namespace) - response = self.__render(ns_json, response, 200) + response = self.__render(ns_json, response, http.OK) def delete(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT def delete_objects(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT def delete_properties(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT def __render(self, json_data, response, response_status=None): body = jsonutils.dumps(json_data, ensure_ascii=False) diff --git a/glance/api/v2/metadef_objects.py b/glance/api/v2/metadef_objects.py index 6c0fb8bc93..c42d69f394 100644 --- a/glance/api/v2/metadef_objects.py +++ b/glance/api/v2/metadef_objects.py @@ -17,6 +17,7 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils import six +from six.moves import http_client as http import webob.exc from wsme.rest import json @@ -327,7 +328,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): self.schema = schema or get_schema() def create(self, response, metadata_object): - response.status_int = 201 + response.status_int = http.CREATED self.show(response, metadata_object) def show(self, response, metadata_object): @@ -337,7 +338,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): response.content_type = 'application/json' def update(self, response, metadata_object): - response.status_int = 200 + response.status_int = http.OK self.show(response, metadata_object) def index(self, response, result): @@ -348,7 +349,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): response.content_type = 'application/json' def delete(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT def get_object_href(namespace_name, metadef_object): diff --git a/glance/api/v2/metadef_properties.py b/glance/api/v2/metadef_properties.py index 9824ca58e8..c8685e2c86 100644 --- a/glance/api/v2/metadef_properties.py +++ b/glance/api/v2/metadef_properties.py @@ -17,6 +17,7 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils import six +from six.moves import http_client as http import webob.exc from wsme.rest import json @@ -245,15 +246,15 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): response.content_type = 'application/json' def create(self, response, result): - response.status_int = 201 + response.status_int = http.CREATED self.show(response, result) def update(self, response, result): - response.status_int = 200 + response.status_int = http.OK self.show(response, result) def delete(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT def _get_base_definitions(): diff --git a/glance/api/v2/metadef_resource_types.py b/glance/api/v2/metadef_resource_types.py index f4885642d0..ef5956fcf5 100644 --- a/glance/api/v2/metadef_resource_types.py +++ b/glance/api/v2/metadef_resource_types.py @@ -17,6 +17,7 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils import six +from six.moves import http_client as http import webob.exc from wsme.rest import json @@ -188,13 +189,13 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): def create(self, response, result): resource_type_json = json.tojson(ResourceTypeAssociation, result) - response.status_int = 201 + response.status_int = http.CREATED body = jsonutils.dumps(resource_type_json, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json' def delete(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT def _get_base_properties(): diff --git a/glance/api/v2/metadef_tags.py b/glance/api/v2/metadef_tags.py index a65f6d2c76..571a8fca94 100644 --- a/glance/api/v2/metadef_tags.py +++ b/glance/api/v2/metadef_tags.py @@ -18,6 +18,7 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils import six +from six.moves import http_client as http import webob.exc from wsme.rest import json @@ -368,11 +369,11 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): self.schema = schema or get_schema() def create(self, response, metadata_tag): - response.status_int = 201 + response.status_int = http.CREATED self.show(response, metadata_tag) def create_tags(self, response, result): - response.status_int = 201 + response.status_int = http.CREATED metadata_tags_json = json.tojson(MetadefTags, result) body = jsonutils.dumps(metadata_tags_json, ensure_ascii=False) response.unicode_body = six.text_type(body) @@ -385,7 +386,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): response.content_type = 'application/json' def update(self, response, metadata_tag): - response.status_int = 200 + response.status_int = http.OK self.show(response, metadata_tag) def index(self, response, result): @@ -395,7 +396,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): response.content_type = 'application/json' def delete(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT def get_tag_href(namespace_name, metadef_tag): diff --git a/glance/api/v2/tasks.py b/glance/api/v2/tasks.py index c6d6115812..a7f064707f 100644 --- a/glance/api/v2/tasks.py +++ b/glance/api/v2/tasks.py @@ -24,6 +24,7 @@ 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 @@ -289,7 +290,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): return task_view def create(self, response, task): - response.status_int = 201 + response.status_int = http.CREATED self._inject_location_header(response, task) self.get(response, task) diff --git a/glance/cmd/replicator.py b/glance/cmd/replicator.py index eb00b691e2..01da00a2cc 100644 --- a/glance/cmd/replicator.py +++ b/glance/cmd/replicator.py @@ -27,7 +27,7 @@ from oslo_serialization import jsonutils from oslo_utils import encodeutils from oslo_utils import uuidutils import six -from six.moves import http_client +from six.moves import http_client as http import six.moves.urllib.parse as urlparse from webob import exc @@ -147,29 +147,29 @@ class ImageService(object): response = self.conn.getresponse() headers = self._header_list_to_dict(response.getheaders()) code = response.status - code_description = http_client.responses[code] + code_description = http.responses[code] LOG.debug('Response: %(code)s %(status)s %(headers)s', {'code': code, 'status': code_description, 'headers': repr(headers)}) - if code == 400: + if code == http.BAD_REQUEST: raise exc.HTTPBadRequest( explanation=response.read()) - if code == 500: + if code == http.INTERNAL_SERVER_ERROR: raise exc.HTTPInternalServerError( explanation=response.read()) - if code == 401: + if code == http.UNAUTHORIZED: raise exc.HTTPUnauthorized( explanation=response.read()) - if code == 403: + if code == http.FORBIDDEN: raise exc.HTTPForbidden( explanation=response.read()) - if code == 409: + if code == http.CONFLICT: raise exc.HTTPConflict( explanation=response.read()) @@ -339,7 +339,7 @@ def replication_size(options, args): count = 0 imageservice = get_image_service() - client = imageservice(http_client.HTTPConnection(server, port), + client = imageservice(http.HTTPConnection(server, port), options.slavetoken) for image in client.get_images(): LOG.debug('Considering image: %(image)s', {'image': image}) @@ -371,7 +371,7 @@ def replication_dump(options, args): server, port = utils.parse_valid_host_port(args.pop()) imageservice = get_image_service() - client = imageservice(http_client.HTTPConnection(server, port), + client = imageservice(http.HTTPConnection(server, port), options.mastertoken) for image in client.get_images(): LOG.debug('Considering: %(image_id)s (%(image_name)s) ' @@ -457,7 +457,7 @@ def replication_load(options, args): server, port = utils.parse_valid_host_port(args.pop()) imageservice = get_image_service() - client = imageservice(http_client.HTTPConnection(server, port), + client = imageservice(http.HTTPConnection(server, port), options.slavetoken) updated = [] @@ -531,11 +531,11 @@ def replication_livecopy(options, args): imageservice = get_image_service() slave_server, slave_port = utils.parse_valid_host_port(args.pop()) - slave_conn = http_client.HTTPConnection(slave_server, slave_port) + slave_conn = http.HTTPConnection(slave_server, slave_port) slave_client = imageservice(slave_conn, options.slavetoken) master_server, master_port = utils.parse_valid_host_port(args.pop()) - master_conn = http_client.HTTPConnection(master_server, master_port) + master_conn = http.HTTPConnection(master_server, master_port) master_client = imageservice(master_conn, options.mastertoken) updated = [] @@ -609,11 +609,11 @@ def replication_compare(options, args): imageservice = get_image_service() slave_server, slave_port = utils.parse_valid_host_port(args.pop()) - slave_conn = http_client.HTTPConnection(slave_server, slave_port) + slave_conn = http.HTTPConnection(slave_server, slave_port) slave_client = imageservice(slave_conn, options.slavetoken) master_server, master_port = utils.parse_valid_host_port(args.pop()) - master_conn = http_client.HTTPConnection(master_server, master_port) + master_conn = http.HTTPConnection(master_server, master_port) master_client = imageservice(master_conn, options.mastertoken) differences = {} diff --git a/glance/common/auth.py b/glance/common/auth.py index 721a29babd..3a5e94a011 100644 --- a/glance/common/auth.py +++ b/glance/common/auth.py @@ -31,6 +31,7 @@ Keystone (an identity management system). import httplib2 from keystoneclient import service_catalog as ks_service_catalog from oslo_serialization import jsonutils +from six.moves import http_client as http # NOTE(jokke): simplified transition to py3, behaves like py2 xrange from six.moves import range import six.moves.urllib.parse as urlparse @@ -167,20 +168,20 @@ class KeystoneStrategy(BaseStrategy): not_found = e raise not_found - if resp.status in (200, 204): + if resp.status in (http.OK, http.NO_CONTENT): try: if self.configure_via_auth: self.management_url = _management_url(self, resp) self.auth_token = resp['x-auth-token'] except KeyError: raise exception.AuthorizationFailure() - elif resp.status == 305: + elif resp.status == http.USE_PROXY: raise exception.AuthorizationRedirect(uri=resp['location']) - elif resp.status == 400: + elif resp.status == http.BAD_REQUEST: raise exception.AuthBadRequest(url=token_url) - elif resp.status == 401: + elif resp.status == http.UNAUTHORIZED: raise exception.NotAuthenticated() - elif resp.status == 404: + elif resp.status == http.NOT_FOUND: raise exception.AuthUrlNotFound(url=token_url) else: raise Exception(_('Unexpected response: %s') % resp.status) @@ -205,7 +206,7 @@ class KeystoneStrategy(BaseStrategy): resp, resp_body = self._do_request( token_url, 'POST', headers=headers, body=req_body) - if resp.status == 200: + if resp.status == http.OK: resp_auth = jsonutils.loads(resp_body)['access'] creds_region = self.creds.get('region') if self.configure_via_auth: @@ -213,13 +214,13 @@ class KeystoneStrategy(BaseStrategy): endpoint_region=creds_region) self.management_url = endpoint self.auth_token = resp_auth['token']['id'] - elif resp.status == 305: + elif resp.status == http.USE_PROXY: raise exception.RedirectException(resp['location']) - elif resp.status == 400: + elif resp.status == http.BAD_REQUEST: raise exception.AuthBadRequest(url=token_url) - elif resp.status == 401: + elif resp.status == http.UNAUTHORIZED: raise exception.NotAuthenticated() - elif resp.status == 404: + elif resp.status == http.NOT_FOUND: raise exception.AuthUrlNotFound(url=token_url) else: raise Exception(_('Unexpected response: %s') % resp.status)