Skip to content

Commit 86b8df2

Browse files
committed
fix(linux): GA-only latest/major version pick; exact RC dirs; integration tests
Align _get_desired_salt_version_fn with Windows: filter GA CalVer dirs for latest, default branch, and four-digit major; require exact directory match or legacy pattern for prerelease; fail when no GA exists for major/latest. Extend tests/linux/test-linux.sh: default testarea latest stays on 3007.1 GA when 3008.0rc1 is present; -m 3008 leaves minion uninstalled without GA; -m 3008.0rc1 installs RC (needs matching linux-*-onedir-*.tar.xz in testarea).
1 parent 6a00c5f commit 86b8df2

4 files changed

Lines changed: 112 additions & 28 deletions

File tree

linux/svtminion.sh

Lines changed: 83 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ esac
302302
echo " silent error warning debug info"
303303
echo " default loglevel is warning"
304304
echo " -m, --minionversion install salt-minion version, default[latest]"
305+
echo " 'latest' and four-digit major (e.g. 3006) pick"
306+
echo " newest GA onedir only; prerelease dirs need"
307+
echo " the exact directory name (e.g. 3008.0rc1)"
305308
echo " -n, --reconfig salt-minion restarts after reading updated config"
306309
echo " -q, --stop stop salt-minion"
307310
echo " -p, --start start salt-minion (restarts salt-minion)"
@@ -401,28 +404,42 @@ _set_log_level() {
401404

402405

403406

407+
#
408+
# _salt_onedir_dir_is_ga
409+
#
410+
# True (status 0) if the onedir directory name is GA numeric CalVer only
411+
# (digits and dots). Prerelease names (e.g. 3008.0rc1) are not GA.
412+
#
413+
# Results:
414+
# 0 if GA, 1 otherwise
415+
#
416+
_salt_onedir_dir_is_ga() {
417+
local _ga_re='^[0-9]+\.[0-9]+(\.[0-9]+)*$'
418+
[[ -n "$1" && "$1" =~ ${_ga_re} ]]
419+
}
420+
421+
404422
#
405423
# _get_desired_salt_version_fn
406424
#
407425
# Get the appropriate desirted salt version based on salt_url_version,
408-
# latest or specified input Salt version, 3007, 3006, 3006.x, 3007.1
426+
# latest or specified input Salt version, 3008, 3006.10, 3008.0rc1
409427
# and set salt_specific_version accordinly
410428
#
411-
# Note: typically Salt version includes the release number in addition to
412-
# version number or 'latest' for the most recent release
413-
#
414-
# for example: currently major version 3006 implies 3006.9
415-
# the latest version of Salt 3006.x
429+
# Note: 'latest' and four-digit major (e.g. 3006) choose the newest GA
430+
# onedir only (sort -V among dirs matching ^[0-9]+\\.[0-9]+(\\.[0-9]+)*$).
431+
# Prerelease directories must be requested by exact name (directory
432+
# match or legacy CalVer pattern).
416433
#
417434
# if an unsupported version is input, for example: 3004.2
418-
# it will default to installing the latest version
435+
# it will default to installing the latest GA version
419436
#
420437
# Input:
421438
# directory contains directory list of current available
422-
# Salt versions, 3006.x - 3007.1
439+
# Salt versions, e.g. 3006.x, 3007.1, 3008.0rc1
423440
#
424441
# Results:
425-
# Returns with exit code
442+
# Returns with exit code (1 if no GA match for latest/major/default)
426443
#
427444
_get_desired_salt_version_fn() {
428445

@@ -440,46 +457,79 @@ _get_desired_salt_version_fn() {
440457

441458
# something werid is happening with tail, that does not fail in test
442459
# programs getting failures inside tail hence use bash loop
460+
_GENERIC_PKG_VERSION=""
443461
if [ "$salt_url_version" = "latest" ]; then
444462
# shellcheck disable=SC2010,SC2012
445-
## _GENERIC_PKG_VERSION=$(ls ./. | grep -v 'index.html' | sort -V -u | tail -n 1)
446463
test_dir=$(ls ./. | grep -v 'index.html' | sort -V -u)
447464
for idx in $test_dir
448465
do
449-
_GENERIC_PKG_VERSION="$idx"
466+
if _salt_onedir_dir_is_ga "$idx"; then
467+
_GENERIC_PKG_VERSION="$idx"
468+
fi
450469
done
451-
_debug_log "$0:${FUNCNAME[0]} latest found version '${_GENERIC_PKG_VERSION}'"
470+
if [[ -z "${_GENERIC_PKG_VERSION}" ]]; then
471+
cd "${curr_pwd}" || return 1
472+
_error_log "$0:${FUNCNAME[0]} no GA onedir version directories "\
473+
"found for 'latest' at '${generic_versions_tmpdir}'"
474+
return 1
475+
fi
476+
_debug_log "$0:${FUNCNAME[0]} latest found GA version "\
477+
"'${_GENERIC_PKG_VERSION}'"
452478

453-
elif [ "$(echo "$salt_url_version" | grep -E '^(3006|3007)$')" != "" ]; then
454-
# want major latest version of Salt
479+
elif [[ "${salt_url_version}" =~ ^[0-9]{4}$ ]]; then
480+
# want newest GA in this major series (3006, 3007, 3008, ...)
455481
# shellcheck disable=SC2010,SC2012
456-
## _GENERIC_PKG_VERSION=$(ls ./. | grep -v 'index.html' | sort -V -u | grep -E "$salt_url_version" | tail -n 1)
457-
test_dir=$(ls ./. | grep -v 'index.html' | sort -V -u | grep -E "$salt_url_version")
482+
test_dir=$(ls ./. | grep -v 'index.html' | sort -V -u \
483+
| grep -E "^${salt_url_version}\\.")
458484
for idx in $test_dir
459485
do
460-
_GENERIC_PKG_VERSION="$idx"
486+
if _salt_onedir_dir_is_ga "$idx"; then
487+
_GENERIC_PKG_VERSION="$idx"
488+
fi
461489
done
462-
_debug_log "$0:${FUNCNAME[0]} input $salt_url_version found "\
463-
"version '${_GENERIC_PKG_VERSION}'"
490+
if [[ -z "${_GENERIC_PKG_VERSION}" ]]; then
491+
cd "${curr_pwd}" || return 1
492+
_error_log "$0:${FUNCNAME[0]} no GA onedir version found for "\
493+
"major series '${salt_url_version}' at "\
494+
"'${generic_versions_tmpdir}'"
495+
return 1
496+
fi
497+
_debug_log "$0:${FUNCNAME[0]} input ${salt_url_version} found "\
498+
"GA version '${_GENERIC_PKG_VERSION}'"
499+
500+
elif [[ -d "./${salt_url_version}" ]]; then
501+
_GENERIC_PKG_VERSION="${salt_url_version}"
502+
_debug_log "$0:${FUNCNAME[0]} exact directory match "\
503+
"'${_GENERIC_PKG_VERSION}'"
464504

465505
elif [ "$(echo "$salt_url_version" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
466-
# Minor version Salt, want specific minor version
506+
# Minor version Salt, want specific minor version (incl. prerelease tags)
467507
# if old style VMTools version 3004.2-1 is used
468-
# defaults to else and install latest
508+
# defaults to else and install latest GA
469509
_GENERIC_PKG_VERSION="$salt_url_version"
510+
_debug_log "$0:${FUNCNAME[0]} explicit version "\
511+
"'${_GENERIC_PKG_VERSION}'"
470512
else
471-
# default to latest version Salt
513+
# default to latest GA version Salt
472514
# shellcheck disable=SC2010,SC2012
473-
## _GENERIC_PKG_VERSION=$(ls ./. | grep -v 'index.html' | sort -V -u | tail -n 1)
474515
test_dir=$(ls ./. | grep -v 'index.html' | sort -V -u)
475516
for idx in $test_dir
476517
do
477-
_GENERIC_PKG_VERSION="$idx"
518+
if _salt_onedir_dir_is_ga "$idx"; then
519+
_GENERIC_PKG_VERSION="$idx"
520+
fi
478521
done
479-
_debug_log "$0:${FUNCNAME[0]} default found version '${_GENERIC_PKG_VERSION}'"
522+
if [[ -z "${_GENERIC_PKG_VERSION}" ]]; then
523+
cd "${curr_pwd}" || return 1
524+
_error_log "$0:${FUNCNAME[0]} no GA onedir version directories "\
525+
"found for default latest at '${generic_versions_tmpdir}'"
526+
return 1
527+
fi
528+
_debug_log "$0:${FUNCNAME[0]} default found GA version "\
529+
"'${_GENERIC_PKG_VERSION}'"
480530

481531
fi
482-
cd ${curr_pwd} || return 1
532+
cd "${curr_pwd}" || return 1
483533

484534
# set specific version of Salt to use
485535
salt_specific_version="${_GENERIC_PKG_VERSION}"
@@ -926,7 +976,7 @@ _fetch_salt_minion() {
926976
_debug_log "$0:${FUNCNAME[0]} current directory ${curr_dir}"
927977

928978
# get desired specific version of Salt
929-
_get_desired_salt_version_fn "${salt_url}"
979+
_get_desired_salt_version_fn "${salt_url}" || return 1
930980
cd "${salt_url}" || return 1
931981
cd "${salt_specific_version}" || return 1
932982
salt_pkg_name=$(ls "${salt_name}-${salt_specific_version}-onedir-linux-${sys_arch}.tar.xz")
@@ -949,7 +999,12 @@ _fetch_salt_minion() {
949999
cd ${curr_pwd} || return 1
9501000

9511001
# get desired specific version of Salt
952-
_get_desired_salt_version_fn "${generic_versions_tmpdir}/artifactory/saltproject-generic/onedir"
1002+
if ! _get_desired_salt_version_fn \
1003+
"${generic_versions_tmpdir}/artifactory/saltproject-generic/onedir"
1004+
then
1005+
rm -fR "${generic_versions_tmpdir}"
1006+
return 1
1007+
fi
9531008

9541009
# clean up temp dir
9551010
rm -fR ${generic_versions_tmpdir}

tests/linux/test-linux.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,34 @@ sleep 1
136136
cat /etc/salt/minion
137137
cat /etc/salt/minion | grep 'master:\ 192.168.0.5' 1>/dev/null
138138
./svtminion.sh --remove || { _retn=$?; echo "test failed, did not uninstall the salt-minion, returned '${_retn}'"; }
139+
# GA vs RC (testarea includes 3008.0rc1 Linux onedir): default latest must be
140+
# max GA (3007.1), not the RC; major 3008 has no GA yet; exact 3008.0rc1 installs RC.
141+
./svtminion.sh --source ${oldpwd}/tests/testarea --install master=192.168.0.5 --loglevel debug
142+
./svtminion.sh --status --loglevel debug || { _retn=$?; if [[ ${_retn} -ne 100 ]]; then echo "test failed, salt-minion should be installed (latest GA), returned '${_retn}'"; exit 1; fi; }
143+
_salt_ver_out=$(/usr/bin/salt-call --local test.version --out=txt 2>/dev/null || true)
144+
if echo "${_salt_ver_out}" | grep -q "3007.1" && ! echo "${_salt_ver_out}" | grep -qi "rc"; then
145+
echo "test correct: default latest from testarea is GA 3007.1 not RC"
146+
else
147+
echo "test failed: expected GA 3007.1 without rc in test.version, got '${_salt_ver_out}'"
148+
exit 1
149+
fi
150+
./svtminion.sh --remove || { _retn=$?; echo "test failed, did not uninstall the salt-minion, returned '${_retn}'"; exit 1; }
151+
152+
./svtminion.sh --source ${oldpwd}/tests/testarea --minionversion 3008 --install master=192.168.0.5 --loglevel debug
153+
./svtminion.sh --status --loglevel debug || { _retn=$?; if [[ ${_retn} -eq 102 ]]; then echo "test correct: no GA for major 3008, minion not installed"; else echo "test failed, expected status 102 after install with -m 3008 and no GA, got '${_retn}'"; exit 1; fi; }
154+
./svtminion.sh --remove || true
155+
156+
./svtminion.sh --source ${oldpwd}/tests/testarea --minionversion 3008.0rc1 --install master=192.168.0.5 --loglevel debug
157+
./svtminion.sh --status --loglevel debug || { _retn=$?; if [[ ${_retn} -ne 100 ]]; then echo "test failed, salt-minion should be installed (3008.0rc1), returned '${_retn}'"; exit 1; fi; }
158+
_salt_ver_rc=$(/usr/bin/salt-call --local test.version --out=txt 2>/dev/null || true)
159+
if echo "${_salt_ver_rc}" | grep -qi "3008.0rc1"; then
160+
echo "test correct: exact RC 3008.0rc1 installed"
161+
else
162+
echo "test failed: expected 3008.0rc1 in test.version, got '${_salt_ver_rc}'"
163+
exit 1
164+
fi
165+
./svtminion.sh --remove || { _retn=$?; echo "test failed, did not uninstall the salt-minion, returned '${_retn}'"; exit 1; }
166+
139167
./svtminion.sh --source ${oldpwd}/tests/testarea --install master=192.168.0.5 --loglevel debug --minionversion 3007
140168
./svtminion.sh --status --loglevel debug || { _retn=$?; if [[ ${_retn} -eq 100 ]]; then echo "test correct"; else echo "test failed, salt-minion should be installed, returned '${_retn}'"; exit 1; fi; }
141169
sleep 1
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
salt-3007.1-onedir-windows-amd64.zip

0 commit comments

Comments
 (0)