Commit 5ecc34b2 authored by Marco Mariani's avatar Marco Mariani

bubble up errors from subprocesses

parent d4c77c66
...@@ -40,13 +40,16 @@ def main(): ...@@ -40,13 +40,16 @@ def main():
command.stdin.flush() command.stdin.flush()
command.stdin.close() command.stdin.close()
if command.wait() != 0: command_failed = (command.wait() != 0)
command_stderr = command.stderr.read()
if command_failed:
content = ("<p>Failed with returncode <em>%d</em>.</p>" content = ("<p>Failed with returncode <em>%d</em>.</p>"
"<p>Standard error output is :</p><pre>%s</pre>") % ( "<p>Standard error output is :</p><pre>%s</pre>") % (
command.poll(), command.poll(),
command.stderr.read().replace('&', '&amp;')\ command_stderr.replace('&', '&amp;')\
.replace('<', '&lt;')\ .replace('<', '&lt;')\
.replace('>', '&gt;'), .replace('>', '&gt;'),
) )
else: else:
content = "<p>Everything went well.</p>" content = "<p>Everything went well.</p>"
...@@ -60,10 +63,14 @@ def main(): ...@@ -60,10 +63,14 @@ def main():
'slapos:%s' % uuid.uuid4(), 'slapos:%s' % uuid.uuid4(),
]) ])
if command_failed:
sys.stderr.write('%s\n' % command_stderr)
sys.exit(1)
feed = urllib2.urlopen(args.feed_url[0]) feed = urllib2.urlopen(args.feed_url[0])
body = feed.read() body = feed.read()
failed = False some_notification_failed = False
for notif_url in args.notification_url: for notif_url in args.notification_url:
notification_url = urlparse.urlparse(notif_url) notification_url = urlparse.urlparse(notif_url)
notification_port = notification_url.port notification_port = notification_url.port
...@@ -72,16 +79,16 @@ def main(): ...@@ -72,16 +79,16 @@ def main():
headers = {'Content-Type': feed.info().getheader('Content-Type')} headers = {'Content-Type': feed.info().getheader('Content-Type')}
notification = httplib.HTTPConnection(notification_url.hostname, notification = httplib.HTTPConnection(notification_url.hostname,
notification_port) notification_port)
notification.request('POST', notification_url.path, body, headers) notification.request('POST', notification_url.path, body, headers)
response = notification.getresponse() response = notification.getresponse()
if not (200 <= response.status < 300): if not (200 <= response.status < 300):
sys.stderr.write("The remote server at %s didn't send a successful reponse.\n" % notif_url) sys.stderr.write("The remote server at %s didn't send a successful reponse.\n" % notif_url)
sys.stderr.write("Its response was %r\n" % response.reason) sys.stderr.write("Its response was %r\n" % response.reason)
failed = True some_notification_failed = True
if failed: if some_notification_failed:
sys.exit(1) sys.exit(1)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment