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: Rob Crittenden <rcritten@redhat.com>
Reviewed-By: Francois Cami <fcami@redhat.com>
This commit is contained in:
Chris Kelley 2021-07-27 21:57:26 +01:00 committed by Rob Crittenden
parent e3304ff3aa
commit 9310366a6f

View File

@ -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