diff --git a/base/univention-system-activation/src/wsgi.py b/base/univention-system-activation/src/wsgi.py index 994adeafb7..8b47a8bd8b 100644 --- a/base/univention-system-activation/src/wsgi.py +++ b/base/univention-system-activation/src/wsgi.py @@ -70,6 +70,10 @@ def clean_license_output(out): def application(environ, start_response): + + class LdapLicenceFetchError(Exception): + pass + def _error(message, trace=None): return { 'status': 500, @@ -92,13 +96,16 @@ def application(environ, start_response): # output the license upon GET request if environ.get('REQUEST_METHOD') == 'GET': + cmd = ['usr/bin/sudo', '/usr/bin/univention-ldapsearch', '-LLL', 'objectClass=univentionLicense'] + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: - out = subprocess.check_output(['/usr/bin/sudo', '/usr/bin/univention-ldapsearch', '-LLL', 'objectClass=univentionLicense']) + out, err = proc.communicate() + if proc.returncode: + raise LdapLicenceFetchError('cmd: {}\nreturn code: {}\nstdout: {}\nstderr: {}'.format(cmd, proc.returncode, out, err)) out = clean_license_output(out) return _finish(data=out) - except subprocess.CalledProcessError as exc: - _log('Failed to read license data from LDAP:\n%s' % exc) - return _finish('500 Internal Server Error', _error('Failed to read license data from LDAP:\n%s' % exc)) + except LdapLicenceFetchError as exc: + return _finish('500 Internal Server Error', data=_error('Could not fetch licence from ldap', traceback.format_exc())) except Exception as exc: return _finish('500 Internal Server Error', data=_error(str(exc), traceback.format_exc()))