Skip to content

Commit

Permalink
Add compatibility with RHEL7 (and YUM v3) (#45)
Browse files Browse the repository at this point in the history
* Add compatibility with RHEL 7 (and YUM v3)

Related: https://issues.redhat.com/browse/OSCI-5194
  • Loading branch information
janblazek authored Apr 16, 2024
1 parent 7d851d3 commit 9910ec3
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 21 deletions.
23 changes: 16 additions & 7 deletions mini-tps.spec
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
%if 0%{?rhel} == 7
%define yumcmd yum
%else
%define yumcmd dnf
%endif

Name: mini-tps
Version: 0.1
Release: 170%{?dist}
Release: 171%{?dist}
Summary: Mini TPS - Test Package Sanity

License: GPLv2
URL: https://github.com/fedora-ci/mini-tps
Source0: mini-tps.tar.gz
Source0: mini-tps-0.1.tar.gz
BuildArch: noarch
# Don't add any Requires here because those would become protected, see mini-tps.conf

%description
Light version of TPS

%prep
%autosetup -n mini-tps
%autosetup -n mini-tps-0.1

%build

%install
mkdir -p %{buildroot}%{_sbindir} # epel7
install -pD -m 0755 --target-directory=%{buildroot}%{_sbindir} mtps-*

mkdir -p %{buildroot}%{_sysconfdir}/dnf/protected.d/
cat > %{buildroot}%{_sysconfdir}/dnf/protected.d/mini-tps.conf <<EOF
mkdir -p %{buildroot}%{_sysconfdir}/%{yumcmd}/protected.d/
cat > %{buildroot}%{_sysconfdir}/%{yumcmd}/protected.d/mini-tps.conf <<EOF
# Packages for which mini-tps won't run the 'remove' test (i.e. won't try to remove them).

mini-tps
Expand All @@ -31,7 +37,7 @@ yum
yum-utils
EOF
%if 0%{?rhel} > 7
cat >> %{buildroot}%{_sysconfdir}/dnf/protected.d/mini-tps.conf <<EOF
cat >> %{buildroot}%{_sysconfdir}/%{yumcmd}/protected.d/mini-tps.conf <<EOF

# https://bugzilla.redhat.com/show_bug.cgi?id=1641631
dnf-plugins-core
Expand All @@ -58,12 +64,15 @@ install -pD -m 0755 profiles/fedora/prepare-system %{buildroot}%{_libexecdir}/mi

%files
%{_sbindir}/mtps-*
%config %{_sysconfdir}/dnf/protected.d/mini-tps.conf
%config %{_sysconfdir}/%{yumcmd}/protected.d/mini-tps.conf
%{_datarootdir}/mini-tps/*
%{_libexecdir}/mini-tps/*


%changelog
* Fri Mar 22 2024 Jan Blazek <[email protected]> - 0.1-171
- Add compatibility with RHEL 7

* Thu Feb 22 2024 Jiri Popelka <[email protected]> - 0.1-170
- rhel-10.0-beta repo file

Expand Down
22 changes: 13 additions & 9 deletions mtps-pkg-test
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#

: "${PROG:=${0##*/}}"
: "${ALLOWERASING:=--allowerasing}"

EXIT_CODE_SKIP=7
EXIT_CODE_WARN=8
Expand All @@ -43,6 +44,9 @@ if command -v "mtps-setup" >/dev/null; then source "mtps-setup"; fi
# If previous fails source `mtps-setup` from this script dir
if [ -z "${YUMDNFCMD:-}" ]; then source "$(dirname "${BASH_SOURCE[0]}")/mtps-setup" || ( echo "Cannot source mtps-setup" >&2; exit 91 ); fi

YUM_VERSION=$("${YUMDNFCMD}" --version)
[ ${YUM_VERSION:0:1} == "3" ] && ALLOWERASING=""

