Permalink
Browse files

using publish_failed for stderr rather than custom events

  • Loading branch information...
1 parent 57a31a6 commit e4a3be135d19c20c2ab3e1ac6d6f9b3827b63fd0 @mriehl mriehl committed Mar 19, 2013
@@ -39,14 +39,12 @@
TYPE_REQUEST = 'request'
TYPE_SERVICE_CHANGE = 'service-change'
TYPE_HEARTBEAT = 'heartbeat'
-TYPE_ERROR_REPORT = 'error-report'
KNOWN_EVENT_TYPES = [TYPE_COMMAND,
TYPE_FULL_UPDATE,
TYPE_REQUEST,
TYPE_SERVICE_CHANGE,
- TYPE_HEARTBEAT,
- TYPE_ERROR_REPORT]
+ TYPE_HEARTBEAT]
class IncompleteEventDataException(Exception):
@@ -164,10 +162,6 @@ def is_a_command(self):
def is_a_heartbeat(self):
return self.event_type == TYPE_HEARTBEAT
- @property
- def is_an_error_report(self):
- return self.event_type == TYPE_ERROR_REPORT
-
def __str__(self):
if self.is_a_request:
return 'target[{0}] requested command "{1}" using arguments "{2}"'.format(self.target, self.command, self.arguments)
@@ -188,9 +182,6 @@ def __str__(self):
if self.is_a_heartbeat:
return 'Heartbeat on {0}'.format(self.target)
- if self.is_an_error_report:
- return 'Error report on {0}'.format(self.target)
-
raise NotImplementedError('Unknown event type {0}'.format(self.event_type))
class ServiceState (object):
@@ -74,14 +74,9 @@ def publish_failed(self, return_code):
error_message = '(%s) target[%s] request "%s" failed: return code was %s.' \
% (self.hostname, self.target, self.readable_command, return_code)
log.err(error_message)
- self._report_error_summary()
self.broadcaster.publish_cmd_for_target(self.target, self.readable_command, events.FAILED,
- error_message, tracking_id=self.tracking_id)
+ message=self.error_buffer, tracking_id=self.tracking_id)
def errReceived(self, data):
self.error_buffer += str(data)
- def _report_error_summary(self):
- log.msg('Reporting errors of execution of {0} on {1}.'.format(self.readable_command, self.target))
- for error_line in self.error_buffer.split('\n'):
- self.broadcaster._sendEvent(events.TYPE_ERROR_REPORT, data=error_line, tracking_id=self.tracking_id)
@@ -87,14 +87,6 @@ def test_should_return_description_of_heartbeat(self):
'payload': None})
self.assertEqual('Heartbeat on target-name', str(event))
- def test_should_return_description_of_error_report(self):
- event = Event('target-name', {'id': 'error-report',
- 'type': 'event',
- 'target': 'target-name',
- 'tracking_id': None,
- 'payload': None})
- self.assertEqual('Error report on target-name', str(event))
-
def test_should_return_description_of_full_update(self):
event = Event('target-name', {'id': 'full-update'})
@@ -69,18 +69,24 @@ def test_should_publish_finished_event (self):
self.assertEquals(call('dev123', '/usr/bin/python abc', 'finished', '(hostname) target[dev123] request finished: "/usr/bin/python abc" succeeded.', tracking_id='tracking-id'), mock_broadcaster.publish_cmd_for_target.call_args)
@patch('yadtreceiver.protocols.log')
- def test_should_publish_failed_event (self, mock_log):
+ def test_should_publish_failed_event_with_stderr_from_process (self, mock_log):
mock_protocol = Mock(ProcessProtocol)
mock_broadcaster = Mock()
mock_protocol.broadcaster = mock_broadcaster
mock_protocol.hostname = 'hostname'
mock_protocol.target = 'dev123'
mock_protocol.readable_command = '/usr/bin/python abc'
mock_protocol.tracking_id = 'tracking_id'
+ mock_protocol.error_buffer = 'Someone has shut down the internet.'
ProcessProtocol.publish_failed(mock_protocol, 123)
- self.assertEquals(call('dev123', '/usr/bin/python abc', 'failed', '(hostname) target[dev123] request "/usr/bin/python abc" failed: return code was 123.', tracking_id='tracking_id'), mock_broadcaster.publish_cmd_for_target.call_args)
+ self.assertEquals(call('dev123',
+ '/usr/bin/python abc',
+ 'failed',
+ message='Someone has shut down the internet.',
+ tracking_id='tracking_id'),
+ mock_broadcaster.publish_cmd_for_target.call_args)
@patch('yadtreceiver.protocols.log')
def test_should_accumulate_error_output(self, mock_log):
@@ -93,22 +99,3 @@ def test_should_accumulate_error_output(self, mock_log):
protocol.errReceived('baz')
self.assertEqual('foo\nbarbaz', protocol.error_buffer)
-
- @patch('yadtreceiver.protocols.log')
- def test_should_send_error_reports_upon_failure(self, mock_log):
- mock_protocol = Mock(ProcessProtocol)
- mock_broadcaster = Mock()
- mock_protocol.broadcaster = mock_broadcaster
- mock_protocol.hostname = 'hostname'
- mock_protocol.target = 'dev123'
- mock_protocol.readable_command = '/usr/bin/python abc'
- mock_protocol.tracking_id = 'tracking_id'
- mock_protocol.error_buffer= 'foo\nbar\nbaz'
-
- ProcessProtocol._report_error_summary(mock_protocol)
-
- self.assertEqual([call('error-report', data='foo', tracking_id='tracking_id'),
- call('error-report', data='bar', tracking_id='tracking_id'),
- call('error-report', data='baz', tracking_id='tracking_id')],
- mock_broadcaster._sendEvent.call_args_list)
-

0 comments on commit e4a3be1

Please sign in to comment.