From ebef0ebe6c4e5b69e91bc3750bce768bdd4d1d9a Mon Sep 17 00:00:00 2001 From: Jesus Checa Hidalgo Date: Thu, 2 Jul 2026 17:59:45 +0200 Subject: [PATCH] refactor(rpm-rebuild): reduce log verbosity and detect resource failures - Add analyze_build_failure() to distinguish resource failures from build failures - Add EXIT trap to guarantee cleanup on timeout/SIGTERM/rlDie - Execute rpmbuild silently, show only command and result - Detect patterns: disk full, SIGKILL, missing dependencies --- tests/Sanity/rpm-rebuild/main.fmf | 2 +- tests/Sanity/rpm-rebuild/runtest.sh | 64 +++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/tests/Sanity/rpm-rebuild/main.fmf b/tests/Sanity/rpm-rebuild/main.fmf index 8688b85..baac489 100644 --- a/tests/Sanity/rpm-rebuild/main.fmf +++ b/tests/Sanity/rpm-rebuild/main.fmf @@ -4,7 +4,7 @@ require+: - rpm-build duration: 1h -adjust: +adjust+: - require+: - dnf5-plugins when: distro == fedora or distro > rhel-10 or distro > centos-stream-10 diff --git a/tests/Sanity/rpm-rebuild/runtest.sh b/tests/Sanity/rpm-rebuild/runtest.sh index 5499b64..f3537b0 100755 --- a/tests/Sanity/rpm-rebuild/runtest.sh +++ b/tests/Sanity/rpm-rebuild/runtest.sh @@ -2,10 +2,53 @@ # vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k . /usr/share/beakerlib/beakerlib.sh || exit 1 +# Analyze build failure and determine if it's a resource issue or real failure +analyze_build_failure() { + local logfile="$1" + local detected_cause="" + + # Extensible table of known resource failure patterns + # Format: "regex_pattern|diagnostic_message" + local -a RESOURCE_PATTERNS=( + "No space left on device|Disk space exhausted" + "signal: 9|Build killed with SIGKILL" + "SIGKILL: kill|Build killed with SIGKILL" + "Failed build dependencies|Missing build dependencies. Is CRB repo enabled?" + ) + + # Search for each pattern in the log (first match wins) + for pattern_entry in "${RESOURCE_PATTERNS[@]}"; do + IFS='|' read -r pattern message <<< "$pattern_entry" + if grep -qiE "$pattern" "$logfile"; then + detected_cause="$message" + break + fi + done + + # Always show tail of log + rlLogInfo "Last 20 lines of build log:" + tail -n 20 "$logfile" | while IFS= read -r line; do + rlLogInfo "$line" + done + + if [[ -n "$detected_cause" ]]; then + rlFileSubmit "$logfile" + rlDie "Fail reason (likely): $detected_cause" + # rlDie aborts here, but trap guarantees cleanup + fi +} + PACKAGE="$(rpm -qf "$(which rustc)")" rlJournalStart rlPhaseStartSetup + # Trap for guaranteed cleanup (even with rlDie, TMT timeouts, SIGTERM) + cleanup_on_exit() { + [[ -n "$TmpDir" && -d "$TmpDir" ]] && rm -rf "$TmpDir" + [[ -n "$TOPDIR" && -d "$TOPDIR" ]] && rm -rf "$TOPDIR" + } + trap cleanup_on_exit EXIT + declare TmpDir rlAssertRpm "$PACKAGE" || rlDie "rustc not found. Aborting testcase..." rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" @@ -46,13 +89,28 @@ rlJournalStart # builddep needs to be run from the srpm, not the spec file, to be able # to generate them: # https://fedoraproject.org/wiki/Changes/DynamicBuildRequires#rpmbuild - rlRun "dnf builddep -y ${SRPM}" + rlRun "dnf -q builddep -y ${SRPM}" rlPhaseEnd rlPhaseStartTest set -o pipefail - rlRun "rpmbuild -bb ${SPECDIR}/${SPECNAME} |& tee ${SRPM}_rpmbuild.log" - rlFileSubmit "${SRPM}_rpmbuild.log" + LOGFILE="${SRPM}_rpmbuild.log" + BUILD_CMD="rpmbuild -bb ${SPECDIR}/${SPECNAME}" + + # Log the command being executed (for visibility in test output) + rlLog "Executing: $BUILD_CMD" + + # Execute rpmbuild silently, saving complete log to file + if $BUILD_CMD &> "$LOGFILE"; then + rlPass "rpmbuild succeeded" + else + # Analyze cause of failure + analyze_build_failure "$LOGFILE" + # If analyze_build_failure returns (didn't rlDie), it's a real failure + rlFail "rpmbuild failed" + fi + + rlFileSubmit "$LOGFILE" rlPhaseEnd rlPhaseStartCleanup