483b06
From 9303e3d0912e60b2069f7c5bad6b816ed8b033ef Mon Sep 17 00:00:00 2001
483b06
From: Stanislav Laznicka <slaznick@redhat.com>
483b06
Date: Wed, 5 Apr 2017 09:57:44 +0200
483b06
Subject: [PATCH] replicainstall: better client install exception handling
483b06
483b06
The exception handling of client install inside replica installation
483b06
was rather promiscuous, hungrily eating any possible exception thrown
483b06
at it. Scoped down the try-except block and reduced its promiscuity.
483b06
This change should improve the future development experience debugging
483b06
this part of the code.
483b06
483b06
https://pagure.io/freeipa/issue/6183
483b06
483b06
Reviewed-By: Tomas Krizek <tkrizek@redhat.com>
483b06
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
483b06
---
483b06
 ipaserver/install/server/replicainstall.py | 83 +++++++++++++++---------------
483b06
 1 file changed, 41 insertions(+), 42 deletions(-)
483b06
483b06
diff --git a/ipaserver/install/server/replicainstall.py b/ipaserver/install/server/replicainstall.py
483b06
index 383932b39b9ee99a7a5ce3275a5a7e02581b85b7..aa8e67f60b8abe591d55a907c409b584c74d4541 100644
483b06
--- a/ipaserver/install/server/replicainstall.py
483b06
+++ b/ipaserver/install/server/replicainstall.py
483b06
@@ -895,52 +895,51 @@ def install_check(installer):
483b06
 
483b06
 
483b06
 def ensure_enrolled(installer):
483b06
-    # Call client install script
483b06
-    service.print_msg("Configuring client side components")
483b06
+    args = [paths.IPA_CLIENT_INSTALL, "--unattended", "--no-ntp"]
483b06
+    stdin = None
483b06
+    nolog = []
483b06
+
483b06
+    if installer.domain_name:
483b06
+        args.extend(["--domain", installer.domain_name])
483b06
+    if installer.server:
483b06
+        args.extend(["--server", installer.server])
483b06
+    if installer.realm_name:
483b06
+        args.extend(["--realm", installer.realm_name])
483b06
+    if installer.host_name:
483b06
+        args.extend(["--hostname", installer.host_name])
483b06
+
483b06
+    if installer.password:
483b06
+        args.extend(["--password", installer.password])
483b06
+        nolog.append(installer.password)
483b06
+    else:
483b06
+        if installer.admin_password:
483b06
+            # Always set principal if password was set explicitly,
483b06
+            # the password itself gets passed directly via stdin
483b06
+            args.extend(["--principal", installer.principal or "admin"])
483b06
+            stdin = installer.admin_password
483b06
+        if installer.keytab:
483b06
+            args.extend(["--keytab", installer.keytab])
483b06
+
483b06
+    if installer.no_dns_sshfp:
483b06
+        args.append("--no-dns-sshfp")
483b06
+    if installer.ssh_trust_dns:
483b06
+        args.append("--ssh-trust-dns")
483b06
+    if installer.no_ssh:
483b06
+        args.append("--no-ssh")
483b06
+    if installer.no_sshd:
483b06
+        args.append("--no-sshd")
483b06
+    if installer.mkhomedir:
483b06
+        args.append("--mkhomedir")
483b06
+    if installer.force_join:
483b06
+        args.append("--force-join")
483b06
+
483b06
     try:
483b06
+        # Call client install script
483b06
+        service.print_msg("Configuring client side components")
483b06
         installer._enrollment_performed = True
483b06
-
483b06
-        args = [paths.IPA_CLIENT_INSTALL, "--unattended", "--no-ntp"]
483b06
-        stdin = None
483b06
-        nolog = []
483b06
-
483b06
-        if installer.domain_name:
483b06
-            args.extend(["--domain", installer.domain_name])
483b06
-        if installer.server:
483b06
-            args.extend(["--server", installer.server])
483b06
-        if installer.realm_name:
483b06
-            args.extend(["--realm", installer.realm_name])
483b06
-        if installer.host_name:
483b06
-            args.extend(["--hostname", installer.host_name])
483b06
-
483b06
-        if installer.password:
483b06
-            args.extend(["--password", installer.password])
483b06
-            nolog.append(installer.password)
483b06
-        else:
483b06
-            if installer.admin_password:
483b06
-                # Always set principal if password was set explicitly,
483b06
-                # the password itself gets passed directly via stdin
483b06
-                args.extend(["--principal", installer.principal or "admin"])
483b06
-                stdin = installer.admin_password
483b06
-            if installer.keytab:
483b06
-                args.extend(["--keytab", installer.keytab])
483b06
-
483b06
-        if installer.no_dns_sshfp:
483b06
-            args.append("--no-dns-sshfp")
483b06
-        if installer.ssh_trust_dns:
483b06
-            args.append("--ssh-trust-dns")
483b06
-        if installer.no_ssh:
483b06
-            args.append("--no-ssh")
483b06
-        if installer.no_sshd:
483b06
-            args.append("--no-sshd")
483b06
-        if installer.mkhomedir:
483b06
-            args.append("--mkhomedir")
483b06
-        if installer.force_join:
483b06
-            args.append("--force-join")
483b06
-
483b06
         ipautil.run(args, stdin=stdin, nolog=nolog, redirect_output=True)
483b06
         print()
483b06
-    except Exception:
483b06
+    except ipautil.CalledProcessError:
483b06
         raise ScriptError("Configuration of client side components failed!")
483b06
 
483b06
 
483b06
-- 
483b06
2.12.2
483b06