From 099cf98307d4b2f0ace5d5e28754f264808bf59d Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 25 Nov 2015 17:17:18 +0100 Subject: 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 --- ipapython/dnssec/bindmgr.py | 7 ++++--- ipapython/dnssec/odsmgr.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'ipapython/dnssec') diff --git a/ipapython/dnssec/bindmgr.py b/ipapython/dnssec/bindmgr.py index 1822dacf2..a0a9f2eb2 100644 --- a/ipapython/dnssec/bindmgr.py +++ b/ipapython/dnssec/bindmgr.py @@ -40,8 +40,8 @@ class BINDMgr(object): def notify_zone(self, zone): cmd = ['rndc', 'sign', zone.to_text()] - output = ipautil.run(cmd)[0] - self.log.info(output) + result = ipautil.run(cmd, capture_output=True) + self.log.info('%s', result.output_log) def dn2zone_name(self, dn): """cn=KSK-20140813162153Z-cede9e182fc4af76c4bddbc19123a565,cn=keys,idnsname=test,cn=dns,dc=ipa,dc=example""" @@ -110,7 +110,8 @@ class BINDMgr(object): cmd.append(zone.to_text()) # keys has to be readable by ODS & named - basename = ipautil.run(cmd)[0].strip() + result = ipautil.run(cmd, capture_output=True) + basename = result.output.strip() private_fn = "%s/%s.private" % (workdir, basename) os.chmod(private_fn, FILE_PERM) # this is useful mainly for debugging diff --git a/ipapython/dnssec/odsmgr.py b/ipapython/dnssec/odsmgr.py index efbe16cc6..ebcd3aa24 100644 --- a/ipapython/dnssec/odsmgr.py +++ b/ipapython/dnssec/odsmgr.py @@ -128,7 +128,8 @@ class ODSMgr(object): Raises CalledProcessError if returncode != 0. """ cmd = ['ods-ksmutil'] + params - return ipautil.run(cmd)[0] + result = ipautil.run(cmd, capture_output=True) + return result.output def get_ods_zonelist(self): stdout = self.ksmutil(['zonelist', 'export']) -- cgit