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
pull/66991/head
Nathaniel Case 5 years ago committed by GitHub
parent 725bb4d173
commit 3dbc03d58a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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'

@ -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)

Loading…
Cancel
Save