From 5e95fa5ffe9b5db565bf2b547227309f88501c5b Mon Sep 17 00:00:00 2001 From: Jesus Checa Hidalgo Date: Mon, 26 Aug 2024 17:21:59 +0200 Subject: [PATCH] Check that rpms installed in tmt come from copr Add a script to ensure that the llvm package installed comes from the copr repo. A failure in the script aborts the test plan --- tests/assert_llvm.sh | 34 ++++++++++++++++++++++++++++++++++ tests/snapshot-gating.fmf | 5 +++++ 2 files changed, 39 insertions(+) create mode 100755 tests/assert_llvm.sh diff --git a/tests/assert_llvm.sh b/tests/assert_llvm.sh new file mode 100755 index 0000000..25e4de4 --- /dev/null +++ b/tests/assert_llvm.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Script to assert that the llvm rpm installed during tmt prepare steps comes +# from the copr repo and matches exactly. +# Rely on dnf4 (/usr/bin/dnf-3) to avoid conflicts in newer Fedoras with dnf5. +# The script expects $COPR_PROJECT envvar to check the repo. +if [[ -z $COPR_PROJECT ]]; then + echo "*** Missing COPR_PROJECT required environment variable." + exit 1 +fi + +# Ensure the repo is available +if ! dnf-3 repolist | grep -q "$COPR_PROJECT"; then + echo "*** copr repo $COPR_PROJECT not enabled in dnf" +fi + +assert_package_match (){ + local pkg=$1 + local rpm_queryfmt="%{name}-%{version}-%{release}.%{arch}" + local installed_pkg pkg_from_copr + installed_pkg=$(rpm -q --qf "$rpm_queryfmt" "$pkg"."$(uname -m)") + pkg_from_copr=$(dnf-3 -q --disablerepo=* --enablerepo=*"$COPR_PROJECT"* \ + repoquery --queryformat "$rpm_queryfmt" "$pkg"."$(uname -m)") + + if [[ "$installed_pkg" != "$pkg_from_copr" ]]; then + echo "*** Unexpected $pkg package installed: $installed_pkg" + echo "*** Expected $pkg: $pkg_from_copr" + exit 1 + fi +} + +for pkg in llvm clang; do + assert_package_match "$pkg" +done diff --git a/tests/snapshot-gating.fmf b/tests/snapshot-gating.fmf index e3a3818..d91eebf 100644 --- a/tests/snapshot-gating.fmf +++ b/tests/snapshot-gating.fmf @@ -23,6 +23,11 @@ prepare: script: | dnf install -y dnf-plugins-core dnf config-manager --save --setopt="testing-farm-tag-repository.priority=999" || true + + - name: Assert correct llvm package is installed + how: shell + order: 99 + script: tests/assert_llvm.sh adjust: - discover+: - name: redhat-rpm-config-tests