Throw more user-friendly execption inside get_backend_instance method.
# See the License for the specific language governing permissions and
# limitations under the License.
+import traceback
import json
from oslo_config import cfg
@@ -43,9 +44,14 @@ def get_available_backends():
def get_backend_instance(name):
"""
+ Retrieve a class instance for the provided auth backend.
+
:param name: Backend name.
:type name: ``str``
"""
+
+ LOG.debug('Retrieving backend instance for backend "%s"' % (name))
+
try:
manager = DriverManager(namespace=BACKENDS_NAMESPACE, name=name,
invoke_on_load=False)
@@ -60,10 +66,21 @@ def get_backend_instance(name):
try:
kwargs = json.loads(backend_kwargs)
except ValueError as e:
- raise ValueError('Failed to JSON parse backend settings: %s' % (str(e)))
+ raise ValueError('Failed to JSON parse backend settings for backend "%s": %s' %
+ (name, str(e)))
else:
kwargs = {}
cls = manager.driver
+
+ try:
cls_instance = cls(**kwargs)
+ except Exception as e:
+ tb_msg = traceback.format_exc()
+ msg = ('Failed to instantiate auth backend "%s" with backend settings "%s": %s' %
+ (name, str(kwargs), str(e)))
+ msg += '\n\n' + tb_msg
+ exc_cls = type(e)
+ raise exc_cls(msg)
+
return cls_instance
