From 38092dcc27d0ad42e59d604713526f453232c4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=81=BA=28Xia=20Kai=29?= Date: Mon, 21 Mar 2016 07:21:54 +0000 Subject: [PATCH] import the base class and check whether this obj has the required base class. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏恺(Xia Kai) --- lib/ansible/plugins/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ansible/plugins/__init__.py b/lib/ansible/plugins/__init__.py index afeab7a1038..078ab459366 100644 --- a/lib/ansible/plugins/__init__.py +++ b/lib/ansible/plugins/__init__.py @@ -329,8 +329,13 @@ class PluginLoader: obj = getattr(self._module_cache[path], self.class_name) else: obj = getattr(self._module_cache[path], self.class_name)(*args, **kwargs) - if self.base_class and self.base_class not in [base.__name__ for base in obj.__class__.__mro__]: - return None + if self.base_class: + # The import path is hardcoded and should be the right place, + # so we are not expecting an ImportError. + module = __import__(self.package, fromlist=[self.base_class]) + # Check whether this obj has the required base class. + if not issubclass(obj.__class__, getattr(module, self.base_class, None)): + return None return obj