diff options
author | Robin Roth <robin.roth@kit.edu> | 2017-02-11 11:09:45 +0100 |
---|---|---|
committer | Brian Coca <bcoca@users.noreply.github.com> | 2017-02-13 12:28:22 -0500 |
commit | 82eaa9735c7ebfc25ec7b70c9c789cdaa746b9eb (patch) | |
tree | c7ad466eba13470ea9d46c164107889db675b759 | |
parent | 4900201c5bbe63b1c0e2d8315862420aa031ec18 (diff) | |
download | ansible-82eaa9735c7ebfc25ec7b70c9c789cdaa746b9eb.tar.gz |
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.
-rw-r--r-- | lib/ansible/modules/packaging/os/zypper.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/ansible/modules/packaging/os/zypper.py b/lib/ansible/modules/packaging/os/zypper.py index 72e778b0d6..82e7666ca3 100644 --- a/lib/ansible/modules/packaging/os/zypper.py +++ b/lib/ansible/modules/packaging/os/zypper.py @@ -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: |