From ed886236f6c80b4f9379c941398b589b46c6ca6d Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Tue, 15 Jul 2014 22:57:11 -0700 Subject: [PATCH] Track the attempted method when raising UnsupportedVersion This helps in circumstances where the only stacktrace visible is on the target side (e.g. due to cast or fanout operations) and without the method information is difficult to root cause what is going on. Change-Id: I070ecda4d56186fcda8e8bfc49bf723928998393 Closes-bug: #1340277 --- oslo/messaging/rpc/dispatcher.py | 7 +++++-- tests/rpc/test_dispatcher.py | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/oslo/messaging/rpc/dispatcher.py b/oslo/messaging/rpc/dispatcher.py index 7dce7659a..6017cfc7f 100644 --- a/oslo/messaging/rpc/dispatcher.py +++ b/oslo/messaging/rpc/dispatcher.py @@ -67,10 +67,13 @@ class NoSuchMethod(RPCDispatcherError, AttributeError): class UnsupportedVersion(RPCDispatcherError): "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 + if method: + msg = "%s. Attempted method: %s" % (msg, method) super(UnsupportedVersion, self).__init__(msg) self.version = version + self.method = method class RPCDispatcher(object): @@ -183,4 +186,4 @@ class RPCDispatcher(object): if found_compatible: raise NoSuchMethod(method) else: - raise UnsupportedVersion(version) + raise UnsupportedVersion(version, method=method) diff --git a/tests/rpc/test_dispatcher.py b/tests/rpc/test_dispatcher.py index 0b24c6334..2f1fb4d5f 100644 --- a/tests/rpc/test_dispatcher.py +++ b/tests/rpc/test_dispatcher.py @@ -111,6 +111,8 @@ class TestDispatcher(test_utils.BaseTestCase): elif isinstance(ex, messaging.UnsupportedVersion): self.assertEqual(self.msg.get('version', '1.0'), ex.version) + if ex.method: + self.assertEqual(self.msg.get('method'), ex.method) else: self.assertTrue(self.success, failure) self.assertIsNone(failure)