Skip to content

Commit

Permalink
Check that rpms installed in tmt come from copr
Browse files Browse the repository at this point in the history
Add a script to ensure that the llvm package installed comes from the
copr repo. A failure in the script aborts the test plan
  • Loading branch information
Jesus Checa Hidalgo committed Aug 27, 2024
1 parent e93cddd commit 5e95fa5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/assert_llvm.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions tests/snapshot-gating.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e95fa5

Please sign in to comment.