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

zypper_repository: Proper failure when python-xml is missing (#939)

* Proper error when python-xml is missing

* use missing_required_lib to output error

* Add changelog
This commit is contained in:
Amin Vakil 2020-09-20 16:39:02 +04:30 committed by GitHub
parent ba5b86cf4a
commit 09d89da0ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- zypper_repository - proper failure when python-xml is missing (https://github.com/ansible-collections/community.general/pull/939).

View file

@ -123,9 +123,19 @@ EXAMPLES = '''
runrefresh: yes
'''
import traceback
XML_IMP_ERR = None
try:
from xml.dom.minidom import parseString as parseXML
HAS_XML = True
except ImportError:
XML_IMP_ERR = traceback.format_exc()
HAS_XML = False
from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
REPO_OPTS = ['alias', 'name', 'priority', 'enabled', 'autorefresh', 'gpgcheck']
@ -143,7 +153,8 @@ def _parse_repos(module):
"""parses the output of zypper --xmlout repos and return a parse repo dictionary"""
cmd = _get_cmd('--xmlout', 'repos')
from xml.dom.minidom import parseString as parseXML
if not HAS_XML:
module.fail_json(msg=missing_required_lib("python-xml"), exception=XML_IMP_ERR)
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
if rc == 0:
repos = []