Merge "First round cleansing of exceptions"

This commit is contained in:
Jenkins 2015-03-23 05:43:14 +00:00 committed by Gerrit Code Review
commit a7d1768f31
5 changed files with 5 additions and 114 deletions

View File

@ -49,14 +49,10 @@ class FaultWrapper(wsgi.Middleware):
'ActionInProgress': webob.exc.HTTPConflict,
'ActionNotFound': webob.exc.HTTPNotFound,
'AttributeError': webob.exc.HTTPBadRequest,
'ClusterActionNotSupported': webob.exc.HTTPBadRequest,
'ClusterExists': webob.exc.HTTPConflict,
'ClusterNotFound': webob.exc.HTTPNotFound,
'EventNotFound': webob.exc.HTTPNotFound,
'Forbidden': webob.exc.HTTPForbidden,
'Invalid': webob.exc.HTTPBadRequest,
'InvalidParameter': webob.exc.HTTPBadRequest,
'InvalidTenant': webob.exc.HTTPForbidden,
'InvalidSchemaError': webob.exc.HTTPBadRequest,
'NodeNotFound': webob.exc.HTTPNotFound,
'NotFound': webob.exc.HTTPNotFound,
@ -69,11 +65,8 @@ class FaultWrapper(wsgi.Middleware):
'ProjectNotMatch': webob.exc.HTTPBadRequest,
'ProfileTypeNotMatch': webob.exc.HTTPBadRequest,
'RequestLimitExceeded': webob.exc.HTTPBadRequest,
'RevertFailed': webob.exc.HTTPInternalServerError,
'SenlinBadRequest': webob.exc.HTTPBadRequest,
'ServerBuildFailed': webob.exc.HTTPInternalServerError,
'SpecValidationFailed': webob.exc.HTTPBadRequest,
'StopActionFailed': webob.exc.HTTPInternalServerError,
'ValueError': webob.exc.HTTPBadRequest,
}

View File

