diff options
author | Petr Viktorin <pviktori@redhat.com> | 2015-11-25 17:17:18 +0100 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2015-12-14 10:54:23 +0100 |
commit | 099cf98307d4b2f0ace5d5e28754f264808bf59d (patch) | |
tree | a2cfad681ef3e0adf47afdd0810e69d760fa07bf /install/certmonger | |
parent | 4cc206b0f82dd68d615f0aebba5b03acf127f53a (diff) | |
download | freeipa-099cf98307d4b2f0ace5d5e28754f264808bf59d.tar.gz freeipa-099cf98307d4b2f0ace5d5e28754f264808bf59d.tar.xz freeipa-099cf98307d4b2f0ace5d5e28754f264808bf59d.zip |
Refactor ipautil.run
The ipautil.run function now returns an object with returncode and
output are accessible as attributes.
The stdout and stderr of all commands are logged (unless skip_output is given).
The stdout/stderr contents must be explicitly requested with a keyword
argument, otherwise they are None.
This is because in Python 3, the output needs to be decoded, and that can
fail if it's not decodable (human-readable) text.
The raw (bytes) output is always available from the result object,
as is "leniently" decoded output suitable for logging.
All calls are changed to reflect this.
A use of Popen in cainstance is changed to ipautil.run.
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'install/certmonger')
-rwxr-xr-x | install/certmonger/dogtag-ipa-ca-renew-agent-submit | 14 | ||||
-rwxr-xr-x | install/certmonger/ipa-server-guard | 16 |
2 files changed, 22 insertions, 8 deletions
diff --git a/install/certmonger/dogtag-ipa-ca-renew-agent-submit b/install/certmonger/dogtag-ipa-ca-renew-agent-submit index 44993b038..5a6b7fa22 100755 --- a/install/certmonger/dogtag-ipa-ca-renew-agent-submit +++ b/install/certmonger/dogtag-ipa-ca-renew-agent-submit @@ -156,15 +156,23 @@ def request_cert(): args = [path] + sys.argv[1:] if os.environ.get('CERTMONGER_CA_PROFILE') == 'caCACert': args += ['-N', '-O', 'bypassCAnotafter=true'] - stdout, stderr, rc = ipautil.run(args, raiseonerr=False, env=os.environ) - sys.stderr.write(stderr) + result = ipautil.run(args, raiseonerr=False, env=os.environ, + capture_output=True) + if six.PY2: + sys.stderr.write(result.raw_error_output) + else: + # Write bytes directly + sys.stderr.buffer.write(result.raw_error_output) #pylint: disable=no-member sys.stderr.flush() - syslog.syslog(syslog.LOG_NOTICE, "dogtag-ipa-renew-agent returned %d" % rc) + syslog.syslog(syslog.LOG_NOTICE, + "dogtag-ipa-renew-agent returned %d" % result.returncode) + stdout = result.output if stdout.endswith('\n'): stdout = stdout[:-1] + rc = result.returncode if rc == WAIT_WITH_DELAY: delay, sep, cookie = stdout.partition('\n') return (rc, delay, cookie) diff --git a/install/certmonger/ipa-server-guard b/install/certmonger/ipa-server-guard index 7ce3e43fc..2c5409718 100755 --- a/install/certmonger/ipa-server-guard +++ b/install/certmonger/ipa-server-guard @@ -30,6 +30,8 @@ import sys import syslog import traceback +import six + from ipapython import ipautil from ipaserver.install import certs @@ -39,14 +41,18 @@ def main(): raise RuntimeError("Not enough arguments") with certs.renewal_lock: - stdout, stderr, rc = ipautil.run(sys.argv[1:], raiseonerr=False, - env=os.environ) - sys.stdout.write(stdout) + result = ipautil.run(sys.argv[1:], raiseonerr=False, env=os.environ) + if six.PY2: + sys.stdout.write(result.raw_output) + sys.stderr.write(result.raw_error_output) + else: + # Write bytes directly + sys.stdout.buffer.write(result.raw_output) #pylint: disable=no-member + sys.stderr.buffer.write(result.raw_error_output) #pylint: disable=no-member sys.stdout.flush() - sys.stderr.write(stderr) sys.stderr.flush() - return rc + return result.returncode try: |