From e135e439350390c8ee3d5bd8478799acbcb7673a Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Wed, 29 May 2019 17:12:31 -0500 Subject: [PATCH] Fix exception mishandling There were a lot of instances of exceptions being raised or logged incorrectly. When reraising an exception, "raise" should be called, not "raise ex". The second form will cause the original traceback to be modified to the new location. LOG.exception is the same as LOG.error with the additional behavior of logging any exception that is in the current scope. Therefore, doing something like "LOG.exception(ex)" is redundant and causes the exception message to be logged twice. Logging should be done with some sort of textual message without the exception object. Change-Id: I149c8fe7ef4b6628f910943587ab4302cc371441 Signed-off-by: Sean McGinnis --- zaqar/api/v2/endpoints.py | 28 ++++++++--------- zaqar/bootstrap.py | 9 +++--- zaqar/common/api/utils.py | 2 +- zaqar/common/cli.py | 2 +- zaqar/storage/base.py | 5 +-- zaqar/storage/mongodb/messages.py | 18 +++++------ zaqar/storage/mongodb/pools.py | 4 +-- zaqar/storage/mongodb/queues.py | 4 +-- zaqar/storage/mongodb/topic_messages.py | 18 +++++------ zaqar/storage/mongodb/topics.py | 4 +-- zaqar/storage/mongodb/utils.py | 4 +-- zaqar/storage/redis/utils.py | 4 +-- zaqar/storage/sqlalchemy/utils.py | 4 +-- zaqar/storage/swift/driver.py | 4 +-- zaqar/storage/utils.py | 7 ++--- zaqar/transport/wsgi/driver.py | 4 +-- zaqar/transport/wsgi/utils.py | 13 ++++---- zaqar/transport/wsgi/v1_0/claims.py | 16 +++++----- zaqar/transport/wsgi/v1_0/messages.py | 28 ++++++++--------- zaqar/transport/wsgi/v1_0/metadata.py | 8 ++--- zaqar/transport/wsgi/v1_0/pools.py | 4 +-- zaqar/transport/wsgi/v1_0/queues.py | 12 ++++---- zaqar/transport/wsgi/v1_0/stats.py | 4 +-- zaqar/transport/wsgi/v1_1/claims.py | 16 +++++----- zaqar/transport/wsgi/v1_1/flavors.py | 6 ++-- zaqar/transport/wsgi/v1_1/health.py | 4 +-- zaqar/transport/wsgi/v1_1/messages.py | 32 +++++++++---------- zaqar/transport/wsgi/v1_1/pools.py | 8 ++--- zaqar/transport/wsgi/v1_1/queues.py | 18 +++++------ zaqar/transport/wsgi/v1_1/stats.py | 4 +-- zaqar/transport/wsgi/v2_0/claims.py | 16 +++++----- zaqar/transport/wsgi/v2_0/flavors.py | 18 +++++------ zaqar/transport/wsgi/v2_0/health.py | 4 +-- zaqar/transport/wsgi/v2_0/messages.py | 36 +++++++++++----------- zaqar/transport/wsgi/v2_0/pools.py | 8 ++--- zaqar/transport/wsgi/v2_0/purge.py | 4 +-- zaqar/transport/wsgi/v2_0/queues.py | 28 ++++++++--------- zaqar/transport/wsgi/v2_0/stats.py | 4 +-- zaqar/transport/wsgi/v2_0/subscriptions.py | 24 +++++++-------- zaqar/transport/wsgi/v2_0/topic.py | 28 ++++++++--------- zaqar/transport/wsgi/v2_0/topic_purge.py | 4 +-- zaqar/transport/wsgi/v2_0/topic_stats.py | 4 +-- 42 files changed, 231 insertions(+), 241 deletions(-) diff --git a/zaqar/api/v2/endpoints.py b/zaqar/api/v2/endpoints.py index abd1a34f3..40723eeef 100644 --- a/zaqar/api/v2/endpoints.py +++ b/zaqar/api/v2/endpoints.py @@ -72,9 +72,9 @@ class Endpoints(object): headers = {'status': 400} return api_utils.error_response(req, ex, headers) except storage_errors.ExceptionBase as ex: - LOG.exception(ex) error = 'Queues could not be listed.' headers = {'status': 503} + LOG.exception(error) return api_utils.error_response(req, ex, headers, error) # Got some. Prepare the response. @@ -112,9 +112,9 @@ class Endpoints(object): headers = {'status': 400} return api_utils.error_response(req, ex, headers) except storage_errors.ExceptionBase as ex: - LOG.exception(ex) error = _('Queue %s could not be created.') % queue_name headers = {'status': 503} + LOG.exception(error) return api_utils.error_response(req, ex, headers, error) else: body = _('Queue %s created.') % queue_name @@ -138,9 +138,9 @@ class Endpoints(object): try: self._queue_controller.delete(queue_name, project=project_id) except storage_errors.ExceptionBase as ex: - LOG.exception(ex) error = _('Queue %s could not be deleted.') % queue_name headers = {'status': 503} + LOG.exception(error) return api_utils.error_response(req, ex, headers, error) else: body = _('Queue %s removed.') % queue_name @@ -172,9 +172,9 @@ class Endpoints(object): headers = {'status': 404} return api_utils.error_response(req, ex, headers, error) except storage_errors.ExceptionBase as ex: - LOG.exception(ex) headers = {'status': 503} error = _('Cannot retrieve queue %s.') % queue_name + LOG.exception(error) return api_utils.error_response(req, ex, headers, error) else: body = resp_dict @@ -201,8 +201,8 @@ class Endpoints(object): resp_dict = self._queue_controller.stats(queue_name, project=project_id) body = resp_dict - except storage_errors.QueueDoesNotExist as ex: - LOG.exception(ex) + except storage_errors.QueueDoesNotExist: + LOG.exception('Queue "%s" does not exist', queue_name) resp_dict = { 'messages': { 'claimed': 0, @@ -214,9 +214,9 @@ class Endpoints(object): headers = {'status': 404} return response.Response(req, body, headers) except storage_errors.ExceptionBase as ex: - LOG.exception(ex) error = _('Cannot retrieve queue %s stats.') % queue_name headers = {'status': 503} + LOG.exception(error) return api_utils.error_response(req, ex, headers, error) else: headers = {'status': 200} @@ -262,11 +262,11 @@ class Endpoints(object): project=project_id) except storage_errors.QueueDoesNotExist as ex: - LOG.exception(ex) + LOG.exception('Queue "%s" does not exist', queue_name) headers = {'status': 404} return api_utils.error_response(req, ex, headers) except storage_errors.ExceptionBase as ex: - LOG.exception(ex) + LOG.exception('Error deleting queue "%s".', queue_name) headers = {'status': 503} return api_utils.error_response(req, ex, headers) else: @@ -489,9 +489,9 @@ class Endpoints(object): headers = {'status': 404} return api_utils.error_response(req, ex, headers) except storage_errors.MessageConflict as ex: - LOG.exception(ex) error = _(u'No messages could be enqueued.') headers = {'status': 500} + LOG.exception(error) return api_utils.error_response(req, ex, headers, error) # Prepare the response @@ -835,9 +835,9 @@ class Endpoints(object): headers = {'status': 400} return api_utils.error_response(req, ex, headers) except storage_errors.ExceptionBase as ex: - LOG.exception(ex) error = 'Subscriptions could not be listed.' headers = {'status': 503} + LOG.exception(error) return api_utils.error_response(req, ex, headers, error) # Got some. Prepare the response. @@ -889,9 +889,9 @@ class Endpoints(object): headers = {'status': 400} return api_utils.error_response(req, ex, headers) except storage_errors.ExceptionBase as ex: - LOG.exception(ex) error = _('Subscription %s could not be created.') % queue_name headers = {'status': 503} + LOG.exception(error) return api_utils.error_response(req, ex, headers, error) else: if created: @@ -924,11 +924,11 @@ class Endpoints(object): subscription_id, project=project_id) except storage_errors.ExceptionBase as ex: - LOG.exception(ex) error = _('Subscription %(subscription)s for queue %(queue)s ' 'could not be deleted.') % { 'subscription': subscription_id, 'queue': queue_name} headers = {'status': 503} + LOG.exception(error) return api_utils.error_response(req, ex, headers, error) else: body = _('Subscription %s removed.') % subscription_id @@ -964,9 +964,9 @@ class Endpoints(object): headers = {'status': 404} return api_utils.error_response(req, ex, headers, error) except storage_errors.ExceptionBase as ex: - LOG.exception(ex) headers = {'status': 503} error = _('Cannot retrieve subscription %s.') % subscription_id + LOG.exception(error) return api_utils.error_response(req, ex, headers, error) else: body = resp_dict diff --git a/zaqar/bootstrap.py b/zaqar/bootstrap.py index bdf97cd5e..7c67f1a9b 100644 --- a/zaqar/bootstrap.py +++ b/zaqar/bootstrap.py @@ -95,7 +95,7 @@ class Bootstrap(object): oslo_cache.register_config(self.conf) return oslo_cache.get_cache(self.conf) except RuntimeError as exc: - LOG.exception(exc) + LOG.exception('Error loading proxy cache.') raise errors.InvalidDriver(exc) @decorators.lazy_property(write=False) @@ -120,10 +120,9 @@ class Bootstrap(object): invoke_args=args) return mgr.driver except RuntimeError as exc: - LOG.exception(exc) - LOG.error(u'Failed to load transport driver zaqar.transport.' - u'%(driver)s with args %(args)s', - {'driver': transport_name, 'args': args}) + LOG.exception(u'Failed to load transport driver zaqar.transport.' + u'%(driver)s with args %(args)s', + {'driver': transport_name, 'args': args}) raise errors.InvalidDriver(exc) def run(self): diff --git a/zaqar/common/api/utils.py b/zaqar/common/api/utils.py index c05854946..0cfa45853 100644 --- a/zaqar/common/api/utils.py +++ b/zaqar/common/api/utils.py @@ -194,11 +194,11 @@ def on_exception_sends_500(func): try: return func(*args, **kwargs) except Exception as ex: - LOG.exception(ex) error = _("Unexpected error.") headers = {'status': 500} # args[0] - Endpoints object, args[1] - Request object. req = args[1] + LOG.exception(error) return error_response(req, ex, headers, error) return wrapper diff --git a/zaqar/common/cli.py b/zaqar/common/cli.py index f56939416..c72b25816 100644 --- a/zaqar/common/cli.py +++ b/zaqar/common/cli.py @@ -34,7 +34,7 @@ def _fail(returncode, ex): print(ex, file=sys.stderr) - LOG.exception(ex) + LOG.exception('Exception encountered:') sys.exit(returncode) diff --git a/zaqar/storage/base.py b/zaqar/storage/base.py index 80335c474..4cae060f5 100644 --- a/zaqar/storage/base.py +++ b/zaqar/storage/base.py @@ -155,9 +155,10 @@ class DataDriverBase(DriverBase): try: start = time.time() result = callable_operation() - except Exception as e: + except Exception: ref = uuidutils.generate_uuid() - LOG.exception(e, extra={'instance_uuid': ref}) + LOG.exception('Error calling operation.', + extra={'instance_uuid': ref}) succeeded = False status = status_template(succeeded, time.time() - start, ref) op_status[operation_type] = status diff --git a/zaqar/storage/mongodb/messages.py b/zaqar/storage/mongodb/messages.py index b75566a8f..daa068e52 100644 --- a/zaqar/storage/mongodb/messages.py +++ b/zaqar/storage/mongodb/messages.py @@ -24,7 +24,6 @@ Field Mappings: import datetime import time -from bson import errors as bsonerror from bson import objectid from oslo_log import log as logging from oslo_utils import timeutils @@ -458,8 +457,8 @@ class MessageController(storage.Message): projection={'c.v': 1, '_id': 0}) break - except pymongo.errors.AutoReconnect as ex: - LOG.exception(ex) + except pymongo.errors.AutoReconnect: + LOG.exception('Auto reconnect error') if doc is None: if window is None: @@ -523,8 +522,8 @@ class MessageController(storage.Message): projection={'c.v': 1, '_id': 0}) return doc['c']['v'] - except pymongo.errors.AutoReconnect as ex: - LOG.exception(ex) + except pymongo.errors.AutoReconnect: + LOG.exception('Auto reconnect error') # ---------------------------------------------------------------------- # Public interface @@ -912,7 +911,7 @@ class FIFOMessageController(MessageController): return [str(id_) for id_ in res.inserted_ids] except (pymongo.errors.DuplicateKeyError, - pymongo.errors.BulkWriteError) as ex: + pymongo.errors.BulkWriteError): # TODO(kgriffs): Record stats of how often retries happen, # and how many attempts, on average, are required to insert # messages. @@ -994,11 +993,8 @@ class FIFOMessageController(MessageController): for index, message in enumerate(prepared_messages): message['k'] = next_marker + index - except bsonerror.InvalidDocument as ex: - LOG.exception(ex) - raise - except Exception as ex: - LOG.exception(ex) + except Exception: + LOG.exception('Error parsing document') raise msgtmpl = (u'Hit maximum number of attempts (%(max)s) for queue ' diff --git a/zaqar/storage/mongodb/pools.py b/zaqar/storage/mongodb/pools.py index 80b9d02c5..b22275f26 100644 --- a/zaqar/storage/mongodb/pools.py +++ b/zaqar/storage/mongodb/pools.py @@ -117,8 +117,8 @@ class PoolsController(base.PoolsBase): 'f': flavor, 'o': options}}, upsert=True) - except mongo_error.DuplicateKeyError as ex: - LOG.exception(ex) + except mongo_error.DuplicateKeyError: + LOG.exception('Pool "%s" already exists', name) raise errors.PoolAlreadyExists() @utils.raises_conn_error diff --git a/zaqar/storage/mongodb/queues.py b/zaqar/storage/mongodb/queues.py index 9938896d6..59328478f 100644 --- a/zaqar/storage/mongodb/queues.py +++ b/zaqar/storage/mongodb/queues.py @@ -162,8 +162,8 @@ class QueueController(storage.Queue): projection={'c.v': 1, '_id': 0}) break - except pymongo.errors.AutoReconnect as ex: - LOG.exception(ex) + except pymongo.errors.AutoReconnect: + LOG.exception('Auto reconnect failure') if doc is None: if window is None: diff --git a/zaqar/storage/mongodb/topic_messages.py b/zaqar/storage/mongodb/topic_messages.py index 55bd2cc23..425c526be 100644 --- a/zaqar/storage/mongodb/topic_messages.py +++ b/zaqar/storage/mongodb/topic_messages.py @@ -24,7 +24,6 @@ Field Mappings: import datetime import time -from bson import errors as bsonerror from bson import objectid from oslo_log import log as logging from oslo_utils import timeutils @@ -365,8 +364,8 @@ class MessageController(storage.Message): projection={'c.v': 1, '_id': 0}) break - except pymongo.errors.AutoReconnect as ex: - LOG.exception(ex) + except pymongo.errors.AutoReconnect: + LOG.exception('Auto reconnect error.') if doc is None: if window is None: @@ -430,8 +429,8 @@ class MessageController(storage.Message): projection={'c.v': 1, '_id': 0}) return doc['c']['v'] - except pymongo.errors.AutoReconnect as ex: - LOG.exception(ex) + except pymongo.errors.AutoReconnect: + LOG.exception('Auto reconnect error.') # ---------------------------------------------------------------------- # Public interface @@ -813,7 +812,7 @@ class FIFOMessageController(MessageController): return [str(id_) for id_ in res.inserted_ids] except (pymongo.errors.DuplicateKeyError, - pymongo.errors.BulkWriteError) as ex: + pymongo.errors.BulkWriteError): # TODO(kgriffs): Record stats of how often retries happen, # and how many attempts, on average, are required to insert # messages. @@ -895,11 +894,8 @@ class FIFOMessageController(MessageController): for index, message in enumerate(prepared_messages): message['k'] = next_marker + index - except bsonerror.InvalidDocument as ex: - LOG.exception(ex) - raise - except Exception as ex: - LOG.exception(ex) + except Exception: + LOG.exception('Error parsing document.') raise msgtmpl = (u'Hit maximum number of attempts (%(max)s) for topic ' diff --git a/zaqar/storage/mongodb/topics.py b/zaqar/storage/mongodb/topics.py index 1dca69052..6eddd0303 100644 --- a/zaqar/storage/mongodb/topics.py +++ b/zaqar/storage/mongodb/topics.py @@ -148,8 +148,8 @@ class TopicController(storage.Topic): projection={'c.v': 1, '_id': 0}) break - except pymongo.errors.AutoReconnect as ex: - LOG.exception(ex) + except pymongo.errors.AutoReconnect: + LOG.exception('Auto reconnect failure') if doc is None: if window is None: diff --git a/zaqar/storage/mongodb/utils.py b/zaqar/storage/mongodb/utils.py index 2227b3385..9a87a48f5 100644 --- a/zaqar/storage/mongodb/utils.py +++ b/zaqar/storage/mongodb/utils.py @@ -268,8 +268,8 @@ def raises_conn_error(func): def wrapper(*args, **kwargs): try: return func(*args, **kwargs) - except errors.ConnectionFailure as ex: - LOG.exception(ex) + except errors.ConnectionFailure: + LOG.exception('Connection failure.') raise storage_errors.ConnectionError() return wrapper diff --git a/zaqar/storage/redis/utils.py b/zaqar/storage/redis/utils.py index 3d41af502..7669cb162 100644 --- a/zaqar/storage/redis/utils.py +++ b/zaqar/storage/redis/utils.py @@ -152,8 +152,8 @@ def raises_conn_error(func): def wrapper(*args, **kwargs): try: return func(*args, **kwargs) - except redis.exceptions.ConnectionError as ex: - LOG.exception(ex) + except redis.exceptions.ConnectionError: + LOG.exception('Connection failure:') raise errors.ConnectionError() return wrapper diff --git a/zaqar/storage/sqlalchemy/utils.py b/zaqar/storage/sqlalchemy/utils.py index 614b4eb7f..a2ec26b8c 100644 --- a/zaqar/storage/sqlalchemy/utils.py +++ b/zaqar/storage/sqlalchemy/utils.py @@ -42,8 +42,8 @@ def raises_conn_error(func): def wrapper(*args, **kwargs): try: return func(*args, **kwargs) - except exc.InvalidRequestError as ex: - LOG.exception(ex) + except exc.InvalidRequestError: + LOG.exception('Connection error:') raise errors.ConnectionError() return wrapper diff --git a/zaqar/storage/swift/driver.py b/zaqar/storage/swift/driver.py index 730154c55..58a8d38f9 100644 --- a/zaqar/storage/swift/driver.py +++ b/zaqar/storage/swift/driver.py @@ -55,8 +55,8 @@ class DataDriver(storage.DataDriverBase): try: self.connection.get_capabilities() return True - except Exception as e: - LOG.exception(e) + except Exception: + LOG.exception('Aliveness check failed:') return False @decorators.lazy_property(write=False) diff --git a/zaqar/storage/utils.py b/zaqar/storage/utils.py index 9130a7400..0468fdabb 100644 --- a/zaqar/storage/utils.py +++ b/zaqar/storage/utils.py @@ -95,7 +95,7 @@ def load_storage_impl(uri, control_mode=False, default_store=None): return mgr.driver except Exception as exc: - LOG.exception(exc) + LOG.exception('Error loading storage driver') raise errors.InvalidDriver(exc) @@ -148,9 +148,8 @@ def load_storage_driver(conf, cache, storage_type=None, return mgr.driver except Exception as exc: - LOG.error('Failed to load "{}" driver for "{}"'.format( - driver_type, storage_type)) - LOG.exception(exc) + LOG.exception('Failed to load "%s" driver for "%s"', + driver_type, storage_type) raise errors.InvalidDriver(exc) diff --git a/zaqar/transport/wsgi/driver.py b/zaqar/transport/wsgi/driver.py index a95f30b2d..3e1dfc46b 100644 --- a/zaqar/transport/wsgi/driver.py +++ b/zaqar/transport/wsgi/driver.py @@ -164,8 +164,8 @@ class Driver(transport.DriverBase): def _error_handler(self, exc, request, response, params): if isinstance(exc, falcon.HTTPError): - raise exc - LOG.exception(exc) + raise + LOG.exception('Internal server error') raise falcon.HTTPInternalServerError('Internal server error', six.text_type(exc)) diff --git a/zaqar/transport/wsgi/utils.py b/zaqar/transport/wsgi/utils.py index 4e35ea551..e577bb605 100644 --- a/zaqar/transport/wsgi/utils.py +++ b/zaqar/transport/wsgi/utils.py @@ -69,10 +69,10 @@ def deserialize(stream, len): description = _(u'JSON contains integer that is too large.') raise errors.HTTPBadRequestBody(description) - except Exception as ex: + except Exception: # Error while reading from the network/server - LOG.exception(ex) description = _(u'Request body could not be read.') + LOG.exception(description) raise errors.HTTPServiceUnavailable(description) @@ -192,11 +192,10 @@ def load(req): """ try: return utils.read_json(req.stream, req.content_length) - except (utils.MalformedJSON, utils.OverflowedJSONInteger) as ex: - LOG.exception(ex) - raise errors.HTTPBadRequestBody( - 'JSON could not be parsed.' - ) + except (utils.MalformedJSON, utils.OverflowedJSONInteger): + message = 'JSON could not be parsed.' + LOG.exception(message) + raise errors.HTTPBadRequestBody(message) # TODO(cpp-cabrera): generalize this diff --git a/zaqar/transport/wsgi/v1_0/claims.py b/zaqar/transport/wsgi/v1_0/claims.py index 8df308c2a..2a36b7c36 100644 --- a/zaqar/transport/wsgi/v1_0/claims.py +++ b/zaqar/transport/wsgi/v1_0/claims.py @@ -70,9 +70,9 @@ class CollectionResource(Resource): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Claim could not be created.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Serialize claimed messages, if any. This logic assumes @@ -111,9 +111,9 @@ class ItemResource(Resource): except storage_errors.DoesNotExist as ex: LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Claim could not be queried.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Serialize claimed messages @@ -153,9 +153,9 @@ class ItemResource(Resource): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Claim could not be updated.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) @decorators.TransportLog("Claim item") @@ -167,7 +167,7 @@ class ItemResource(Resource): resp.status = falcon.HTTP_204 - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Claim could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) diff --git a/zaqar/transport/wsgi/v1_0/messages.py b/zaqar/transport/wsgi/v1_0/messages.py index d84a15dbe..7cf6f4686 100644 --- a/zaqar/transport/wsgi/v1_0/messages.py +++ b/zaqar/transport/wsgi/v1_0/messages.py @@ -57,9 +57,9 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Message could not be retrieved.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Prepare response @@ -100,9 +100,9 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Messages could not be listed.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) if not messages: @@ -161,14 +161,14 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except storage_errors.MessageConflict as ex: - LOG.exception(ex) + except storage_errors.MessageConflict: description = _(u'No messages could be enqueued.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Messages could not be enqueued.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Prepare the response @@ -222,9 +222,9 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Messages could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_204 @@ -249,9 +249,9 @@ class ItemResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Message could not be retrieved.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.content_location = req.relative_uri @@ -289,9 +289,9 @@ class ItemResource(object): u'deleted without a valid claim ID.') raise falcon.HTTPForbidden(error_title, description) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Message could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Alles guete diff --git a/zaqar/transport/wsgi/v1_0/metadata.py b/zaqar/transport/wsgi/v1_0/metadata.py index f044ad89a..3ea2db46e 100644 --- a/zaqar/transport/wsgi/v1_0/metadata.py +++ b/zaqar/transport/wsgi/v1_0/metadata.py @@ -47,9 +47,9 @@ class Resource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue metadata could not be retrieved.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.content_location = req.path @@ -87,9 +87,9 @@ class Resource(object): except storage_errors.QueueDoesNotExist as ex: raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Metadata could not be updated.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_204 diff --git a/zaqar/transport/wsgi/v1_0/pools.py b/zaqar/transport/wsgi/v1_0/pools.py index dbe39b28e..48b51b27a 100644 --- a/zaqar/transport/wsgi/v1_0/pools.py +++ b/zaqar/transport/wsgi/v1_0/pools.py @@ -179,7 +179,7 @@ class Resource(object): response.status = falcon.HTTP_201 response.location = request.path except errors.PoolAlreadyExists as e: - LOG.exception(e) + LOG.exception('Pool "%s" already exists', pool) raise wsgi_errors.HTTPConflict(six.text_type(e)) def on_delete(self, request, response, project_id, pool): @@ -231,5 +231,5 @@ class Resource(object): try: self._ctrl.update(pool, **fields) except errors.PoolDoesNotExist as ex: - LOG.exception(ex) + LOG.exception('Pool "%s" does not exist', pool) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) diff --git a/zaqar/transport/wsgi/v1_0/queues.py b/zaqar/transport/wsgi/v1_0/queues.py index e43274c62..0d115e8e0 100644 --- a/zaqar/transport/wsgi/v1_0/queues.py +++ b/zaqar/transport/wsgi/v1_0/queues.py @@ -41,9 +41,9 @@ class ItemResource(object): created = self._queue_controller.create( queue_name, project=project_id) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue could not be created.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_201 if created else falcon.HTTP_204 @@ -65,9 +65,9 @@ class ItemResource(object): try: self._queue_controller.delete(queue_name, project=project_id) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_204 @@ -103,9 +103,9 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queues could not be listed.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Check for an empty list diff --git a/zaqar/transport/wsgi/v1_0/stats.py b/zaqar/transport/wsgi/v1_0/stats.py index a296c8945..fd45076ae 100644 --- a/zaqar/transport/wsgi/v1_0/stats.py +++ b/zaqar/transport/wsgi/v1_0/stats.py @@ -67,7 +67,7 @@ class Resource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue stats could not be read.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) diff --git a/zaqar/transport/wsgi/v1_1/claims.py b/zaqar/transport/wsgi/v1_1/claims.py index aa11225ce..2b55aa84d 100644 --- a/zaqar/transport/wsgi/v1_1/claims.py +++ b/zaqar/transport/wsgi/v1_1/claims.py @@ -90,9 +90,9 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Claim could not be created.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Serialize claimed messages, if any. This logic assumes @@ -138,9 +138,9 @@ class ItemResource(object): except storage_errors.DoesNotExist as ex: LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Claim could not be queried.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Serialize claimed messages @@ -180,9 +180,9 @@ class ItemResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Claim could not be updated.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) @decorators.TransportLog("Claim item") @@ -194,7 +194,7 @@ class ItemResource(object): resp.status = falcon.HTTP_204 - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Claim could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) diff --git a/zaqar/transport/wsgi/v1_1/flavors.py b/zaqar/transport/wsgi/v1_1/flavors.py index 7a90dd287..cf22d0629 100644 --- a/zaqar/transport/wsgi/v1_1/flavors.py +++ b/zaqar/transport/wsgi/v1_1/flavors.py @@ -150,10 +150,10 @@ class Resource(object): capabilities=data['capabilities']) response.status = falcon.HTTP_201 response.location = request.path - except errors.PoolGroupDoesNotExist as ex: - LOG.exception(ex) + except errors.PoolGroupDoesNotExist: description = (_(u'Flavor %(flavor)s could not be created. ') % dict(flavor=flavor)) + LOG.exception(description) raise falcon.HTTPBadRequest(_('Unable to create'), description) def on_delete(self, request, response, project_id, flavor): @@ -199,5 +199,5 @@ class Resource(object): try: self._ctrl.update(flavor, project=project_id, **fields) except errors.FlavorDoesNotExist as ex: - LOG.exception(ex) + LOG.exception('Flavor "%s" does not exist', flavor) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) diff --git a/zaqar/transport/wsgi/v1_1/health.py b/zaqar/transport/wsgi/v1_1/health.py index def3a3d13..c832c156d 100644 --- a/zaqar/transport/wsgi/v1_1/health.py +++ b/zaqar/transport/wsgi/v1_1/health.py @@ -33,7 +33,7 @@ class Resource(object): try: resp_dict = self._driver.health() resp.body = utils.to_json(resp_dict) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Health status could not be read.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) diff --git a/zaqar/transport/wsgi/v1_1/messages.py b/zaqar/transport/wsgi/v1_1/messages.py index e140dd133..eff6111a2 100644 --- a/zaqar/transport/wsgi/v1_1/messages.py +++ b/zaqar/transport/wsgi/v1_1/messages.py @@ -70,9 +70,9 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Message could not be retrieved.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Prepare response @@ -116,9 +116,9 @@ class CollectionResource(object): LOG.debug(ex) messages = None - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Messages could not be listed.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) if not messages: @@ -192,14 +192,14 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except storage_errors.MessageConflict as ex: - LOG.exception(ex) + except storage_errors.MessageConflict: description = _(u'No messages could be enqueued.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Messages could not be enqueued.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Prepare the response @@ -263,9 +263,9 @@ class CollectionResource(object): message_ids=ids, project=project_id) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Messages could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) return falcon.HTTP_204 @@ -281,9 +281,9 @@ class CollectionResource(object): project=project_id, limit=pop_limit) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Messages could not be popped.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Prepare response @@ -314,9 +314,9 @@ class ItemResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Message could not be retrieved.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Prepare response @@ -357,9 +357,9 @@ class ItemResource(object): u'deleted without a valid claim ID.') raise falcon.HTTPForbidden(error_title, description) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Message could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Alles guete diff --git a/zaqar/transport/wsgi/v1_1/pools.py b/zaqar/transport/wsgi/v1_1/pools.py index 728bc3765..2d65a955d 100644 --- a/zaqar/transport/wsgi/v1_1/pools.py +++ b/zaqar/transport/wsgi/v1_1/pools.py @@ -182,11 +182,11 @@ class Resource(object): response.status = falcon.HTTP_201 response.location = request.path except errors.PoolCapabilitiesMismatch as e: - LOG.exception(e) title = _(u'Unable to create pool') + LOG.exception(title) raise falcon.HTTPBadRequest(title, six.text_type(e)) except errors.PoolAlreadyExists as e: - LOG.exception(e) + LOG.exception('Pool "%s" already exists', pool) raise wsgi_errors.HTTPConflict(six.text_type(e)) def on_delete(self, request, response, project_id, pool): @@ -200,11 +200,11 @@ class Resource(object): try: self._ctrl.delete(pool) except errors.PoolInUseByFlavor as ex: - LOG.exception(ex) title = _(u'Unable to delete') description = _(u'This pool is used by flavors {flavor}; ' u'It cannot be deleted.') description = description.format(flavor=ex.flavor) + LOG.exception(description) raise falcon.HTTPForbidden(title, description) response.status = falcon.HTTP_204 @@ -248,5 +248,5 @@ class Resource(object): try: self._ctrl.update(pool, **fields) except errors.PoolDoesNotExist as ex: - LOG.exception(ex) + LOG.exception('Pool "%s" does not exist', pool) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) diff --git a/zaqar/transport/wsgi/v1_1/queues.py b/zaqar/transport/wsgi/v1_1/queues.py index e61c48085..d0788edf5 100644 --- a/zaqar/transport/wsgi/v1_1/queues.py +++ b/zaqar/transport/wsgi/v1_1/queues.py @@ -48,9 +48,9 @@ class ItemResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue metadata could not be retrieved.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.body = utils.to_json(resp_dict) @@ -81,12 +81,12 @@ class ItemResource(object): project=project_id) except storage_errors.FlavorDoesNotExist as ex: - LOG.exception(ex) + LOG.exception('"%s" does not exist', queue_name) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue could not be created.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_201 if created else falcon.HTTP_204 @@ -97,9 +97,9 @@ class ItemResource(object): try: self._queue_controller.delete(queue_name, project=project_id) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_204 @@ -134,9 +134,9 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queues could not be listed.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Got some. Prepare the response. diff --git a/zaqar/transport/wsgi/v1_1/stats.py b/zaqar/transport/wsgi/v1_1/stats.py index f816072e5..646312eb8 100644 --- a/zaqar/transport/wsgi/v1_1/stats.py +++ b/zaqar/transport/wsgi/v1_1/stats.py @@ -68,7 +68,7 @@ class Resource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue stats could not be read.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) diff --git a/zaqar/transport/wsgi/v2_0/claims.py b/zaqar/transport/wsgi/v2_0/claims.py index c6df69a00..548f1d324 100644 --- a/zaqar/transport/wsgi/v2_0/claims.py +++ b/zaqar/transport/wsgi/v2_0/claims.py @@ -92,9 +92,9 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Claim could not be created.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Serialize claimed messages, if any. This logic assumes @@ -141,9 +141,9 @@ class ItemResource(object): except storage_errors.DoesNotExist as ex: LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Claim could not be queried.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Serialize claimed messages @@ -184,9 +184,9 @@ class ItemResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Claim could not be updated.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) @decorators.TransportLog("Claims item") @@ -199,7 +199,7 @@ class ItemResource(object): resp.status = falcon.HTTP_204 - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Claim could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) diff --git a/zaqar/transport/wsgi/v2_0/flavors.py b/zaqar/transport/wsgi/v2_0/flavors.py index da02e4120..dcca48ea4 100644 --- a/zaqar/transport/wsgi/v2_0/flavors.py +++ b/zaqar/transport/wsgi/v2_0/flavors.py @@ -202,10 +202,10 @@ class Resource(object): try: self._check_pools_exists(pool_list) except errors.PoolDoesNotExist as ex: - LOG.exception(ex) description = (_(u'Flavor %(flavor)s could not be created, ' 'error:%(msg)s') % dict(flavor=flavor, msg=str(ex))) + LOG.exception(description) raise falcon.HTTPBadRequest(_('Unable to create'), description) capabilities = self._pools_ctrl.capabilities(name=pool_list[0]) try: @@ -215,19 +215,19 @@ class Resource(object): response.status = falcon.HTTP_201 response.location = request.path except errors.ConnectionError as ex: - LOG.exception(ex) description = (_(u'Flavor %(flavor)s could not be created, ' 'error:%(msg)s') % dict(flavor=flavor, msg=str(ex))) + LOG.exception(description) raise falcon.HTTPBadRequest(_('Unable to create'), description) # NOTE(gengchc2): Update the 'flavor' field in pools tables. try: self._update_pools_by_flavor(flavor, pool_list) except errors.ConnectionError as ex: - LOG.exception(ex) description = (_(u'Flavor %(flavor)s could not be created, ' 'error:%(msg)s') % dict(flavor=flavor, msg=str(ex))) + LOG.exception(description) raise falcon.HTTPBadRequest(_('Unable to create'), description) @decorators.TransportLog("Flavors item") @@ -267,10 +267,10 @@ class Resource(object): # need to be cleaned. try: self._clean_pools_by_flavor(flavor) - except errors.ConnectionError as ex: - LOG.exception(ex) + except errors.ConnectionError: description = (_(u'Flavor %(flavor)s could not be deleted.') % dict(flavor=flavor)) + LOG.exception(description) raise falcon.HTTPBadRequest(_('Unable to create'), description) self._ctrl.delete(flavor, project=project_id) response.status = falcon.HTTP_204 @@ -298,10 +298,10 @@ class Resource(object): try: self._check_pools_exists(pool_list) except errors.PoolDoesNotExist as ex: - LOG.exception(ex) description = (_(u'Flavor %(flavor)s cant be updated, ' 'error:%(msg)s') % dict(flavor=flavor, msg=str(ex))) + LOG.exception(description) raise falcon.HTTPBadRequest(_('updatefail'), description) capabilities = self._pools_ctrl.capabilities(name=pool_list[0]) try: @@ -311,17 +311,17 @@ class Resource(object): resp_data['capabilities'] = [str(cap).split('.')[-1] for cap in capabilities] except errors.FlavorDoesNotExist as ex: - LOG.exception(ex) + LOG.exception('Flavor "%s" does not exist', flavor) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) # (gengchc) Update flavor field in new pool list. try: self._update_pools_by_flavor(flavor, pool_list) except errors.ConnectionError as ex: - LOG.exception(ex) description = (_(u'Flavor %(flavor)s could not be updated, ' 'error:%(msg)s') % dict(flavor=flavor, msg=str(ex))) + LOG.exception(description) raise falcon.HTTPBadRequest(_('Unable to create'), description) # (gengchc) Remove flavor from old pool list. try: @@ -331,10 +331,10 @@ class Resource(object): pool_list_removed.append(pool_old['name']) self._clean_pools_by_flavor(flavor, pool_list_removed) except errors.ConnectionError as ex: - LOG.exception(ex) description = (_(u'Flavor %(flavor)s could not be updated, ' 'error:%(msg)s') % dict(flavor=flavor, msg=str(ex))) + LOG.exception(description) raise falcon.HTTPBadRequest(_('Unable to create'), description) resp_data['pool_list'] = pool_list resp_data['href'] = request.path diff --git a/zaqar/transport/wsgi/v2_0/health.py b/zaqar/transport/wsgi/v2_0/health.py index 26790600f..c50cf8f23 100644 --- a/zaqar/transport/wsgi/v2_0/health.py +++ b/zaqar/transport/wsgi/v2_0/health.py @@ -37,7 +37,7 @@ class Resource(object): try: resp_dict = self._driver.health() resp.body = utils.to_json(resp_dict) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Health status could not be read.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) diff --git a/zaqar/transport/wsgi/v2_0/messages.py b/zaqar/transport/wsgi/v2_0/messages.py index ff5c3f297..e61b136c9 100644 --- a/zaqar/transport/wsgi/v2_0/messages.py +++ b/zaqar/transport/wsgi/v2_0/messages.py @@ -67,9 +67,9 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Message could not be retrieved.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Prepare response @@ -103,8 +103,8 @@ class CollectionResource(object): # So maybe a refactor is needed in the future. queue_meta = self._queue_controller.get_metadata(queue_name, project_id) - except storage_errors.DoesNotExist as ex: - LOG.exception(ex) + except storage_errors.DoesNotExist: + LOG.exception('Queue name "%s" does not exist', queue_name) queue_delay = queue_meta.get('_default_message_delay') if not queue_delay: # NOTE(cdyangzhenyu): If the queue without the metadata @@ -131,9 +131,9 @@ class CollectionResource(object): LOG.debug(ex) messages = None - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Messages could not be listed.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) if not messages: @@ -231,14 +231,14 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except storage_errors.MessageConflict as ex: - LOG.exception(ex) + except storage_errors.MessageConflict: description = _(u'No messages could be enqueued.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Messages could not be enqueued.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Prepare the response @@ -309,9 +309,9 @@ class CollectionResource(object): project=project_id, claim_ids=claim_ids) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Messages could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) return falcon.HTTP_204 @@ -327,9 +327,9 @@ class CollectionResource(object): project=project_id, limit=pop_limit) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Messages could not be popped.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Prepare response @@ -361,9 +361,9 @@ class ItemResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Message could not be retrieved.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Prepare response @@ -405,9 +405,9 @@ class ItemResource(object): u'deleted without a valid claim ID.') raise falcon.HTTPForbidden(error_title, description) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Message could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Alles guete diff --git a/zaqar/transport/wsgi/v2_0/pools.py b/zaqar/transport/wsgi/v2_0/pools.py index 88ff1bf3e..2c5c2e669 100644 --- a/zaqar/transport/wsgi/v2_0/pools.py +++ b/zaqar/transport/wsgi/v2_0/pools.py @@ -199,11 +199,11 @@ class Resource(object): response.status = falcon.HTTP_201 response.location = request.path except errors.PoolCapabilitiesMismatch as e: - LOG.exception(e) title = _(u'Unable to create pool') + LOG.exception(title) raise falcon.HTTPBadRequest(title, six.text_type(e)) except errors.PoolAlreadyExists as e: - LOG.exception(e) + LOG.exception('Pool "%s" already exists', pool) raise wsgi_errors.HTTPConflict(six.text_type(e)) @decorators.TransportLog("Pools item") @@ -219,11 +219,11 @@ class Resource(object): try: self._ctrl.delete(pool) except errors.PoolInUseByFlavor as ex: - LOG.exception(ex) title = _(u'Unable to delete') description = _(u'This pool is used by flavors {flavor}; ' u'It cannot be deleted.') description = description.format(flavor=ex.flavor) + LOG.exception(description) raise falcon.HTTPForbidden(title, description) response.status = falcon.HTTP_204 @@ -271,7 +271,7 @@ class Resource(object): self._ctrl.update(pool, **fields) resp_data = self._ctrl.get(pool, False) except errors.PoolDoesNotExist as ex: - LOG.exception(ex) + LOG.exception('Pool "%s" does not exist', pool) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) resp_data['href'] = request.path diff --git a/zaqar/transport/wsgi/v2_0/purge.py b/zaqar/transport/wsgi/v2_0/purge.py index 76283bfd9..e89f34348 100644 --- a/zaqar/transport/wsgi/v2_0/purge.py +++ b/zaqar/transport/wsgi/v2_0/purge.py @@ -75,9 +75,9 @@ class Resource(object): project=project_id) except ValueError as err: raise wsgi_errors.HTTPBadRequestAPI(str(err)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue could not be purged.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_204 diff --git a/zaqar/transport/wsgi/v2_0/queues.py b/zaqar/transport/wsgi/v2_0/queues.py index 59f322cdb..766bb0829 100644 --- a/zaqar/transport/wsgi/v2_0/queues.py +++ b/zaqar/transport/wsgi/v2_0/queues.py @@ -68,9 +68,9 @@ class ItemResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue metadata could not be retrieved.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.body = utils.to_json(resp_dict) @@ -99,11 +99,11 @@ class ItemResource(object): project=project_id) except storage_errors.FlavorDoesNotExist as ex: - LOG.exception(ex) + LOG.exception('Flavor "%s" does not exist', queue_name) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue could not be created.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_201 if created else falcon.HTTP_204 @@ -118,9 +118,9 @@ class ItemResource(object): try: self._queue_controller.delete(queue_name, project=project_id) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_204 @@ -173,10 +173,10 @@ class ItemResource(object): description = _(u'JSON contains integer that is too large.') raise wsgi_errors.HTTPBadRequestBody(description) - except Exception as ex: + except Exception: # Error while reading from the network/server - LOG.exception(ex) description = _(u'Request body could not be read.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) else: msg = _("PATCH body could not be empty for update.") @@ -209,10 +209,10 @@ class ItemResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestBody(six.text_type(ex)) except wsgi_errors.HTTPConflict as ex: - raise ex - except Exception as ex: - LOG.exception(ex) + raise + except Exception: description = _(u'Queue could not be updated.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) for meta, value in _get_reserved_metadata(self._validate).items(): if not metadata.get(meta): @@ -266,9 +266,9 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queues could not be listed.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Got some. Prepare the response. diff --git a/zaqar/transport/wsgi/v2_0/stats.py b/zaqar/transport/wsgi/v2_0/stats.py index 2258ee8cc..d8dbfce86 100644 --- a/zaqar/transport/wsgi/v2_0/stats.py +++ b/zaqar/transport/wsgi/v2_0/stats.py @@ -72,7 +72,7 @@ class Resource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Queue stats could not be read.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) diff --git a/zaqar/transport/wsgi/v2_0/subscriptions.py b/zaqar/transport/wsgi/v2_0/subscriptions.py index a0a7f1463..2001bcf17 100644 --- a/zaqar/transport/wsgi/v2_0/subscriptions.py +++ b/zaqar/transport/wsgi/v2_0/subscriptions.py @@ -55,9 +55,9 @@ class ItemResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Subscription could not be retrieved.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.body = utils.to_json(resp_dict) @@ -71,9 +71,9 @@ class ItemResource(object): subscription_id, project=project_id) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Subscription could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_204 @@ -102,11 +102,11 @@ class ItemResource(object): except validation.ValidationFailed as ex: LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = (_(u'Subscription %(subscription_id)s could not be' ' updated.') % dict(subscription_id=subscription_id)) + LOG.exception(description) raise falcon.HTTPBadRequest(_('Unable to update subscription'), description) @@ -147,9 +147,9 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Subscriptions could not be listed.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Got some. Prepare the response. @@ -201,9 +201,9 @@ class CollectionResource(object): except validation.ValidationFailed as ex: LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Subscription could not be created.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) now = timeutils.utcnow_ts() @@ -295,10 +295,10 @@ class ConfirmResource(object): except validation.ValidationFailed as ex: LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = (_(u'Subscription %(subscription_id)s could not be' ' confirmed.') % dict(subscription_id=subscription_id)) + LOG.exception(description) raise falcon.HTTPBadRequest(_('Unable to confirm subscription'), description) diff --git a/zaqar/transport/wsgi/v2_0/topic.py b/zaqar/transport/wsgi/v2_0/topic.py index c8171aad4..6fb7aad2c 100644 --- a/zaqar/transport/wsgi/v2_0/topic.py +++ b/zaqar/transport/wsgi/v2_0/topic.py @@ -65,9 +65,9 @@ class ItemResource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Topic metadata could not be retrieved.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.body = utils.to_json(resp_dict) @@ -96,11 +96,11 @@ class ItemResource(object): project=project_id) except storage_errors.FlavorDoesNotExist as ex: - LOG.exception(ex) + LOG.exception('Flavor "%s" does not exist', topic_name) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Topic could not be created.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_201 if created else falcon.HTTP_204 @@ -115,9 +115,9 @@ class ItemResource(object): try: self._topic_controller.delete(topic_name, project=project_id) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Topic could not be deleted.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_204 @@ -170,10 +170,10 @@ class ItemResource(object): description = _(u'JSON contains integer that is too large.') raise wsgi_errors.HTTPBadRequestBody(description) - except Exception as ex: + except Exception: # Error while reading from the network/server - LOG.exception(ex) description = _(u'Request body could not be read.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) else: msg = _("PATCH body could not be empty for update.") @@ -206,10 +206,10 @@ class ItemResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestBody(six.text_type(ex)) except wsgi_errors.HTTPConflict as ex: - raise ex - except Exception as ex: - LOG.exception(ex) + raise + except Exception: description = _(u'Topic could not be updated.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) for meta, value in _get_reserved_metadata(self._validate).items(): if not metadata.get(meta): @@ -263,9 +263,9 @@ class CollectionResource(object): LOG.debug(ex) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Topics could not be listed.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) # Got some. Prepare the response. diff --git a/zaqar/transport/wsgi/v2_0/topic_purge.py b/zaqar/transport/wsgi/v2_0/topic_purge.py index 3869616bb..e982256dd 100644 --- a/zaqar/transport/wsgi/v2_0/topic_purge.py +++ b/zaqar/transport/wsgi/v2_0/topic_purge.py @@ -74,9 +74,9 @@ class Resource(object): project=project_id) except ValueError as err: raise wsgi_errors.HTTPBadRequestAPI(str(err)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Topic could not be purged.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_204 diff --git a/zaqar/transport/wsgi/v2_0/topic_stats.py b/zaqar/transport/wsgi/v2_0/topic_stats.py index 89c6c4f5c..0c42fb61e 100644 --- a/zaqar/transport/wsgi/v2_0/topic_stats.py +++ b/zaqar/transport/wsgi/v2_0/topic_stats.py @@ -72,7 +72,7 @@ class Resource(object): LOG.debug(ex) raise wsgi_errors.HTTPNotFound(six.text_type(ex)) - except Exception as ex: - LOG.exception(ex) + except Exception: description = _(u'Topic stats could not be read.') + LOG.exception(description) raise wsgi_errors.HTTPServiceUnavailable(description)