From 4543e7691ce0e164c2ceb3535f107c83bf9dbe8f Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sat, 2 Nov 2024 18:04:10 +0900 Subject: [PATCH] Fix compatibility with falcon >= 4.0 The falcon library deprecated some interfaces used in zaqar in 3.0 and removed these in 4.0 . Replace the removed interfaces to fix compatibility with the latest release of the library. * The `body` attribute of Reponse class was removed [1] * HTTP error classes now accepts only keyword arguments [2] [1] https://github.com/falconry/falcon/commit/c76f44248af3f44d92b9658bcf7abecd3e1fb038 [2] https://github.com/falconry/falcon/commit/0b9d26c7f60aa4984e4b055701295c2a0c4bdf6b Change-Id: Ied13446be2e1b5cb7c5839a84e8ad2413cca6fe3 --- .../notes/falcon-4-e4b5aab856e3228c.yaml | 4 + zaqar/common/transport/wsgi/helpers.py | 74 ++++++++++--------- zaqar/transport/wsgi/driver.py | 5 +- zaqar/transport/wsgi/errors.py | 39 +++++----- zaqar/transport/wsgi/v1_0/claims.py | 4 +- zaqar/transport/wsgi/v1_0/messages.py | 15 ++-- zaqar/transport/wsgi/v1_0/metadata.py | 2 +- zaqar/transport/wsgi/v1_0/pools.py | 4 +- zaqar/transport/wsgi/v1_0/queues.py | 2 +- zaqar/transport/wsgi/v1_0/stats.py | 4 +- zaqar/transport/wsgi/v1_1/claims.py | 4 +- zaqar/transport/wsgi/v1_1/flavors.py | 7 +- zaqar/transport/wsgi/v1_1/health.py | 2 +- zaqar/transport/wsgi/v1_1/messages.py | 17 +++-- zaqar/transport/wsgi/v1_1/pools.py | 8 +- zaqar/transport/wsgi/v1_1/queues.py | 4 +- zaqar/transport/wsgi/v1_1/stats.py | 4 +- zaqar/transport/wsgi/v2_0/claims.py | 4 +- zaqar/transport/wsgi/v2_0/flavors.py | 33 ++++++--- zaqar/transport/wsgi/v2_0/health.py | 2 +- zaqar/transport/wsgi/v2_0/messages.py | 17 +++-- zaqar/transport/wsgi/v2_0/pools.py | 10 +-- zaqar/transport/wsgi/v2_0/queues.py | 6 +- zaqar/transport/wsgi/v2_0/stats.py | 4 +- zaqar/transport/wsgi/v2_0/subscriptions.py | 18 +++-- zaqar/transport/wsgi/v2_0/topic.py | 6 +- zaqar/transport/wsgi/v2_0/topic_stats.py | 4 +- zaqar/transport/wsgi/v2_0/urls.py | 2 +- zaqar/transport/wsgi/version.py | 2 +- 29 files changed, 172 insertions(+), 135 deletions(-) create mode 100644 releasenotes/notes/falcon-4-e4b5aab856e3228c.yaml diff --git a/releasenotes/notes/falcon-4-e4b5aab856e3228c.yaml b/releasenotes/notes/falcon-4-e4b5aab856e3228c.yaml new file mode 100644 index 000000000..b7c2f6974 --- /dev/null +++ b/releasenotes/notes/falcon-4-e4b5aab856e3228c.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Fixed compatibility with falcon 4.0.0 and later. diff --git a/zaqar/common/transport/wsgi/helpers.py b/zaqar/common/transport/wsgi/helpers.py index 3077034e5..06d9e1a3b 100644 --- a/zaqar/common/transport/wsgi/helpers.py +++ b/zaqar/common/transport/wsgi/helpers.py @@ -96,15 +96,16 @@ def extract_project_id(req, resp, params): # a check for the project-id. return if params['project_id'] == "": - raise falcon.HTTPBadRequest('Empty project header not allowed', - _(u'X-PROJECT-ID cannot be an empty ' - u'string. Specify the right header ' - u'X-PROJECT-ID and retry.')) + raise falcon.HTTPBadRequest( + title='Empty project header not allowed', + description=_('X-PROJECT-ID cannot be an empty string. Specify ' + 'the right header X-PROJECT-ID and retry.')) if not params['project_id'] and versionutils.is_compatible( 'v1.1', api_version_string, same_major=False): - raise falcon.HTTPBadRequest('Project-Id Missing', - _(u'The header X-PROJECT-ID was missing')) + raise falcon.HTTPBadRequest( + title='Project-Id Missing', + description=_('The header X-PROJECT-ID was missing')) def require_client_id(validate, req, resp, params): @@ -127,10 +128,11 @@ def require_client_id(validate, req, resp, params): try: validate(req.get_header('Client-ID', required=True)) except ValueError: - description = _(u'Malformed hexadecimal UUID.') - raise falcon.HTTPBadRequest('Wrong UUID value', description) + description = _('Malformed hexadecimal UUID.') + raise falcon.HTTPBadRequest( + title='Wrong UUID value', description=description) except validation.ValidationFailed as ex: - raise falcon.HTTPBadRequest(str(ex)) + raise falcon.HTTPBadRequest(title=str(ex)) else: # NOTE(wanghao): Since we changed the get_client_uuid to support # other format of client id, so need to check the uuid here for @@ -140,8 +142,9 @@ def require_client_id(validate, req, resp, params): if client_id or client_id == '': uuid.UUID(client_id) except ValueError: - description = _(u'Malformed hexadecimal UUID.') - raise falcon.HTTPBadRequest('Wrong UUID value', description) + description = _('Malformed hexadecimal UUID.') + raise falcon.HTTPBadRequest( + title='Wrong UUID value', description=description) def validate_queue_identification(validate, req, resp, params): @@ -178,9 +181,10 @@ def validate_queue_identification(validate, req, resp, params): u'project: %(project)s', {'queue': queue, 'project': project}) - raise falcon.HTTPBadRequest(_(u'Invalid queue identification'), - _(u'The format of the submitted queue ' - u'name or project id is not valid.')) + raise falcon.HTTPBadRequest( + title=_('Invalid queue identification'), + description=_('The format of the submitted queue ' + 'name or project id is not valid.')) def require_accepts_json(req, resp, params): @@ -199,11 +203,11 @@ def require_accepts_json(req, resp, params): """ if not req.client_accepts('application/json'): raise falcon.HTTPNotAcceptable( - u''' -Endpoint only serves `application/json`; specify client-side -media type support with the "Accept" header.''', - href=u'http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html', - href_text=u'14.1 Accept, Hypertext Transfer Protocol -- HTTP/1.1') + description='Endpoint only serves `application/json`; ' + 'specify client-side media type support with ' + 'the "Accept" header.', + href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html', + href_text='14.1 Accept, Hypertext Transfer Protocol -- HTTP/1.1') def require_content_type_be_non_urlencoded(req, resp, params): @@ -232,13 +236,13 @@ def require_content_type_be_non_urlencoded(req, resp, params): return if req.content_type and (req.content_type.lower() == 'application/x-www-form-urlencoded'): - title = _(u'Invalid Content-Type') - description = _(u'Endpoint does not accept ' - u'`application/x-www-form-urlencoded` content; ' - u'currently supported media type is ' - u'`application/json`; specify proper client-side ' - u'media type with the "Content-Type" header.') - raise falcon.HTTPBadRequest(title, description) + title = _('Invalid Content-Type') + description = _('Endpoint does not accept ' + '`application/x-www-form-urlencoded` content; ' + 'currently supported media type is ' + '`application/json`; specify proper client-side ' + 'media type with the "Content-Type" header.') + raise falcon.HTTPBadRequest(title=title, description=description) def inject_context(req, resp, params): @@ -306,13 +310,14 @@ def validate_topic_identification(validate, req, resp, params): project = params['project_id'] queue = params['topic_name'] - LOG.debug(u'Invalid topic name "%(topic)s" submitted for ' - u'project: %(project)s', + LOG.debug('Invalid topic name "%(topic)s" submitted for ' + 'project: %(project)s', {'topic': queue, 'project': project}) - raise falcon.HTTPBadRequest(_(u'Invalid topic identification'), - _(u'The format of the submitted topic ' - u'name or project id is not valid.')) + raise falcon.HTTPBadRequest( + title=_('Invalid topic identification'), + description=_('The format of the submitted topic ' + 'name or project id is not valid.')) def verify_extra_spec(req, resp, params): @@ -333,9 +338,10 @@ def verify_extra_spec(req, resp, params): return if extra_spec == "": - raise falcon.HTTPBadRequest('Empty extra spec not allowed', - _(u'Extra spec cannot be an empty ' - u'if specify the header.')) + raise falcon.HTTPBadRequest( + title='Empty extra spec not allowed', + description=_('Extra spec cannot be an empty ' + 'if specify the header.')) extra_spec_schema = extra_spec.split(':')[0] if extra_spec_schema: mgr = driver.DriverManager('zaqar.extraspec.tasks', extra_spec_schema, diff --git a/zaqar/transport/wsgi/driver.py b/zaqar/transport/wsgi/driver.py index f94ef7acf..1aec03912 100644 --- a/zaqar/transport/wsgi/driver.py +++ b/zaqar/transport/wsgi/driver.py @@ -170,8 +170,9 @@ class Driver(transport.DriverBase): if isinstance(exc, falcon.HTTPError): raise LOG.exception('Internal server error') - raise falcon.HTTPInternalServerError('Internal server error', - str(exc)) + raise falcon.HTTPInternalServerError( + title='Internal server error', + description=str(exc)) def _get_server_cls(self, host): """Return an appropriate WSGI server class base on provided host diff --git a/zaqar/transport/wsgi/errors.py b/zaqar/transport/wsgi/errors.py index 480697d1d..5b548e92a 100644 --- a/zaqar/transport/wsgi/errors.py +++ b/zaqar/transport/wsgi/errors.py @@ -21,37 +21,39 @@ from zaqar.i18n import _ class HTTPServiceUnavailable(falcon.HTTPServiceUnavailable): """Wraps falcon.HTTPServiceUnavailable with Zaqar messaging.""" - TITLE = _(u'Service temporarily unavailable') - DESCRIPTION = _(u'Please try again in a few seconds.') + TITLE = _('Service temporarily unavailable') + DESCRIPTION = _('Please try again in a few seconds.') def __init__(self, description): description = description + ' ' + self.DESCRIPTION super(HTTPServiceUnavailable, self).__init__( - self.TITLE, description) + title=self.TITLE, description=description) class HTTPBadRequestAPI(falcon.HTTPBadRequest): """Wraps falcon.HTTPBadRequest with a contextual title.""" - TITLE = _(u'Invalid API request') + TITLE = _('Invalid API request') def __init__(self, description): - super(HTTPBadRequestAPI, self).__init__(self.TITLE, description) + super(HTTPBadRequestAPI, self).__init__( + title=self.TITLE, description=description) class HTTPBadRequestBody(falcon.HTTPBadRequest): """Wraps falcon.HTTPBadRequest with a contextual title.""" - TITLE = _(u'Invalid request body') + TITLE = _('Invalid request body') def __init__(self, description): - super(HTTPBadRequestBody, self).__init__(self.TITLE, description) + super(HTTPBadRequestBody, self).__init__( + title=self.TITLE, description=description) class HTTPDocumentTypeNotSupported(HTTPBadRequestBody): """Wraps HTTPBadRequestBody with a standard description.""" - DESCRIPTION = _(u'Document type not supported.') + DESCRIPTION = _('Document type not supported.') def __init__(self): super(HTTPDocumentTypeNotSupported, self).__init__(self.DESCRIPTION) @@ -60,34 +62,37 @@ class HTTPDocumentTypeNotSupported(HTTPBadRequestBody): class HTTPForbidden(falcon.HTTPForbidden): """Wraps falcon.HTTPForbidden with a contextual title.""" - TITLE = _(u'Not authorized') - DESCRIPTION = _(u'You are not authorized to complete this action.') + TITLE = _('Not authorized') + DESCRIPTION = _('You are not authorized to complete this action.') def __init__(self): - super(HTTPForbidden, self).__init__(self.TITLE, self.DESCRIPTION) + super(HTTPForbidden, self).__init__( + title=self.TITLE, description=self.DESCRIPTION) class HTTPConflict(falcon.HTTPConflict): """Wraps falcon.HTTPConflict with contextual title.""" - TITLE = _(u'Resource conflict') + TITLE = _('Resource conflict') def __init__(self, description, **kwargs): - super(HTTPConflict, self).__init__(self.TITLE, description, **kwargs) + super(HTTPConflict, self).__init__( + title=self.TITLE, description=description, **kwargs) class HTTPNotFound(falcon.HTTPNotFound): """Wraps falcon.HTTPConflict with contextual title.""" - TITLE = _(u'Not found') + TITLE = _('Not found') def __init__(self, description): - super(HTTPNotFound, self).__init__(title=self.TITLE, - description=description) + super(HTTPNotFound, self).__init__( + title=self.TITLE, description=description) class HTTPUnsupportedMediaType(falcon.HTTPUnsupportedMediaType): """Wraps falcon.HTTPUnsupportedMediaType with contextual title.""" def __init__(self, description): - super(HTTPUnsupportedMediaType, self).__init__(description) + super(HTTPUnsupportedMediaType, self).__init__( + description=description) diff --git a/zaqar/transport/wsgi/v1_0/claims.py b/zaqar/transport/wsgi/v1_0/claims.py index df9673113..180735ff9 100644 --- a/zaqar/transport/wsgi/v1_0/claims.py +++ b/zaqar/transport/wsgi/v1_0/claims.py @@ -81,7 +81,7 @@ class CollectionResource(Resource): msg, req.path.rpartition('/')[0], cid) for msg in resp_msgs] resp.location = req.path + '/' + cid - resp.body = utils.to_json(resp_msgs) + resp.text = utils.to_json(resp_msgs) resp.status = falcon.HTTP_201 else: resp.status = falcon.HTTP_204 @@ -125,7 +125,7 @@ class ItemResource(Resource): del meta['id'] resp.content_location = req.relative_uri - resp.body = utils.to_json(meta) + resp.text = utils.to_json(meta) # status defaults to 200 @decorators.TransportLog("Claim item") diff --git a/zaqar/transport/wsgi/v1_0/messages.py b/zaqar/transport/wsgi/v1_0/messages.py index 71f5e95d5..a45b27c5e 100644 --- a/zaqar/transport/wsgi/v1_0/messages.py +++ b/zaqar/transport/wsgi/v1_0/messages.py @@ -183,7 +183,7 @@ class CollectionResource(object): # field has been removed in v1.1. body = {'resources': hrefs, 'partial': False} - resp.body = utils.to_json(body) + resp.text = utils.to_json(body) resp.status = falcon.HTTP_201 @decorators.TransportLog("Messages collection") @@ -201,7 +201,7 @@ class CollectionResource(object): resp.status = falcon.HTTP_204 return - resp.body = utils.to_json(response) + resp.text = utils.to_json(response) # status defaults to 200 @decorators.TransportLog("Messages collection") @@ -256,7 +256,7 @@ class ItemResource(object): resp.content_location = req.relative_uri message = wsgi_utils.format_message_v1( message, req.path.rsplit('/', 2)[0]) - resp.body = utils.to_json(message) + resp.text = utils.to_json(message) # status defaults to 200 @decorators.TransportLog("Messages item") @@ -274,19 +274,22 @@ class ItemResource(object): LOG.debug(ex) description = _(u'A claim was specified, but the message ' u'is not currently claimed.') - raise falcon.HTTPBadRequest(error_title, description) + raise falcon.HTTPBadRequest( + title=error_title, description=description) except storage_errors.ClaimDoesNotExist as ex: LOG.debug(ex) description = _(u'The specified claim does not exist or ' u'has expired.') - raise falcon.HTTPBadRequest(error_title, description) + raise falcon.HTTPBadRequest( + title=error_title, description=description) except storage_errors.NotPermitted as ex: LOG.debug(ex) description = _(u'This message is claimed; it cannot be ' u'deleted without a valid claim ID.') - raise falcon.HTTPForbidden(error_title, description) + raise falcon.HTTPForbidden( + title=error_title, description=description) except Exception: description = _(u'Message could not be deleted.') diff --git a/zaqar/transport/wsgi/v1_0/metadata.py b/zaqar/transport/wsgi/v1_0/metadata.py index 23db1251c..ee3228bf4 100644 --- a/zaqar/transport/wsgi/v1_0/metadata.py +++ b/zaqar/transport/wsgi/v1_0/metadata.py @@ -52,7 +52,7 @@ class Resource(object): raise wsgi_errors.HTTPServiceUnavailable(description) resp.content_location = req.path - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) # status defaults to 200 @decorators.TransportLog("Queue metadata") diff --git a/zaqar/transport/wsgi/v1_0/pools.py b/zaqar/transport/wsgi/v1_0/pools.py index c1e53cc5b..e8899eb49 100644 --- a/zaqar/transport/wsgi/v1_0/pools.py +++ b/zaqar/transport/wsgi/v1_0/pools.py @@ -105,7 +105,7 @@ class Listing(object): results['pools'] = pools response.content_location = request.relative_uri - response.body = transport_utils.to_json(results) + response.text = transport_utils.to_json(results) response.status = falcon.HTTP_200 @@ -147,7 +147,7 @@ class Resource(object): data['href'] = request.path - response.body = transport_utils.to_json(data) + response.text = transport_utils.to_json(data) response.content_location = request.relative_uri def on_put(self, request, response, project_id, pool): diff --git a/zaqar/transport/wsgi/v1_0/queues.py b/zaqar/transport/wsgi/v1_0/queues.py index 362345284..5fa2b2209 100644 --- a/zaqar/transport/wsgi/v1_0/queues.py +++ b/zaqar/transport/wsgi/v1_0/queues.py @@ -128,5 +128,5 @@ class CollectionResource(object): } resp.content_location = req.relative_uri - resp.body = utils.to_json(response_body) + resp.text = utils.to_json(response_body) # status defaults to 200 diff --git a/zaqar/transport/wsgi/v1_0/stats.py b/zaqar/transport/wsgi/v1_0/stats.py index 93552aeef..8a83d7008 100644 --- a/zaqar/transport/wsgi/v1_0/stats.py +++ b/zaqar/transport/wsgi/v1_0/stats.py @@ -50,7 +50,7 @@ class Resource(object): del oldest['id'] resp.content_location = req.path - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) # status defaults to 200 except storage_errors.QueueIsEmpty: @@ -61,7 +61,7 @@ class Resource(object): 'total': 0 } } - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) except storage_errors.DoesNotExist as ex: LOG.debug(ex) raise wsgi_errors.HTTPNotFound(str(ex)) diff --git a/zaqar/transport/wsgi/v1_1/claims.py b/zaqar/transport/wsgi/v1_1/claims.py index 7aacec822..71aab9c72 100644 --- a/zaqar/transport/wsgi/v1_1/claims.py +++ b/zaqar/transport/wsgi/v1_1/claims.py @@ -102,7 +102,7 @@ class CollectionResource(object): for msg in resp_msgs] resp.location = req.path + '/' + cid - resp.body = utils.to_json({'messages': resp_msgs}) + resp.text = utils.to_json({'messages': resp_msgs}) resp.status = falcon.HTTP_201 else: resp.status = falcon.HTTP_204 @@ -152,7 +152,7 @@ class ItemResource(object): meta['href'] = req.path del meta['id'] - resp.body = utils.to_json(meta) + resp.text = utils.to_json(meta) # status defaults to 200 @decorators.TransportLog("Claim item") diff --git a/zaqar/transport/wsgi/v1_1/flavors.py b/zaqar/transport/wsgi/v1_1/flavors.py index b39ebda51..69372a1aa 100644 --- a/zaqar/transport/wsgi/v1_1/flavors.py +++ b/zaqar/transport/wsgi/v1_1/flavors.py @@ -83,7 +83,7 @@ class Listing(object): results['flavors'] = flavors - response.body = transport_utils.to_json(results) + response.text = transport_utils.to_json(results) response.status = falcon.HTTP_200 @@ -125,7 +125,7 @@ class Resource(object): data['href'] = request.path - response.body = transport_utils.to_json(data) + response.text = transport_utils.to_json(data) def on_put(self, request, response, project_id, flavor): """Registers a new flavor. Expects the following input: @@ -153,7 +153,8 @@ class Resource(object): description = (_(u'Flavor %(flavor)s could not be created. ') % dict(flavor=flavor)) LOG.exception(description) - raise falcon.HTTPBadRequest(_('Unable to create'), description) + raise falcon.HTTPBadRequest( + title=_('Unable to create'), description=description) def on_delete(self, request, response, project_id, flavor): """Deregisters a flavor. diff --git a/zaqar/transport/wsgi/v1_1/health.py b/zaqar/transport/wsgi/v1_1/health.py index c832c156d..311577237 100644 --- a/zaqar/transport/wsgi/v1_1/health.py +++ b/zaqar/transport/wsgi/v1_1/health.py @@ -32,7 +32,7 @@ class Resource(object): def on_get(self, req, resp, **kwargs): try: resp_dict = self._driver.health() - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) except Exception: description = _(u'Health status could not be read.') LOG.exception(description) diff --git a/zaqar/transport/wsgi/v1_1/messages.py b/zaqar/transport/wsgi/v1_1/messages.py index 374d07535..16b183a26 100644 --- a/zaqar/transport/wsgi/v1_1/messages.py +++ b/zaqar/transport/wsgi/v1_1/messages.py @@ -207,7 +207,7 @@ class CollectionResource(object): hrefs = [req.path + '/' + id for id in message_ids] body = {'resources': hrefs} - resp.body = utils.to_json(body) + resp.text = utils.to_json(body) resp.status = falcon.HTTP_201 @decorators.TransportLog("Messages collection") @@ -232,7 +232,7 @@ class CollectionResource(object): raise wsgi_errors.HTTPNotFound(description) else: - resp.body = utils.to_json(response) + resp.text = utils.to_json(response) # status defaults to 200 @decorators.TransportLog("Messages collection") @@ -251,7 +251,7 @@ class CollectionResource(object): project_id) elif pop_limit: - resp.status, resp.body = self._pop_messages(queue_name, + resp.status, resp.text = self._pop_messages(queue_name, project_id, pop_limit) @@ -324,7 +324,7 @@ class ItemResource(object): req.path.rsplit('/', 2)[0], message['claim_id']) - resp.body = utils.to_json(message) + resp.text = utils.to_json(message) # status defaults to 200 @decorators.TransportLog("Messages item") @@ -342,19 +342,22 @@ class ItemResource(object): LOG.debug(ex) description = _(u'A claim was specified, but the message ' u'is not currently claimed.') - raise falcon.HTTPBadRequest(error_title, description) + raise falcon.HTTPBadRequest( + title=error_title, description=description) except storage_errors.ClaimDoesNotExist as ex: LOG.debug(ex) description = _(u'The specified claim does not exist or ' u'has expired.') - raise falcon.HTTPBadRequest(error_title, description) + raise falcon.HTTPBadRequest( + title=error_title, description=description) except storage_errors.NotPermitted as ex: LOG.debug(ex) description = _(u'This message is claimed; it cannot be ' u'deleted without a valid claim ID.') - raise falcon.HTTPForbidden(error_title, description) + raise falcon.HTTPForbidden( + title=error_title, description=description) except Exception: description = _(u'Message could not be deleted.') diff --git a/zaqar/transport/wsgi/v1_1/pools.py b/zaqar/transport/wsgi/v1_1/pools.py index 0f47c6ff2..fe3f26272 100644 --- a/zaqar/transport/wsgi/v1_1/pools.py +++ b/zaqar/transport/wsgi/v1_1/pools.py @@ -107,7 +107,7 @@ class Listing(object): results['pools'] = pools response.content_location = request.relative_uri - response.body = transport_utils.to_json(results) + response.text = transport_utils.to_json(results) response.status = falcon.HTTP_200 @@ -151,7 +151,7 @@ class Resource(object): data['href'] = request.path - response.body = transport_utils.to_json(data) + response.text = transport_utils.to_json(data) def on_put(self, request, response, project_id, pool): """Registers a new pool. Expects the following input: @@ -183,7 +183,7 @@ class Resource(object): except errors.PoolCapabilitiesMismatch as e: title = _(u'Unable to create pool') LOG.exception(title) - raise falcon.HTTPBadRequest(title, str(e)) + raise falcon.HTTPBadRequest(title=title, description=str(e)) except errors.PoolAlreadyExists as e: LOG.exception('Pool "%s" already exists', pool) raise wsgi_errors.HTTPConflict(str(e)) @@ -204,7 +204,7 @@ class Resource(object): u'It cannot be deleted.') description = description.format(flavor=ex.flavor) LOG.exception(description) - raise falcon.HTTPForbidden(title, description) + raise falcon.HTTPForbidden(title=title, description=description) response.status = falcon.HTTP_204 diff --git a/zaqar/transport/wsgi/v1_1/queues.py b/zaqar/transport/wsgi/v1_1/queues.py index 504568fa5..28d83dfa0 100644 --- a/zaqar/transport/wsgi/v1_1/queues.py +++ b/zaqar/transport/wsgi/v1_1/queues.py @@ -52,7 +52,7 @@ class ItemResource(object): LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) # status defaults to 200 @decorators.TransportLog("Queue item") @@ -157,5 +157,5 @@ class CollectionResource(object): 'links': links } - resp.body = utils.to_json(response_body) + resp.text = utils.to_json(response_body) # status defaults to 200 diff --git a/zaqar/transport/wsgi/v1_1/stats.py b/zaqar/transport/wsgi/v1_1/stats.py index 6295901bd..4cbdd172e 100644 --- a/zaqar/transport/wsgi/v1_1/stats.py +++ b/zaqar/transport/wsgi/v1_1/stats.py @@ -49,7 +49,7 @@ class Resource(object): oldest['href'] = base_path + oldest['id'] del oldest['id'] - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) # status defaults to 200 except (storage_errors.QueueDoesNotExist, @@ -61,7 +61,7 @@ class Resource(object): 'total': 0 } } - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) except storage_errors.DoesNotExist as ex: LOG.debug(ex) diff --git a/zaqar/transport/wsgi/v2_0/claims.py b/zaqar/transport/wsgi/v2_0/claims.py index 38c86a119..4c3d20aa2 100644 --- a/zaqar/transport/wsgi/v2_0/claims.py +++ b/zaqar/transport/wsgi/v2_0/claims.py @@ -104,7 +104,7 @@ class CollectionResource(object): for msg in resp_msgs] resp.location = req.path + '/' + cid - resp.body = utils.to_json({'messages': resp_msgs}) + resp.text = utils.to_json({'messages': resp_msgs}) resp.status = falcon.HTTP_201 else: resp.status = falcon.HTTP_204 @@ -155,7 +155,7 @@ class ItemResource(object): meta['href'] = req.path del meta['id'] - resp.body = utils.to_json(meta) + resp.text = utils.to_json(meta) # status defaults to 200 @decorators.TransportLog("Claims item") diff --git a/zaqar/transport/wsgi/v2_0/flavors.py b/zaqar/transport/wsgi/v2_0/flavors.py index 6a9a0d50d..6a4cbfc64 100644 --- a/zaqar/transport/wsgi/v2_0/flavors.py +++ b/zaqar/transport/wsgi/v2_0/flavors.py @@ -110,7 +110,7 @@ class Listing(object): results['flavors'] = flavors - response.body = transport_utils.to_json(results) + response.text = transport_utils.to_json(results) response.status = falcon.HTTP_200 @@ -162,7 +162,7 @@ class Resource(object): data['href'] = request.path - response.body = transport_utils.to_json(data) + response.text = transport_utils.to_json(data) def _check_pools_exists(self, pool_list): if pool_list is not None: @@ -194,7 +194,8 @@ class Resource(object): if len(pool_list) == 0: response.status = falcon.HTTP_400 response.location = request.path - raise falcon.HTTPBadRequest(_('Unable to create'), 'Bad Request') + raise falcon.HTTPBadRequest( + title=_('Unable to create'), description='Bad Request') # NOTE(gengchc2): Check if pools in the pool_list exist. try: self._check_pools_exists(pool_list) @@ -203,7 +204,8 @@ class Resource(object): 'error:%(msg)s') % dict(flavor=flavor, msg=str(ex))) LOG.exception(description) - raise falcon.HTTPBadRequest(_('Unable to create'), description) + raise falcon.HTTPBadRequest( + title=_('Unable to create'), description=description) capabilities = self._pools_ctrl.capabilities(name=pool_list[0]) try: self._ctrl.create(flavor, @@ -216,7 +218,8 @@ class Resource(object): 'error:%(msg)s') % dict(flavor=flavor, msg=str(ex))) LOG.exception(description) - raise falcon.HTTPBadRequest(_('Unable to create'), description) + raise falcon.HTTPBadRequest( + title=_('Unable to create'), description=description) # NOTE(gengchc2): Update the 'flavor' field in pools tables. try: self._update_pools_by_flavor(flavor, pool_list) @@ -225,7 +228,8 @@ class Resource(object): 'error:%(msg)s') % dict(flavor=flavor, msg=str(ex))) LOG.exception(description) - raise falcon.HTTPBadRequest(_('Unable to create'), description) + raise falcon.HTTPBadRequest( + title=_('Unable to create'), description=description) @decorators.TransportLog("Flavors item") @acl.enforce("flavors:create") @@ -268,7 +272,8 @@ class Resource(object): description = (_(u'Flavor %(flavor)s could not be deleted.') % dict(flavor=flavor)) LOG.exception(description) - raise falcon.HTTPBadRequest(_('Unable to create'), description) + raise falcon.HTTPBadRequest( + title=_('Unable to create'), description=description) self._ctrl.delete(flavor, project=project_id) response.status = falcon.HTTP_204 @@ -278,7 +283,8 @@ class Resource(object): if len(pool_list) == 0: response.status = falcon.HTTP_400 response.location = request.path - raise falcon.HTTPBadRequest(_('Unable to create'), 'Bad Request') + raise falcon.HTTPBadRequest( + title=_('Unable to create'), description='Bad Request') # NOTE(gengchc2): If the flavor does not exist, return try: self._ctrl.get(flavor, project=project_id) @@ -299,7 +305,8 @@ class Resource(object): 'error:%(msg)s') % dict(flavor=flavor, msg=str(ex))) LOG.exception(description) - raise falcon.HTTPBadRequest(_('updatefail'), description) + raise falcon.HTTPBadRequest( + title=_('updatefail'), description=description) capabilities = self._pools_ctrl.capabilities(name=pool_list[0]) try: self._ctrl.update(flavor, project=project_id, @@ -318,7 +325,8 @@ class Resource(object): 'error:%(msg)s') % dict(flavor=flavor, msg=str(ex))) LOG.exception(description) - raise falcon.HTTPBadRequest(_('Unable to create'), description) + raise falcon.HTTPBadRequest( + title=_('Unable to create'), description=description) # (gengchc) Remove flavor from old pool list. try: pool_list_removed = [] @@ -331,10 +339,11 @@ class Resource(object): 'error:%(msg)s') % dict(flavor=flavor, msg=str(ex))) LOG.exception(description) - raise falcon.HTTPBadRequest(_('Unable to create'), description) + raise falcon.HTTPBadRequest( + title=_('Unable to create'), description=description) resp_data['pool_list'] = pool_list resp_data['href'] = request.path - response.body = transport_utils.to_json(resp_data) + response.text = transport_utils.to_json(resp_data) @decorators.TransportLog("Flavors item") @acl.enforce("flavors:update") diff --git a/zaqar/transport/wsgi/v2_0/health.py b/zaqar/transport/wsgi/v2_0/health.py index c50cf8f23..9d61c02fe 100644 --- a/zaqar/transport/wsgi/v2_0/health.py +++ b/zaqar/transport/wsgi/v2_0/health.py @@ -36,7 +36,7 @@ class Resource(object): def on_get(self, req, resp, **kwargs): try: resp_dict = self._driver.health() - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) except Exception: description = _(u'Health status could not be read.') LOG.exception(description) diff --git a/zaqar/transport/wsgi/v2_0/messages.py b/zaqar/transport/wsgi/v2_0/messages.py index 6d9870a87..c8d95ff13 100644 --- a/zaqar/transport/wsgi/v2_0/messages.py +++ b/zaqar/transport/wsgi/v2_0/messages.py @@ -264,7 +264,7 @@ class CollectionResource(object): hrefs = [req.path + '/' + id for id in message_ids] body = {'resources': hrefs} - resp.body = utils.to_json(body) + resp.text = utils.to_json(body) resp.status = falcon.HTTP_201 @decorators.TransportLog("Messages collection") @@ -290,7 +290,7 @@ class CollectionResource(object): raise wsgi_errors.HTTPNotFound(description) else: - resp.body = utils.to_json(response) + resp.text = utils.to_json(response) # status defaults to 200 @decorators.TransportLog("Messages collection") @@ -313,7 +313,7 @@ class CollectionResource(object): project_id, claim_ids) elif pop_limit: - resp.status, resp.body = self._pop_messages(queue_name, + resp.status, resp.text = self._pop_messages(queue_name, project_id, pop_limit) @@ -402,7 +402,7 @@ class ItemResource(object): req.path.rsplit('/', 2)[0], message['claim_id']) - resp.body = utils.to_json(message) + resp.text = utils.to_json(message) # status defaults to 200 @decorators.TransportLog("Messages item") @@ -421,19 +421,22 @@ class ItemResource(object): LOG.debug(ex) description = _(u'A claim was specified, but the message ' u'is not currently claimed.') - raise falcon.HTTPBadRequest(error_title, description) + raise falcon.HTTPBadRequest( + title=error_title, description=description) except storage_errors.ClaimDoesNotExist as ex: LOG.debug(ex) description = _(u'The specified claim does not exist or ' u'has expired.') - raise falcon.HTTPBadRequest(error_title, description) + raise falcon.HTTPBadRequest( + title=error_title, description=description) except storage_errors.NotPermitted as ex: LOG.debug(ex) description = _(u'This message is claimed; it cannot be ' u'deleted without a valid claim ID.') - raise falcon.HTTPForbidden(error_title, description) + raise falcon.HTTPForbidden( + title=error_title, description=description) except Exception: description = _(u'Message could not be deleted.') diff --git a/zaqar/transport/wsgi/v2_0/pools.py b/zaqar/transport/wsgi/v2_0/pools.py index 5428763aa..03c86333b 100644 --- a/zaqar/transport/wsgi/v2_0/pools.py +++ b/zaqar/transport/wsgi/v2_0/pools.py @@ -119,7 +119,7 @@ class Listing(object): results['pools'] = pools response.content_location = request.relative_uri - response.body = transport_utils.to_json(results) + response.text = transport_utils.to_json(results) response.status = falcon.HTTP_200 @@ -165,7 +165,7 @@ class Resource(object): data['href'] = request.path - response.body = transport_utils.to_json(data) + response.text = transport_utils.to_json(data) @decorators.TransportLog("Pools item") @acl.enforce("pools:create") @@ -200,7 +200,7 @@ class Resource(object): except errors.PoolCapabilitiesMismatch as e: title = _(u'Unable to create pool') LOG.exception(title) - raise falcon.HTTPBadRequest(title, str(e)) + raise falcon.HTTPBadRequest(title=title, description=str(e)) except errors.PoolAlreadyExists as e: LOG.exception('Pool "%s" already exists', pool) raise wsgi_errors.HTTPConflict(str(e)) @@ -223,7 +223,7 @@ class Resource(object): u'It cannot be deleted.') description = description.format(flavor=ex.flavor) LOG.exception(description) - raise falcon.HTTPForbidden(title, description) + raise falcon.HTTPForbidden(title=title, description=description) response.status = falcon.HTTP_204 @@ -274,4 +274,4 @@ class Resource(object): raise wsgi_errors.HTTPNotFound(str(ex)) resp_data['href'] = request.path - response.body = transport_utils.to_json(resp_data) + response.text = transport_utils.to_json(resp_data) diff --git a/zaqar/transport/wsgi/v2_0/queues.py b/zaqar/transport/wsgi/v2_0/queues.py index 80161d8b2..35e80b530 100644 --- a/zaqar/transport/wsgi/v2_0/queues.py +++ b/zaqar/transport/wsgi/v2_0/queues.py @@ -73,7 +73,7 @@ class ItemResource(object): LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) # status defaults to 200 @decorators.TransportLog("Queues item") @@ -217,7 +217,7 @@ class ItemResource(object): for meta, value in _get_reserved_metadata(self._validate).items(): if not metadata.get(meta): metadata[meta] = value - resp.body = utils.to_json(metadata) + resp.text = utils.to_json(metadata) def _do_replace(self, req, metadata, reserved_metadata, change): path = change['path'] @@ -321,7 +321,7 @@ class CollectionResource(object): if total_number: response_body['count'] = total_number - resp.body = utils.to_json(response_body) + resp.text = utils.to_json(response_body) # status defaults to 200 @decorators.TransportLog("Queues collection") diff --git a/zaqar/transport/wsgi/v2_0/stats.py b/zaqar/transport/wsgi/v2_0/stats.py index 5c404c3a0..e308bd36e 100644 --- a/zaqar/transport/wsgi/v2_0/stats.py +++ b/zaqar/transport/wsgi/v2_0/stats.py @@ -53,7 +53,7 @@ class Resource(object): oldest['href'] = base_path + oldest['id'] del oldest['id'] - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) # status defaults to 200 except (storage_errors.QueueDoesNotExist, @@ -65,7 +65,7 @@ class Resource(object): 'total': 0 } } - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) except storage_errors.DoesNotExist as ex: LOG.debug(ex) diff --git a/zaqar/transport/wsgi/v2_0/subscriptions.py b/zaqar/transport/wsgi/v2_0/subscriptions.py index 45b97a819..531ebdc85 100644 --- a/zaqar/transport/wsgi/v2_0/subscriptions.py +++ b/zaqar/transport/wsgi/v2_0/subscriptions.py @@ -59,7 +59,7 @@ class ItemResource(object): LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) # status defaults to 200 @decorators.TransportLog("Subscriptions item") @@ -106,8 +106,9 @@ class ItemResource(object): ' updated.') % dict(subscription_id=subscription_id)) LOG.exception(description) - raise falcon.HTTPBadRequest(_('Unable to update subscription'), - description) + raise falcon.HTTPBadRequest( + title=_('Unable to update subscription'), + description=description) class CollectionResource(object): @@ -167,7 +168,7 @@ class CollectionResource(object): 'links': links } - resp.body = utils.to_json(response_body) + resp.text = utils.to_json(response_body) # status defaults to 200 @decorators.TransportLog("Subscriptions collection") @@ -221,7 +222,7 @@ class CollectionResource(object): resp.location = req.path resp.status = falcon.HTTP_201 - resp.body = utils.to_json( + resp.text = utils.to_json( {'subscription_id': str(created)}) else: subscription = self._subscription_controller.get_with_subscriber( @@ -242,7 +243,7 @@ class CollectionResource(object): resp.location = req.path resp.status = falcon.HTTP_201 - resp.body = utils.to_json( + resp.text = utils.to_json( {'subscription_id': str(subscription['id'])}) @@ -301,5 +302,6 @@ class ConfirmResource(object): ' confirmed.') % dict(subscription_id=subscription_id)) LOG.exception(description) - raise falcon.HTTPBadRequest(_('Unable to confirm subscription'), - description) + raise falcon.HTTPBadRequest( + title=_('Unable to confirm subscription'), + description=description) diff --git a/zaqar/transport/wsgi/v2_0/topic.py b/zaqar/transport/wsgi/v2_0/topic.py index 2d9a48801..aa0ad0d9e 100644 --- a/zaqar/transport/wsgi/v2_0/topic.py +++ b/zaqar/transport/wsgi/v2_0/topic.py @@ -69,7 +69,7 @@ class ItemResource(object): LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) # status defaults to 200 @decorators.TransportLog("Topics item") @@ -213,7 +213,7 @@ class ItemResource(object): for meta, value in _get_reserved_metadata(self._validate).items(): if not metadata.get(meta): metadata[meta] = value - resp.body = utils.to_json(metadata) + resp.text = utils.to_json(metadata) def _do_replace(self, req, metadata, reserved_metadata, change): path = change['path'] @@ -307,7 +307,7 @@ class CollectionResource(object): 'links': links } - resp.body = utils.to_json(response_body) + resp.text = utils.to_json(response_body) # status defaults to 200 @decorators.TransportLog("Topics collection") diff --git a/zaqar/transport/wsgi/v2_0/topic_stats.py b/zaqar/transport/wsgi/v2_0/topic_stats.py index 3911c89df..d6bf490b8 100644 --- a/zaqar/transport/wsgi/v2_0/topic_stats.py +++ b/zaqar/transport/wsgi/v2_0/topic_stats.py @@ -53,7 +53,7 @@ class Resource(object): oldest['href'] = base_path + oldest['id'] del oldest['id'] - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) # status defaults to 200 except (storage_errors.TopicDoesNotExist, @@ -65,7 +65,7 @@ class Resource(object): 'total': 0 } } - resp.body = utils.to_json(resp_dict) + resp.text = utils.to_json(resp_dict) except storage_errors.DoesNotExist as ex: LOG.debug(ex) diff --git a/zaqar/transport/wsgi/v2_0/urls.py b/zaqar/transport/wsgi/v2_0/urls.py index 8256752ea..7e96fe422 100644 --- a/zaqar/transport/wsgi/v2_0/urls.py +++ b/zaqar/transport/wsgi/v2_0/urls.py @@ -74,4 +74,4 @@ class Resource(object): except ValueError as err: raise wsgi_errors.HTTPBadRequestAPI(str(err)) - resp.body = utils.to_json(data) + resp.text = utils.to_json(data) diff --git a/zaqar/transport/wsgi/version.py b/zaqar/transport/wsgi/version.py index fcb82a303..3d29f69b1 100644 --- a/zaqar/transport/wsgi/version.py +++ b/zaqar/transport/wsgi/version.py @@ -34,6 +34,6 @@ class Resource(object): self.versions = utils.to_json(VERSIONS) def on_get(self, req, resp, project_id): - resp.body = self.versions + resp.text = self.versions resp.status = falcon.HTTP_300