summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathaniel Case <ncase@redhat.com>2020-01-31 12:49:37 -0500
committerGitHub <noreply@github.com>2020-01-31 12:49:37 -0500
commit3dbc03d58a9dc17d3bb11873b026eeb3f001564b (patch)
tree9224b0061dc89a67a7dd95ca92cd34b8cc5fdeab
parent725bb4d1739c75a023b4987f79f1739b1a854b95 (diff)
downloadansible-3dbc03d58a9dc17d3bb11873b026eeb3f001564b.tar.gz
Try to load action plugin from the same collection as the module (#66701)
* Try to load network action plugin from the same collection as the module * Alter tests to match Just make sure the action plugin is as qualified as the module it is paired with
-rw-r--r--lib/ansible/executor/task_executor.py15
-rw-r--r--test/units/executor/test_task_executor.py12
2 files changed, 17 insertions, 10 deletions
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py
index 17dbebcdba..bda38b0bdf 100644
--- a/lib/ansible/executor/task_executor.py
+++ b/lib/ansible/executor/task_executor.py
@@ -1017,16 +1017,23 @@ class TaskExecutor:
Returns the correct action plugin to handle the requestion task action
'''
- module_prefix = self._task.action.split('.')[-1].split('_')[0]
+ module_collection, separator, module_name = self._task.action.rpartition(".")
+ module_prefix = module_name.split('_')[0]
+ if module_collection:
+ # For network modules, which look for one action plugin per platform, look for the
+ # action plugin in the same collection as the module by prefixing the action plugin
+ # with the same collection.
+ network_action = "{0}.{1}".format(module_collection, module_prefix)
+ else:
+ network_action = module_prefix
collections = self._task.collections
# let action plugin override module, fallback to 'normal' action plugin otherwise
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, self._shared_loader_obj.action_loader.has_plugin(module_prefix, collection_list=collections))):
- handler_name = module_prefix
+ elif all((module_prefix in C.NETWORK_GROUP_MODULES, self._shared_loader_obj.action_loader.has_plugin(network_action, collection_list=collections))):
+ handler_name = network_action
else:
# FUTURE: once we're comfortable with collections impl, preface this action with ansible.builtin so it can't be hijacked
handler_name = 'normal'
diff --git a/test/units/executor/test_task_executor.py b/test/units/executor/test_task_executor.py
index 4dbce95512..0ae7995a8d 100644
--- a/test/units/executor/test_task_executor.py
+++ b/test/units/executor/test_task_executor.py
@@ -393,7 +393,7 @@ class TestTaskExecutor(unittest.TestCase):
mock_connection = MagicMock()
mock_templar = MagicMock()
- action = 'namespace.prefix_sufix'
+ action = 'namespace.prefix_suffix'
te._task.action = action
handler = te._get_action_handler(mock_connection, mock_templar)
@@ -428,8 +428,8 @@ class TestTaskExecutor(unittest.TestCase):
mock_connection = MagicMock()
mock_templar = MagicMock()
- action = 'namespace.netconf_sufix'
- module_prefix = action.split('.')[-1].split('_')[0]
+ action = 'namespace.netconf_suffix'
+ module_prefix = action.split('_')[0]
te._task.action = action
handler = te._get_action_handler(mock_connection, mock_templar)
@@ -439,7 +439,7 @@ class TestTaskExecutor(unittest.TestCase):
mock.call(module_prefix, collection_list=te._task.collections)])
action_loader.get.assert_called_once_with(
- 'netconf', task=te._task, connection=mock_connection,
+ module_prefix, task=te._task, connection=mock_connection,
play_context=te._play_context, loader=te._loader,
templar=mock_templar, shared_loader_obj=te._shared_loader_obj,
collection_list=te._task.collections)
@@ -463,8 +463,8 @@ class TestTaskExecutor(unittest.TestCase):
mock_connection = MagicMock()
mock_templar = MagicMock()
- action = 'namespace.prefix_sufix'
- module_prefix = action.split('.')[-1].split('_')[0]
+ action = 'namespace.prefix_suffix'
+ module_prefix = action.split('_')[0]
te._task.action = action
handler = te._get_action_handler(mock_connection, mock_templar)