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:
parent
07514e4294
commit
347de15c96
@ -49,14 +49,10 @@ class FaultWrapper(wsgi.Middleware):
|
|||||||
'ActionInProgress': webob.exc.HTTPConflict,
|
'ActionInProgress': webob.exc.HTTPConflict,
|
||||||
'ActionNotFound': webob.exc.HTTPNotFound,
|
'ActionNotFound': webob.exc.HTTPNotFound,
|
||||||
'AttributeError': webob.exc.HTTPBadRequest,
|
'AttributeError': webob.exc.HTTPBadRequest,
|
||||||
'ClusterActionNotSupported': webob.exc.HTTPBadRequest,
|
|
||||||
'ClusterExists': webob.exc.HTTPConflict,
|
|
||||||
'ClusterNotFound': webob.exc.HTTPNotFound,
|
'ClusterNotFound': webob.exc.HTTPNotFound,
|
||||||
'EventNotFound': webob.exc.HTTPNotFound,
|
'EventNotFound': webob.exc.HTTPNotFound,
|
||||||
'Forbidden': webob.exc.HTTPForbidden,
|
'Forbidden': webob.exc.HTTPForbidden,
|
||||||
'Invalid': webob.exc.HTTPBadRequest,
|
|
||||||
'InvalidParameter': webob.exc.HTTPBadRequest,
|
'InvalidParameter': webob.exc.HTTPBadRequest,
|
||||||
'InvalidTenant': webob.exc.HTTPForbidden,
|
|
||||||
'InvalidSchemaError': webob.exc.HTTPBadRequest,
|
'InvalidSchemaError': webob.exc.HTTPBadRequest,
|
||||||
'NodeNotFound': webob.exc.HTTPNotFound,
|
'NodeNotFound': webob.exc.HTTPNotFound,
|
||||||
'NotFound': webob.exc.HTTPNotFound,
|
'NotFound': webob.exc.HTTPNotFound,
|
||||||
@ -69,11 +65,8 @@ class FaultWrapper(wsgi.Middleware):
|
|||||||
'ProjectNotMatch': webob.exc.HTTPBadRequest,
|
'ProjectNotMatch': webob.exc.HTTPBadRequest,
|
||||||
'ProfileTypeNotMatch': webob.exc.HTTPBadRequest,
|
'ProfileTypeNotMatch': webob.exc.HTTPBadRequest,
|
||||||
'RequestLimitExceeded': webob.exc.HTTPBadRequest,
|
'RequestLimitExceeded': webob.exc.HTTPBadRequest,
|
||||||
'RevertFailed': webob.exc.HTTPInternalServerError,
|
|
||||||
'SenlinBadRequest': webob.exc.HTTPBadRequest,
|
'SenlinBadRequest': webob.exc.HTTPBadRequest,
|
||||||
'ServerBuildFailed': webob.exc.HTTPInternalServerError,
|
|
||||||
'SpecValidationFailed': webob.exc.HTTPBadRequest,
|
'SpecValidationFailed': webob.exc.HTTPBadRequest,
|
||||||
'StopActionFailed': webob.exc.HTTPInternalServerError,
|
|
||||||
'ValueError': webob.exc.HTTPBadRequest,
|
'ValueError': webob.exc.HTTPBadRequest,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,20 +32,6 @@ _FATAL_EXCEPTION_FORMAT_ERRORS = False
|
|||||||
LOG = logging.getLogger(__name__)
|
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,
|
def wrap_exception(notifier=None, publisher_id=None, event_type=None,
|
||||||
level=None):
|
level=None):
|
||||||
'''Decorator that wraps a method to catch any exceptions.
|
'''Decorator that wraps a method to catch any exceptions.
|
||||||
@ -127,27 +113,6 @@ class SenlinException(Exception):
|
|||||||
return self.__class__(**self.kwargs)
|
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):
|
class NotAuthenticated(SenlinException):
|
||||||
msg_fmt = _("You are not authenticated.")
|
msg_fmt = _("You are not authenticated.")
|
||||||
|
|
||||||
@ -156,40 +121,10 @@ class Forbidden(SenlinException):
|
|||||||
msg_fmt = _("You are not authorized to complete this action.")
|
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):
|
class SenlinBadRequest(SenlinException):
|
||||||
msg_fmt = _("The request is malformed: %(msg)s")
|
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):
|
class ProjectNotMatch(SenlinException):
|
||||||
msg_fmt = _("%(message)s")
|
msg_fmt = _("%(message)s")
|
||||||
|
|
||||||
@ -199,31 +134,14 @@ class MultipleChoices(SenlinException):
|
|||||||
"Please be more specific.")
|
"Please be more specific.")
|
||||||
|
|
||||||
|
|
||||||
class UserParameterMissing(SenlinException):
|
|
||||||
msg_fmt = _("The Parameter (%(key)s) was not provided.")
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidParameter(SenlinException):
|
class InvalidParameter(SenlinException):
|
||||||
msg_fmt = _("Invalid value '%(value)s' specified for '%(name)s'")
|
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):
|
class ClusterNotFound(SenlinException):
|
||||||
msg_fmt = _("The cluster (%(cluster)s) could not be found.")
|
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):
|
class NodeNotFound(SenlinException):
|
||||||
msg_fmt = _("The node (%(node)s) could not be found.")
|
msg_fmt = _("The node (%(node)s) could not be found.")
|
||||||
|
|
||||||
@ -284,10 +202,6 @@ class NotSupported(SenlinException):
|
|||||||
msg_fmt = _("%(feature)s is not supported.")
|
msg_fmt = _("%(feature)s is not supported.")
|
||||||
|
|
||||||
|
|
||||||
class ClusterActionNotSupported(SenlinException):
|
|
||||||
msg_fmt = _("%(action)s is not supported for Cluster.")
|
|
||||||
|
|
||||||
|
|
||||||
class Error(SenlinException):
|
class Error(SenlinException):
|
||||||
msg_fmt = "%(message)s"
|
msg_fmt = "%(message)s"
|
||||||
|
|
||||||
@ -342,24 +256,10 @@ class ActionBeingWorked(SenlinException):
|
|||||||
msg_fmt = _("Worker %(owner)s is working on this action.")
|
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):
|
class EventNotFound(SenlinException):
|
||||||
msg_fmt = _("The event (%(event)s) could not be found.")
|
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):
|
class HTTPExceptionDisguise(Exception):
|
||||||
"""Disguises HTTP exceptions.
|
"""Disguises HTTP exceptions.
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ def _paginate_query(context, query, model, limit=None, marker=None,
|
|||||||
model_marker, sort_dir)
|
model_marker, sort_dir)
|
||||||
except utils.InvalidSortKey as ex:
|
except utils.InvalidSortKey as ex:
|
||||||
# TODO(Qiming): Catch this exception and return to user
|
# 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
|
return query
|
||||||
|
|
||||||
|
|
||||||
|
@ -205,8 +205,8 @@ class ResourceTest(base.SenlinTestCase):
|
|||||||
class ResourceExceptionHandlingTest(base.SenlinTestCase):
|
class ResourceExceptionHandlingTest(base.SenlinTestCase):
|
||||||
scenarios = [
|
scenarios = [
|
||||||
('client_exceptions', dict(
|
('client_exceptions', dict(
|
||||||
exception=exception.ClusterNotSpecified,
|
exception=exception.NotAuthenticated,
|
||||||
exception_catch=exception.ClusterNotSpecified)),
|
exception_catch=exception.NotAuthenticated)),
|
||||||
('webob_bad_request', dict(
|
('webob_bad_request', dict(
|
||||||
exception=webob.exc.HTTPBadRequest,
|
exception=webob.exc.HTTPBadRequest,
|
||||||
exception_catch=exception.HTTPExceptionDisguise)),
|
exception_catch=exception.HTTPExceptionDisguise)),
|
||||||
|
Loading…
Reference in New Issue
Block a user