Bypass ipa-replica-conncheck ssh tests when ssh is not installed

https://fedorahosted.org/freeipa/ticket/3777
This commit is contained in:
Nathaniel McCallum 2013-08-07 15:40:28 -04:00 committed by Petr Viktorin
parent ed3791d2f3
commit fb95f379f0

View File

@ -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: