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
pull/64961/merge
Ganesh Nalawade 5 years ago committed by GitHub
parent 093d1500b9
commit 74e9b1e219
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

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

Loading…
Cancel
Save