Commit 68c99a12 by Toshio Kuratomi

Merge pull request #10346 from lekum/find_plugin_bugfix

Bug fix: Search only for files as candidates
parents 9399290c b8cf1313
...@@ -176,7 +176,8 @@ class PluginLoader(object): ...@@ -176,7 +176,8 @@ class PluginLoader(object):
found = None found = None
for path in [p for p in self._get_paths() if p not in self._searched_paths]: for path in [p for p in self._get_paths() if p not in self._searched_paths]:
if os.path.isdir(path): if os.path.isdir(path):
for potential_file in os.listdir(path): for potential_file in (f for f in os.listdir(path)
if os.path.isfile(os.path.join(path, f))):
for suffix in suffixes: for suffix in suffixes:
if potential_file.endswith(suffix): if potential_file.endswith(suffix):
full_path = os.path.join(path, potential_file) full_path = os.path.join(path, potential_file)
......
...@@ -11,8 +11,11 @@ import passlib.hash ...@@ -11,8 +11,11 @@ import passlib.hash
import string import string
import StringIO import StringIO
import copy import copy
import tempfile
import shutil
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
from mock import patch
import ansible.utils import ansible.utils
import ansible.errors import ansible.errors
...@@ -914,3 +917,29 @@ class TestUtils(unittest.TestCase): ...@@ -914,3 +917,29 @@ class TestUtils(unittest.TestCase):
for (role, result) in tests: for (role, result) in tests:
self.assertEqual(ansible.utils.role_yaml_parse(role), result) self.assertEqual(ansible.utils.role_yaml_parse(role), result)
@patch('ansible.utils.plugins.module_finder._get_paths')
def test_find_plugin(self, mock_get_paths):
tmp_path = tempfile.mkdtemp()
mock_get_paths.return_value = [tmp_path,]
right_module_1 = 'module.py'
right_module_2 = 'module_without_extension'
wrong_module_1 = 'folder'
wrong_module_2 = 'inexistent'
path_right_module_1 = os.path.join(tmp_path, right_module_1)
path_right_module_2 = os.path.join(tmp_path, right_module_2)
path_wrong_module_1 = os.path.join(tmp_path, wrong_module_1)
open(path_right_module_1, 'w').close()
open(path_right_module_2, 'w').close()
os.mkdir(path_wrong_module_1)
self.assertEqual(ansible.utils.plugins.module_finder.find_plugin(right_module_1),
path_right_module_1)
self.assertEqual(ansible.utils.plugins.module_finder.find_plugin(right_module_2),
path_right_module_2)
self.assertEqual(ansible.utils.plugins.module_finder.find_plugin(wrong_module_1),
None)
self.assertEqual(ansible.utils.plugins.module_finder.find_plugin(wrong_module_2),
None)
shutil.rmtree(tmp_path)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment