Skip to content

Commit

Permalink
Fix default subject of "None" in fatalmailbatch. Refs #109
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaberez committed Dec 23, 2021
1 parent f22a423 commit f13f61b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -11,6 +11,9 @@
than the time to wait between retries, the httpok check never executed.
Issue #110.

- Fixed a bug where ``crashmailbatch`` and ``fatalmatchbatch`` did not set
the intended default subject. Patch by Joe Portela.

1.0.0 (2016-10-02)
------------------

Expand Down
9 changes: 5 additions & 4 deletions superlance/fatalmailbatch.py
Expand Up @@ -38,7 +38,7 @@
--interval - batch cycle length (in minutes). The default is 1 minute.
This means that all events in each cycle are batched together
and sent as a single email
--toEmail - the email address(es) to send alerts to - comma separated
--fromEmail - the email address to send alerts from
Expand All @@ -55,14 +55,15 @@
from superlance.process_state_email_monitor import ProcessStateEmailMonitor

class FatalMailBatch(ProcessStateEmailMonitor):

process_state_events = ['PROCESS_STATE_FATAL']

def __init__(self, **kwargs):
kwargs['subject'] = kwargs.get('subject', 'Fatal start alert from supervisord')
if kwargs.get('subject') is None:
kwargs['subject'] = 'Fatal start alert from supervisord'
ProcessStateEmailMonitor.__init__(self, **kwargs)
self.now = kwargs.get('now', None)

def get_process_state_change_msg(self, headers, payload):
pheaders, pdata = childutils.eventdata(payload+'\n')

Expand Down
4 changes: 4 additions & 0 deletions superlance/tests/test_crashmailbatch.py
Expand Up @@ -64,5 +64,9 @@ def test_handle_event_exit_unexpected(self):
self.assertTrue(self.unexpected_err_msg in msgs[0])
self.assertTrue(self.unexpected_err_msg in crash.stderr.getvalue())

def test_sets_default_subject_when_None(self):
crash = self._make_one_mocked(subject=None) # see issue #109
self.assertEqual(crash.subject, "Crash alert from supervisord")

if __name__ == '__main__':
unittest.main()
6 changes: 5 additions & 1 deletion superlance/tests/test_crashsms.py
Expand Up @@ -3,12 +3,16 @@
from .test_crashmailbatch import CrashMailBatchTests

class CrashSMSTests(CrashMailBatchTests):
subject = 'None'
subject = None
unexpected_err_msg = '[bar:foo](58597) exited unexpectedly'

def _get_target_class(self):
from superlance.crashsms import CrashSMS
return CrashSMS

def test_sets_default_subject_when_None(self):
crash = self._make_one_mocked(subject=None)
self.assertEqual(crash.subject, self.subject)

if __name__ == '__main__':
unittest.main()
4 changes: 4 additions & 0 deletions superlance/tests/test_fatalmailbatch.py
Expand Up @@ -43,5 +43,9 @@ def test_get_process_state_change_msg(self):
msg = crash.get_process_state_change_msg(hdrs, payload)
self.assertTrue(self.unexpected_err_msg in msg)

def test_sets_default_subject_when_None(self):
crash = self._make_one_mocked(subject=None) # see issue #109
self.assertEqual(crash.subject, "Fatal start alert from supervisord")

if __name__ == '__main__':
unittest.main()

0 comments on commit f13f61b

Please sign in to comment.