From 5865d41dc45d7369f17db5aefba33cc4f98fd875 Mon Sep 17 00:00:00 2001
From: Thomas Woerner <twoerner@redhat.com>
Date: Wed, 14 Sep 2022 19:56:00 +0200
Subject: [PATCH] ipabackup_get_backup_dir: 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.
---
 roles/ipabackup/library/ipabackup_get_backup_dir.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/roles/ipabackup/library/ipabackup_get_backup_dir.py b/roles/ipabackup/library/ipabackup_get_backup_dir.py
index 14ceaa41..6036cde8 100644
--- a/roles/ipabackup/library/ipabackup_get_backup_dir.py
+++ b/roles/ipabackup/library/ipabackup_get_backup_dir.py
@@ -56,7 +56,13 @@ backup_dir:
 '''
 
 from ansible.module_utils.basic import AnsibleModule
-from ipaplatform.paths import paths
+try:
+    from ipaplatform.paths import paths
+except ImportError as _err:
+    MODULE_IMPORT_ERROR = str(_err)
+    paths = None
+else:
+    MODULE_IMPORT_ERROR = None
 
 
 def main():
@@ -65,6 +71,9 @@ def main():
         supports_check_mode=True,
     )
 
+    if MODULE_IMPORT_ERROR is not None:
+        module.fail_json(msg=MODULE_IMPORT_ERROR)
+
     module.exit_json(changed=False,
                      backup_dir=paths.IPA_BACKUP_DIR)
 
-- 
GitLab