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]c76f44248a
[2]0b9d26c7f6
Change-Id: Ied13446be2e1b5cb7c5839a84e8ad2413cca6fe3
This commit is contained in:
parent
fecef8a839
commit
4543e7691c
4
releasenotes/notes/falcon-4-e4b5aab856e3228c.yaml
Normal file
4
releasenotes/notes/falcon-4-e4b5aab856e3228c.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixed compatibility with falcon 4.0.0 and later.
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
|
@ -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.')
|
||||
|
@ -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")
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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")
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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.')
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
|
@ -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.')
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user