tests/ci: split regression tests

Regression test suite has grown considerably and is taking too long to
run with a single wrapper. Splitting them into individual standalone
tests instead and making them run in parallel.
This commit is contained in:
Jakub Rusz 2022-03-30 14:30:02 +02:00 committed by Alexander Todorov
parent b782b6cced
commit e1bb8ab47c
8 changed files with 88 additions and 112 deletions

View file

@ -4,11 +4,8 @@
# Get OS data.
source /usr/libexec/osbuild-composer-test/set-env-variables.sh
# Provision the software under test.
/usr/libexec/osbuild-composer-test/provision.sh
case "${ID}-${VERSION_ID}" in
"rhel-8.6" | "rhel-9.0" | "centos-9")
"rhel-8.6" | "rhel-9.0" | "centos-9" | "centos-8")
;;
*)
echo "$0 is not enabled for ${ID}-${VERSION_ID} skipping..."
@ -34,6 +31,7 @@ function get_build_info() {
}
# Provision the software under test.
/usr/libexec/osbuild-composer-test/provision.sh
BLUEPRINT_FILE=/tmp/blueprint.toml
COMPOSE_START=/tmp/compose-start.json
COMPOSE_INFO=/tmp/compose-info.json
@ -94,7 +92,10 @@ sudo composer-cli compose delete "${COMPOSE_ID}" >/dev/null
jq . "${COMPOSE_INFO}"
# Did the compose finish with success?
if [[ $COMPOSE_STATUS != FINISHED ]]; then
if [[ $COMPOSE_STATUS == FINISHED ]]; then
echo "Test passed!"
exit 0
else
echo "Something went wrong with the compose. 😢"
exit 1
fi

View file

