Merge "Don't hard fail when a plugin can't be imported"
This commit is contained in:
commit
d687248000
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
|
from cloudbaseinit.openstack.common import log as logging
|
||||||
from cloudbaseinit.utils import classloader
|
from cloudbaseinit.utils import classloader
|
||||||
|
|
||||||
opts = [
|
opts = [
|
||||||
@ -44,11 +45,19 @@ opts = [
|
|||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
CONF.register_opts(opts)
|
CONF.register_opts(opts)
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def load_plugins():
|
def load_plugins():
|
||||||
plugins = []
|
plugins = []
|
||||||
cl = classloader.ClassLoader()
|
cl = classloader.ClassLoader()
|
||||||
for class_path in CONF.plugins:
|
for class_path in CONF.plugins:
|
||||||
plugins.append(cl.load_class(class_path)())
|
try:
|
||||||
|
plugin_cls = cl.load_class(class_path)
|
||||||
|
except ImportError:
|
||||||
|
LOG.error("Could not import plugin module %r", class_path)
|
||||||
|
continue
|
||||||
|
|
||||||
|
plugin = plugin_cls()
|
||||||
|
plugins.append(plugin)
|
||||||
return plugins
|
return plugins
|
||||||
|
@ -21,6 +21,7 @@ except ImportError:
|
|||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from cloudbaseinit.plugins.common import factory
|
from cloudbaseinit.plugins.common import factory
|
||||||
|
from cloudbaseinit.tests import testutils
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
@ -35,3 +36,13 @@ class PluginFactoryTests(unittest.TestCase):
|
|||||||
response = factory.load_plugins()
|
response = factory.load_plugins()
|
||||||
self.assertEqual(expected, mock_load_class.call_args_list)
|
self.assertEqual(expected, mock_load_class.call_args_list)
|
||||||
self.assertTrue(response is not None)
|
self.assertTrue(response is not None)
|
||||||
|
|
||||||
|
@testutils.ConfPatcher('plugins', ['missing.plugin'])
|
||||||
|
def test_load_plugins_plugin_failed(self):
|
||||||
|
with testutils.LogSnatcher('cloudbaseinit.plugins.'
|
||||||
|
'common.factory') as snatcher:
|
||||||
|
plugins = factory.load_plugins()
|
||||||
|
|
||||||
|
self.assertEqual([], plugins)
|
||||||
|
self.assertEqual(["Could not import plugin module 'missing.plugin'"],
|
||||||
|
snatcher.output)
|
||||||
|
Loading…
Reference in New Issue
Block a user