-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
package_tests: Invoke tests according to the specification
Lets invoke tests according to the specification in the following document section 1.7.2 https://fedoraproject.org/wiki/Changes/InvokingTests
- Loading branch information
1 parent
849ea90
commit f431f1f
Showing
2 changed files
with
94 additions
and
104 deletions.
There are no files selected for viewing
92 changes: 48 additions & 44 deletions
92
config/Dockerfiles/package_tests/ansible/ansible_package_test.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,54 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
# This script requires that the docker run mounts the artifacts | ||
# dir to /tmp/artifacts, the ansible inventory file to /tmp/inventory, | ||
# and the ssh private key to /tmp/ssh_key, so mount some dir with | ||
# the inventory and ssh_key to /tmp and expect artifacts there | ||
# Invoke tests according to section 1.7.2 here: | ||
# https://fedoraproject.org/wiki/Changes/InvokingTests | ||
|
||
# Check if there is an upstream first repo for this package | ||
curl -s --head https://upstreamfirst.fedorainfracloud.org/${package} | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null | ||
if [ $? -ne 0 ]; then | ||
echo "No upstream repo for this package! Exiting..." | ||
exit 0 | ||
if [ -z "${package:-}" ]; then | ||
if [ $# -lt 1 ]; then | ||
echo "No package defined" | ||
exit 2 | ||
else | ||
package="$1" | ||
fi | ||
fi | ||
git clone https://upstreamfirst.fedorainfracloud.org/${package} | ||
if [[ $(grep "standard-test-beakerlib" ${package}/*.yml) == "" ]]; then | ||
echo "No beakerlib tests in this repo! Exiting.." | ||
exit 0 | ||
|
||
# Make sure we have or have downloaded the test subject | ||
if [ -z "${TEST_SUBJECTS:-}" ]; then | ||
echo "No subject defined" | ||
exit 2 | ||
elif ! file ${TEST_SUBJECTS:-}; then | ||
wget -q -O testimage.qcow2 ${TEST_SUBJECTS} | ||
export TEST_SUBJECTS=${PWD}/testimage.qcow2 | ||
fi | ||
if [ -f ${package}/tests.yml ]; then | ||
if [[ $(ansible-playbook --list-tags ${package}/tests.yml) != *"atomic"* ]]; then | ||
echo "No atomic tagged tests for this package!" | ||
exit 0 | ||
fi | ||
sed 's/hosts: localhost/hosts: all/g' ${package}/tests.yml > ${package}/test_atomic.yml | ||
ansible-playbook -i /tmp/inventory --private-key=/tmp/ssh_key --tags=atomic --start-at-task='Define remote_artifacts if it is not already defined' ${package}/test_atomic.yml | ||
exit $? | ||
# All code from here down is for legacy purposes and does not | ||
# guarantee the tests running are meant to pass on atomic host | ||
elif [ -f ${package}/test_local.yml ]; then | ||
sed 's/hosts: localhost/hosts: all/g' ${package}/test_local.yml > ${package}/test_atomic.yml | ||
else | ||
# Write test_atomic.yml header | ||
cat << EOF > ${package}/test_atomic.yml | ||
--- | ||
- hosts: all | ||
roles: | ||
- role: standard-test-beakerlib | ||
tests: | ||
EOF | ||
# Find the tests | ||
if [ $(find ${package} -name "runtest.sh" | wc -l) -eq 0 ]; then | ||
echo "No runtest.sh files found in package's repo. Exiting..." | ||
exit 1 | ||
fi | ||
for test in $(find ${package} -name "runtest.sh"); do | ||
echo " - $test" >> ${package}/test_atomic.yml | ||
done | ||
|
||
# Check out the dist-git repository for this package | ||
if ! git clone https://src.fedoraproject.org/rpms/${package}; then | ||
echo "No dist-git repo for this package! Exiting..." | ||
exit 0 | ||
fi | ||
ansible-playbook -i /tmp/inventory --private-key=/tmp/ssh_key --start-at-task='Define remote_artifacts if it is not already defined' ${package}/test_atomic.yml | ||
exit $? | ||
|
||
# The specification requires us to invoke the tests in the checkout directory | ||
cd ${package} | ||
|
||
# Check out the appropriate branch | ||
# TODO: Where does this branch come from, currently f26? | ||
git checkout f26 | ||
|
||
# The test artifacts must be an empty directory | ||
TEST_ARTIFACTS=${TEST_ARTIFACTS:-$PWD/artifacts} | ||
rm -rf $TEST_ARTIFACTS | ||
export TEST_ARTIFACTS | ||
|
||
# The inventory must be from the test if present (file or directory) or defaults | ||
ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory) | ||
export ANSIBLE_INVENTORY | ||
|
||
# Invoke each playbook according to the specification | ||
for playbook in tests/tests*.yml; do | ||
if [ -f ${playbook} ]; then | ||
ansible-playbook --inventory=$ANSIBLE_INVENTORY \ | ||
--extra-vars "subjects=$TEST_SUBJECTS" --extra-vars "artifacts=$TEST_ARTIFACTS" \ | ||
--tags atomic ${playbook} | ||
fi | ||
done |
106 changes: 46 additions & 60 deletions
106
config/Dockerfiles/package_tests/image/image_package_test.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,54 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
# Check if there is an upstream first repo for this package | ||
curl -s --head https://upstreamfirst.fedorainfracloud.org/${package} | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null | ||
if [ $? -ne 0 ]; then | ||
echo "No upstream repo for this package! Exiting..." | ||
exit 0 | ||
fi | ||
git clone https://upstreamfirst.fedorainfracloud.org/${package} | ||
if [[ $(grep "standard-test-beakerlib" ${package}/*.yml) == "" ]]; then | ||
echo "No beakerlib tests in this repo! Exiting.." | ||
exit 0 | ||
# Invoke tests according to section 1.7.2 here: | ||
# https://fedoraproject.org/wiki/Changes/InvokingTests | ||
|
||
if [ -z "${package:-}" ]; then | ||
if [ $# -lt 1 ]; then | ||
echo "No package defined" | ||
exit 2 | ||
else | ||
package="$1" | ||
fi | ||
fi | ||
if [[ $(file ${TEST_SUBJECTS}) == *"No such file or directory"* ]]; then | ||
|
||
# Make sure we have or have downloaded the test subject | ||
if [ -z "${TEST_SUBJECTS:-}" ]; then | ||
echo "No subject defined" | ||
exit 2 | ||
elif ! file ${TEST_SUBJECTS:-}; then | ||
wget -q -O testimage.qcow2 ${TEST_SUBJECTS} | ||
export TEST_SUBJECTS=${PWD}/testimage.qcow2 | ||
fi | ||
if [ -f ${package}/tests.yml ]; then | ||
if [[ $(ansible-playbook --list-tags ${package}/tests.yml) != *"atomic"* ]]; then | ||
echo "No atomic tagged tests for this package!" | ||
exit 0 | ||
fi | ||
# Execute the tests | ||
ansible-playbook --tags atomic ${package}/tests.yml | ||
exit $? | ||
|
||
# Check out the dist-git repository for this package | ||
if ! git clone https://src.fedoraproject.org/rpms/${package}; then | ||
echo "No dist-git repo for this package! Exiting..." | ||
exit 0 | ||
fi | ||
# Note: The below code should work, but we are not calling it. | ||
# The reason for this is that if repos do not have a tests.yml file, | ||
# then they have not been modified since test tagging came out, | ||
# which means we have no idea if the tests are meant to run/will pass | ||
# on atomic hosts. | ||
|
||
#else | ||
# # Write test_cloud.yml file | ||
# cat << EOF > test_cloud.yml | ||
#--- | ||
#- hosts: localhost | ||
# vars: | ||
# artifacts: ./ | ||
# playbooks: ./${package}/test_local.yml | ||
# vars_prompt: | ||
# - name: subjects | ||
# prompt: "A QCow2/raw test subject file" | ||
# private: no | ||
# | ||
# roles: | ||
# - standard-test-cloud | ||
#EOF | ||
# # Write test_local.yml header | ||
# cat << EOF > ${package}/test_local.yml | ||
#--- | ||
#- hosts: all | ||
# roles: | ||
# - role: standard-test-beakerlib | ||
# tests: | ||
#EOF | ||
# # Find the tests | ||
# if [ $(find ${package} -name "runtest.sh" | wc -l) -eq 0 ]; then | ||
# echo "No runtest.sh files found in package's repo. Exiting..." | ||
# exit 1 | ||
# fi | ||
# for test in $(find ${package} -name "runtest.sh"); do | ||
# echo " - $test" >> ${package}/test_local.yml | ||
# done | ||
# # Execute the tests legacy method | ||
# ansible-playbook test_cloud.yml -e subjects=$TEST_SUBJECTS -e artifacts=$TEST_ARTIFACTS | ||
# exit $? | ||
#fi | ||
# The specification requires us to invoke the tests in the checkout directory | ||
cd ${package} | ||
|
||
# Check out the appropriate branch | ||
# TODO: Where does this branch come from, currently f26? | ||
git checkout f26 | ||
|
||
# The test artifacts must be an empty directory | ||
TEST_ARTIFACTS=${TEST_ARTIFACTS:-$PWD/artifacts} | ||
rm -rf $TEST_ARTIFACTS | ||
export TEST_ARTIFACTS | ||
|
||
# The inventory must be from the test if present (file or directory) or defaults | ||
ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory) | ||
export ANSIBLE_INVENTORY | ||
|
||
# Invoke each playbook according to the specification | ||
for playbook in tests/tests*.yml; do | ||
if [ -f ${playbook} ]; then | ||
ansible-playbook --inventory=$ANSIBLE_INVENTORY \ | ||
--extra-vars "subjects=$TEST_SUBJECTS" --extra-vars "artifacts=$TEST_ARTIFACTS" \ | ||
--tags atomic ${playbook} | ||
fi | ||
done |