Actually kill the tests sshd process. Provide a custom know_hosts file to use.

This commit is contained in:
Pedro Algarvio 2014-10-30 06:45:52 +00:00
parent 53dae1b3e4
commit 17564057c9

View file

@ -13,6 +13,7 @@ import copy
import json
import time
import errno
import signal
import shutil
import pprint
import logging
@ -400,8 +401,10 @@ class TestDaemon(object):
ssh_config.write('HostKey {0}\n'.format(server_dsa_priv_key_file))
ssh_config.write('HostKey {0}\n'.format(server_ecdsa_priv_key_file))
ssh_config.write('HostKey {0}\n'.format(server_ed25519_priv_key_file))
self.sshd_pidfile = os.path.join(TMP_CONF_DIR, 'sshd.pid')
self.sshd_process = subprocess.Popen(
[sshd, '-f', 'sshd_config'],
[sshd, '-f', 'sshd_config', '-oPidFile={0}'.format(self.sshd_pidfile)],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True,
@ -440,6 +443,10 @@ class TestDaemon(object):
running_tests_user = pwd.getpwuid(os.getuid()).pw_name
master_opts = salt.config._read_conf_file(os.path.join(CONF_DIR, 'master'))
master_opts['user'] = running_tests_user
tests_know_hosts_file = os.path.join(TMP_CONF_DIR, 'salt_ssh_known_hosts')
with salt.utils.fopen(tests_know_hosts_file, 'w') as known_hosts:
known_hosts.write('')
master_opts['known_hosts_file'] = tests_know_hosts_file
minion_config_path = os.path.join(CONF_DIR, 'minion')
minion_opts = salt.config._read_conf_file(minion_config_path)
@ -715,8 +722,14 @@ class TestDaemon(object):
if hasattr(self, 'sshd_process'):
try:
self.sshd_process.kill()
except OSError:
pass
except OSError as exc:
if exc.errno != 3:
raise
try:
os.kill(int(open(self.sshd_pidfile).read()), signal.SIGKILL)
except OSError as exc:
if exc.errno != 3:
raise
def _exit_mockbin(self):
path = os.environ.get('PATH', '')