If a hostname configured in /etc/ipa/default.conf is changed and
is different from the one stored in LDAP in cn=ipa,cn=etc,$SUFFIX
ipactl gives an unintelligible error.

This patch improves the error message and also offers a list of
configured master so that the hostname setting in IPA configuration
can be easily fixed.

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

>From 386836c7cfd6ef30857ef5c38d059fb784c7a0eb Mon Sep 17 00:00:00 2001
From: Martin Kosek <mko...@redhat.com>
Date: Wed, 3 Aug 2011 12:44:46 +0200
Subject: [PATCH] Improve error message in ipactl

If a hostname configured in /etc/ipa/default.conf is changed and
is different from the one stored in LDAP in cn=ipa,cn=etc,$SUFFIX
ipactl gives an unintelligible error.

This patch improves the error message and also offers a list of
configured master so that the hostname setting in IPA configuration
can be easily fixed.

https://fedorahosted.org/freeipa/ticket/1558
---
 install/tools/ipactl |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/install/tools/ipactl b/install/tools/ipactl
index a9445170f556eb419514d41087d6b305360b89d4..f43c2e3291531539dabb1241fbbb37a8b680c771 100755
--- a/install/tools/ipactl
+++ b/install/tools/ipactl
@@ -25,6 +25,7 @@ try:
     from ipapython import sysrestore
     from ipapython import config
     from ipalib import api, errors
+    from ipalib.dn import DN
     import logging
     import ldap
     import ldap.sasl
@@ -88,6 +89,25 @@ def get_config():
         # LSB status code 3: program is not running
         raise IpactlError("Failed to get list of services to probe status:\n" +
                           "Directory Server is stopped", 3)
+    except ldap.NO_SUCH_OBJECT:
+        masters_list = []
+        dn = str(DN('cn=masters,cn=ipa,cn=etc,%s' % api.env.basedn))
+        attrs = ['cn']
+        try:
+            entries = con.search_s(dn,
+                                    ldap.SCOPE_ONELEVEL,
+                                    attrlist=attrs,)
+        except Exception, e:
+            masters_list.append("No master found because of error: %s" % str(e))
+        else:
+            for dn,master_entry in entries:
+                masters_list.append(master_entry.get('cn', [None])[0])
+
+        masters = "\n".join(masters_list)
+
+        raise IpactlError("Failed to get list of services to probe status!\n"
+                          "Configured hostname '%s' does not match any master server in LDAP:\n%s"
+                          % (api.env.host, masters))
     except Exception, e:
         raise IpactlError("Unknown error when retrieving list of services from LDAP: " + str(e))
 
@@ -296,7 +316,8 @@ def main():
     api.finalize()
 
     if '.' not in api.env.host:
-        raise IpactlError("Invalid hostname, must be fully-qualified")
+        raise IpactlError("Invalid hostname '%s' in IPA configuration!\n"
+                          "The hostname must be fully-qualified" % api.env.host)
 
     if args[0].lower() == "start":
         ipa_start()
-- 
1.7.6

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

Reply via email to