First round cleansing of exceptions

There are too many exception types defined. This patch cleanse some of
them. Following patches upcoming will try combine some exceptions.

Change-Id: I17608a9c01677ec25a7905242944cf14ad1d0dda
This commit is contained in:
tengqm 2015-03-20 12:30:10 +08:00
parent 07514e4294
commit 347de15c96
4 changed files with 3 additions and 110 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

@ -32,20 +32,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 +113,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 +121,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 +134,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.")
@ -284,10 +202,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"
@ -342,24 +256,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

@ -112,7 +112,7 @@ def _paginate_query(context, query, model, limit=None, marker=None,
model_marker, sort_dir)
except utils.InvalidSortKey as ex:
# TODO(Qiming): Catch this exception and return to user
raise exception.Invalid(reason=ex.message)
raise exception.InvalidParameter(name='sort_keys', value=sort_keys)
return 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)),