In the interest of getting ticket 3777 moving, I have created the
attached patch. It is *NOT* tested as I don't have a replica setup at
the moment and won't have time until after Flock. If someone else has a
replica setup and has a few minutes to burn, you are welcome to test the
patch.

Nathaniel
>From 71c24d15b1ce9663a456131bb278d45d34b92702 Mon Sep 17 00:00:00 2001
From: Nathaniel McCallum <npmccal...@redhat.com>
Date: Wed, 7 Aug 2013 15:40:28 -0400
Subject: [PATCH] Bypass ipa-replica-conncheck ssh tests when ssh is not
 installed

https://fedorahosted.org/freeipa/ticket/3777
---
 install/tools/ipa-replica-conncheck | 60 +++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/install/tools/ipa-replica-conncheck b/install/tools/ipa-replica-conncheck
index 583b5d5e75090483ddd9549862de04ea30fe820f..af91930fce6b303ddddf492f982034c4d0296fac 100755
--- a/install/tools/ipa-replica-conncheck
+++ b/install/tools/ipa-replica-conncheck
@@ -36,6 +36,7 @@ import time
 import threading
 import errno
 from socket import SOCK_STREAM, SOCK_DGRAM
+import distutils.spawn
 
 CONNECT_TIMEOUT = 5
 RESPONDERS = [ ]
@@ -43,6 +44,32 @@ QUIET = False
 CCACHE_FILE = "/etc/ipa/.conncheck_ccache"
 KRB5_CONFIG = None
 
+class SshExec(object):
+    def __init__(self, user, addr):
+        self.user = user
+        self.addr = addr
+        self.cmd = distutils.spawn.find_executable('ssh')
+    
+    def __call__(self, command, verbose=False):
+        # Bail if ssh is not installed
+        if self.cmd is None:
+            print "WARNING: ssh not installed, skipping ssh test"
+            return ('', '', 0)
+        
+        tmpf = tempfile.NamedTemporaryFile()
+        cmd = [
+            self.cmd,
+            '-o StrictHostKeychecking=no',
+            '-o UserKnownHostsFile=%s' % tmpf.name,
+            '%s@%s' % (self.user, self.addr), command
+        ]
+        if verbose:
+            cmd.insert(1, '-v')
+            
+        env = {'KRB5_CONFIG': KRB5_CONFIG, 'KRB5CCNAME': CCACHE_FILE},
+        return ipautil.run(cmd, env=env, raiseonerr=False)
+
+
 class CheckedPort(object):
     def __init__(self, port, port_type, description):
         self.port = port
@@ -359,32 +386,10 @@ def main():
             if returncode != 0:
                 raise RuntimeError("Could not get ticket for master server: %s" % stderr)
 
+            ssh = SshExec(user, options.master)
+            
             print_info("Check SSH connection to remote master")
-
-            remote_addr = "%s@%s" % (user, options.master)
-            temp_known_hosts = tempfile.NamedTemporaryFile()
-
-            def run_ssh(command, verbose=False):
-                """Run given command on remote master over SSH
-
-                Return stdout, stderr, returncode
-                """
-                ssh_command = ['ssh']
-                if verbose:
-                    ssh_command.append('-v')
-                ssh_command += [
-                    '-o StrictHostKeychecking=no',
-                    '-o UserKnownHostsFile=%s' % temp_known_hosts.name,
-                    remote_addr, command
-                ]
-                return ipautil.run(
-                    ssh_command,
-                    env={'KRB5_CONFIG': KRB5_CONFIG,
-                         'KRB5CCNAME' : CCACHE_FILE},
-                    raiseonerr=False)
-
-            stdout, stderr, returncode = run_ssh('echo OK', verbose=True)
-
+            stdout, stderr, returncode = ssh('echo OK', verbose=True)
             if returncode != 0:
                 print 'Could not SSH into remote host. Error output:'
                 for line in stderr.splitlines():
@@ -392,13 +397,10 @@ def main():
                 raise RuntimeError('Could not SSH to remote host.')
 
             print_info("Execute check on remote master")
-
-            stdout, stderr, returncode = run_ssh(
+            stdout, stderr, returncode = ssh(
                 "/usr/sbin/ipa-replica-conncheck " +
                     " ".join(remote_check_opts))
-
             print_info(stdout)
-
             if returncode != 0:
                 raise RuntimeError("Remote master check failed with following error message(s):\n%s" % stderr)
         else:
-- 
1.8.3.1

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

Reply via email to