Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip update if old package can't be installed #37

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 31 additions & 39 deletions mtps-pkg-test
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

: "${PROG:=${0##*/}}"

EXIT_CODE_SKIP=7

# Source `mtps-setup' from $PATH
if command -v "mtps-setup" >/dev/null; then source "mtps-setup"; fi
# If previous fails source `mtps-setup` from this script dir
Expand Down Expand Up @@ -209,20 +211,18 @@ pkg_remove_any() {
return $ret
}

pkg_install_new_if_absent() {
pkg_install_if_absent() {
local nevra="$1" && shift
local name="$(from_nevra "$nevra" "name")"
debug "${FUNCNAME[0]}: $name"
if pkg_is_present "$name"; then
debug "${FUNCNAME[0]}: package $name is present. Not installing $nevra."
return 0
fi
local ret=0
"$YUMDNFCMD" -y install --allowerasing "$nevra" || ret=1
if [ "$ret" -ne 0 ]; then
if ! "$YUMDNFCMD" -y install --allowerasing "$nevra"; then
echo "Installation of $nevra failed."
echo "See $YUMDNFCMD command output above for more information."
exit 1
return 1
fi
if pkg_is_absent "$name"; then
echo "Package $name is absent after installation."
Expand Down Expand Up @@ -335,7 +335,7 @@ pkg_downgrade_if_present() {
fi
# installonlypkg(foo) case
local installed_nevra_old="$(get_installed_nevra_oldest "$name")"
echo "The oldest installed package: $installed_nevra_old"
echo "The (oldest) installed package: $installed_nevra_old"
if nevra_older_then "$installed_nevra_old" "$nevra"; then
echo "Not downgrading package: $nevra. There is already installed old package: $installed_nevra_old"
return 0
Expand Down Expand Up @@ -412,25 +412,6 @@ pkg_remove_any_older() {
done
}

pkg_install_old_if_absent() {
# Installs package < nevra, if pkg with name is absent.
# 2nd column yum output: 12:4.3.6-25.el8+7
local nevra="$1" && shift
local name="$(from_nevra "$nevra" "name")"
if pkg_is_present "$name"; then
debug "Package $name is present. Not installing."
return 0
fi
local old_nevra="$(get_old_nevra "$nevra")"
echo "Installing older $old_nevra for $nevra"
"$YUMDNFCMD" -y install --allowerasing "$old_nevra"
if pkg_is_absent "$old_nevra"; then
echo "Could not install: $old_nevra."
return 1
fi
return 0
}

pkg_update_to_new_if_present() {
local nevra="$1" && shift
local name="$(from_nevra "$nevra" "name")"
Expand Down Expand Up @@ -615,7 +596,7 @@ fi
if [[ "$TEST" == "install" || "$TEST" == "remove" ]]; then
if ! pkg_can_be_removed "$NEVRA"; then
echo "Skipping test: $TEST for $NEVRA. Package cannot be clearly removed."
exit 0
exit $EXIT_CODE_SKIP
fi
fi

Expand All @@ -625,9 +606,9 @@ case $TEST in
pkg_remove_any "$NEVRA"
msg_run "install" "$NEVRA"
if [ -n "$CHECK_SCRIPTLETS" ]; then
run_with_scriptlet_check pkg_install_new_if_absent "$NEVRA"
run_with_scriptlet_check pkg_install_if_absent "$NEVRA"
else
pkg_install_new_if_absent "$NEVRA"
pkg_install_if_absent "$NEVRA"
fi
ret=$?
if [[ "$ret" -eq 0 && -n "$RPM_VERIFY" ]]; then
Expand All @@ -642,13 +623,22 @@ case $TEST in
old_nevra="$(get_old_nevra "$NEVRA" || true)"
if [ -z "$old_nevra" ]; then
echo "Cannot find older package than $NEVRA. Skipping test."
# Skipping test
exit 0
exit $EXIT_CODE_SKIP
fi
# If there's a bug preventing the old package from installing
# the dnf downgrade fails but we can't say whether it's because
# of the new package or the old one.
# So rather, remove the package, install old version, and if that fails
# skip the test.
if pkg_can_be_removed "$NEVRA"; then
pkg_remove_any "$NEVRA"
else
pkg_downgrade_if_present "$NEVRA"
fi
if ! pkg_install_if_absent "$old_nevra"; then
echo "Failed to install $old_nevra. Skipping test."
exit $EXIT_CODE_SKIP
fi
echo "Found available older package: $old_nevra"
# At this point an old pkg is available in repo
pkg_downgrade_if_present "$NEVRA"
pkg_install_old_if_absent "$NEVRA"
# At this point pkg is installed, but can be many installonlypkg(foo) packages
pkg_remove_any_newer "$NEVRA"
msg_run "update" "$NEVRA"
Expand All @@ -670,12 +660,14 @@ case $TEST in
old_nevra="$(get_old_nevra "$NEVRA" || true)"
if [ -z "$old_nevra" ]; then
echo "Cannot find older package than $NEVRA. Skipping test."
# Skipping test
exit 0
exit $EXIT_CODE_SKIP
fi
echo "Older available package is: $old_nevra"
pkg_update_to_new_if_present "$NEVRA"
pkg_install_new_if_absent "$NEVRA"
if ! pkg_install_if_absent "$NEVRA"; then
echo "Failed to install $NEVRA. Skipping test."
exit $EXIT_CODE_SKIP
fi
pkg_remove_any_older "$NEVRA" # This is for installonlypkg(foo) packages, like kernel
msg_run "downgrade" "$NEVRA"
if [ -n "$CHECK_SCRIPTLETS" ]; then
Expand All @@ -687,15 +679,15 @@ case $TEST in
remove)
msg_prepare "removing" "$NEVRA"
pkg_update_to_new_if_present "$NEVRA"
pkg_install_new_if_absent "$NEVRA"
pkg_install_if_absent "$NEVRA" || exit 1

# OSCI-4333: We have to check again if the package can be removed
# now after we installed its latest version. It can happen that
# the update introduced new /etc/yum/protected.d/* file which makes
# it uninstallable.
if ! pkg_can_be_removed "$NEVRA"; then
echo "Skipping test: $TEST for $NEVRA. Package cannot be clearly removed."
exit 0
exit $EXIT_CODE_SKIP
fi

msg_run "remove" "$NEVRA"
Expand Down
9 changes: 6 additions & 3 deletions mtps-run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

: "${PROG:=${0##*/}}"

EXIT_CODE_SKIP=7

# Source `mtps-setup' from $PATH
if command -v "mtps-setup" >/dev/null; then source "mtps-setup"; fi
# If previous fails source `mtps-setup` from this script dir
Expand Down Expand Up @@ -205,18 +207,19 @@ for nevra in $nevras_in_repo; do
## Ignore errors on rollback due to: https://bugzilla.redhat.com/show_bug.cgi?id=1614346
## Rollback fails after Downgrade / Update tests
#yum -y history rollback "$START" || echo "Ignoring rollback error: RHBZ#1614346"
if [ "$test_status" -ne "0" ]; then
if [ "$test_status" -eq $EXIT_CODE_SKIP ]; then
new_logfname="$(dirname "$logfname")/SKIP-$(basename "$logfname")"
elif [ "$test_status" -ne 0 ]; then
ret=1
if [ -n "$CRITICAL" ]; then
new_logfname="$(dirname "$logfname")/FAIL-$(basename "$logfname")"
else
new_logfname="$(dirname "$logfname")/WARN-$(basename "$logfname")"
fi
mv "$logfname" "$new_logfname"
else
new_logfname="$(dirname "$logfname")/PASS-$(basename "$logfname")"
mv "$logfname" "$new_logfname"
fi
mv "$logfname" "$new_logfname"
if [ -n "$SELINUX" ] && rpm --quiet -q audit; then
selinux_status=0
ausearch --format raw -m avc,user_avc,selinux_err,user_selinux_err -ts "$START_DATE" "$START_TIME" 2>&1 | sed -e '/received policyload notice/d' | grep -s -o '^' && selinux_status=1
Expand Down