# TODO(gibi): apply strutils.mask_password on exception_message and
# consider emitting the exception_message only if the safe flag is
# true in the exception like in the REST API
+ module = inspect.getmodule(trace[0])
+ module_name = module.__name__ if module else 'unknown'
return cls(
function_name=trace[3],
- module_name=inspect.getmodule(trace[0]).__name__,
+ module_name=module_name,
exception=fault.__class__.__name__,
exception_message=six.text_type(fault))
raise test.TestingException('bad things happened')
+def bad_function_unknown_module(self, context):
+ """Example traceback that points to a module that getmodule() can't find.
+
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ File "src/lxml/lxml.etree.pyx", line 2402, in
+ lxml.etree._Attrib.__setitem__ (src/lxml/lxml.etree.c:67548)
+ File "src/lxml/apihelpers.pxi", line 570, in
+ lxml.etree._setAttributeValue (src/lxml/lxml.etree.c:21551)
+ File "src/lxml/apihelpers.pxi", line 1437, in
+ lxml.etree._utf8 (src/lxml/lxml.etree.c:30194)
+ TypeError: Argument must be bytes or unicode, got 'NoneType'
+
+ """
+ from lxml import etree
+ x = etree.fromstring('<hello/>')
+ x.attrib['foo'] = None
+
+
class WrapExceptionTestCase(test.NoDBTestCase):
def setUp(self):
super(WrapExceptionTestCase, self).setUp()
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
self.assertEqual(0, len(fake_notifier.VERSIONED_NOTIFICATIONS))
+ def test_wrap_exception_unknown_module(self):
+ ctxt = context.get_admin_context()
+ wrapped = exception_wrapper.wrap_exception(
+ rpc.get_notifier('fake'), binary='fake-binary')
+ self.assertRaises(
+ TypeError, wrapped(bad_function_unknown_module), None, ctxt)
+ self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS))
+ notification = fake_notifier.VERSIONED_NOTIFICATIONS[0]
+ payload = notification['payload']['nova_object.data']
+ self.assertEqual('unknown', payload['module_name'])
+
def test_wrap_exception_with_notifier(self):
wrapped = exception_wrapper.wrap_exception(rpc.get_notifier('fake'),
binary='fake-binary')