
Stevedore was being used to both discover configured plugins and to create instances of these plugins. If the plugin's __init__() function raised an exception however, stevedore logged the exception but otherwise kept processing plugins in the list. The logger also is disabled so no stack trace is seen in the log file, hence the init error is swallowed. It wasn't until the plugin was searched for later in the flow that an error was appearent to the client, but the original root cause of the issue was not found. This CR creates these plugins outside of stevedore so that issues are immediately raised for attention, as these represent configuration issues that must be fixed for proper operation. Change-Id: I2fd533302ac5e0364aee6e24fd03fcf962c7a3ef
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
# Copyright (c) 2015 Rackspace, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
# implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
"""
|
|
Utilities to support plugins and plugin managers.
|
|
"""
|
|
from barbican.common import utils
|
|
from barbican import i18n as u
|
|
|
|
LOG = utils.getLogger(__name__)
|
|
|
|
|
|
def instantiate_plugins(extension_manager, invoke_args=(), invoke_kwargs={}):
|
|
"""Attempt to create each plugin managed by a stevedore manager.
|
|
|
|
While we could have let the stevedore 'extension_manager' create our
|
|
plugins by passing 'invoke_on_load=True' to its initializer, its logic
|
|
handles and suppresses any root cause exceptions emanating from the
|
|
plugins' initializers. This function allows those exceptions to be exposed.
|
|
|
|
:param extension_manager: A :class:`NamedExtensionManager` instance that
|
|
has already processed the configured plugins, but has not yet created
|
|
instances of these plugins.
|
|
:param invoke_args: Arguments to pass to the new plugin instance.
|
|
:param invoke_kwargs: Keyword arguments to pass to the new plugin instance.
|
|
"""
|
|
for ext in extension_manager.extensions:
|
|
if not ext.obj:
|
|
try:
|
|
plugin_instance = ext.plugin(*invoke_args, **invoke_kwargs)
|
|
except Exception:
|
|
LOG.logger.disabled = False # Ensure not suppressing logs.
|
|
LOG.exception(
|
|
u._LE("Problem seen creating plugin: '%s'"),
|
|
ext.name
|
|
)
|
|
else:
|
|
ext.obj = plugin_instance
|
|
|
|
|
|
def get_active_plugins(extension_manager):
|
|
return [ext.obj for ext in extension_manager.extensions if ext.obj]
|