Fix python3 compatibility

Change-Id: Id8a0913dde556a3e59b1ffdb22ca5e2aabd257a2
Closes-Bug: #1803972
This commit is contained in:
Michal Arbet 2018-11-19 15:07:53 +01:00 committed by Spyros Trigazis
parent 49d0444974
commit 54bea06b5a
4 changed files with 28 additions and 5 deletions

View File

@ -14,6 +14,7 @@
from magnum.common.cert_manager import cert_manager
from magnum import objects
import six
class Cert(cert_manager.Cert):
@ -58,6 +59,10 @@ class CertManager(cert_manager.CertManager):
:returns: the UUID of the stored cert
"""
if six.PY3 and isinstance(certificate, six.binary_type):
certificate = certificate.decode()
if six.PY3 and isinstance(private_key, six.binary_type):
private_key = private_key.decode()
x509keypair = {'certificate': certificate, 'private_key': private_key,
'private_key_passphrase': private_key_passphrase,
'intermediates': intermediates,

View File

@ -134,6 +134,9 @@ def _generate_certificate(issuer_name, subject_name, extensions,
csr = csr.sign(private_key, hashes.SHA256(), default_backend())
if six.PY3 and isinstance(encryption_password, six.text_type):
encryption_password = encryption_password.encode()
if encryption_password:
encryption_algorithm = serialization.BestAvailableEncryption(
encryption_password)

View File

@ -19,6 +19,7 @@ from magnum.common import profiler
from magnum.conductor.handlers.common import cert_manager
from magnum.drivers.common import driver
from magnum import objects
import six
LOG = logging.getLogger(__name__)
@ -39,6 +40,9 @@ class Handler(object):
signed_cert = cert_manager.sign_node_certificate(cluster,
certificate.csr,
context=context)
if six.PY3 and isinstance(signed_cert, six.binary_type):
certificate.pem = signed_cert.decode()
else:
certificate.pem = signed_cert
return certificate
@ -46,6 +50,9 @@ class Handler(object):
ca_cert = cert_manager.get_cluster_ca_certificate(cluster,
context=context)
certificate = objects.Certificate.from_object_cluster(cluster)
if six.PY3 and isinstance(ca_cert.get_certificate(), six.binary_type):
certificate.pem = ca_cert.get_certificate().decode()
else:
certificate.pem = ca_cert.get_certificate()
return certificate

View File

@ -20,6 +20,7 @@ from magnum.drivers.heat import k8s_template_def
from magnum.drivers.heat import template_def
from magnum.i18n import _
from oslo_config import cfg
import six
CONF = cfg.CONF
@ -132,6 +133,13 @@ class K8sFedoraTemplateDefinition(k8s_template_def.K8sTemplateDefinition):
if strutils.bool_from_string(cert_manager_api):
extra_params['cert_manager_api'] = cert_manager_api
ca_cert = cert_manager.get_cluster_ca_certificate(cluster)
if six.PY3 and isinstance(ca_cert.get_private_key_passphrase(),
six.text_type):
extra_params['ca_key'] = x509.decrypt_key(
ca_cert.get_private_key(),
ca_cert.get_private_key_passphrase().encode()
).decode().replace("\n", "\\n")
else:
extra_params['ca_key'] = x509.decrypt_key(
ca_cert.get_private_key(),
ca_cert.get_private_key_passphrase()).replace("\n", "\\n")