Skip to content

Commit

Permalink
testing-farm: install the correct package versions
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup committed Jan 25, 2024
1 parent 0101b7c commit 399820b
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 1 deletion.
98 changes: 98 additions & 0 deletions mock/integration-tests/setup-playbook/files/install-copr-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#! /bin/bash

# Install an RPM package (and its dependencies) identified by
# the (a) package name, (b) upstream commmit and (c) Copr directory. The short
# variant of the upstream commit must be part of the package Release tag.
#
# ARG1: coprowner/projectname:dir or https://
# ARG2: upstream-commit
# ARGN: packagename1 packagename2 ...

# TODO: DNF5/YUM compat?
DNF=/usr/bin/dnf-3
REPOQUERY=( "$DNF" repoquery )

copr_dir=$1 ; shift
commit=${1} ; shift
copr_uri=https://download.copr.fedorainfracloud.org/results

copr_chroot() (
# mimic: https://github.com/rpm-software-management/dnf5/blob/c6edcd75260accf7070f261e5b406fcf1f5db328/dnf5-plugins/copr_plugin/copr_config.cpp#L71-L80
. /etc/os-release
name=$ID
version=$VERSION_ID
arch=$(rpm --eval %_arch)
if test "$name" = fedora; then
if test "$REDHAT_SUPPORT_PRODUCT_VERSION" = rawhide; then
version=rawhide
fi
fi
echo "$name-$version-$arch"
)

repo=$copr_uri/$copr_dir/$(copr_chroot)

echo >&2 "using repo: $repo"

repoid=xyztest

export clean_cache=true


repos=( "--repofrompath=$repoid,$repo" )

_repoquery() {
local opts=( "${repos[@]}" --disablerepo='*' --enablerepo "$repoid" )
if ${clean_cache-true}; then
opts+=( "--setopt=$repoid.metadata_expire=1" )
fi
local cmd=( "${REPOQUERY[@]}" "${opts[@]}" "$@" )
info "Executing: ${cmd[*]}"
"${cmd[@]}" 2>/dev/null
}

info() { echo >&2 "INFO: $*" ; }
error() { echo >&2 "ERROR: $*" ; false; }
die() { echo >&2 "FATAL: $*" ; exit 1 ; }

find_nvr() {
# ARGS: $1=pkg $2=commit
# RETURN: $find_nvr_result
# STATUS: true if found
local _pkgname=$1 _commit=${2:0:7} _found=false
while read -r name version release; do
test -z "$name" && continue
test "$name" = "$_pkgname" || continue
case $release in
*$_commit*)
find_nvr_result=$name-$version-$release
$_found && error "second occurence of $name-$version-$release"
_found=true
;;
*)
continue
;;
esac
done < <( _repoquery --qf='%{NAME} %{VERSION} %{RELEASE}\n' )
$_found || error "$_pkgname with $commit in release not found"
}

nvrs=()
SECONDS=0
TIMEOUT=${TIMEOUT-1200} # 20 minutes by default
for pkg; do
while true; do
if find_nvr "$pkg" "$commit"; then
nvrs+=( "$find_nvr_result" )
clean_cache=false
break
fi
test "$SECONDS" -gt "$TIMEOUT" && die "The timeout ${TIMEOUT}s left"
clean_cache=true
sleep 5
done
done

cmd=( "$DNF" -y install "${nvrs[@]}" "${repos[@]}" --nogpgcheck )
info "Running: ${cmd[*]}"
"${cmd[@]}"
6 changes: 6 additions & 0 deletions mock/integration-tests/setup-playbook/play-tf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@

tasks:
- include_tasks: tasks/main.yml

- name: upload the "install copr package" script
copy:
src: install-copr-packages
dest: /usr/bin/install-copr-packages
mode: '0755'
9 changes: 8 additions & 1 deletion testing-farm/tests/behave/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/bin/sh -eux
#!/bin/sh -xe

test -n "$PACKIT_COPR_PROJECT" || {
PACKIT_COPR_PROJECT=@mock/mock
PACKIT_COMMIT_SHA=$(curl -H "Accept: application/vnd.github.VERSION.sha" https://api.github.com/repos/rpm-software-management/mock/commits/main)
}

install-copr-packages "$PACKIT_COPR_PROJECT" "$PACKIT_COMMIT_SHA" mock-core-configs mock

cd ../../../behave
behave

0 comments on commit 399820b

Please sign in to comment.