Browse Source

[core] Fix error handling in kt_renewer.py for python3

On python3, if kinit fails to renew then the kt_renewer.py dies due
to a error handling logging not supporting binary strings.
Luca Toscano 5 years ago
parent
commit
56cc487839
1 changed files with 8 additions and 2 deletions
  1. 8 2
      desktop/core/src/desktop/kt_renewer.py

+ 8 - 2
desktop/core/src/desktop/kt_renewer.py

@@ -45,9 +45,15 @@ def renew_from_kt():
     max_retries = 0 if subp.returncode == 0 else max_retries
     max_retries = 0 if subp.returncode == 0 else max_retries
     if subp.returncode != 0:
     if subp.returncode != 0:
       retries = retries + 1
       retries = retries + 1
+      subp_stdout = subp.stdout.readlines()
+      subp_stderr = subp.stderr.readlines()
+
+      if sys.version_info[0] > 2:
+        subp_stdout = [line.decode() for line in subp.stdout.readlines()]
+        subp_stderr = [line.decode() for line in subp.stderr.readlines()]
+
       LOG.error("Couldn't reinit from keytab! `kinit' exited with %s.\n%s\n%s" % (
       LOG.error("Couldn't reinit from keytab! `kinit' exited with %s.\n%s\n%s" % (
-                subp.returncode,
-                "\n".join(subp.stdout.readlines()), "\n".join(subp.stderr.readlines())))
+                subp.returncode, "\n".join(subp_stdout), "\n".join(subp_stderr)))
       if retries >= max_retries:
       if retries >= max_retries:
         LOG.error("FATAL: max_retries of %s reached. Exiting..." % max_retries)
         LOG.error("FATAL: max_retries of %s reached. Exiting..." % max_retries)
         sys.exit(subp.returncode)
         sys.exit(subp.returncode)