From 0ab2ba73018675187ed932dc0b421488af17600a Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sun, 16 Aug 2015 19:00:00 +0200 Subject: 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 --- base/server/python/pki/server/deployment/pkihelper.py | 8 +++++--- base/server/python/pki/server/deployment/pkiparser.py | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'base/server/python/pki') 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' -- cgit