Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

buffering stderr output from child processes. logging it out if the p…

…rocess died.
  • Loading branch information...
commit 2a36d24b6d51d9b15f9162154249f277ff978cb5 1 parent 46f5c34
@mriehl mriehl authored
View
10 src/main/python/yadtreceiver/protocols.py
@@ -18,7 +18,7 @@
Provides the ProcessProtocol.
"""
-__author__ = 'Michael Gruber'
+__author__ = 'Michael Gruber, Maximilien Riehl'
from twisted.internet import protocol
from twisted.python import log
@@ -36,6 +36,7 @@ def __init__(self, hostname, broadcaster, target, readable_command, tracking_id=
self.readable_command = readable_command
self.target = target
self.tracking_id = tracking_id
+ self.error_buffer = ''
log.msg('(%s) target[%s] executing "%s"' % (self.hostname, target, readable_command))
@@ -75,3 +76,10 @@ def publish_failed(self, return_code):
log.err(error_message)
self.broadcaster.publish_cmd_for_target(self.target, self.readable_command, events.FAILED,
error_message, tracking_id=self.tracking_id)
+ log.err('Errors from execution : {0}'.format(self._get_error_summary()))
+
+ def errReceived(self, data):
+ self.error_buffer += data
+
+ def _get_error_summary(self):
+ return self.error_buffer
View
10 src/unittest/python/protocols_tests.py
@@ -82,3 +82,13 @@ def test_should_publish_failed_event (self, mock_log):
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)
+ def test_should_accumulate_error_output(self):
+ mock_broadcaster = Mock()
+ protocol = ProcessProtocol('hostname', mock_broadcaster, 'devabc123', '/usr/bin/python abc 123', tracking_id='tracking-id')
+
+ self.assertEqual(protocol.error_buffer, '')
+
+ protocol.errReceived('foo')
+ protocol.errReceived('bar')
+
+ self.assertEqual(protocol._get_error_summary(), 'foobar')
Please sign in to comment.
Something went wrong with that request. Please try again.