Merge "Protect agent startup from import errors in plugins"
This commit is contained in:
commit
35d375dabc
@ -238,10 +238,17 @@ class AgentManager(os_service.Service):
|
||||
else 'ceilometer.%s' % category)
|
||||
|
||||
def _catch_extension_load_error(mgr, ep, exc):
|
||||
# Extension raising ExtensionLoadError can be ignored
|
||||
# Extension raising ExtensionLoadError can be ignored,
|
||||
# and ignore anything we can't import as a safety measure.
|
||||
if isinstance(exc, plugin_base.ExtensionLoadError):
|
||||
LOG.error(_("Skip loading extension for %s") % ep.name)
|
||||
return
|
||||
if isinstance(exc, ImportError):
|
||||
LOG.error(
|
||||
_("Failed to import extension for %(name)s: %(error)s"),
|
||||
{'name': ep.name, 'error': exc},
|
||||
)
|
||||
return
|
||||
raise exc
|
||||
|
||||
return extension.ExtensionManager(
|
||||
|
@ -80,6 +80,17 @@ class TestManager(base.BaseTestCase):
|
||||
LOG.error.assert_has_calls(calls=calls,
|
||||
any_order=True)
|
||||
|
||||
# Skip loading pollster upon ImportError
|
||||
@mock.patch('ceilometer.ipmi.pollsters.node._Base.__init__',
|
||||
mock.Mock(side_effect=ImportError))
|
||||
@mock.patch('ceilometer.ipmi.pollsters.sensor.SensorPollster.__init__',
|
||||
mock.Mock(return_value=None))
|
||||
def test_import_error_in_plugin(self):
|
||||
mgr = manager.AgentManager(namespaces=['ipmi'],
|
||||
pollster_list=['hardware.ipmi.node.*'])
|
||||
# 0 pollsters
|
||||
self.assertEqual(0, len(mgr.extensions))
|
||||
|
||||
# Exceptions other than ExtensionLoadError are propagated
|
||||
@mock.patch('ceilometer.ipmi.pollsters.node._Base.__init__',
|
||||
mock.Mock(side_effect=PollingException))
|
||||
|
Loading…
Reference in New Issue
Block a user