From 4982bb54895eae5e338eb67e8c6ddd1bc52396ca Mon Sep 17 00:00:00 2001 From: Torsten Rehn Date: Thu, 13 Oct 2011 12:33:08 +0200 Subject: improve error logging during LDAP query processing This replaces the mostly useless error messages likes LdapPlugin error: list index out of range with information about which query failed and a traceback for debugging --- src/lib/Server/Plugins/Ldap.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib/Server/Plugins/Ldap.py b/src/lib/Server/Plugins/Ldap.py index 06ecaed7b..f1e2198d2 100644 --- a/src/lib/Server/Plugins/Ldap.py +++ b/src/lib/Server/Plugins/Ldap.py @@ -2,6 +2,7 @@ import imp import logging import sys import time +import traceback import Bcfg2.Options import Bcfg2.Server.Plugin @@ -64,7 +65,7 @@ class Ldap(Bcfg2.Server.Plugin.Plugin, Bcfg2.Server.Plugin.Connector): name = "Ldap" version = "$Revision: $" experimental = True - debug_flag = True + debug_flag = False def __init__(self, core, datastore): Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) @@ -76,6 +77,7 @@ class Ldap(Bcfg2.Server.Plugin.Plugin, Bcfg2.Server.Plugin.Connector): self.logger.error(message) def get_additional_data(self, metadata): + query = None try: data = {} self.debug_log("LdapPlugin debug: found queries " + @@ -91,13 +93,18 @@ class Ldap(Bcfg2.Server.Plugin.Plugin, Bcfg2.Server.Plugin.Connector): "' not applicable to host '" + metadata.hostname + "'") return data except Exception: - error_msg = sys.exc_info()[1] - if self.debug_flag: - raise - else: + if hasattr(query, "name"): + Bcfg2.Server.Plugin.logger.error("LdapPlugin error: " + + "Exception during processing of query named '" + + str(query.name) + + "', query results will be empty" + + " and may cause bind failures") + for line in traceback.format_exception(sys.exc_info()[0], + sys.exc_info()[1], + sys.exc_info()[2]): Bcfg2.Server.Plugin.logger.error("LdapPlugin error: " + - str(error_msg)) - return {} + line.replace("\n", "")) + return {} class LdapConnection(object): """ -- cgit v1.2.3-1-g7c22