@ -38,9 +38,7 @@ function generate_certificates {
sudo openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 365 -sha256
}
source /etc/os-release
ARCH=$(uname -m)
source /usr/libexec/osbuild-composer-test/set-env-variables.sh
# Skip if running on subscribed RHEL
if [[ "$ID" == rhel ]] && sudo subscription-manager status; then
@ -325,7 +323,10 @@ function try_image_build {
sudo journalctl -xe --unit "${WORKER_UNIT}"
# Did the compose finish with success?
if [[ $COMPOSE_STATUS != FINISHED ]]; then
if [[ $COMPOSE_STATUS == FINISHED ]]; then
echo "Test passed!"
exit 0
else
echo "Something went wrong with the compose. 😢"
exit 1
fi
@ -338,7 +339,7 @@ if [ -f "${REDHAT_REPO}" ];
then
echo "The ${REDHAT_REPO} file shouldn't exist, removing it for the test"
REDHAT_REPO_BACKUP="${REDHAT_REPO}.backup"
chattr -i ${REDHAT_REPO}
sudo chattr -i ${REDHAT_REPO}
sudo mv "${REDHAT_REPO}" "${REDHAT_REPO_BACKUP}"
fi
@ -369,7 +370,7 @@ CLIENT_CERT="/etc/pki/entitlement/0.pem"
sudo cp "${PKI_DIR}/ca1/client.key" "${CLIENT_KEY}"
sudo cp "${PKI_DIR}/ca1/client.crt" "${CLIENT_CERT}"
update-ca-trust
sudo update-ca-trust
# Allow httpd process to create network connections
sudo setsebool httpd_can_network_connect on

View file

@ -44,14 +44,14 @@ function cleanup {
set +eu
greenprint "Display httpd logs"
cat /var/log/httpd/access_log
cat /var/log/httpd/error_log
sudo cat /var/log/httpd/access_log
sudo cat /var/log/httpd/error_log
greenprint "Putting things back to their previous configuration"
if [ -n "${REDHAT_REPO}" ] && [ -n "${REDHAT_REPO_BACKUP}" ];
then
lsattr "${REDHAT_REPO}"
chattr -i "${REDHAT_REPO}"
sudo chattr -i "${REDHAT_REPO}"
sudo rm -f "${REDHAT_REPO}"
sudo mv "${REDHAT_REPO_BACKUP}" "${REDHAT_REPO}" || echo "no redhat.repo backup"
sudo mv "${REPOSITORY_OVERRIDE}.backup" "${REPOSITORY_OVERRIDE}" || echo "no repo override backup"
@ -66,8 +66,7 @@ function cleanup {
sudo systemctl stop httpd || echo "failed to stop httpd"
}
source /etc/os-release
ARCH=$(uname -m)
source /usr/libexec/osbuild-composer-test/set-env-variables.sh
# Skip if running on subscribed RHEL
if [[ "$ID" == rhel ]] && sudo subscription-manager status; then
@ -271,7 +270,7 @@ metadata_expire = 86400
enabled_metadata = 0
STOPHERE
chattr +i ${REDHAT_REPO}
sudo chattr +i ${REDHAT_REPO}
lsattr ${REDHAT_REPO}
cat ${REDHAT_REPO}
@ -363,7 +362,10 @@ function try_image_build {
sudo journalctl -xe --unit "${WORKER_UNIT}"
# Did the compose finish with success?
if [[ $COMPOSE_STATUS != FINISHED ]]; then
if [[ $COMPOSE_STATUS == FINISHED ]]; then
echo "Test passed!"
exit 0
else
echo "Something went wrong with the compose. 😢"
exit 1
fi

View file

@ -12,13 +12,10 @@
# Bug report: https://github.com/osbuild/osbuild-composer/issues/921
# Get OS data.
source /etc/os-release
# Provision the software under test.
/usr/libexec/osbuild-composer-test/provision.sh
source /usr/libexec/osbuild-composer-test/set-env-variables.sh
case "${ID}-${VERSION_ID}" in
"rhel-8.6" | "rhel-9.0" | "centos-9")
"rhel-8.6" | "rhel-9.0" | "centos-9" | "centos-8")
;;
*)
echo "$0 is not enabled for ${ID}-${VERSION_ID} skipping..."
@ -39,6 +36,7 @@ function get_build_info() {
}
# Provision the software under test.
/usr/libexec/osbuild-composer-test/provision.sh
BLUEPRINT_FILE=/tmp/blueprint.toml
COMPOSE_START=/tmp/compose-start.json
COMPOSE_INFO=/tmp/compose-info.json
@ -80,7 +78,10 @@ sudo composer-cli compose delete "${COMPOSE_ID}" >/dev/null
jq . "${COMPOSE_INFO}"
# Did the compose finish with success?
if [[ $COMPOSE_STATUS != FINISHED ]]; then
if [[ $COMPOSE_STATUS == FINISHED ]]; then
echo "Test passed!"
exit 0
else
echo "Something went wrong with the compose. 😢"
exit 1
fi

View file

@ -14,17 +14,19 @@
set -xeuo pipefail
# Provision the software under test.
BLUEPRINT_FILE=/tmp/blueprint.toml
COMPOSE_START=/tmp/compose-start.json
COMPOSE_INFO=/tmp/compose-info.json
source /usr/libexec/osbuild-composer-test/set-env-variables.sh
source /etc/os-release
if [[ "${ID}" == "fedora" ]]; then
echo "$0 is only enabled for rhel like systems; skipping..."
exit 0
fi
# Provision the software under test.
/usr/libexec/osbuild-composer-test/provision.sh
BLUEPRINT_FILE=/tmp/blueprint.toml
COMPOSE_START=/tmp/compose-start.json
COMPOSE_INFO=/tmp/compose-info.json
# Write a basic blueprint for our image.
tee "$BLUEPRINT_FILE" > /dev/null << EOF
name = "nss-devel"
@ -74,7 +76,10 @@ sudo composer-cli compose delete "${COMPOSE_ID}" >/dev/null
jq . "${COMPOSE_INFO}"
# Did the compose finish with success?
if [[ $COMPOSE_STATUS != FINISHED ]]; then
if [[ $COMPOSE_STATUS == FINISHED ]]; then
echo "Test passed!"
exit 0
else
echo "Something went wrong with the compose. 😢"
exit 1
fi

