ipadnsrecord: Fix for ansible-test fake execution test

All imports that are only available after installing IPA need to be in a
try exception clause to be able to pass the fake execution test.

If the imports can not be done, all used and needed attributes are
defined with the value None, MODULE_IMPORT_ERROR is set to the import
error and fail_json is called.
This commit is contained in:
Thomas Woerner
2022-09-14 20:50:20 +02:00
parent 71f3f11031
commit fe364cc2db

View File

@@ -866,8 +866,13 @@ RETURN = """
from ansible.module_utils._text import to_text
from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, is_ipv4_addr, is_ipv6_addr, ipalib_errors
import dns.reversename
import dns.resolver
try:
import dns.reversename
import dns.resolver
except ImportError as _err:
MODULE_IMPORT_ERROR = str(_err)
else:
MODULE_IMPORT_ERROR = None
from ansible.module_utils import six
@@ -1131,6 +1136,9 @@ def configure_module():
ansible_module._ansible_debug = True
if MODULE_IMPORT_ERROR is not None:
ansible_module.fail_json(msg=MODULE_IMPORT_ERROR)
return ansible_module