Skip to content

Commit 6f52349

Browse files
committed
If an external command fails, capture stderr and raise Exception.
This handles the RFC-Editor and IANA sync external commands, but need to be generalised, and applied to all external commands: TODO. - Legacy-Id: 11646
1 parent e2c332e commit 6f52349

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

ietf/sync/views.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import json
55

6-
from django.http import HttpResponse, HttpResponseForbidden, HttpResponseServerError, HttpResponseRedirect, Http404
6+
from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect, Http404
77
from django.shortcuts import render_to_response
88
from django.template import RequestContext
99
from django.conf import settings
@@ -15,6 +15,7 @@
1515
from ietf.ietfauth.utils import role_required, has_role
1616
from ietf.sync.discrepancies import find_discrepancies
1717
from ietf.utils.serialize import object_as_shallow_dict
18+
from ietf.utils.log import log
1819

1920
SYNC_BIN_PATH = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../bin"))
2021

@@ -75,30 +76,29 @@ def notify(request, org, notification):
7576

7677
if request.method == "POST":
7778
def runscript(name):
78-
p = subprocess.Popen(["python", os.path.join(SYNC_BIN_PATH, name)],
79-
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
80-
out, _ = p.communicate()
81-
return (p.returncode, out)
79+
cmd = ["python", os.path.join(SYNC_BIN_PATH, name)]
80+
cmdstring = " ".join(cmd)
81+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
82+
out, err = p.communicate()
83+
if p.returncode:
84+
log("Subprocess error %s when running '%s': %s %s" % (p.returncode, cmd, err, out))
85+
raise subprocess.CalledProcessError(p.returncode, cmdstring, "\n".join([err, out]))
8286

83-
import syslog
84-
syslog.syslog("Running sync script from notify view POST")
87+
log("Running sync script from notify view POST")
8588

8689
if notification == "protocols":
87-
failed, out = runscript("iana-protocols-updates")
90+
runscript("iana-protocols-updates")
8891

8992
if notification == "changes":
90-
failed, out = runscript("iana-changes-updates")
93+
runscript("iana-changes-updates")
9194

9295
if notification == "queue":
93-
failed, out = runscript("rfc-editor-queue-updates")
96+
runscript("rfc-editor-queue-updates")
9497

9598
if notification == "index":
96-
failed, out = runscript("rfc-editor-index-updates")
99+
runscript("rfc-editor-index-updates")
97100

98-
if failed:
99-
return HttpResponseServerError("FAIL\n\n" + out, content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET)
100-
else:
101-
return HttpResponse("OK", content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET)
101+
return HttpResponse("OK", content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET)
102102

103103
return render_to_response('sync/notify.html',
104104
dict(org=known_orgs[org],

0 commit comments

Comments
 (0)