Better error handling in server.start()
Transport drivers can raise transport driver specific exceptions in listen(). Catch such exceptions and wrap them in a ServerListenError which callers to start() can explicitly handle.
This commit is contained in:
parent
f0f3d4b5f2
commit
badb0fa4e6
@ -47,6 +47,7 @@ RPCVersionCapError = client.RPCVersionCapError
|
||||
|
||||
MessagingServerError = server.MessagingServerError
|
||||
ExecutorLoadFailure = server.ExecutorLoadFailure
|
||||
ServerListenError = server.ServerListenError
|
||||
|
||||
RPCDispatcherError = rpc_dispatcher.RPCDispatcherError
|
||||
NoSuchMethod = rpc_dispatcher.NoSuchMethod
|
||||
|
@ -15,6 +15,12 @@
|
||||
|
||||
import abc
|
||||
|
||||
from openstack.common.messaging import exceptions
|
||||
|
||||
|
||||
class TransportDriverError(exceptions.MessagingException):
|
||||
"""Base class for transport driver specific exceptions."""
|
||||
|
||||
|
||||
class IncomingMessage(object):
|
||||
|
||||
|
@ -24,15 +24,13 @@ from openstack.common.messaging._drivers import base
|
||||
from openstack.common.messaging import _utils as utils
|
||||
|
||||
|
||||
class InvalidTarget(ValueError):
|
||||
class InvalidTarget(base.TransportDriverError, ValueError):
|
||||
|
||||
def __init__(self, msg, target):
|
||||
self.msg = msg
|
||||
msg = msg + ":" + str(target)
|
||||
super(InvalidTarget, self).__init__(msg)
|
||||
self.target = target
|
||||
|
||||
def __str__(self):
|
||||
return self.msg + ":" + str(self.target)
|
||||
|
||||
|
||||
class FakeIncomingMessage(base.IncomingMessage):
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
from stevedore import driver
|
||||
|
||||
from openstack.common import log as logging
|
||||
from openstack.common.messaging._drivers import base as driver_base
|
||||
from openstack.common.messaging import exceptions
|
||||
|
||||
_LOG = logging.getLogger(__name__)
|
||||
@ -38,6 +39,16 @@ class ExecutorLoadFailure(MessagingServerError):
|
||||
self.ex = ex
|
||||
|
||||
|
||||
class ServerListenError(MessagingServerError):
|
||||
"""Raised if we failed to listen on a target."""
|
||||
|
||||
def __init__(self, target, ex):
|
||||
msg = 'Failed to listen on target "%s": %s' % (target, ex)
|
||||
super(ServerListenError, self).__init__(msg)
|
||||
self.target = target
|
||||
self.ex = ex
|
||||
|
||||
|
||||
class MessageHandlingServer(object):
|
||||
"""Server for handling messages.
|
||||
|
||||
@ -101,7 +112,12 @@ class MessageHandlingServer(object):
|
||||
"""
|
||||
if self._executor is not None:
|
||||
return
|
||||
listener = self.transport._listen(self.target)
|
||||
|
||||
try:
|
||||
listener = self.transport._listen(self.target)
|
||||
except driver_base.TransportDriverError as ex:
|
||||
raise ServerListenError(self.target, ex)
|
||||
|
||||
self._executor = self._executor_cls(self.conf, listener,
|
||||
self.dispatcher)
|
||||
self._executor.start()
|
||||
|
Loading…
x
Reference in New Issue
Block a user