From 7fb95cc638b1c9b7f2e9a67dba859ef8126f2c5f Mon Sep 17 00:00:00 2001
From: Chris Kelley <ckelley@redhat.com>
Date: Tue, 27 Jul 2021 21:57:26 +0100
Subject: [PATCH] Parse getStatus as JSON not XML
On dogtagpki/pki master XML is being replaced by JSON, getStatus will
return JSON in PKI 11.0+
The PR for dogtagpki/pki that makes this change necessary is:
https://github.com/dogtagpki/pki/pull/3674
Reviewed-By: Francois Cami <fcami@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
---
install/tools/ipa-pki-wait-running.in | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/install/tools/ipa-pki-wait-running.in b/install/tools/ipa-pki-wait-running.in
index 4f0f2f34a7b0a43210676e7fd50e7029e798f301..9ca6e974e55a4d68afd06e1d9c7b67c5f926e48c 100644
--- a/install/tools/ipa-pki-wait-running.in
+++ b/install/tools/ipa-pki-wait-running.in
@@ -13,6 +13,7 @@ import logging
import sys
import time
from xml.etree import ElementTree
+import json
from ipalib import api
from ipaplatform.paths import paths
@@ -74,10 +75,19 @@ def get_status(conn, timeout):
"""
client = SystemStatusClient(conn)
response = client.get_status(timeout=timeout)
- root = ElementTree.fromstring(response)
- status = root.findtext("Status")
- error = root.findtext("Error")
- logging.debug("Got status '%s', error '%s'", status, error)
+ status = None
+ error = None
+ try:
+ json_response = json.loads(response)
+ status = json_response['Response']['Status']
+ except KeyError as e:
+ error = repr(e)
+ except json.JSONDecodeError:
+ logger.debug("Response is not valid JSON, try XML")
+ root = ElementTree.fromstring(response)
+ status = root.findtext("Status")
+ error = root.findtext("Error")
+ logger.debug("Got status '%s', error '%s'", status, error)
return status, error
--
2.31.1