diff --git a/test/cases/aws.sh b/test/cases/aws.sh index 3247ebc0d..2df94bfb6 100755 --- a/test/cases/aws.sh +++ b/test/cases/aws.sh @@ -32,6 +32,8 @@ fi TEMPDIR=$(mktemp -d) function cleanup() { greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" sudo rm -rf "$TEMPDIR" } trap cleanup EXIT @@ -127,8 +129,6 @@ sudo composer-cli blueprints depsolve bash WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! -# Stop watching the worker journal when exiting. -trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose and upload to AWS. greenprint "๐Ÿš€ Starting compose" @@ -155,9 +155,8 @@ greenprint "๐Ÿ’ฌ Getting compose log and metadata" get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" -# Kill the journal monitor immediately and remove the trap +# Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} -trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/azure.sh b/test/cases/azure.sh index c6e186c6f..30f8cd6b8 100755 --- a/test/cases/azure.sh +++ b/test/cases/azure.sh @@ -36,6 +36,8 @@ fi TEMPDIR=$(mktemp -d) function cleanup() { greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" sudo rm -rf "$TEMPDIR" } trap cleanup EXIT @@ -156,8 +158,6 @@ sudo composer-cli blueprints depsolve bash WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! -# Stop watching the worker journal when exiting. -trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose and upload to Azure. greenprint "๐Ÿš€ Starting compose" @@ -184,9 +184,8 @@ greenprint "๐Ÿ’ฌ Getting compose log and metadata" get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" -# Kill the journal monitor immediately and remove the trap +# Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} -trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/container-embedding.sh b/test/cases/container-embedding.sh index de71bc124..ed4a921cf 100755 --- a/test/cases/container-embedding.sh +++ b/test/cases/container-embedding.sh @@ -14,6 +14,8 @@ source /usr/libexec/tests/osbuild-composer/shared_lib.sh TEMPDIR=$(mktemp -d) function cleanup() { greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" sudo rm -rf "$TEMPDIR" } trap cleanup EXIT @@ -82,8 +84,6 @@ sudo composer-cli blueprints depsolve image WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! -# Stop watching the worker journal when exiting. -trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose and upload to CI registry. greenprint "๐Ÿš€ Starting compose" @@ -111,9 +111,8 @@ greenprint "๐Ÿ’ฌ Getting compose log and metadata" get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" -# Kill the journal monitor immediately and remove the trap +# Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} -trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/container-upload.sh b/test/cases/container-upload.sh index f0aceed7c..adc4aa1ad 100755 --- a/test/cases/container-upload.sh +++ b/test/cases/container-upload.sh @@ -15,6 +15,8 @@ ARTIFACTS="${ARTIFACTS:-/tmp/artifacts}" TEMPDIR=$(mktemp -d) function cleanup() { greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" sudo rm -rf "$TEMPDIR" } trap cleanup EXIT @@ -88,8 +90,6 @@ UPLOAD_TARGET="$CI_REGISTRY_IMAGE/fedora-container:$CI_COMMIT_REF_SLUG" WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! -# Stop watching the worker journal when exiting. -trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose and upload to CI registry. greenprint "๐Ÿš€ Starting compose with upload to $UPLOAD_TARGET" @@ -117,9 +117,8 @@ greenprint "๐Ÿ’ฌ Getting compose log and metadata" get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" -# Kill the journal monitor immediately and remove the trap +# Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} -trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/filesystem.sh b/test/cases/filesystem.sh index 0369ec5a8..47ac24e81 100644 --- a/test/cases/filesystem.sh +++ b/test/cases/filesystem.sh @@ -21,6 +21,13 @@ BLUEPRINT_FILE=${TEMPDIR}/blueprint.toml COMPOSE_START=${TEMPDIR}/compose-start-${IMAGE_KEY}.json COMPOSE_INFO=${TEMPDIR}/compose-info-${IMAGE_KEY}.json +function cleanup_on_exit() { + greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" +} +trap cleanup_on_exit EXIT + # Workaround the problem that 'image-info' can not read SELinux labels unknown to the host from the image OSBUILD_LABEL=$(matchpathcon -n "$(which osbuild)") sudo chcon "$OSBUILD_LABEL" /usr/libexec/osbuild-composer-test/image-info @@ -41,8 +48,6 @@ build_image() { WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! - # Stop watching the worker journal when exiting. - trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose. greenprint "๐Ÿš€ Starting compose" @@ -53,11 +58,9 @@ build_image() { if [[ $want_fail == "$STATUS" ]]; then redprint "Something went wrong with the compose. ๐Ÿ˜ข" sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT exit 1 elif [[ $want_fail == true && $STATUS == false ]]; then sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT # use get_build_info to extract errors before picking the first errors=$(get_build_info ".errors" "$COMPOSE_START") ERROR_MSG=$(jq 'first(.[] | select(.id == "ManifestCreationFailed")) | .msg' <<< "${errors}") @@ -81,9 +84,8 @@ build_image() { sleep 5 done - # Kill the journal monitor immediately and remove the trap + # Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then @@ -97,7 +99,7 @@ clean_up () { greenprint "๐Ÿงผ Cleaning up" # Remove "remote" repo. sudo rm -f "$IMAGE_FILENAME" - # Remomve tmp dir. + # Remove tmp dir. sudo rm -rf "$TEMPDIR" } check_result () { diff --git a/test/cases/gcp.sh b/test/cases/gcp.sh index 79b48ed25..7198b7354 100755 --- a/test/cases/gcp.sh +++ b/test/cases/gcp.sh @@ -45,6 +45,8 @@ function cleanupGCP() { TEMPDIR=$(mktemp -d) function cleanup() { greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" cleanupGCP sudo rm -rf "$TEMPDIR" } @@ -226,8 +228,6 @@ sudo composer-cli blueprints depsolve "$BLUEPRINT_NAME" WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! -# Stop watching the worker journal when exiting. -trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose and upload to GCP. greenprint "๐Ÿš€ Starting compose" @@ -254,11 +254,8 @@ greenprint "๐Ÿ’ฌ Getting compose log and metadata" get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" -# Kill the journal monitor immediately and remove the trap +# Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} -trap - EXIT -# trap cleanup again -trap cleanup EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/generic_s3.sh b/test/cases/generic_s3.sh index 10f53a5e4..6344261ae 100755 --- a/test/cases/generic_s3.sh +++ b/test/cases/generic_s3.sh @@ -22,9 +22,14 @@ else fi TEMPDIR=$(mktemp -d) +# note: moved here to avoid undefined variable in cleanup() +MINIO_CONTAINER_NAME="minio-server" function cleanup() { echo "== Script execution stopped or finished - Cleaning up ==" sudo rm -rf "$TEMPDIR" + + # Kill the MinIO server once we're done + ${CONTAINER_RUNTIME} kill ${MINIO_CONTAINER_NAME} } trap cleanup EXIT @@ -60,7 +65,6 @@ fi mkdir "${MINIO_CONFIG_DIR}" $MC_CMD --version -MINIO_CONTAINER_NAME="minio-server" MINIO_ENDPOINT="http://localhost:9000" MINIO_ROOT_USER="X29DU5Q6C5NKDQ8PLGVT" MINIO_ROOT_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32 ; echo) @@ -88,8 +92,6 @@ ${CONTAINER_RUNTIME} run --rm -d \ -e MINIO_ROOT_USER="${MINIO_ROOT_USER}" \ -e MINIO_ROOT_PASSWORD="${MINIO_ROOT_PASSWORD}" \ ${CONTAINER_MINIO_SERVER} server /data - # Kill the server once we're done - trap '${CONTAINER_RUNTIME} kill ${MINIO_CONTAINER_NAME}' EXIT # Configure the local server (retry until the service is up) MINIO_CONFIGURE_RETRY=0 diff --git a/test/cases/minimal-raw.sh b/test/cases/minimal-raw.sh index 9e92da84d..c41729b07 100755 --- a/test/cases/minimal-raw.sh +++ b/test/cases/minimal-raw.sh @@ -5,6 +5,13 @@ set -euo pipefail source /usr/libexec/osbuild-composer-test/set-env-variables.sh source /usr/libexec/tests/osbuild-composer/shared_lib.sh +function cleanup() { + greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" +} +trap cleanup EXIT + # Provision the software under test. /usr/libexec/osbuild-composer-test/provision.sh none @@ -141,8 +148,6 @@ build_image() { WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! - # Stop watching the worker journal when exiting. - trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose. greenprint "๐Ÿš€ Starting compose" @@ -171,9 +176,8 @@ build_image() { get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" - # Kill the journal monitor immediately and remove the trap + # Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/openshift_virtualization.sh b/test/cases/openshift_virtualization.sh index 7e392e289..1f127e0bd 100755 --- a/test/cases/openshift_virtualization.sh +++ b/test/cases/openshift_virtualization.sh @@ -15,6 +15,9 @@ TEMPDIR=$(mktemp -d) function cleanup() { greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" + # since this function can be called at any time, ensure that we don't expand unbound variables OC_CLI="${OC_CLI:-}" VM_NAME="${VM_NAME:-}" @@ -24,10 +27,6 @@ function cleanup() { [[ "$OC_CLI" && "$PVC_NAME" ]] && $OC_CLI delete pvc "$PVC_NAME" sudo rm -rf "$TEMPDIR" - - # Stop watching the worker journal when exiting. - WORKER_JOURNAL_PID="${WORKER_JOURNAL_PID:-}" - [ "$WORKER_JOURNAL_PID" ] && sudo pkill -P "$WORKER_JOURNAL_PID" } trap cleanup EXIT @@ -131,7 +130,7 @@ greenprint "๐Ÿ’ฌ Getting compose log and metadata" get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" -# Kill the journal monitor immediately and remove the trap +# Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} # Did the compose finish with success? diff --git a/test/cases/ostree-ami-image.sh b/test/cases/ostree-ami-image.sh index 93d58f1d1..5c9df5632 100755 --- a/test/cases/ostree-ami-image.sh +++ b/test/cases/ostree-ami-image.sh @@ -10,6 +10,13 @@ ARCH=$(uname -m) source /usr/libexec/tests/osbuild-composer/shared_lib.sh +function cleanup_on_exit() { + greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" +} +trap cleanup_on_exit EXIT + # Start libvirtd and test it. greenprint "๐Ÿš€ Starting libvirt daemon" sudo systemctl start libvirtd @@ -139,8 +146,6 @@ build_image() { WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! - # Stop watching the worker journal when exiting. - trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose. greenprint "๐Ÿš€ Starting compose" @@ -179,9 +184,8 @@ build_image() { get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" - # Kill the journal monitor immediately and remove the trap + # Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/ostree-ignition.sh b/test/cases/ostree-ignition.sh index 82df2e91b..7af59f2a9 100755 --- a/test/cases/ostree-ignition.sh +++ b/test/cases/ostree-ignition.sh @@ -10,6 +10,13 @@ ARCH=$(uname -m) source /usr/libexec/tests/osbuild-composer/shared_lib.sh +function cleanup_on_exit() { + greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" +} +trap cleanup_on_exit EXIT + # Install and start firewalld greenprint "๐Ÿ”ง Install and start firewalld" sudo dnf install -y firewalld @@ -158,8 +165,6 @@ build_image() { WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! - # Stop watching the worker journal when exiting. - trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose. greenprint "๐Ÿš€ Starting compose" @@ -193,9 +198,8 @@ build_image() { get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" - # Kill the journal monitor immediately and remove the trap + # Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/ostree-iot-qcow2.sh b/test/cases/ostree-iot-qcow2.sh index 9533a5d1d..bd6bbf3e2 100755 --- a/test/cases/ostree-iot-qcow2.sh +++ b/test/cases/ostree-iot-qcow2.sh @@ -10,6 +10,13 @@ ARCH=$(uname -m) source /usr/libexec/tests/osbuild-composer/shared_lib.sh +function cleanup_on_exit() { + greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" +} +trap cleanup_on_exit EXIT + # Start libvirtd and test it. greenprint "๐Ÿš€ Starting libvirt daemon" sudo systemctl start libvirtd @@ -136,8 +143,6 @@ build_image() { WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! - # Stop watching the worker journal when exiting. - trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose. greenprint "๐Ÿš€ Starting compose" @@ -173,9 +178,8 @@ build_image() { get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" - # Kill the journal monitor immediately and remove the trap + # Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/ostree-ng.sh b/test/cases/ostree-ng.sh index d4b42d6a6..305d58b75 100755 --- a/test/cases/ostree-ng.sh +++ b/test/cases/ostree-ng.sh @@ -285,10 +285,6 @@ build_image() { get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" - # Kill the journal monitor immediately and remove the trap - sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT - # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then redprint "Something went wrong with the compose. ๐Ÿ˜ข" diff --git a/test/cases/ostree-pulp.sh b/test/cases/ostree-pulp.sh index 9939277a6..49833d6bb 100644 --- a/test/cases/ostree-pulp.sh +++ b/test/cases/ostree-pulp.sh @@ -7,6 +7,13 @@ ARCH=$(uname -m) source /usr/libexec/tests/osbuild-composer/shared_lib.sh +function cleanup_on_exit() { + greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" +} +trap cleanup_on_exit EXIT + # Get compose url if it's running on unsubscried RHEL if [[ ${ID} == "rhel" ]] && ! sudo subscription-manager status; then source /usr/libexec/osbuild-composer-test/define-compose-url.sh @@ -145,8 +152,6 @@ build_image() { WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! - # Stop watching the worker journal when exiting. - trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose. greenprint "๐Ÿš€ Starting compose" @@ -187,9 +192,8 @@ build_image() { get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" - # Kill the journal monitor immediately and remove the trap + # Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/ostree-raw-image.sh b/test/cases/ostree-raw-image.sh index e639bd276..94d6ff29c 100755 --- a/test/cases/ostree-raw-image.sh +++ b/test/cases/ostree-raw-image.sh @@ -10,6 +10,13 @@ ARCH=$(uname -m) source /usr/libexec/tests/osbuild-composer/shared_lib.sh +function cleanup_on_exit() { + greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" +} +trap cleanup_on_exit EXIT + # Start libvirtd and test it. greenprint "๐Ÿš€ Starting libvirt daemon" sudo systemctl start libvirtd @@ -178,8 +185,6 @@ build_image() { WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! - # Stop watching the worker journal when exiting. - trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose. greenprint "๐Ÿš€ Starting compose" @@ -215,9 +220,8 @@ build_image() { get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" - # Kill the journal monitor immediately and remove the trap + # Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/ostree-simplified-installer.sh b/test/cases/ostree-simplified-installer.sh index d193bf3c1..985a35878 100755 --- a/test/cases/ostree-simplified-installer.sh +++ b/test/cases/ostree-simplified-installer.sh @@ -10,6 +10,13 @@ ARCH=$(uname -m) source /usr/libexec/tests/osbuild-composer/shared_lib.sh +function cleanup_on_exit() { + greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" +} +trap cleanup_on_exit EXIT + # Start firewalld sudo systemctl enable --now firewalld sudo pip3 install yq==v3.2.1 @@ -219,8 +226,6 @@ build_image() { WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! - # Stop watching the worker journal when exiting. - trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose. greenprint "๐Ÿš€ Starting compose" @@ -256,9 +261,8 @@ build_image() { get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" - # Kill the journal monitor immediately and remove the trap + # Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/ostree-vsphere.sh b/test/cases/ostree-vsphere.sh index 8d6f90eeb..e772c091a 100755 --- a/test/cases/ostree-vsphere.sh +++ b/test/cases/ostree-vsphere.sh @@ -10,6 +10,14 @@ ARCH=$(uname -m) source /usr/libexec/tests/osbuild-composer/shared_lib.sh +function cleanup_on_exit() { + greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" +} +trap cleanup_on_exit EXIT + + # Install govc GOVC_VERSION="v0.30.5" sudo curl -L -o - "https://github.com/vmware/govmomi/releases/download/${GOVC_VERSION}/govc_Linux_x86_64.tar.gz" | sudo tar -C /usr/local/bin -xvzf - govc @@ -155,8 +163,6 @@ build_image() { WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! - # Stop watching the worker journal when exiting. - trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose. greenprint "๐Ÿš€ Starting compose" @@ -188,9 +194,8 @@ build_image() { get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" - # Kill the journal monitor immediately and remove the trap + # Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/ostree.sh b/test/cases/ostree.sh index b75ba17fa..2b85bc6e3 100755 --- a/test/cases/ostree.sh +++ b/test/cases/ostree.sh @@ -7,6 +7,14 @@ ARCH=$(uname -m) source /usr/libexec/tests/osbuild-composer/shared_lib.sh +function cleanup_on_exit() { + greenprint "== Script execution stopped or finished - Cleaning up ==" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" +} +trap cleanup_on_exit EXIT + + # Get compose url if it's running on unsubscried RHEL if [[ ${ID} == "rhel" ]] && ! sudo subscription-manager status; then source /usr/libexec/osbuild-composer-test/define-compose-url.sh @@ -199,8 +207,6 @@ build_image() { WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! - # Stop watching the worker journal when exiting. - trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose. greenprint "๐Ÿš€ Starting compose" @@ -233,9 +239,8 @@ build_image() { get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" - # Kill the journal monitor immediately and remove the trap + # Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} - trap - EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then diff --git a/test/cases/vmware.sh b/test/cases/vmware.sh index 615bfb94b..dfd8c3775 100755 --- a/test/cases/vmware.sh +++ b/test/cases/vmware.sh @@ -73,6 +73,8 @@ SSH_KEY_PUB=$(cat "$SSH_KEY".pub) function cleanup() { set +eu greenprint "๐Ÿงผ Cleaning up" + # kill dangling journalctl processes to prevent GitLab CI from hanging + sudo pkill journalctl || echo "Nothing killed" $GOVC_CMD vm.destroy -u "${GOVMOMI_USERNAME}":"${GOVMOMI_PASSWORD}"@"${GOVMOMI_URL}" -k=true "${IMAGE_KEY}" set -eu } @@ -160,8 +162,6 @@ sudo composer-cli blueprints depsolve bash WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service") sudo journalctl -af -n 1 -u "${WORKER_UNIT}" & WORKER_JOURNAL_PID=$! -# Stop watching the worker journal when exiting. -trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose and upload to VMWare. greenprint "๐Ÿš€ Starting compose" @@ -189,11 +189,8 @@ greenprint "๐Ÿ’ฌ Getting compose log and metadata" get_compose_log "$COMPOSE_ID" get_compose_metadata "$COMPOSE_ID" -# Kill the journal monitor immediately and remove the trap -# while adding just the cleanup trap +# Kill the journal monitor sudo pkill -P ${WORKER_JOURNAL_PID} -trap - EXIT -trap cleanup EXIT # Did the compose finish with success? if [[ $COMPOSE_STATUS != FINISHED ]]; then