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:
parent
4900201c5b
commit
82eaa9735c
1 changed files with 9 additions and 1 deletions
|
@ -175,6 +175,8 @@ EXAMPLES = '''
|
||||||
ZYPP_LOCK_TIMEOUT: 20
|
ZYPP_LOCK_TIMEOUT: 20
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
import xml
|
||||||
|
from ansible.module_utils.pycompat24 import get_exception
|
||||||
from xml.dom.minidom import parseString as parseXML
|
from xml.dom.minidom import parseString as parseXML
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -239,7 +241,13 @@ def get_installed_state(m, packages):
|
||||||
def parse_zypper_xml(m, cmd, fail_not_found=True, packages=None):
|
def parse_zypper_xml(m, cmd, fail_not_found=True, packages=None):
|
||||||
rc, stdout, stderr = m.run_command(cmd, check_rc=False)
|
rc, stdout, stderr = m.run_command(cmd, check_rc=False)
|
||||||
|
|
||||||
|
try:
|
||||||
dom = parseXML(stdout)
|
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:
|
if rc == 104:
|
||||||
# exit code 104 is ZYPPER_EXIT_INF_CAP_NOT_FOUND (no packages found)
|
# exit code 104 is ZYPPER_EXIT_INF_CAP_NOT_FOUND (no packages found)
|
||||||
if fail_not_found:
|
if fail_not_found:
|
||||||
|
|
Loading…
Reference in a new issue