from_nevra() {
# Input: foo-1.0-1.i386 or foo-1:1.0-1.i386
local nevra="$1" && shift
Expand Down Expand Up @@ -205,7 +209,7 @@ pkg_remove_any() {
#Removing:
# kernel-rt-kvm x86_64 4.18.0-39.rt9.82.el8 @rhel-8-buildroot 361 k
# kernel-rt-kvm x86_64 4.18.0-37.rt9.80.el8 @rhel-8-buildroot-old 361 k
"$YUMDNFCMD" -y remove --allowerasing "$name" || :
"$YUMDNFCMD" -y remove ${ALLOWERASING} "$name" || :
# yum returns 1 for removing non-existing package for yum4/dnf
local ret=0
pkg_is_present "$name" && ret=1
Expand All @@ -220,7 +224,7 @@ pkg_install_if_absent() {
debug "${FUNCNAME[0]}: package $name is present. Not installing $nevra."
return 0
fi
if ! "$YUMDNFCMD" -y install --allowerasing "$nevra"; then
if ! "$YUMDNFCMD" -y install ${ALLOWERASING} "$nevra"; then
echo "Installation of $nevra failed."
echo "See $YUMDNFCMD command output above for more information."
return 1
Expand Down Expand Up @@ -341,7 +345,7 @@ pkg_downgrade_if_present() {
echo "Not downgrading package: $nevra. There is already installed old package: $installed_nevra_old"
return 0
fi
"$YUMDNFCMD" -y downgrade --allowerasing "$name"
"$YUMDNFCMD" -y downgrade "$ALLOWERASING" "$name"
}

get_old_nevra() {
Expand All @@ -353,9 +357,9 @@ get_old_nevra() {
local arch="$(from_nevra "$nevra" "arch")"
# Find previous version of the package.
local old_nevras=($(
"$YUMDNFCMD" repoquery -q $name.$arch --qf="%{name}-%{epoch}:%{version}-%{release}.%{arch}" | \
repoquery -q "$name"."$arch" --qf="%{name}-%{epoch}:%{version}-%{release}.%{arch}" | \
tr -s ' ' | \
grep $arch | \
grep "$arch" | \
sed -n -e "/^${name}-${epoch}:${version}-${release}.${arch}$/"'!p'
))
if [ ${#old_nevras[@]} -eq 0 ]; then
Expand Down Expand Up @@ -389,7 +393,7 @@ pkg_remove_any_newer() {
continue
fi
echo "Removing package: $to_remove"
"$YUMDNFCMD" -y remove --allowerasing "$to_remove" || :
"$YUMDNFCMD" -y remove "$ALLOWERASING" "$to_remove" || :
done
}

Expand All @@ -405,7 +409,7 @@ pkg_remove_any_older() {
fi
if nevra_older_then "$to_remove" "$nevra"; then
echo "Removing older package: $to_remove"
"$YUMDNFCMD" -y remove --allowerasing "$to_remove" || :
"$YUMDNFCMD" -y remove "$ALLOWERASING" "$to_remove" || :
else
debug "Not removing newer package: $to_remove"
continue
Expand All @@ -428,7 +432,7 @@ pkg_update_to_new_if_present() {
debug "Installed package $installed_nevra_new is not older. Not updating."
return 0
fi
"$YUMDNFCMD" -y upgrade --allowerasing "$nevra"
"$YUMDNFCMD" -y upgrade "$ALLOWERASING" "$nevra"
if pkg_is_absent "$nevra"; then
echo "Could not update to: $nevra"
return 1
Expand All @@ -453,7 +457,7 @@ pkg_downgrade_to_old() {
return 1
fi
# dnf returns 1 if no downgrade available
"$YUMDNFCMD" -y downgrade --allowerasing "$name"
"$YUMDNFCMD" -y downgrade "$ALLOWERASING" "$name"
}

box_out() {
Expand Down
4 changes: 2 additions & 2 deletions mtps-run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fi

# https://bugzilla.redhat.com/show_bug.cgi?id=584525
nevras_in_repo="$(
"$YUMDNFCMD" repoquery \
repoquery --repoid=${REPONAME} --all \
--qf "%{repoid} %{name}-%{epoch}:%{version}-%{release}.%{arch}" 2>&1 | \
sed -n -e "/^${REPONAME}[[:space:]]/ s/^${REPONAME}[[:space:]]//p"
)"
Expand All @@ -164,7 +164,7 @@ pkgs_list=()
for i in $nevras_in_repo; do
pkgs_list+=(" * $i")
done
box_out "# $(echo $TEST | tr '[:lower:]' '[:upper:]') TEST" "" "Packages:" "" "${pkgs_list[@]}"
box_out "# $(echo "$TEST" | tr '[:lower:]' '[:upper:]') TEST" "" "Packages:" "" "${pkgs_list[@]}"

# Put logs by default at CDIR/mtps-logs
mkdir -p "${LOGS_DIR:=mtps-logs}"
Expand Down
6 changes: 3 additions & 3 deletions profiles/rhel/prepare-system
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ if [ -n "$FIXREPO" ]; then
done
fi

yum config-manager --set-disabled '*'
yum-config-manager --disable '*'
declare -a yumrepos
for repofile in "${INSTALLED_REPO_FILES[@]}"; do
yumrepos=($(cat "$repofile" | sed -n -e '/buildroot/d' -e '/^\[/p' | tr -d '[]'))
yum config-manager --set-enabled "${yumrepos[@]}"
yum-config-manager --enable "${yumrepos[@]}"
done

if [ -n "$ENABLE_BUILD_ROOT" ]; then
buildroot_repo=$(cat "$REPOFILE" | sed -n -e '/^\[/{/buildroot/p}' | tr -d '[]')
yum config-manager --set-enabled "$buildroot_repo"
yum-config-manager --enable "$buildroot_repo"
fi

# repoquery util acts not on live system, but rather on set of enabled repos. mini-tps hold personal list of protected packages, such as openssh-server
Expand Down
191 changes: 191 additions & 0 deletions profiles/rhel/repos/rhel-7.9-z.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
[rhel]
name=rhel
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server/x86_64/os/
enabled=1
gpgcheck=0

[rhel-opt]
name=rhel-opt
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server-optional/x86_64/os/
enabled=1
gpgcheck=0

[rhel-debuginfo]
name=rhel-debuginfo
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server/x86_64/debug/tree/
enabled=0
gpgcheck=0

[rhel-opt-debuginfo]
name=rhel-opt-debuginfo
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server-optional/x86_64/debug/tree/
enabled=0
gpgcheck=0

[rhel-source]
name=rhel-source
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server/source/tree/
enabled=0
gpgcheck=0

[rhel-opt-source]
name=rhel-opt-source
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server-optional/source/tree/
enabled=0
gpgcheck=0

[rhel-SAP]
name=rhel-SAP
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server-SAP/x86_64/os/
enabled=1
gpgcheck=0

[rhel-SAP-debuginfo]
name=rhel-SAP-debuginfo
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server-SAP/x86_64/debug/tree/
enabled=1
gpgcheck=0

[rhel-SAPHANA]
name=rhel-SAPHANA
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server-SAPHANA/x86_64/os/
enabled=1
gpgcheck=0

[rhel-SAPHANA-debuginfo]
name=rhel-SAPHANA-debuginfo
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server-SAPHANA/x86_64/debug/tree/
enabled=1
gpgcheck=0

[rhel-HighAvailability]
name=rhel-HighAvailability
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server/x86_64/os/addons/HighAvailability/
enabled=1
gpgcheck=0

[rhel-HighAvailability-debuginfo]
name=rhel-HighAvailability
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server/x86_64/debug/tree/addons/HighAvailability/
enabled=1
gpgcheck=0

[rhel-ResilientStorage]
name=rhel-ResilientStorage
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server/x86_64/os/addons/ResilientStorage/
enabled=1
gpgcheck=0

[rhel-ResilientStorage-debuginfo]
name=rhel-ResilientStorage
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server/x86_64/debug/tree/addons/ResilientStorage/
enabled=1
gpgcheck=0

[rhel-RT]
name=rhel-RT
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server-RT/x86_64/os/
enabled=1
gpgcheck=0

[rhel-RT-debuginfo]
name=rhel-RT-debuginfo
baseurl=http://download.eng.rdu2.redhat.com/released/RHEL-7/7.9/Server-RT/x86_64/debug/tree/
enabled=1
gpgcheck=0

[rhel-updates]
name=rhel-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server/x86_64/os/
enabled=1
gpgcheck=0

[rhel-opt-updates]
name=rhel-opt-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server-optional/x86_64/os/
enabled=1
gpgcheck=0

[rhel-debuginfo-updates]
name=rhel-debuginfo-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server/x86_64/debug/tree/
enabled=0
gpgcheck=0

[rhel-opt-debuginfo-updates]
name=rhel-opt-debuginfo-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server-optional/x86_64/debug/tree/
enabled=0
gpgcheck=0

[rhel-source-updates]
name=rhel-source-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server/source/tree/
enabled=0
gpgcheck=0

[rhel-opt-source-updates]
name=rhel-opt-source-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server-optional/source/tree/
enabled=0
gpgcheck=0

[rhel-SAP-updates]
name=rhel-SAP-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server-SAP/x86_64/os/
enabled=1
gpgcheck=0

[rhel-SAP-debuginfo-updates]
name=rhel-SAP-debuginfo-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server-SAP/x86_64/debug/tree/
enabled=1
gpgcheck=0

[rhel-SAPHANA-updates]
name=rhel-SAPHANA-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server-SAPHANA/x86_64/os/
enabled=1
gpgcheck=0

[rhel-SAPHANA-debuginfo-updates]
name=rhel-SAPHANA-debuginfo-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server-SAPHANA/x86_64/debug/tree/
enabled=1
gpgcheck=0

[rhel-HighAvailability-updates]
name=rhel-HighAvailability-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server/x86_64/os/addons/HighAvailability/
enabled=1
gpgcheck=0

[rhel-HighAvailability-debuginfo-updates]
name=rhel-HighAvailability-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server/x86_64/debug/tree/addons/HighAvailability/
enabled=1
gpgcheck=0

[rhel-ResilientStorage-updates]
name=rhel-ResilientStorage-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server/x86_64/os/addons/ResilientStorage/
enabled=1
gpgcheck=0

[rhel-ResilientStorage-debuginfo-updates]
name=rhel-ResilientStorage-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server/x86_64/debug/tree/addons/ResilientStorage/
enabled=1
gpgcheck=0

[rhel-RT-updates]
name=rhel-RT-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server-RT/x86_64/os/
enabled=1
gpgcheck=0

[rhel-RT-debuginfo-updates]
name=rhel-RT-debuginfo-updates
baseurl=http://download.eng.rdu2.redhat.com/rhel-7/rel-eng/updates/RHEL-7/latest-RHEL-7.9/compose/Server-RT/x86_64/debug/tree/
enabled=1
gpgcheck=0

0 comments on commit 9910ec3

Please sign in to comment.