summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-03-27 22:37:32 +0000
committerGerrit Code Review <review@openstack.org>2013-03-27 22:37:32 +0000
commit649dcb30dbb69a57bba9ea1271f2733aa1139583 (patch)
tree9f1cf9caeb47fbdf67afa21cc3877f990af01920
parent1400a5c0eca534c5ba550f81fb7f9d59d910b1c5 (diff)
parentb936df8c1ec47300540403ebb6833f0fbf5f195f (diff)
downloadnova-649dcb30dbb69a57bba9ea1271f2733aa1139583.tar.gz
nova-649dcb30dbb69a57bba9ea1271f2733aa1139583.tar.xz
nova-649dcb30dbb69a57bba9ea1271f2733aa1139583.zip
Merge "Add a format_message method to the Exceptions"
-rw-r--r--nova/exception.py6
-rw-r--r--nova/tests/test_exception.py29
2 files changed, 35 insertions, 0 deletions
diff --git a/nova/exception.py b/nova/exception.py
index cfc237120..1f32b0671 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -161,6 +161,12 @@ class NovaException(Exception):
super(NovaException, self).__init__(message)
+ def format_message(self):
+ if self.__class__.__name__.endswith('_Remote'):
+ return self.args[0]
+ else:
+ return unicode(self)
+
class EC2APIError(NovaException):
message = _("Unknown")
diff --git a/nova/tests/test_exception.py b/nova/tests/test_exception.py
index 6f5a9909e..040b56b13 100644
--- a/nova/tests/test_exception.py
+++ b/nova/tests/test_exception.py
@@ -140,3 +140,32 @@ class NovaExceptionTestCase(test.TestCase):
kwargs = {}
self.assertEquals(exception._cleanse_dict(kwargs), {})
+
+ def test_format_message_local(self):
+ class FakeNovaException(exception.NovaException):
+ message = "some message"
+
+ exc = FakeNovaException()
+ self.assertEquals(unicode(exc), exc.format_message())
+
+ def test_format_message_remote(self):
+ class FakeNovaException_Remote(exception.NovaException):
+ message = "some message"
+
+ def __unicode__(self):
+ return u"print the whole trace"
+
+ exc = FakeNovaException_Remote()
+ self.assertEquals(unicode(exc), u"print the whole trace")
+ self.assertEquals(exc.format_message(), "some message")
+
+ def test_format_message_remote_error(self):
+ class FakeNovaException_Remote(exception.NovaException):
+ message = "some message %(somearg)s"
+
+ def __unicode__(self):
+ return u"print the whole trace"
+
+ self.flags(fatal_exception_format_errors=False)
+ exc = FakeNovaException_Remote(lame_arg='lame')
+ self.assertEquals(exc.format_message(), "some message %(somearg)s")