View file

@ -7,6 +7,18 @@
set -exuo pipefail
source /usr/libexec/osbuild-composer-test/set-env-variables.sh
# Only run this on x86 and rhel8 GA; since the container is based on the ubi
# container, and we use the weldr api
if [ "$ARCH" != "x86_64" ] || [ "$ID" != rhel ] || ! sudo subscription-manager status; then
echo "Test only supported on GA RHEL."
exit 0
fi
# Provision the software under test.
/usr/libexec/osbuild-composer-test/provision.sh
function get_build_info() {
key="$1"
fname="$2"
@ -153,9 +165,12 @@ tee "dnf-json-request.json" <<EOF
}
EOF
DNF_JSON_OUT=$(curl -d"@dnf-json-request.json" --unix-socket "$DNF_SOCK" http:/dump | jq '.packages | length')
DNF_JSON_OUT=$(sudo curl -d"@dnf-json-request.json" --unix-socket "$DNF_SOCK" http:/dump | jq '.packages | length')
# expect more than 1 package
if [ ! "$DNF_JSON_OUT" -gt "1" ]; then
echo "dnf-json endpoint didn't return list of packages"
exit 1
fi
echo "Test passed!"
exit 0

View file

@ -1,79 +0,0 @@
#!/bin/bash
set -euo pipefail
#
# script that servers as a base for all the regression tests
#
source /usr/libexec/osbuild-composer-test/set-env-variables.sh
TESTS_PATH=/usr/libexec/tests/osbuild-composer/
mkdir --parents /tmp/logs
LOGS_DIRECTORY=$(mktemp --directory --tmpdir=/tmp/logs)
PASSED_TESTS=()
FAILED_TESTS=()
TEST_CASES=(
"regression-excluded-dependency.sh"
"regression-include-excluded-packages.sh"
"regression-composer-works-behind-satellite.sh"
"regression-composer-works-behind-satellite-fallback.sh"
"regression-bigiso.sh"
)
# Print out a nice test divider so we know when tests stop and start.
test_divider () {
printf "%0.s-" {1..78} && echo
}
# Run a test case and store the result as passed or failed.
run_test_case () {
TEST_NAME=$(basename "$1")
echo
test_divider
echo "🏃🏻 Running test: ${TEST_NAME}"
test_divider
if sudo -E "${1}" -test.v | tee "${LOGS_DIRECTORY}"/"${TEST_NAME}".log; then
PASSED_TESTS+=("$TEST_NAME")
else
FAILED_TESTS+=("$TEST_NAME")
fi
test_divider
echo
}
# Provision the software under test.
/usr/libexec/osbuild-composer-test/provision.sh
ARCH=$(uname -m)
# Only run this on x86 and rhel8 GA; since the container is based on the ubi
# container, and we use the weldr api
if [ "$ARCH" = "x86_64" ] && [ "$ID" = rhel ] && sudo subscription-manager status; then
# Always run this one last as it force-installs an older worker
TEST_CASES+=("regression-old-worker-new-composer.sh")
fi
# Run test cases common for all distros.
for TEST_CASE in "${TEST_CASES[@]}"; do
run_test_case ${TESTS_PATH}/"$TEST_CASE"
done
# Print a report of the test results.
test_divider
echo "😃 Passed tests:" "${PASSED_TESTS[@]}"
echo "☹ Failed tests:" "${FAILED_TESTS[@]}"
test_divider
# Exit with a failure if tests were executed and any of them failed.
if [ ${#PASSED_TESTS[@]} -gt 0 ] && [ ${#FAILED_TESTS[@]} -eq 0 ]; then
echo "🎉 All tests passed."
exit 0
else
echo "🔥 One or more tests failed."
exit 1
fi