--
/ Alexander Bokovoy
From d29143ce5f6364dfc93dd0228dc58199f956b0a6 Mon Sep 17 00:00:00 2001
From: Alexander Bokovoy <aboko...@redhat.com>
Date: Fri, 1 Jul 2011 12:15:12 +0300
Subject: [PATCH] Make error reporting more 'local' for various configurations
 of nss_ldap packages

https://fedorahosted.org/freeipa/ticket/1369

When nss_ldap-based configuration does not work, report proper package name 
instead of always assuming nss_ldap.
At least, in RHEL6 and Fedora appropriate package is called nss-pam-ldapd while 
in older releases and other
distributions it might be called differently.

The change makes less confusing error reporting. It also introduces common 
utility function package_installed_name()
which provides an interface to query package manager for existence of mutually 
exclusive packages which is
helpful to distinguish between different configuration paths.
---
 ipa-client/ipa-install/ipa-client-install |    3 ++-
 ipapython/ipautil.py                      |   18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/ipa-client/ipa-install/ipa-client-install 
b/ipa-client/ipa-install/ipa-client-install
index 
884dd213b82bf5c29d6cb4928fde6789057b16af..d3218d3759c40f08b6afbc74f2376a783faf8100
 100755
--- a/ipa-client/ipa-install/ipa-client-install
+++ b/ipa-client/ipa-install/ipa-client-install
@@ -974,7 +974,8 @@ def main():
                 n = n + 1
 
         if not found:
-            print "nss_ldap is not able to use DNS discovery!"
+            package = package_installed_name(["nss-pam-ldapd","nss_ldap"])
+            print "Unable to use DNS discovery! Recognized configuration: %s" 
% (package)
             print "Changing configuration to use hardcoded server name: " 
+cli_server
 
             try:
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index 
91d19e95f570e0ef189b6fdc5519a9e344b2dab8..1573e0a172350444e3296e19e0092995721f5991
 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -1169,3 +1169,21 @@ def bind_port_responder(port, socket_stream=True, 
socket_timeout=None, responder
                 s.sendto(responder_data, addr)
     finally:
         s.close()
+
+def package_installed_name(packages):
+    """
+    Find out which of mutually exclusive packages is installed
+    
+    packages is a list of package names to check
+    
+    Returns package name or None
+    """
+
+    args = ["/bin/rpm","-q","--queryformat","%{NAME}"]
+    for package in packages:
+        try:
+            (package_name, error, retcode) = run(args+[package])
+            return package_name
+        except CalledProcessError:
+            continue
+    return None
-- 
1.7.5.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to