1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add try/except around xml parsing in zypper

Zypper sometimes produces invalid XML. Catch that in a nicer way.

Potential future improvement: Work around broken XML by removing some
sections.
This commit is contained in:
Robin Roth 2017-02-11 11:09:45 +01:00 committed by Brian Coca
parent 4900201c5b
commit 82eaa9735c

View file

@ -175,6 +175,8 @@ EXAMPLES = '''
ZYPP_LOCK_TIMEOUT: 20
'''
import xml
from ansible.module_utils.pycompat24 import get_exception
from xml.dom.minidom import parseString as parseXML
import re
@ -239,7 +241,13 @@ def get_installed_state(m, packages):
def parse_zypper_xml(m, cmd, fail_not_found=True, packages=None):
rc, stdout, stderr = m.run_command(cmd, check_rc=False)
dom = parseXML(stdout)
try:
dom = parseXML(stdout)
except xml.parsers.expat.ExpatError:
e = get_exception()
m.fail_json(msg="Failed to parse zypper xml output: %s" % e,
rc=rc, stdout=stdout, stderr=stderr, cmd=cmd)
if rc == 104:
# exit code 104 is ZYPPER_EXIT_INF_CAP_NOT_FOUND (no packages found)
if fail_not_found: