Additional fix for https://fedorahosted.org/freeipa/ticket/5424

In current implementation the topology suffices are checked first and after that the error about non-existent host is raised. This does not make much sense to me, we should check for host existence before any work is done.

--
Martin^3 Babinsky
From 93d9f706d31a1f57438fecb7dd10b97b52b0b240 Mon Sep 17 00:00:00 2001
From: Martin Babinsky <mbabi...@redhat.com>
Date: Wed, 18 Nov 2015 13:12:50 +0100
Subject: [PATCH] check whether replica exists before executing the domain
 level 1 deletion code

Move this check before the parts that check topology suffix connectivity, wait
for removed segments etc. If the hostname does not exist, it should really be
one of the first errors user encounters during ipa-replica-manage del.

https://fedorahosted.org/freeipa/ticket/5424
---
 install/tools/ipa-replica-manage | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/install/tools/ipa-replica-manage b/install/tools/ipa-replica-manage
index 469b1d43a3aeb2f959f24defe5a73fae756bbc21..942ddc042b271ff1304be23469adb58d2cea7581 100755
--- a/install/tools/ipa-replica-manage
+++ b/install/tools/ipa-replica-manage
@@ -759,6 +759,15 @@ def del_master_managed(realm, hostname, options):
         print("Can't remove itself: %s" % (options.host))
         sys.exit(1)
 
+    try:
+        api.Command.host_show(hostname_u)
+    except errors.NotFound:
+        if not options.cleanup:
+            print("{hostname} does not exist.".format(hostname=hostname))
+            print("Please specify an actual server or add the --cleanup "
+                  "option to force clean up.")
+            sys.exit(1)
+
     # 1. Connect to the local server
     try:
         thisrepl = replication.ReplicationManager(realm, options.host,
@@ -791,13 +800,7 @@ def del_master_managed(realm, hostname, options):
     try:
         api.Command.server_del(hostname_u)
     except errors.NotFound:
-        if not options.cleanup:
-            print("{hostname} does not exist.".format(hostname=hostname))
-            print("Please specify an actual server or add the --cleanup "
-                  "option to force clean up.")
-            sys.exit(1)
-        else:
-            print("Server entry already deleted: %s" % (hostname))
+        print("Server entry already deleted: %s" % (hostname))
 
     # 6. Cleanup
     try:
-- 
2.4.3

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to