From 74e9b1e2190b4fa7f6fa59294d03ea154d44cfd8 Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Mon, 16 Dec 2019 19:15:41 +0530 Subject: [PATCH] Fix network action plugin load in collection (#65849) * Fix network action plugin load in collection Fixes https://github.com/ansible/ansible/issues/65071 * Load network action plugin that matches the module prefix name from list of collections. * Update changelog * Fix unit test --- .../fragments/network_action_plugin_load.yml | 2 ++ lib/ansible/executor/task_executor.py | 2 +- test/units/executor/test_task_executor.py | 14 ++++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/network_action_plugin_load.yml diff --git a/changelogs/fragments/network_action_plugin_load.yml b/changelogs/fragments/network_action_plugin_load.yml new file mode 100644 index 00000000000..2a23c4acc56 --- /dev/null +++ b/changelogs/fragments/network_action_plugin_load.yml @@ -0,0 +1,2 @@ +bugfixes: + - Fixes in network action plugins load from collections using module prefix (https://github.com/ansible/ansible/issues/65071) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index b18f4339dbc..e92fc1fed7e 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -1025,7 +1025,7 @@ class TaskExecutor: if self._shared_loader_obj.action_loader.has_plugin(self._task.action, collection_list=collections): handler_name = self._task.action # FIXME: is this code path even live anymore? check w/ networking folks; it trips sometimes when it shouldn't - elif all((module_prefix in C.NETWORK_GROUP_MODULES, module_prefix in self._shared_loader_obj.action_loader)): + elif all((module_prefix in C.NETWORK_GROUP_MODULES, self._shared_loader_obj.action_loader.has_plugin(module_prefix, collection_list=collections))): handler_name = module_prefix else: # FUTURE: once we're comfortable with collections impl, preface this action with ansible.builtin so it can't be hijacked diff --git a/test/units/executor/test_task_executor.py b/test/units/executor/test_task_executor.py index 512f137f841..4dbce955125 100644 --- a/test/units/executor/test_task_executor.py +++ b/test/units/executor/test_task_executor.py @@ -422,20 +422,21 @@ class TestTaskExecutor(unittest.TestCase): ) action_loader = te._shared_loader_obj.action_loader - action_loader.has_plugin.return_value = False + action_loader.has_plugin.side_effect = [False, True] action_loader.get.return_value = mock.sentinel.handler action_loader.__contains__.return_value = True mock_connection = MagicMock() mock_templar = MagicMock() action = 'namespace.netconf_sufix' + module_prefix = action.split('.')[-1].split('_')[0] te._task.action = action handler = te._get_action_handler(mock_connection, mock_templar) self.assertIs(mock.sentinel.handler, handler) - action_loader.has_plugin.assert_called_once_with( - action, collection_list=te._task.collections) + action_loader.has_plugin.assert_has_calls([mock.call(action, collection_list=te._task.collections), + mock.call(module_prefix, collection_list=te._task.collections)]) action_loader.get.assert_called_once_with( 'netconf', task=te._task, connection=mock_connection, @@ -463,13 +464,14 @@ class TestTaskExecutor(unittest.TestCase): mock_connection = MagicMock() mock_templar = MagicMock() action = 'namespace.prefix_sufix' + module_prefix = action.split('.')[-1].split('_')[0] te._task.action = action - handler = te._get_action_handler(mock_connection, mock_templar) self.assertIs(mock.sentinel.handler, handler) - action_loader.has_plugin.assert_called_once_with( - action, collection_list=te._task.collections) + + action_loader.has_plugin.assert_has_calls([mock.call(action, collection_list=te._task.collections), + mock.call(module_prefix, collection_list=te._task.collections)]) action_loader.get.assert_called_once_with( 'normal', task=te._task, connection=mock_connection,