mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add descriptive error message to Linode inventory plugin file checkin… (#8133)
* 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>
This commit is contained in:
parent
795a855d0e
commit
b389f8637f
3 changed files with 37 additions and 7 deletions
|
@ -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).
|
||||||
|
|
|
@ -271,12 +271,25 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
strict=strict)
|
strict=strict)
|
||||||
|
|
||||||
def verify_file(self, path):
|
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):
|
if super(InventoryModule, self).verify_file(path):
|
||||||
endings = ('linode.yaml', 'linode.yml')
|
if path.endswith(("linode.yaml", "linode.yml")):
|
||||||
if any((path.endswith(ending) for ending in endings)):
|
valid = True
|
||||||
return True
|
else:
|
||||||
return False
|
self.display.vvv('Inventory source not ending in "linode.yaml" or "linode.yml"')
|
||||||
|
return valid
|
||||||
|
|
||||||
def parse(self, inventory, loader, path, cache=True):
|
def parse(self, inventory, loader, path, cache=True):
|
||||||
"""Dynamically parse Linode the cloud inventory."""
|
"""Dynamically parse Linode the cloud inventory."""
|
||||||
|
|
|
@ -37,11 +37,25 @@ def test_missing_access_token_lookup(inventory):
|
||||||
assert 'Could not retrieve Linode access token' in error_message
|
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 = tmp_path / "foobar.linode.yml"
|
||||||
file.touch()
|
file.touch()
|
||||||
assert inventory.verify_file(str(file)) is True
|
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):
|
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
|
||||||
|
|
Loading…
Reference in a new issue