Remove legacy test code.

This commit is contained in:
Matt Clay 2016-12-06 16:18:40 -05:00
commit 580401c02b
27 changed files with 0 additions and 1102 deletions

View file

@ -1,7 +0,0 @@
#!/bin/bash -eux
set -o pipefail
source_root=$(python -c "from os import path; print(path.abspath(path.join(path.dirname('$0'), '../../..')))")
"${source_root}/test/utils/shippable/${TEST}.sh" 2>&1 | gawk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }'

View file

@ -1 +0,0 @@
yamllint

View file

@ -1,31 +0,0 @@
#!/bin/bash -eux
source_root=$(python -c "from os import path; print(path.abspath(path.join(path.dirname('$0'), '../../..')))")
install_deps="${INSTALL_DEPS:-}"
cd "${source_root}"
if [ "${install_deps}" != "" ]; then
apt-add-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports universe'
apt-get update -qq
apt-get install shellcheck
pip install -r "${source_root}/test/utils/shippable/code-smell-requirements.txt" --upgrade
pip list
fi
yamllint ./test
test/sanity/code-smell/replace-urlopen.sh
test/sanity/code-smell/use-compat-six.sh
test/sanity/code-smell/boilerplate.sh
test/sanity/code-smell/required-and-default-attributes.sh
test/sanity/code-smell/shebang.sh
test/sanity/code-smell/line-endings.sh
test/sanity/code-smell/empty-init.sh
test/sanity/code-smell/no-basestring.sh
shellcheck \
test/integration/targets/*/*.sh \
test/utils/shippable/*.sh

View file

@ -1,288 +0,0 @@
#!/usr/bin/env python
# (c) 2016 Matt Clay <matt@mystile.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import os
import subprocess
import sys
from os import path
from argparse import ArgumentParser
import ansible.constants as C
from ansible.playbook import Playbook
from ansible.vars import VariableManager
from ansible.parsing.dataloader import DataLoader
def main():
"""Generate an integration test script for changed modules."""
C.DEPRECATION_WARNINGS = False
C.DEFAULT_ROLES_PATH = [os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'..', '..', '..', 'integration', 'targets'))]
posix_targets = [
'non_destructive',
'destructive',
]
windows_targets = [
'test_win_group1',
'test_win_group2',
'test_win_group3',
]
parser = ArgumentParser(description='Generate an integration test script for changed modules.')
parser.add_argument('module_group', choices=['core', 'extras'], help='module group to test')
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='write verbose output to stderr')
parser.add_argument('--changes', dest='changes', default=None,
help='file listing changed paths (default: query git)')
parser.add_argument('--image', dest='image', default=os.environ.get('IMAGE'),
help='image to run tests with')
parser.add_argument('--privileged', dest='privileged', action='store_true',
default=os.environ.get('PRIVILEGED') == 'true',
help='run container in privileged mode')
parser.add_argument('--python3', dest='python3', action='store_true',
default=os.environ.get('PYTHON3', '') != '',
help='run tests using python3')
parser.add_argument('--platform', dest='platform', default=os.environ.get('PLATFORM'),
help='platform to run tests on')
parser.add_argument('--version', dest='version', default=os.environ.get('VERSION'),
help='version of platform to run tests on')
parser.add_argument('--output', dest='output', required=True,
help='path to write output script to')
args = parser.parse_args()
targets = posix_targets
if args.image is not None:
script = 'integration'
options = ''
if args.privileged:
options += ' PRIVILEGED=true'
if args.python3:
options += ' PYTHON3=1'
jobs = ['IMAGE=%s%s' % (args.image, options)]
elif args.platform is not None and args.version is not None:
script = 'remote'
jobs = ['PLATFORM=%s VERSION=%s' % (args.platform, args.version)]
if args.platform == 'windows':
targets = windows_targets
else:
raise Exception('job parameters not specified')
generate_test_commands(args.module_group, targets, script, args.output, jobs=jobs, verbose=args.verbose, changes=args.changes)
def generate_test_commands(module_group, targets, script, output, jobs=None, verbose=False, changes=None):
"""Generate test commands for the given module group and test targets.
Args:
module_group: The module group (core, extras) to examine.
targets: The test targets to examine.
script: The script used to execute the test targets.
output: The path to write the output script to.
jobs: The test jobs to execute, or None to auto-detect.
verbose: True to write detailed output to stderr.
changes: Path to file containing list of changed files, or None to query git.
"""
base_dir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', '..'))
job_config_path = path.join(base_dir, 'shippable.yml')
module_dir = os.path.join(base_dir, 'lib', 'ansible', 'modules', module_group)
if verbose:
print_stderr(' config: %s' % job_config_path)
print_stderr('modules: %s' % module_dir)
print_stderr('targets: %s' % ' '.join(targets))
print_stderr()
if changes is None:
paths_changed = get_changed_paths(module_dir)
else:
with open(changes, 'r') as f:
paths_changed = f.read().strip().split('\n')
if len(paths_changed) == 0:
print_stderr('No changes to files detected.')
exit()
if verbose:
dump_stderr('paths_changed', paths_changed)
modules_changed = get_modules(paths_changed)
if len(modules_changed) == 0:
print_stderr('No changes to modules detected.')
exit()
if verbose:
dump_stderr('modules_changed', modules_changed)
module_tags = get_module_test_tags(modules_changed)
if verbose:
dump_stderr('module_tags', module_tags)
available_tags = get_target_tags(base_dir, targets)
if verbose:
dump_stderr('available_tags', available_tags)
use_tags = module_tags & available_tags
if len(use_tags) == 0:
print_stderr('No tagged test roles found for changed modules.')
exit()
if verbose:
dump_stderr('use_tags', use_tags)
target = ' '.join(targets)
tags = ','.join(use_tags)
script_path = 'test/utils/shippable/%s.sh' % script
commands = ['TARGET="%s" TEST_FLAGS="-t %s" %s %s' % (target, tags, j, script_path) for j in jobs]
with open(output, 'w') as f:
f.writelines(commands)
f.write('\n')
def print_stderr(*args, **kwargs):
"""Print to stderr."""
print(*args, file=sys.stderr, **kwargs)
sys.stderr.flush()
def dump_stderr(label, l):
"""Write a label and list contents to stderr.
Args:
label: The label to print for this list.
l: The list to dump to stderr.
"""
print_stderr('[%s:%s]\n%s\n' % (label, len(l), '\n'.join(l)))
def get_target_tags(base_dir, targets):
"""Get role tags from the integration tests for the given test targets.
Args:
base_dir: The root of the ansible source code.
targets: The test targets to scan for tags.
Returns: Set of role tags.
"""
playbook_dir = os.path.join(base_dir, 'test', 'integration')
tags = set()
for target in targets:
playbook_path = os.path.join(playbook_dir, target + '.yml')
tags |= get_role_tags(playbook_path)
return tags
def get_role_tags(playbook_path):
"""Get role tags from the given playbook.
Args:
playbook_path: Path to the playbook to get role tags from.
Returns: Set of role tags.
"""
variable_manager = VariableManager()
loader = DataLoader()
playbook = Playbook.load(playbook_path, variable_manager=variable_manager, loader=loader)
tags = set()
for play in playbook.get_plays():
for role in play.get_roles():
for tag in role.tags:
tags.add(tag)
return tags
def get_changed_paths(git_root, branch='devel'):
"""Get file paths changed in current branch vs given branch.
Args:
git_root: The root of the git clone.
branch: The branch to compare against (default: devel)
Returns: List of file paths changed.
"""
paths = subprocess.check_output(['git', 'diff', '--name-only', branch], cwd=git_root).strip().split('\n')
return paths
def get_modules(paths):
"""Get module names from file paths.
Args:
paths: List of paths to extract module names from.
Returns: List of module names.
"""
module_extensions = [
'.py',
'.ps1',
]
modules = [path.splitext(path.basename(c))[0].strip('_') for c in paths if
path.splitext(c)[1] in module_extensions and
'/' in c and
not c.startswith('test/') and
not path.basename(c)[0] == '__init__.py']
return modules
def get_module_test_tags(modules):
"""Get test tags from module names.
Args:
modules: List of module names to get test tags for.
Returns: Set of test tags.
"""
tags = set(['test_' + m for m in modules])
return tags
if __name__ == '__main__':
main()

View file

@ -1,2 +0,0 @@
jinja2
pyyaml

View file

@ -1,169 +0,0 @@
#!/bin/sh
set -eux
env
container="${PLATFORM}"
build_dir="${HOME}/ansible"
test_target="${TARGET:-}"
test_flags="${TEST_FLAGS:-}"
# Force ansible color output by default.
# To disable color force mode use FORCE_COLOR=0
force_color="${FORCE_COLOR:-1}"
# FIXME: these tests fail
skip_tags='test_service,test_postgresql,test_mysql_db,test_mysql_user,test_mysql_variables,test_uri,test_get_url'
cd ~/
make="make"
if [ "${container}" = "freebsd" ]; then
make="gmake"
pkg install -y curl
if [ ! -f bootstrap.sh ]; then
curl "https://raw.githubusercontent.com/mattclay/ansible-hacking/master/bootstrap.sh" -o bootstrap.sh
fi
chmod +x bootstrap.sh
./bootstrap.sh pip -y -q
# tests require these packages
# TODO: bootstrap.sh should be capable of installing these
pkg install -y \
bash \
devel/ruby-gems \
gtar \
mercurial \
rsync \
ruby \
subversion \
sudo \
zip
fi
# TODO: bootstrap.sh should install these
pip install \
junit-xml \
virtualenv \
jmespath
# Tests assume loopback addresses other than 127.0.0.1 will work.
# Add aliases for loopback addresses used by tests.
for i in 3 4 254; do
ifconfig lo0 alias "127.0.0.${i}" up
done
ifconfig lo0
# Since tests run as root, we also need to be able to ssh to localhost as root.
sed -i '' 's/^# *PermitRootLogin.*$/PermitRootLogin yes/;' /etc/ssh/sshd_config
if [ "${container}" = "freebsd" ]; then
# Restart sshd for configuration changes and loopback aliases to work.
service sshd restart
fi
# Generate our ssh key and add it to our authorized_keys file.
# We also need to add localhost's server keys to known_hosts.
if [ ! -f "${HOME}/.ssh/id_rsa.pub" ]; then
ssh-keygen -q -t rsa -N '' -f "${HOME}/.ssh/id_rsa"
cp "${HOME}/.ssh/id_rsa.pub" "${HOME}/.ssh/authorized_keys"
for key in /etc/ssh/ssh_host_*_key.pub; do
pk=$(cat "${key}")
echo "localhost ${pk}" >> "${HOME}/.ssh/known_hosts"
done
fi
repo_name="${REPO_NAME:-ansible}"
if [ -d "${build_dir}" ]; then
cd "${build_dir}"
elif [ "${repo_name}" = "ansible" ]; then
git clone "${REPOSITORY_URL:-https://github.com/ansible/ansible.git}" "${build_dir}"
cd "${build_dir}"
if [ "${PULL_REQUEST:-false}" = "false" ]; then
git checkout -f "${BRANCH:-devel}" --
git reset --hard "${COMMIT:-HEAD}"
else
git fetch origin "pull/${PULL_REQUEST}/head"
git checkout -f FETCH_HEAD
git merge "origin/${BRANCH}"
fi
git submodule init
git submodule sync
git submodule update
else
case "${repo_name}" in
"ansible-modules-core")
this_module_group="core"
;;
"ansible-modules-extras")
this_module_group="extras"
;;
*)
echo "Unsupported repo name: ${repo_name}"
exit 1
;;
esac
git clone "https://github.com/ansible/ansible.git" "${build_dir}"
cd "${build_dir}"
git submodule init
git submodule sync
git submodule update
cd "${build_dir}/lib/ansible/modules/${this_module_group}"
if [ "${PULL_REQUEST:-false}" = "false" ]; then
echo "Only pull requests are supported for module repositories."
exit
else
git fetch origin "pull/${PULL_REQUEST}/head"
git checkout -f FETCH_HEAD
git merge "origin/${BRANCH}"
fi
cd "${build_dir}"
fi
set +u
. hacking/env-setup
set -u
cd test/integration
if [ "${container}" = "osx" ]; then
# FIXME: these test targets fail
sed -i '' 's/ test_gathering_facts / /;' Makefile
# FIXME: these tests fail
skip_tags="${skip_tags},test_iterators,test_git"
# test_template assumes the group 'root' exists if this variable is not set
export GROUP=wheel
fi
# TODO: support httptester via reverse ssh tunnel
rm -rf "/tmp/shippable"
mkdir -p "/tmp/shippable/testresults"
# TODO: enable jail test
# shellcheck disable=SC2086
JUNIT_OUTPUT_DIR="/tmp/shippable/testresults" \
ANSIBLE_FORCE_COLOR="${force_color}" \
ANSIBLE_CALLBACK_WHITELIST=junit \
TEST_FLAGS="-e ansible_python_interpreter=/usr/local/bin/python2 --skip-tags '${skip_tags}' ${test_flags}" \
container="${container}" \
${make} ${test_target}

View file

@ -1,8 +0,0 @@
cryptography
junit-xml
ndg-httpsclient
pyasn1
pyopenssl
requests
pywinrm
xmltodict

View file

@ -1,191 +0,0 @@
#!/bin/bash -eux
set -o pipefail
source_root=$(python -c "from os import path; print(path.abspath(path.join(path.dirname('$0'), '../../..')))")
test_flags="${TEST_FLAGS:-}"
test_platform="${PLATFORM}"
test_version="${VERSION}"
test_target=(${TARGET})
instance_id="${INSTANCE_ID:-}"
start_instance=
if [ "${instance_id}" == "" ]; then
instance_id=$(python -c 'import uuid; print(uuid.uuid4())')
start_instance=1
fi
# Set this to a non-empty value to skip immediate termination of the remote instance after tests finish.
# The remote instance will still be auto-terminated when the remote time limit is reached.
keep_instance="${KEEP_INSTANCE:-}"
# Force ansible color output by default.
# To disable color force mode use FORCE_COLOR=0
force_color="${FORCE_COLOR:-1}"
if [ "${SHIPPABLE:-}" = "true" ]; then
test_auth="shippable"
else
test_auth="remote"
fi
case "${test_platform}" in
"windows")
ci_endpoint="https://14blg63h2i.execute-api.us-east-1.amazonaws.com"
;;
"freebsd")
ci_endpoint="https://14blg63h2i.execute-api.us-east-1.amazonaws.com"
;;
"osx")
ci_endpoint="https://osx.testing.ansible.com"
;;
*)
echo "unsupported platform: ${test_platform}"
exit 1
;;
esac
env
case "${test_platform}" in
"windows")
args=""
;;
*)
ssh_key="${HOME}/.ssh/id_rsa"
args="--public-key=${ssh_key}.pub"
if [ ! -f "${ssh_key}.pub" ]; then
ssh-keygen -q -t rsa -N '' -f "${ssh_key}"
fi
;;
esac
pre_cleanup=
function cleanup
{
if [ "${pre_cleanup}" != '' ]; then
"${pre_cleanup}"
fi
if [ "${keep_instance}" = '' ]; then
"${source_root}/test/utils/shippable/ansible-core-ci" --endpoint "${ci_endpoint}" -v stop "${instance_id}"
fi
echo "instance_id: ${instance_id}"
}
trap cleanup EXIT INT TERM
if [ ${start_instance} ]; then
# shellcheck disable=SC2086
"${source_root}/test/utils/shippable/ansible-core-ci" --endpoint "${ci_endpoint}" -v \
start --id "${instance_id}" "${test_auth}" "${test_platform}" "${test_version}" ${args}
fi
pip install "${source_root}" --upgrade
pip install -r "${source_root}/test/utils/shippable/remote-requirements.txt" --upgrade
pip list
cd "${source_root}"
source hacking/env-setup
cd test/integration
case "${test_platform}" in
"windows")
inventory_template="${source_root}/test/integration/inventory.winrm.template"
inventory_file="${source_root}/test/integration/inventory.winrm"
ping_module="win_ping"
ping_host="windows"
test_function="test_windows"
;;
*)
inventory_template="${source_root}/test/integration/inventory.remote.template"
inventory_file="${source_root}/test/integration/inventory.remote"
ping_module="ping"
ping_host="remote"
test_function="test_remote"
;;
esac
"${source_root}/test/utils/shippable/ansible-core-ci" --endpoint "${ci_endpoint}" -v \
get "${instance_id}" \
--template "${inventory_template}" \
> "${inventory_file}" \
# hack to make sure instance is responding before beginning tests
n=60
for i in $(seq 1 ${n}); do
echo "Verifying host is responding ($i of $n)"
if \
ANSIBLE_SSH_ARGS='' \
ANSIBLE_HOST_KEY_CHECKING=False \
ANSIBLE_FORCE_COLOR="${force_color}" \
ansible -m "${ping_module}" -i "${inventory_file}" "${ping_host}"; then
break
fi
sleep 5
done
test_windows() {
JUNIT_OUTPUT_DIR="${source_root}/shippable/testresults" \
ANSIBLE_FORCE_COLOR="${force_color}" \
ANSIBLE_CALLBACK_WHITELIST=junit \
TEST_FLAGS="${test_flags}" \
LC_ALL=en_US.utf-8 \
make "${test_target[@]}"
}
test_remote() {
endpoint=$("${source_root}/test/utils/shippable/ansible-core-ci" --endpoint "${ci_endpoint}" get \
"${instance_id}" \
--template <(echo "@ansible_user@@ansible_host"))
ssh_port=$("${source_root}/test/utils/shippable/ansible-core-ci" --endpoint "${ci_endpoint}" get \
"${instance_id}" \
--template <(echo "@ansible_port"))
(
cat <<EOF
env \
PLATFORM='${test_platform}' \
REPOSITORY_URL='${REPOSITORY_URL:-}' \
REPO_NAME='${REPO_NAME:-}' \
PULL_REQUEST='${PULL_REQUEST:-}' \
BRANCH='${BRANCH:-}' \
COMMIT='${COMMIT:-}' \
FORCE_COLOR='${force_color}' \
TARGET='${test_target[*]}' \
TEST_FLAGS='${test_flags}' \
/bin/sh -e /tmp/remote-integration.sh
EOF
) > /tmp/remote-script.sh
(
cat <<EOF
put "${source_root}/test/utils/shippable/remote-integration.sh" "/tmp/remote-integration.sh"
put "/tmp/remote-script.sh" "/tmp/remote-script.sh"
EOF
) | sftp -b - -o StrictHostKeyChecking=no -P "${ssh_port}" "${endpoint}"
pre_cleanup=test_remote_cleanup
case "${test_platform}" in
"osx")
become="sudo -i PATH=/usr/local/bin:\$PATH"
;;
*)
become="su -l root -c"
;;
esac
ssh -p "${ssh_port}" "${endpoint}" "${become}" "'chmod +x /tmp/remote-script.sh; /tmp/remote-script.sh'"
}
test_remote_cleanup() {
scp -r -P "${ssh_port}" "${endpoint}:/tmp/shippable" "${source_root}"
}
"${test_function}"

View file

@ -1,6 +0,0 @@
tox
pyyaml
jinja2
setuptools
mock
voluptuous==0.8.8

View file

@ -1,32 +0,0 @@
#!/bin/bash -eux
source_root=$(python -c "from os import path; print(path.abspath(path.join(path.dirname('$0'), '../../..')))")
install_deps="${INSTALL_DEPS:-}"
cd "${source_root}"
if [ "${TOXENV}" = 'py24' ]; then
if [ "${install_deps}" != "" ]; then
add-apt-repository ppa:fkrull/deadsnakes && apt-get update -qq && apt-get install python2.4 -qq
fi
python2.4 -V
python2.4 -m compileall -fq -x 'module_utils/(a10|rax|openstack|cloud|ec2|gce|lxd|docker_common|azure_rm_common|vca|vmware|gcp|gcdns).py' lib/ansible/module_utils
else
if [ "${install_deps}" != "" ]; then
pip install -r "${source_root}/test/utils/shippable/sanity-requirements.txt" --upgrade
pip list
fi
xunit_dir="${source_root}/shippable/testresults"
coverage_dir="${source_root}/shippable/codecoverage"
mkdir -p "${xunit_dir}"
mkdir -p "${coverage_dir}"
xunit_file="${xunit_dir}/nosetests-xunit.xml"
coverage_file="${coverage_dir}/nosetests-coverage.xml"
TOX_TESTENV_PASSENV=NOSETESTS NOSETESTS="nosetests --with-xunit --xunit-file='${xunit_file}' --cover-xml --cover-xml-file='${coverage_file}'" tox
fi