From 01b2c481611a4839762426356d7b8a9480657d91 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Thu, 4 Nov 2021 13:02:18 +0100 Subject: [PATCH] a_module test: fix crash in case of tombstoning (#3660) (#3662) * Fix crash in case of tombstoning. * Extend tests. (cherry picked from commit c23bbb5c4a7a1c4c2ed913967a0b62e5a0a34846) Co-authored-by: Felix Fontein --- .../fragments/3660-a_module-tombstone.yml | 2 ++ plugins/test/a_module.py | 24 ++++++++++++------- .../targets/test_a_module/runme.yml | 12 ++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/3660-a_module-tombstone.yml diff --git a/changelogs/fragments/3660-a_module-tombstone.yml b/changelogs/fragments/3660-a_module-tombstone.yml new file mode 100644 index 0000000000..d2408d4a26 --- /dev/null +++ b/changelogs/fragments/3660-a_module-tombstone.yml @@ -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)." diff --git a/plugins/test/a_module.py b/plugins/test/a_module.py index ad57cda792..36c13ffabd 100644 --- a/plugins/test/a_module.py +++ b/plugins/test/a_module.py @@ -7,6 +7,11 @@ __metaclass__ = type from ansible.plugins.loader import action_loader, module_loader +try: + from ansible.errors import AnsiblePluginRemovedError +except ImportError: + AnsiblePluginRemovedError = Exception + def a_module(term): """ @@ -14,14 +19,17 @@ def a_module(term): - 'community.general.ufw' is community.general.a_module - 'community.general.does_not_exist' is not community.general.a_module """ - for loader in (action_loader, module_loader): - data = loader.find_plugin(term) - # Ansible 2.9 returns a tuple - if isinstance(data, tuple): - data = data[0] - if data is not None: - return True - return False + try: + for loader in (action_loader, module_loader): + data = loader.find_plugin(term) + # Ansible 2.9 returns a tuple + if isinstance(data, tuple): + data = data[0] + if data is not None: + return True + return False + except AnsiblePluginRemovedError: + return False class TestModule(object): diff --git a/tests/integration/targets/test_a_module/runme.yml b/tests/integration/targets/test_a_module/runme.yml index 9f7618341a..1175bef20c 100644 --- a/tests/integration/targets/test_a_module/runme.yml +++ b/tests/integration/targets/test_a_module/runme.yml @@ -23,3 +23,15 @@ # Local collection module (that exist or not) - "'testns.testcoll.collection_module' is 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', '>=')