capture attribute errors for invalid class plugins

also switched to py3 safe to_str
pull/15327/head
Brian Coca 8 years ago
parent fd9838f1a0
commit 5225048df9

@ -31,6 +31,7 @@ import warnings
from collections import defaultdict
from ansible import constants as C
from ansible.utils.unicode import to_str
try:
from __main__ import display
@ -247,7 +248,7 @@ class PluginLoader:
try:
full_paths = (os.path.join(path, f) for f in os.listdir(path))
except OSError as e:
display.warning("Error accessing plugin paths: %s" % str(e))
display.warning("Error accessing plugin paths: %s" % to_str(e))
for full_path in (f for f in full_paths if os.path.isfile(f) and not f.endswith('__init__.py')):
full_name = os.path.basename(full_path)
@ -354,7 +355,7 @@ class PluginLoader:
class_only = kwargs.pop('class_only', False)
all_matches = []
for i in self._get_paths():
all_matches.extend(glob.glob(os.path.join(i, "*.py")))
@ -366,7 +367,11 @@ class PluginLoader:
if path not in self._module_cache:
self._module_cache[path] = self._load_module_source(name, path)
obj = getattr(self._module_cache[path], self.class_name)
try:
obj = getattr(self._module_cache[path], self.class_name)
except AttributeError as e:
display.warning("Skipping plugin (%s) as it seems to be invalid: %s" % (path, to_str(e)))
if self.base_class:
# The import path is hardcoded and should be the right place,
# so we are not expecting an ImportError.

Loading…
Cancel
Save