Merge "Track the attempted method when raising UnsupportedVersion"

This commit is contained in:
Jenkins 2014-10-15 14:05:44 +00:00 committed by Gerrit Code Review
commit a1489a252d
2 changed files with 7 additions and 2 deletions
oslo/messaging/rpc
tests/rpc

@ -67,10 +67,13 @@ class NoSuchMethod(RPCDispatcherError, AttributeError):
class UnsupportedVersion(RPCDispatcherError): class UnsupportedVersion(RPCDispatcherError):
"Raised if there is no endpoint which supports the requested version." "Raised if there is no endpoint which supports the requested version."
def __init__(self, version): def __init__(self, version, method=None):
msg = "Endpoint does not support RPC version %s" % version msg = "Endpoint does not support RPC version %s" % version
if method:
msg = "%s. Attempted method: %s" % (msg, method)
super(UnsupportedVersion, self).__init__(msg) super(UnsupportedVersion, self).__init__(msg)
self.version = version self.version = version
self.method = method
class RPCDispatcher(object): class RPCDispatcher(object):
@ -183,4 +186,4 @@ class RPCDispatcher(object):
if found_compatible: if found_compatible:
raise NoSuchMethod(method) raise NoSuchMethod(method)
else: else:
raise UnsupportedVersion(version) raise UnsupportedVersion(version, method=method)

@ -111,6 +111,8 @@ class TestDispatcher(test_utils.BaseTestCase):
elif isinstance(ex, messaging.UnsupportedVersion): elif isinstance(ex, messaging.UnsupportedVersion):
self.assertEqual(self.msg.get('version', '1.0'), self.assertEqual(self.msg.get('version', '1.0'),
ex.version) ex.version)
if ex.method:
self.assertEqual(self.msg.get('method'), ex.method)
else: else:
self.assertTrue(self.success, failure) self.assertTrue(self.success, failure)
self.assertIsNone(failure) self.assertIsNone(failure)