From a41e35174fd17dfdc1f3bed09ef49017f00b3a86 Mon Sep 17 00:00:00 2001 From: Thales Elero Cervi Date: Tue, 29 Nov 2022 13:28:28 -0300 Subject: [PATCH] Decode cmd return string for keyring password When running the application on Debian, now on Python 3 strings are stored as Byte Strings instead of Unicode Strings. The return of cmd execution that is stored as a Byte String is problematic for keyring password saving function, that requires an Unicode string. This change simply decode the bytes to Unicode, so the plugin is now compatible with Python 3. By Duck Typing it, the plugin will still be compatible with Python 2 for ensuring upgrades are still possible. TEST PLAN: PASS - Build stx-openstack-helm-fluxcd package PASS - Run build-helm-charts.sh (build app) PASS - Upload stx-openstack app on Debian PASS - Upload stx-openstack app on CentOS Closes-Bug: 1998231 Signed-off-by: Thales Elero Cervi Change-Id: Ib28bca757c1946513e0b7bc57d4c22937842587a --- .../k8sapp_openstack/k8sapp_openstack/helm/openstack.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/helm/openstack.py b/python-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/helm/openstack.py index ad010f3c..380254c7 100644 --- a/python-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/helm/openstack.py +++ b/python-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/helm/openstack.py @@ -126,6 +126,12 @@ class OpenstackBaseHelm(FluxCDBaseHelm): try: cmd = ['ceph-authtool', '--gen-print-key'] password = subprocess.check_output(cmd).strip() + # TODO: Remove it when Debian is default for + # at least two STX releases (prob. ~ stx/9.0) + # Python Duck Typing to ensure compatibility with + # both Python 2 (CentOS) and Python 3 (Debian) + if hasattr(password, "decode"): + password = password.decode() except subprocess.CalledProcessError: raise exception.SysinvException( 'Failed to generate ceph key')