Skip to content

Commit

Permalink
test/integration: Fix cleanups when the test fails
Browse files Browse the repository at this point in the history
The script runs with `set -e`. Thus, if the actual test fails, the cleanups
are not run.

This wouldn't be normally an issue, because we run in an ephemeral
environment, but one of the scripts (run-openid.sh) runs a command in
background. This is unfortunately a nemesis of our CI setup: GitLab
keeps running any jobs until their timeout if they have a hanging process
in the background. By ensuring that the cleanup scripts are run properly,
the process should get killed, and the job will be able to fail gracefully.
  • Loading branch information
ondrejbudai committed Nov 20, 2023
1 parent f900ff9 commit 85ea03d
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions test/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ sudo dnf -y \
download \
"koji-osbuild*"

function cleanup() {
echo "== Script execution stopped or finished - Cleaning up =="

# Clean up as many things as possible
set +e

greenprint "Stopping koji builder"
sudo /usr/libexec/koji-osbuild-tests/run-builder.sh stop /usr/share/koji-osbuild-tests

greenprint "Stopping containers"
sudo /usr/libexec/koji-osbuild-tests/run-koji-container.sh stop

greenprint "Stopping mock OpenID server"
sudo /usr/libexec/koji-osbuild-tests/run-openid.sh stop

greenprint "Removing generated CA cert"
sudo rm /etc/pki/ca-trust/source/anchors/osbuild-ca-crt.pem
sudo update-ca-trust
}
trap cleanup EXIT

greenprint "Creating composer SSL certificates"
sudo /usr/libexec/koji-osbuild-tests/make-certs.sh /usr/share/koji-osbuild-tests

Expand Down Expand Up @@ -67,16 +88,3 @@ greenprint "Running integration tests"
AWS_ACCESS_KEY_ID="${V2_AWS_ACCESS_KEY_ID:-}" \
AWS_SECRET_ACCESS_KEY="${V2_AWS_SECRET_ACCESS_KEY:-}" \
python3 -m unittest discover -v /usr/libexec/koji-osbuild-tests/integration/

greenprint "Stopping koji builder"
sudo /usr/libexec/koji-osbuild-tests/run-builder.sh stop /usr/share/koji-osbuild-tests

greenprint "Stopping containers"
sudo /usr/libexec/koji-osbuild-tests/run-koji-container.sh stop

greenprint "Stopping mock OpenID server"
sudo /usr/libexec/koji-osbuild-tests/run-openid.sh stop

greenprint "Removing generated CA cert"
sudo rm /etc/pki/ca-trust/source/anchors/osbuild-ca-crt.pem
sudo update-ca-trust

0 comments on commit 85ea03d

Please sign in to comment.