diff --git a/keystoneclient/exceptions.py b/keystoneclient/exceptions.py index 0150bf528..81f948d4c 100644 --- a/keystoneclient/exceptions.py +++ b/keystoneclient/exceptions.py @@ -27,18 +27,114 @@ Exception definitions. """ +from keystoneauth import exceptions as new_exceptions + from keystoneclient.i18n import _ -from keystoneclient.openstack.common.apiclient.exceptions import * # noqa + + +# NOTE(jamielennox): Import only the exceptions we need from keystoneauth. Lots +# of other places read exceptions from keystoneclient and so we need to +# maintain these for backwards compatibility. I'm naming them individually so +# that we don't import a lot of new exceptions and make more compatibility +# issues for ourselves in the future. + +ClientException = new_exceptions.ClientException +HttpError = new_exceptions.HttpError +HTTPClientError = new_exceptions.HTTPClientError +BadRequest = new_exceptions.BadRequest +Unauthorized = new_exceptions.Unauthorized +PaymentRequired = new_exceptions.PaymentRequired +Forbidden = new_exceptions.Forbidden +NotFound = new_exceptions.NotFound +MethodNotAllowed = new_exceptions.MethodNotAllowed +NotAcceptable = new_exceptions.NotAcceptable +ProxyAuthenticationRequired = new_exceptions.ProxyAuthenticationRequired +Conflict = new_exceptions.Conflict +Gone = new_exceptions.Gone +LengthRequired = new_exceptions.LengthRequired +PreconditionFailed = new_exceptions.PreconditionFailed +RequestEntityTooLarge = new_exceptions.RequestEntityTooLarge +RequestUriTooLong = new_exceptions.RequestUriTooLong +UnsupportedMediaType = new_exceptions.UnsupportedMediaType +RequestedRangeNotSatisfiable = new_exceptions.RequestedRangeNotSatisfiable +ExpectationFailed = new_exceptions.ExpectationFailed +UnprocessableEntity = new_exceptions.UnprocessableEntity +HttpServerError = new_exceptions.HttpServerError +InternalServerError = new_exceptions.InternalServerError +HttpNotImplemented = new_exceptions.HttpNotImplemented +BadGateway = new_exceptions.BadGateway +ServiceUnavailable = new_exceptions.ServiceUnavailable +GatewayTimeout = new_exceptions.GatewayTimeout +HttpVersionNotSupported = new_exceptions.HttpVersionNotSupported +from_response = new_exceptions.from_response + + +# NOTE(jamielennox): Rahh! this is just wrong. In the apiclient conversion +# someone mapped the connection timeout onto the HTTP timeout exception. Assume +# people want the connection timeout as this is much more common. +RequestTimeout = new_exceptions.ConnectTimeout + +ConnectionError = new_exceptions.ConnectionError +SSLError = new_exceptions.SSLError +Timeout = new_exceptions.ConnectTimeout + # NOTE(akurilin): This alias should be left here to support backwards # compatibility until we are sure that usage of these exceptions in # projects is correct. -ConnectionError = ConnectionRefused +ConnectionRefused = ConnectionError HTTPNotImplemented = HttpNotImplemented Timeout = RequestTimeout HTTPError = HttpError +class HTTPRedirection(HttpError): + """HTTP Redirection.""" + message = _("HTTP Redirection") + + +class MultipleChoices(HTTPRedirection): + """HTTP 300 - Multiple Choices. + + Indicates multiple options for the resource that the client may follow. + """ + + http_status = 300 + message = _("Multiple Choices") + + +class ValidationError(ClientException): + """Error in validation on API client side.""" + + +class UnsupportedVersion(ClientException): + """User is trying to use an unsupported version of the API.""" + + +class CommandError(ClientException): + """Error in CLI tool.""" + + +AuthorizationFailure = new_exceptions.AuthorizationFailure + + +class AuthPluginOptionsMissing(AuthorizationFailure): + """Auth plugin misses some options.""" + def __init__(self, opt_names): + super(AuthPluginOptionsMissing, self).__init__( + _("Authentication failed. Missing options: %s") % + ", ".join(opt_names)) + self.opt_names = opt_names + + +class AuthSystemNotFound(AuthorizationFailure): + """User has specified an AuthSystem that is not installed.""" + def __init__(self, auth_system): + super(AuthSystemNotFound, self).__init__( + _("AuthSystemNotFound: %s") % repr(auth_system)) + self.auth_system = auth_system + + class CertificateConfigError(Exception): """Error reading the certificate.""" def __init__(self, output): @@ -55,51 +151,32 @@ class CMSError(Exception): super(CMSError, self).__init__(msg) -class EmptyCatalog(EndpointNotFound): - """The service catalog is empty.""" +EndpointException = new_exceptions.CatalogException +EmptyCatalog = new_exceptions.EmptyCatalog +EndpointNotFound = new_exceptions.EndpointNotFound + + +class NoUniqueMatch(EndpointException): + """Multiple entities found instead of one.""" pass -class SSLError(ConnectionRefused): - """An SSL error occurred.""" +class AmbiguousEndpoints(EndpointException): + """Found more than one matching endpoint in Service Catalog.""" + def __init__(self, endpoints=None): + super(AmbiguousEndpoints, self).__init__( + _("AmbiguousEndpoints: %s") % repr(endpoints)) + self.endpoints = endpoints -class DiscoveryFailure(ClientException): - """Discovery of client versions failed.""" - - -class VersionNotAvailable(DiscoveryFailure): - """Discovery failed as the version you requested is not available.""" +DiscoveryFailure = new_exceptions.DiscoveryFailure +VersionNotAvailable = new_exceptions.VersionNotAvailable class MethodNotImplemented(ClientException): """Method not implemented by the keystoneclient API.""" -class MissingAuthPlugin(ClientException): - """An authenticated request is required but no plugin available.""" - - -class NoMatchingPlugin(ClientException): - """There were no auth plugins that could be created from the parameters - provided. - - :param str name: The name of the plugin that was attempted to load. - - .. py:attribute:: name - - The name of the plugin that was attempted to load. - """ - - def __init__(self, name): - self.name = name - msg = _('The plugin %s could not be found') % name - super(NoMatchingPlugin, self).__init__(msg) - - -class InvalidResponse(ClientException): - """The response from the server is not valid for this request.""" - - def __init__(self, response): - super(InvalidResponse, self).__init__() - self.response = response +MissingAuthPlugin = new_exceptions.MissingAuthPlugin +NoMatchingPlugin = new_exceptions.NoMatchingPlugin +InvalidResponse = new_exceptions.InvalidResponse