2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-09-26 17:54:05 +00:00

fix(xcat-core): otherpkgs refreshes a zypper repository it did not add

The local otherpkgs repository is written with the alias xcat-otherpkgs$localrepoindex, where
localrepoindex is urlrepoindex plus the array index. Lines 833 and 843 of
xCAT/postscripts/otherpkgs then refresh and delete xcat-otherpkgs$index. With http OTHERPKGDIR
entries present urlrepoindex is not zero, so zypper names a repository that block did not add:
the refresh fails for a repository that exists, and the delete removes another one.

Both lines now use $localrepoindex. The log and the echo of a failed SDK repository add name
$bname, which is what zypper ar used; they said bname without the $.

postscripts_otherpkgs.bats drives the add, the refresh and the delete with zypper shadowed and
urlrepoindex set to 2, and reads the alias back out of the repository file the script wrote.
Against the unfixed script the refresh and the delete name xcat-otherpkgs0 while the file says
xcat-otherpkgs2, and the SDK log carries no repository name.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-09-14 15:56:14 -03:00
parent 7bd04f012d
commit 73c293f03e
2 changed files with 73 additions and 4 deletions
+69
View File
@@ -265,3 +265,72 @@ run_url_repo_block()
[ "$status" -eq 0 ]
[ "$(cat "${BATS_TEST_TMPDIR}/xCAT-otherpkgs0.list")" = "deb http://192.0.2.1/repo-a" ]
}
# Drives the lines that name the local otherpkgs repository for zypper: the alias written into
# the repository file, and the alias the refresh and the delete use.
run_zypper_local_repo()
{
local urlrepoindex="$1" index="$2"
local repo_base="$BATS_TEST_TMPDIR" mounted=1 whole_path=/install/post/otherpkgs/sles15/x86_64
local OSVER=sles15 VERBOSE= localrepoindex REPOFILE rc=1 result="" path=/pkgdir
zypper()
{
printf '%s\n' "$*" >>"$CMD_LOG"
case "$1" in
ar) sed -n '1s/^\[\(.*\)\]$/added=\1/p' "$3" >>"$CMD_LOG" ;;
esac
return "${ZYPPER_STATUS:-0}"
}
array_set_element() { :; }
# The extraction is kept apart from the eval: a failing zypper must not read as a failed
# extraction.
local pattern line
for pattern in \
'localrepoindex=' \
'REPOFILE="[$]repo_base/xCAT-otherpkgs[$]localrepoindex.repo"' \
'echo "[[]xcat-otherpkgs[$]localrepoindex[]]"' \
'result=`zypper ar -c [$]REPOFILE`' \
'zypper --non-interactive refresh xcat-otherpkgs' \
'result=`zypper sd xcat-otherpkgs'; do
line="$(extract_first_matching_line "$OTHERPKGS" "$pattern")" || return 99
eval "$line"
done
return 0
}
@test "zypper refreshes the otherpkgs repository it added" {
run run_zypper_local_repo 2 0
[ "$status" -eq 0 ]
[ "$(cmd_call 2)" = "added=xcat-otherpkgs2" ]
[ "$(cmd_call 3)" = "--non-interactive refresh xcat-otherpkgs2" ]
}
@test "zypper deletes the otherpkgs repository it added when the refresh fails" {
ZYPPER_STATUS=1 run run_zypper_local_repo 2 0
[ "$status" -eq 0 ]
[ "$(cmd_call 2)" = "added=xcat-otherpkgs2" ]
[ "$(cmd_call 4)" = "sd xcat-otherpkgs2" ]
}
run_sdk_block()
{
local block
block="$(otherpkgs_block '#adds SDK repository' 'if [ "$SDKDIR" != "" ]; then')" || return 99
local SDKDIR=/install/sles15/x86_64/sdk1 OSVER=sles15 mounted=1 VERBOSE= log_label=otherpkgs result=""
local NFSSERVER=192.0.2.1 HTTPPORT=80
eval "$(extract_shell_function "$OTHERPKGS" pmatch)" || return 99
shadow_logger
zypper()
{
printf 'zypper failed\n'
return 1
}
eval "$block"
return 0
}
@test "a failed SDK repository add is logged with the repository name" {
run run_sdk_block
[ "$status" -eq 0 ]
grep -q 'xCAT-sles15-sdk1' "$LOGGER_LOG"
}
+4 -4
View File
@@ -576,9 +576,9 @@ if ( ! ( pmatch "$OSVER" "sles10*" ) && [ $haszypper -eq 1 ] ); then
result=`zypper ar $sdk_src xCAT-$OSVER-$bname 2>&1`
if [ $? -ne 0 ]; then
if ( ! pmatch "$result" "*exists*" ); then
logger -t $log_label -p local4.info "otherpkgs: zypper ar $sdk_src xCAT-$OSVER-bname\n $result"
logger -t $log_label -p local4.info "otherpkgs: zypper ar $sdk_src xCAT-$OSVER-$bname\n $result"
if [ $VERBOSE ]; then
echo "otherpkgs: zypper ar $sdk_src xCAT-$OSVER-bname"
echo "otherpkgs: zypper ar $sdk_src xCAT-$OSVER-$bname"
echo " $result"
fi
fi
@@ -830,7 +830,7 @@ EOF`
result=`zypper ar -c $REPOFILE`
fi
result=`zypper --non-interactive refresh xcat-otherpkgs$index 2>&1`
result=`zypper --non-interactive refresh xcat-otherpkgs$localrepoindex 2>&1`
if [ $? -eq 0 ]; then
rc=0
array_set_element repo_path $index $path
@@ -840,7 +840,7 @@ EOF`
rc=0
array_set_element repo_path $index $path
else
result=`zypper sd xcat-otherpkgs$index`
result=`zypper sd xcat-otherpkgs$localrepoindex`
fi
fi
elif [ $hasapt -eq 1 ]; then