@ -23,7 +23,6 @@ import sys
from oslo_log import log as logging
import six
from six.moves.urllib import parse as urlparse
from senlin.common.i18n import _
from senlin.common.i18n import _LE
@ -32,20 +31,6 @@ _FATAL_EXCEPTION_FORMAT_ERRORS = False
LOG = logging.getLogger(__name__)
class RedirectException(Exception):
def __init__(self, url):
self.url = urlparse.urlparse(url)
class KeystoneError(Exception):
def __init__(self, code, message):
self.code = code
self.message = message
def __str__(self):
return "Code: %s, message: %s" % (self.code, self.message)
def wrap_exception(notifier=None, publisher_id=None, event_type=None,
level=None):
'''Decorator that wraps a method to catch any exceptions.
@ -127,27 +112,6 @@ class SenlinException(Exception):
return self.__class__(**self.kwargs)
class MissingCredentialError(SenlinException):
msg_fmt = _("Missing required credential: %(required)s")
class BadAuthStrategy(SenlinException):
msg_fmt = _("Incorrect auth strategy, expected \"%(expected)s\" but "
"received \"%(received)s\"")
class AuthBadRequest(SenlinException):
msg_fmt = _("Connect error/bad request to Auth service at URL %(url)s.")
class AuthUrlNotFound(SenlinException):
msg_fmt = _("Auth service at URL %(url)s not found.")
class AuthorizationFailure(SenlinException):
msg_fmt = _("Authorization failed.")
class NotAuthenticated(SenlinException):
msg_fmt = _("You are not authenticated.")
@ -156,40 +120,10 @@ class Forbidden(SenlinException):
msg_fmt = _("You are not authorized to complete this action.")
class NotAuthorized(Forbidden):
msg_fmt = _("You are not authorized to complete this action.")
class Invalid(SenlinException):
msg_fmt = _("Data supplied was not valid: %(reason)s")
class AuthorizationRedirect(SenlinException):
msg_fmt = _("Redirecting to %(uri)s for authorization.")
class RequestUriTooLong(SenlinException):
msg_fmt = _("The URI was too long.")
class SenlinBadRequest(SenlinException):
msg_fmt = _("The request is malformed: %(msg)s")
class MaxRedirectsExceeded(SenlinException):
msg_fmt = _("Maximum redirects (%(redirects)s) was exceeded.")
class InvalidRedirect(SenlinException):
msg_fmt = _("Received invalid HTTP redirect.")
class RegionAmbiguity(SenlinException):
msg_fmt = _("Multiple 'image' service matches for region %(region)s. This "
"generally means that a region is required and you have not "
"supplied one.")
class ProjectNotMatch(SenlinException):
msg_fmt = _("%(message)s")
@ -199,31 +133,14 @@ class MultipleChoices(SenlinException):
"Please be more specific.")
class UserParameterMissing(SenlinException):
msg_fmt = _("The Parameter (%(key)s) was not provided.")
class InvalidParameter(SenlinException):
msg_fmt = _("Invalid value '%(value)s' specified for '%(name)s'")
class InvalidTenant(SenlinException):
msg_fmt = _("Searching Tenant %(target)s "
"from Tenant %(actual)s forbidden.")
class ClusterNotFound(SenlinException):
msg_fmt = _("The cluster (%(cluster)s) could not be found.")
class ClusterExists(SenlinException):
msg_fmt = _("The cluster (%(cluster_name)s) already exists.")
class ClusterNotSpecified(SenlinException):
msg_fmt = _("The cluster was not specified.")
class NodeNotFound(SenlinException):
msg_fmt = _("The node (%(node)s) could not be found.")
@ -289,10 +206,6 @@ class NotSupported(SenlinException):
msg_fmt = _("%(feature)s is not supported.")
class ClusterActionNotSupported(SenlinException):
msg_fmt = _("%(action)s is not supported for Cluster.")
class Error(SenlinException):
msg_fmt = "%(message)s"
@ -347,24 +260,10 @@ class ActionBeingWorked(SenlinException):
msg_fmt = _("Worker %(owner)s is working on this action.")
class StopActionFailed(SenlinException):
msg_fmt = _("Failed to stop cluster (%(cluster_name)s) on other engine "
"(%(engine_id)s)")
class EventNotFound(SenlinException):
msg_fmt = _("The event (%(event)s) could not be found.")
class EventSendFailed(SenlinException):
msg_fmt = _("Failed to send message to cluster (%(cluster_name)s) "
"on other engine (%(engine_id)s)")
class DriverFailure(SenlinException):
msg_fmt = _("Driver '%(driver)s' failed creation: %(exc)s")
class HTTPExceptionDisguise(Exception):
"""Disguises HTTP exceptions.

View File

@ -110,9 +110,8 @@ def _paginate_query(context, query, model, limit=None, marker=None,
try:
query = utils.paginate_query(query, model, limit, sort_keys,
model_marker, sort_dir)
except utils.InvalidSortKey as ex:
# TODO(Qiming): Catch this exception and return to user
raise exception.Invalid(reason=ex.message)
except utils.InvalidSortKey:
raise exception.InvalidParameter(name='sort_keys', value=sort_keys)
return query

View File

@ -491,7 +491,7 @@ class DBAPIClusterTest(base.SenlinTestCase):
model = mock.Mock()
mock_paginate_query.side_effect = db_api.utils.InvalidSortKey()
self.assertRaises(exception.Invalid, db_api._paginate_query,
self.assertRaises(exception.InvalidParameter, db_api._paginate_query,
self.ctx, query, model, sort_keys=['foo'])
@mock.patch.object(db_api.utils, 'paginate_query')

View File

@ -205,8 +205,8 @@ class ResourceTest(base.SenlinTestCase):
class ResourceExceptionHandlingTest(base.SenlinTestCase):
scenarios = [
('client_exceptions', dict(
exception=exception.ClusterNotSpecified,
exception_catch=exception.ClusterNotSpecified)),
exception=exception.NotAuthenticated,
exception_catch=exception.NotAuthenticated)),
('webob_bad_request', dict(
exception=webob.exc.HTTPBadRequest,
exception_catch=exception.HTTPExceptionDisguise)),