Fix network action plugin load in collection ()

* 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
This commit is contained in:
Ganesh Nalawade 2019-12-16 19:15:41 +05:30 committed by GitHub
parent 093d1500b9
commit 74e9b1e219
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions
changelogs/fragments
lib/ansible/executor
test/units/executor

View file

@ -0,0 +1,2 @@
bugfixes:
- Fixes in network action plugins load from collections using module prefix (https://github.com/ansible/ansible/issues/65071)

View file

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

View file

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