From cc36d25c354dc444e0ecbae131c4a5cf2111a8b8 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Tue, 8 Sep 2026 13:10:13 -0300 Subject: [PATCH] test(xcat-core): Keep xcatdsklspost download local xcatdsklspost can run before xcatlib.sh is available beside it in stateless and statelite image contexts. Moving download_postscripts into xcatlib.sh could leave the legacy postscript without its callee when it is copied by itself into the image. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/bats/post_xcat_download_policy.bats | 14 ++-- xCAT/postscripts/xcatdsklspost | 64 ++++++++++++++++++ xCAT/postscripts/xcatlib.sh | 65 ------------------- 3 files changed, 71 insertions(+), 72 deletions(-) diff --git a/xCAT-test/bats/post_xcat_download_policy.bats b/xCAT-test/bats/post_xcat_download_policy.bats index 4ec06387a..ec643410c 100644 --- a/xCAT-test/bats/post_xcat_download_policy.bats +++ b/xCAT-test/bats/post_xcat_download_policy.bats @@ -5,10 +5,10 @@ load 'helpers/shell_source' setup() { SCRIPT_LIB="$(repo_path 'xCAT-server/share/xcat/install/scripts/scriptlib')" - XCATLIB="$(repo_path 'xCAT/postscripts/xcatlib.sh')" + XCATDSKLSPOST="$(repo_path 'xCAT/postscripts/xcatdsklspost')" [ -r "$SCRIPT_LIB" ] || skip "$SCRIPT_LIB is required" - [ -r "$XCATLIB" ] || skip "$XCATLIB is required" - export SCRIPT_LIB XCATLIB + [ -r "$XCATDSKLSPOST" ] || skip "$XCATDSKLSPOST is required" + export SCRIPT_LIB XCATDSKLSPOST } capture_install_scriptlib_wget() @@ -25,7 +25,7 @@ capture_install_scriptlib_wget() xcat_download_postscripts "192.0.2.10:80" "/install" "/xcatpost" "$wget_log" } -capture_xcatlib_wget() +capture_xcatdsklspost_wget() { local wget_log="$1" @@ -45,7 +45,7 @@ capture_xcatlib_wget() return 0 } - source "$XCATLIB" + XCATDSKLSPOST_SOURCE_ONLY=1 source "$XCATDSKLSPOST" download_postscripts 192.0.2.10:80 } @@ -67,10 +67,10 @@ assert_download_policy() assert_download_policy "$(read_file_or_empty "$wget_log")" } -@test "postscript xcatlib recursive download rejects dispatcher scripts" { +@test "xcatdsklspost recursive download rejects dispatcher scripts" { local wget_log="${BATS_TEST_TMPDIR}/xcatdsklspost-wget.log" - run capture_xcatlib_wget "$wget_log" + run capture_xcatdsklspost_wget "$wget_log" [ "$status" -eq 0 ] assert_download_policy "$(read_file_or_empty "$wget_log")" } diff --git a/xCAT/postscripts/xcatdsklspost b/xCAT/postscripts/xcatdsklspost index 6e2ad718e..40d1dde3d 100755 --- a/xCAT/postscripts/xcatdsklspost +++ b/xCAT/postscripts/xcatdsklspost @@ -127,6 +127,66 @@ download_mypostscript() } +download_postscripts() +{ + server=$1 + if [ -z $server ]; then + return 1; + fi + + # Do not override the parameter --installdir + if [ -z "$INSTALLDIR" ]; then + if [ -f /opt/xcat/xcatinfo ]; then + INSTALLDIR=`grep 'INSTALLDIR' /opt/xcat/xcatinfo |cut -d= -f2` + fi + if [ -z "$INSTALLDIR" ]; then + INSTALLDIR="/install" + fi + fi + echolog "debug" "trying to download postscripts from http://$server$INSTALLDIR/postscripts/" + max_retries=5 + retry=0 + rc=1 # this is a fail return + while [ 0 -eq 0 ]; do + if [ -e "$xcatpost" ]; then + rm -rf "$xcatpost" + fi + + # These dispatcher scripts are not needed by the legacy netboot post + # path. Newer wget parses HTML-looking regex strings inside downloaded + # scripts and fails the whole recursive download on bogus URLs. + export LANG=C; wget -l inf -nH -N -r --waitretry=10 --random-wait -e robots=off -T 60 -nH --cut-dirs=2 --reject "index.html*,post.xcat.ng,post.xcat.rhels10" --no-parent http://$server$INSTALLDIR/postscripts/ -P /$xcatpost 2> /tmp/wget.log + rc=$? + if [ $rc -eq 0 ]; then + # return from wget was 0 but some OS do not return errors, so we + # have additional checks for + # failed: Connection httpd not running + # 404: Not Found - if directory does not exist + grep -i -E "... failed: Connection refused.$" /tmp/wget.log + rc1=$? + grep -i -E "ERROR 404: Not Found.$" /tmp/wget.log + rc2=$? + # check to see no errors at all, grep returns 1 + if [ $rc1 -eq 1 ] && [ $rc2 -eq 1 ]; then + echolog "debug" "postscripts are downloaded from $server successfully." + return 0 + fi + fi + + retry=$(($retry+1)) + echolog "debug" "download_postscripts retry $retry" + if [ $retry -eq $max_retries ]; then + echolog "debug" "failed to download postscripts from http://$server$INSTALLDIR/postscripts/ after several retries." + break + fi + + SLI=$(awk 'BEGIN{srand(); printf("%d\n",rand()*20)}') + sleep $SLI + done + return $rc +} + + # pmatch determines if 1st argument string is matched by 2nd argument pattern pmatch () @@ -161,6 +221,10 @@ parsehttpserver () fi } +if [ "$XCATDSKLSPOST_SOURCE_ONLY" = "1" ]; then + return 0 2>/dev/null || exit 0 +fi + # Main # parse the arguments log_label="xcat.updatenode" diff --git a/xCAT/postscripts/xcatlib.sh b/xCAT/postscripts/xcatlib.sh index 8e2dd1431..6dd27ded5 100755 --- a/xCAT/postscripts/xcatlib.sh +++ b/xCAT/postscripts/xcatlib.sh @@ -833,71 +833,6 @@ function msgutil { msgutil_r "" "$@" } -function xcat_download_postscripts { - local server="$1" - local install_dir="${2:-${INSTALLDIR:-/install}}" - local postroot="${3:-/$xcatpost}" - local log_file="${4:-/tmp/wget.log}" - - export LANG=C - wget -l inf -nH -N -r --waitretry=10 --random-wait -e robots=off -T 60 -nH --cut-dirs=2 --reject "index.html*,post.xcat.ng,post.xcat.rhels10" --no-parent "http://$server$install_dir/postscripts/" -P "$postroot" 2> "$log_file" -} - -function download_postscripts { - server=$1 - if [ -z $server ]; then - return 1; - fi - - # Do not override the parameter --installdir - if [ -z "$INSTALLDIR" ]; then - if [ -f /opt/xcat/xcatinfo ]; then - INSTALLDIR=`grep 'INSTALLDIR' /opt/xcat/xcatinfo |cut -d= -f2` - fi - if [ -z "$INSTALLDIR" ]; then - INSTALLDIR="/install" - fi - fi - echolog "debug" "trying to download postscripts from http://$server$INSTALLDIR/postscripts/" - max_retries=5 - retry=0 - rc=1 # this is a fail return - while [ 0 -eq 0 ]; do - if [ -e "$xcatpost" ]; then - rm -rf "$xcatpost" - fi - - xcat_download_postscripts "$server" "$INSTALLDIR" "/$xcatpost" "/tmp/wget.log" - rc=$? - if [ $rc -eq 0 ]; then - # return from wget was 0 but some OS do not return errors, so we - # have additional checks for - # failed: Connection httpd not running - # 404: Not Found - if directory does not exist - grep -i -E "... failed: Connection refused.$" /tmp/wget.log - rc1=$? - grep -i -E "ERROR 404: Not Found.$" /tmp/wget.log - rc2=$? - # check to see no errors at all, grep returns 1 - if [ $rc1 -eq 1 ] && [ $rc2 -eq 1 ]; then - echolog "debug" "postscripts are downloaded from $server successfully." - return 0 - fi - fi - - retry=$(($retry+1)) - echolog "debug" "download_postscripts retry $retry" - if [ $retry -eq $max_retries ]; then - echolog "debug" "failed to download postscripts from http://$server$INSTALLDIR/postscripts/ after several retries." - break - fi - - SLI=$(awk 'BEGIN{srand(); printf("%d\n",rand()*20)}') - sleep $SLI - done - return $rc -} - function xcat_wait_for_processes_to_exit { local pidlist="$1" local max_wait="${2:-10}"