mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-09-10 19:46:24 +00:00
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>
This commit is contained in:
@@ -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")"
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user