From fe364cc2dba944ad9b35ecd3b10becbee9f0269b Mon Sep 17 00:00:00 2001 From: Thomas Woerner <twoerner@redhat.com> Date: Wed, 14 Sep 2022 20:50:20 +0200 Subject: [PATCH] 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. --- plugins/modules/ipadnsrecord.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/modules/ipadnsrecord.py b/plugins/modules/ipadnsrecord.py index 5fbea9dc..2c7a8998 100644 --- a/plugins/modules/ipadnsrecord.py +++ b/plugins/modules/ipadnsrecord.py @@ -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 -- GitLab