From c26a5569294899a2d34aa412deba54921f5ad8b9 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 6 Jul 2017 00:47:28 -0700 Subject: [PATCH] Add check for known_hosts changing during tests. (#26470) * Add check for known_hosts changing during tests. * Don't use known hosts file for delegate_to test. --- test/integration/targets/delegate_to/runme.sh | 3 ++- test/runner/lib/executor.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/test/integration/targets/delegate_to/runme.sh b/test/integration/targets/delegate_to/runme.sh index 782ec0902e2..ce2c0889cc9 100755 --- a/test/integration/targets/delegate_to/runme.sh +++ b/test/integration/targets/delegate_to/runme.sh @@ -2,4 +2,5 @@ set -eux -ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook test_delegate_to.yml -i ../../inventory -v "$@" +ANSIBLE_SSH_ARGS='-C -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null' \ + ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook test_delegate_to.yml -i ../../inventory -v "$@" diff --git a/test/runner/lib/executor.py b/test/runner/lib/executor.py index c08cb174115..308c8e61856 100644 --- a/test/runner/lib/executor.py +++ b/test/runner/lib/executor.py @@ -14,6 +14,7 @@ import stat import random import string import atexit +import hashlib import lib.pytar import lib.thread @@ -1199,6 +1200,7 @@ class EnvironmentDescription(object): pip_paths = dict((v, find_executable('pip%s' % v, required=False)) for v in sorted(versions)) pip_versions = dict((v, self.get_version([pip_paths[v], '--version'])) for v in sorted(pip_paths) if pip_paths[v]) pip_interpreters = dict((v, self.get_shebang(pip_paths[v])) for v in sorted(pip_paths) if pip_paths[v]) + known_hosts_hash = self.get_hash(os.path.expanduser('~/.ssh/known_hosts')) self.data = dict( python_paths=python_paths, @@ -1206,6 +1208,7 @@ class EnvironmentDescription(object): pip_paths=pip_paths, pip_versions=pip_versions, pip_interpreters=pip_interpreters, + known_hosts_hash=known_hosts_hash, ) def __str__(self): @@ -1260,6 +1263,22 @@ class EnvironmentDescription(object): with open(path) as script_fd: return script_fd.readline() + @staticmethod + def get_hash(path): + """ + :type path: str + :rtype: str | None + """ + if not os.path.exists(path): + return None + + file_hash = hashlib.md5() + + with open(path, 'rb') as file_fd: + file_hash.update(file_fd.read()) + + return file_hash.hexdigest() + class NoChangesDetected(ApplicationWarning): """Exception when change detection was performed, but no changes were found."""