From b389f8637f3bcc4f794c708379c9e65ff4f26f6f Mon Sep 17 00:00:00 2001
From: Gideon <soccerman.gid@gmail.com>
Date: Sun, 24 Mar 2024 15:22:44 -0600
Subject: [PATCH] =?UTF-8?q?Add=20descriptive=20error=20message=20to=20Lino?=
 =?UTF-8?q?de=20inventory=20plugin=20file=20checkin=E2=80=A6=20(#8133)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* Add descriptive error message to Linode inventory plugin file checking, tests

* add changelog fragment

* Adjust changelog fragment.

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
---
 ...r-message-for-linode-inventory-plugin.yaml |  3 +++
 plugins/inventory/linode.py                   | 23 +++++++++++++++----
 tests/unit/plugins/inventory/test_linode.py   | 18 +++++++++++++--
 3 files changed, 37 insertions(+), 7 deletions(-)
 create mode 100644 changelogs/fragments/8133-add-error-message-for-linode-inventory-plugin.yaml

diff --git a/changelogs/fragments/8133-add-error-message-for-linode-inventory-plugin.yaml b/changelogs/fragments/8133-add-error-message-for-linode-inventory-plugin.yaml
new file mode 100644
index 0000000000..755d7ed4fe
--- /dev/null
+++ b/changelogs/fragments/8133-add-error-message-for-linode-inventory-plugin.yaml
@@ -0,0 +1,3 @@
+bugfixes:
+  - linode inventory plugin - add descriptive error message for linode inventory plugin (https://github.com/ansible-collections/community.general/pull/8133).
+    
diff --git a/plugins/inventory/linode.py b/plugins/inventory/linode.py
index 34b1fbaf9d..e9b283e076 100644
--- a/plugins/inventory/linode.py
+++ b/plugins/inventory/linode.py
@@ -271,12 +271,25 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
                 strict=strict)
 
     def verify_file(self, path):
-        """Verify the Linode configuration file."""
+        """Verify the Linode configuration file.
+
+        Return true/false if the config-file is valid for this plugin
+
+        Args:
+            str(path): path to the config
+        Kwargs:
+            None
+        Raises:
+            None
+        Returns:
+            bool(valid): is valid config file"""
+        valid = False
         if super(InventoryModule, self).verify_file(path):
-            endings = ('linode.yaml', 'linode.yml')
-            if any((path.endswith(ending) for ending in endings)):
-                return True
-        return False
+            if path.endswith(("linode.yaml", "linode.yml")):
+                valid = True
+            else:
+                self.display.vvv('Inventory source not ending in "linode.yaml" or "linode.yml"')
+        return valid
 
     def parse(self, inventory, loader, path, cache=True):
         """Dynamically parse Linode the cloud inventory."""
diff --git a/tests/unit/plugins/inventory/test_linode.py b/tests/unit/plugins/inventory/test_linode.py
index a4f556761d..0f239f2dd9 100644
--- a/tests/unit/plugins/inventory/test_linode.py
+++ b/tests/unit/plugins/inventory/test_linode.py
@@ -37,11 +37,25 @@ def test_missing_access_token_lookup(inventory):
         assert 'Could not retrieve Linode access token' in error_message
 
 
-def test_verify_file(tmp_path, inventory):
+def test_verify_file_yml(tmp_path, inventory):
     file = tmp_path / "foobar.linode.yml"
     file.touch()
     assert inventory.verify_file(str(file)) is True
 
 
+def test_verify_file_yaml(tmp_path, inventory):
+    file = tmp_path / "foobar.linode.yaml"
+    file.touch()
+    assert inventory.verify_file(str(file)) is True
+
+
+def test_verify_file_bad_config_yml(inventory):
+    assert inventory.verify_file("foobar.linode.yml") is False
+
+
+def test_verify_file_bad_config_yaml(inventory):
+    assert inventory.verify_file("foobar.linode.yaml") is False
+
+
 def test_verify_file_bad_config(inventory):
-    assert inventory.verify_file('foobar.linode.yml') is False
+    assert inventory.verify_file("foobar.wrongcloud.yml") is False