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

bubble up errors from subprocesses

parent d4c77c66
......@@ -40,13 +40,16 @@ def main():
command.stdin.flush()
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>"
"<p>Standard error output is :</p><pre>%s</pre>") % (
command.poll(),
command.stderr.read().replace('&', '&amp;')\
.replace('<', '&lt;')\
.replace('>', '&gt;'),
command_stderr.replace('&', '&amp;')\
.replace('<', '&lt;')\
.replace('>', '&gt;'),
)
else:
content = "<p>Everything went well.</p>"
......@@ -60,10 +63,14 @@ def main():
'slapos:%s' % uuid.uuid4(),
])
if command_failed:
sys.stderr.write('%s\n' % command_stderr)
sys.exit(1)
feed = urllib2.urlopen(args.feed_url[0])
body = feed.read()
failed = False
some_notification_failed = False
for notif_url in args.notification_url:
notification_url = urlparse.urlparse(notif_url)
notification_port = notification_url.port
......@@ -72,16 +79,16 @@ def main():
headers = {'Content-Type': feed.info().getheader('Content-Type')}
notification = httplib.HTTPConnection(notification_url.hostname,
notification_port)
notification_port)
notification.request('POST', notification_url.path, body, headers)
response = notification.getresponse()
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("Its response was %r\n" % response.reason)
failed = True
some_notification_failed = True
if failed:
if some_notification_failed:
sys.exit(1)
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