1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

a_module test: fix crash in case of tombstoning (#3660)

* Fix crash in case of tombstoning.

* Extend tests.
This commit is contained in:
Felix Fontein 2021-11-04 08:29:17 +01:00 committed by GitHub
parent d9398eb8d1
commit c23bbb5c4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 8 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "a_module test plugin - fix crash when testing a module name that was tombstoned (https://github.com/ansible-collections/community.general/pull/3660)."

View file

@ -7,6 +7,11 @@ __metaclass__ = type
from ansible.plugins.loader import action_loader, module_loader from ansible.plugins.loader import action_loader, module_loader
try:
from ansible.errors import AnsiblePluginRemovedError
except ImportError:
AnsiblePluginRemovedError = Exception
def a_module(term): def a_module(term):
""" """
@ -14,6 +19,7 @@ def a_module(term):
- 'community.general.ufw' is community.general.a_module - 'community.general.ufw' is community.general.a_module
- 'community.general.does_not_exist' is not community.general.a_module - 'community.general.does_not_exist' is not community.general.a_module
""" """
try:
for loader in (action_loader, module_loader): for loader in (action_loader, module_loader):
data = loader.find_plugin(term) data = loader.find_plugin(term)
# Ansible 2.9 returns a tuple # Ansible 2.9 returns a tuple
@ -22,6 +28,8 @@ def a_module(term):
if data is not None: if data is not None:
return True return True
return False return False
except AnsiblePluginRemovedError:
return False
class TestModule(object): class TestModule(object):

View file

@ -23,3 +23,15 @@
# Local collection module (that exist or not) # Local collection module (that exist or not)
- "'testns.testcoll.collection_module' is community.general.a_module" - "'testns.testcoll.collection_module' is community.general.a_module"
- "'testns.testcoll.foobar' is not community.general.a_module" - "'testns.testcoll.foobar' is not community.general.a_module"
- name: Test a_module in case of routing
assert:
that:
# Redirected module
- "'ufw' is community.general.a_module"
# Redirected module where target collection does not exist
# (the target collection must not have been installed in CI!)
- "'onyx_pfc_interface' is not community.general.a_module"
# Tombstoned module
- "'community.general.docker_image_facts' is not community.general.a_module"
when: ansible_version.string is version('2.10.0', '>=')