From fb95f379f0a540971212152d389457604502b029 Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Wed, 7 Aug 2013 15:40:28 -0400 Subject: 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(-) (limited to 'install/tools/ipa-replica-conncheck') diff --git a/install/tools/ipa-replica-conncheck b/install/tools/ipa-replica-conncheck index 583b5d5e7..c861e30cf 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) - 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) + ssh = SshExec(user, options.master) + print_info("Check SSH connection to remote master") + 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: -- cgit