From 4de976ccf8f27c152f89aecc7ded2c2cd9d0a710 Mon Sep 17 00:00:00 2001 From: SandyWalsh Date: Wed, 19 Sep 2012 11:19:37 -0300 Subject: Send api.fault notification on API service faults. Exceptions caught by the API middleware will now send "api.fault" notifications indicating the offending URL and the underlying exception. The allows the billing/usage systems to track requests end-to-end without having to monitor log files. Disabled by default. Enable with --notify_api_faults Change-Id: Ied2783259413ba12d686b44b33e0707645e51afb --- nova/tests/test_notifications.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/test_notifications.py b/nova/tests/test_notifications.py index 94922941e..d451d852c 100644 --- a/nova/tests/test_notifications.py +++ b/nova/tests/test_notifications.py @@ -86,6 +86,30 @@ class NotificationsTestCase(test.TestCase): inst.update(params) return db.instance_create(self.context, inst) + def test_send_api_fault_disabled(self): + self.flags(notify_api_faults=False) + notifications.send_api_fault("http://example.com/foo", 500, None) + self.assertEquals(0, len(test_notifier.NOTIFICATIONS)) + + def test_send_api_fault(self): + self.flags(notify_api_faults=True) + exception = None + try: + # Get a real exception with a call stack. + raise test.TestingException("junk") + except test.TestingException, e: + exception = e + + notifications.send_api_fault("http://example.com/foo", 500, exception) + + self.assertEquals(1, len(test_notifier.NOTIFICATIONS)) + n = test_notifier.NOTIFICATIONS[0] + self.assertEquals(n['priority'], 'ERROR') + self.assertEquals(n['event_type'], 'api.fault') + self.assertEquals(n['payload']['url'], 'http://example.com/foo') + self.assertEquals(n['payload']['status'], 500) + self.assertTrue(n['payload']['exception'] is not None) + def test_notif_disabled(self): # test config disable of the notifcations -- cgit