diff options
author | Christian Heimes <cheimes@redhat.com> | 2015-08-16 19:00:00 +0200 |
---|---|---|
committer | Christian Heimes <cheimes@redhat.com> | 2015-08-17 21:14:12 +0200 |
commit | 0ab2ba73018675187ed932dc0b421488af17600a (patch) | |
tree | 8cef2fc045bcdbca93c947ec7ed0bdc088e478be /base | |
parent | 74a355185eeb30e7d42ff2d29c4c3c3c298b2a12 (diff) | |
download | pki-0ab2ba73018675187ed932dc0b421488af17600a.tar.gz pki-0ab2ba73018675187ed932dc0b421488af17600a.tar.xz pki-0ab2ba73018675187ed932dc0b421488af17600a.zip |
Py3 compatibility: encode output of subprocess call
In Python 3 subprocess.Popen() and check_out() return bytes. The rest of
PKI expects text, so the output has to be decoded.
- ascii for dnsdomainname
- sys.getfilesystemencoding() for paths
- utf-8 for the rest
Diffstat (limited to 'base')
-rw-r--r-- | base/java-tools/bin/pki | 5 | ||||
-rw-r--r-- | base/server/python/pki/server/deployment/pkihelper.py | 8 | ||||
-rw-r--r-- | base/server/python/pki/server/deployment/pkiparser.py | 7 | ||||
-rwxr-xr-x | base/server/sbin/pkidestroy | 8 | ||||
-rwxr-xr-x | base/server/sbin/pkispawn | 7 | ||||
-rwxr-xr-x | base/server/upgrade/10.1.99/02-ReplaceJettisonWithJackson | 4 | ||||
-rwxr-xr-x | base/server/upgrade/10.1.99/03-AddedRESTEasyClient | 4 |
7 files changed, 25 insertions, 18 deletions
diff --git a/base/java-tools/bin/pki b/base/java-tools/bin/pki index 568093892..4b8e69a55 100644 --- a/base/java-tools/bin/pki +++ b/base/java-tools/bin/pki @@ -31,7 +31,7 @@ def run_java_cli(args): value = subprocess.check_output( '. /etc/pki/pki.conf && echo $RESTEASY_LIB', shell=True) - resteasy_lib = str(value).strip() + resteasy_lib = value.decode(sys.getfilesystemencoding()).strip() # construct classpath classpath = [ @@ -92,7 +92,8 @@ def main(argv): value = subprocess.check_output( '. /etc/pki/pki.conf && echo $PKI_CLI_OPTIONS', shell=True) - args = shlex.split(value.strip()) + value = value.decode(sys.getfilesystemencoding()).strip() + args = shlex.split(value) args.extend(argv[1:]) client_type = 'java' diff --git a/base/server/python/pki/server/deployment/pkihelper.py b/base/server/python/pki/server/deployment/pkihelper.py index 35e218a7b..61f04d215 100644 --- a/base/server/python/pki/server/deployment/pkihelper.py +++ b/base/server/python/pki/server/deployment/pkihelper.py @@ -2717,10 +2717,10 @@ class Modutil: # execute command p = subprocess.Popen(command, stdout=subprocess.PIPE) output = p.communicate()[0] - p.wait() # ignore return code due to issues with HSM # https://fedorahosted.org/pki/ticket/1444 + output = output.decode('utf-8') # find modules from lines such as '1. NSS Internal PKCS #11 Module' modules = re.findall(r'^ +\d+\. +(.*)$', output, re.MULTILINE) @@ -3052,7 +3052,7 @@ class KRAConnector: output = subprocess.check_output(command, stderr=subprocess.STDOUT) - + output = output.decode('utf-8') error = re.findall("ClientResponseFailure:(.*?)", output) if error: config.pki_log.warning( @@ -3206,7 +3206,7 @@ class TPSConnector: output = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=False) - + output = output.decode('utf-8') error = re.findall("ClientResponseFailure:(.*?)", output) if error: config.pki_log.warning( @@ -3304,6 +3304,7 @@ class SecurityDomain: output = subprocess.check_output( command, stderr=subprocess.STDOUT) + output = output.decode('utf-8') except subprocess.CalledProcessError: config.pki_log.warning( log.PKIHELPER_SECURITY_DOMAIN_UNREACHABLE_1, @@ -3418,6 +3419,7 @@ class SecurityDomain: try: output = subprocess.check_output(command, stderr=subprocess.STDOUT) + output = output.decode('utf-8') return output except subprocess.CalledProcessError as exc: config.pki_log.warning( diff --git a/base/server/python/pki/server/deployment/pkiparser.py b/base/server/python/pki/server/deployment/pkiparser.py index 6eeb74346..1905734f3 100644 --- a/base/server/python/pki/server/deployment/pkiparser.py +++ b/base/server/python/pki/server/deployment/pkiparser.py @@ -31,6 +31,7 @@ import random import requests.exceptions import string import subprocess +import sys import xml.etree.ElementTree as ET from six.moves import input, range # pylint: disable=W0622,F0401 @@ -174,16 +175,18 @@ class PKIConfigParser: resteasy_lib = subprocess.check_output( '. /etc/pki/pki.conf && echo $RESTEASY_LIB', shell=True) + resteasy_lib = resteasy_lib.decode(sys.getfilesystemencoding()) # workaround for pylint error E1103 - resteasy_lib = str(resteasy_lib).strip() + resteasy_lib = resteasy_lib.strip() # JNI jar location jni_jar_dir = subprocess.check_output( '. /usr/share/pki/etc/pki.conf && . /etc/pki/pki.conf ' '&& echo $JNI_JAR_DIR', shell=True) + jni_jar_dir = jni_jar_dir.decode(sys.getfilesystemencoding()) # workaround for pylint error E1103 - jni_jar_dir = str(jni_jar_dir).strip() + jni_jar_dir = jni_jar_dir.strip() default_instance_name = 'pki-tomcat' default_http_port = '8080' diff --git a/base/server/sbin/pkidestroy b/base/server/sbin/pkidestroy index ff7296f7b..032c97984 100755 --- a/base/server/sbin/pkidestroy +++ b/base/server/sbin/pkidestroy @@ -86,11 +86,9 @@ def main(argv): # Retrieve DNS domainname config.pki_dns_domainname = None try: - dnsdomainname = subprocess.check_output( - "dnsdomainname", - shell=True) - # workaround for pylint error E1103 - config.pki_dns_domainname = str(dnsdomainname).rstrip('\n') + dnsdomainname = subprocess.check_output(["dnsdomainname"]) + dnsdomainname = dnsdomainname.decode('ascii').rstrip('\n') + config.pki_dns_domainname = dnsdomainname if not len(config.pki_dns_domainname): print(log.PKI_DNS_DOMAIN_NOT_SET) sys.exit(1) diff --git a/base/server/sbin/pkispawn b/base/server/sbin/pkispawn index 7c87c52c4..f29dec333 100755 --- a/base/server/sbin/pkispawn +++ b/base/server/sbin/pkispawn @@ -88,10 +88,9 @@ def main(argv): # Retrieve DNS domainname try: - dnsdomainname = subprocess.check_output( - "dnsdomainname", shell=True) - # workaround for pylint error E1103 - config.pki_dns_domainname = str(dnsdomainname).rstrip('\n') + dnsdomainname = subprocess.check_output(["dnsdomainname"]) + dnsdomainname = dnsdomainname.decode('ascii').rstrip('\n') + config.pki_dns_domainname = dnsdomainname if not len(config.pki_dns_domainname): print(log.PKI_DNS_DOMAIN_NOT_SET) sys.exit(1) diff --git a/base/server/upgrade/10.1.99/02-ReplaceJettisonWithJackson b/base/server/upgrade/10.1.99/02-ReplaceJettisonWithJackson index 9e4fb4c12..9926b60bf 100755 --- a/base/server/upgrade/10.1.99/02-ReplaceJettisonWithJackson +++ b/base/server/upgrade/10.1.99/02-ReplaceJettisonWithJackson @@ -21,6 +21,7 @@ from __future__ import absolute_import import os +import sys import subprocess import pki.server.upgrade @@ -41,8 +42,9 @@ class ReplaceJettisonWithJackson(pki.server.upgrade.PKIServerUpgradeScriptlet): resteasy_lib = subprocess.check_output( '. /etc/pki/pki.conf && echo $RESTEASY_LIB', shell=True) + resteasy_lib = resteasy_lib.decode(sys.getfilesystemencoding()) # workaround for pylint error E1103 - resteasy_lib = str(resteasy_lib).strip() + resteasy_lib = resteasy_lib.strip() # remove old links link = os.path.join(common_lib, 'jettison.jar') diff --git a/base/server/upgrade/10.1.99/03-AddedRESTEasyClient b/base/server/upgrade/10.1.99/03-AddedRESTEasyClient index 40169bc66..c38e0a62f 100755 --- a/base/server/upgrade/10.1.99/03-AddedRESTEasyClient +++ b/base/server/upgrade/10.1.99/03-AddedRESTEasyClient @@ -21,6 +21,7 @@ from __future__ import absolute_import import os +import sys import subprocess import pki.server.upgrade @@ -41,8 +42,9 @@ class AddedRESTEasyClient(pki.server.upgrade.PKIServerUpgradeScriptlet): resteasy_lib = subprocess.check_output( '. /etc/pki/pki.conf && echo $RESTEASY_LIB', shell=True) + resteasy_lib = resteasy_lib.decode(sys.getfilesystemencoding()) # workaround for pylint error E1103 - resteasy_lib = str(resteasy_lib).strip() + resteasy_lib = resteasy_lib.strip() # create new links source = os.path.join(resteasy_lib, 'resteasy-client.jar') |