Adjust allowing for git version input 3006 or 3007

This commit is contained in:
David Murphy 2024-11-25 12:32:09 -07:00
parent 86d1bb9662
commit 8fa55b714e
No known key found for this signature in database
GPG key ID: 9D7724F37A7424D8
2 changed files with 37 additions and 33 deletions

View file

@ -640,11 +640,7 @@ elif [ "$ITYPE" = "git" ]; then
if [ "$#" -eq 0 ];then
GIT_REV="master"
else
if [ "$(echo "$1" | grep -E '^(3006|3007)$')" != "" ]; then
GIT_REV="$1.x" # branches are 3006.x or 3007.x
else
GIT_REV="$1"
fi
GIT_REV="$1"
shift
fi
@ -2097,6 +2093,7 @@ __tdnf_install_noinput() {
# DESCRIPTION: (DRY) Helper function to clone and checkout salt to a
# specific revision.
#----------------------------------------------------------------------------------------------------------------------
# shellcheck disable=SC2120
__git_clone_and_checkout() {
echodebug "Installed git version: $(git --version | awk '{ print $3 }')"
@ -2105,6 +2102,12 @@ __git_clone_and_checkout() {
export GIT_SSL_NO_VERIFY=1
fi
if [ "$(echo "$GIT_REV" | grep -E '^(3006|3007)$')" != "" ]; then
GIT_REV_ADJ="$1.x" # branches are 3006.x or 3007.x
else
GIT_REV_ADJ="$GIT_REV"
fi
__SALT_GIT_CHECKOUT_PARENT_DIR=$(dirname "${_SALT_GIT_CHECKOUT_DIR}" 2>/dev/null)
__SALT_GIT_CHECKOUT_PARENT_DIR="${__SALT_GIT_CHECKOUT_PARENT_DIR:-/tmp/git}"
__SALT_CHECKOUT_REPONAME="$(basename "${_SALT_GIT_CHECKOUT_DIR}" 2>/dev/null)"
@ -2133,15 +2136,15 @@ __git_clone_and_checkout() {
git fetch --tags upstream
fi
echodebug "Hard reseting the cloned repository to ${GIT_REV}"
git reset --hard "$GIT_REV" || return 1
echodebug "Hard reseting the cloned repository to ${GIT_REV_ADJ}"
git reset --hard "$GIT_REV_ADJ" || return 1
# Just calling `git reset --hard $GIT_REV` on a branch name that has
# Just calling `git reset --hard $GIT_REV_ADJ` on a branch name that has
# already been checked out will not update that branch to the upstream
# HEAD; instead it will simply reset to itself. Check the ref to see
# if it is a branch name, check out the branch, and pull in the
# changes.
if git branch -a | grep -q "${GIT_REV}"; then
if git branch -a | grep -q "${GIT_REV_ADJ}"; then
echodebug "Rebasing the cloned repository branch"
git pull --rebase || return 1
fi
@ -2163,16 +2166,16 @@ __git_clone_and_checkout() {
# cloning we need actually works
if [ "$(git clone 2>&1 | grep 'single-branch')" != "" ]; then
# The "--single-branch" option is supported, attempt shallow cloning
echoinfo "Attempting to shallow clone $GIT_REV from Salt's repository ${_SALT_REPO_URL}"
echoinfo "Attempting to shallow clone $GIT_REV_ADJ from Salt's repository ${_SALT_REPO_URL}"
## Shallow cloning is resulting in the wrong version of Salt, even with a depth of 5
## getting 3007.0+0na.246d066 when it should be 3007.1+410.g246d066457, disabling for now
## if git clone --depth 1 --branch "$GIT_REV" "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME"; then
echodebug "git command, git clone --branch $GIT_REV $_SALT_REPO_URL $__SALT_CHECKOUT_REPONAME"
if git clone --branch "$GIT_REV" "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME"; then
## if git clone --depth 1 --branch "$GIT_REV_ADJ" "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME"; then
echodebug "git command, git clone --branch $GIT_REV_ADJ $_SALT_REPO_URL $__SALT_CHECKOUT_REPONAME"
if git clone --branch "$GIT_REV_ADJ" "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME"; then
# shellcheck disable=SC2164
cd "${_SALT_GIT_CHECKOUT_DIR}"
__SHALLOW_CLONE=$BS_TRUE
echoinfo "shallow path (disabled shallow) git cloned $GIT_REV, version $(python3 salt/version.py)"
echoinfo "shallow path (disabled shallow) git cloned $GIT_REV_ADJ, version $(python3 salt/version.py)"
else
# Shallow clone above failed(missing upstream tags???), let's resume the old behaviour.
echowarn "Failed to shallow clone."
@ -2191,7 +2194,7 @@ __git_clone_and_checkout() {
# shellcheck disable=SC2164
cd "${_SALT_GIT_CHECKOUT_DIR}"
echoinfo "git cloned $GIT_REV, version $(python3 salt/version.py)"
echoinfo "git cloned $GIT_REV_ADJ, version $(python3 salt/version.py)"
if ! echo "$_SALT_REPO_URL" | grep -q -F -w "${_SALTSTACK_REPO_URL#*://}"; then
# We need to add the saltstack repository as a remote and fetch tags for proper versioning
@ -2201,14 +2204,14 @@ __git_clone_and_checkout() {
echodebug "Fetching upstream (SaltStack's Salt repository) git tags"
git fetch --tags upstream || return 1
# Check if GIT_REV is a remote branch or just a commit hash
if git branch -r | grep -q -F -w "origin/$GIT_REV"; then
GIT_REV="origin/$GIT_REV"
# Check if GIT_REV_ADJ is a remote branch or just a commit hash
if git branch -r | grep -q -F -w "origin/$GIT_REV_ADJ"; then
GIT_REV_ADJ="origin/$GIT_REV_ADJ"
fi
fi
echodebug "Checking out $GIT_REV"
git checkout "$GIT_REV" || return 1
echodebug "Checking out $GIT_REV_ADJ"
git checkout "$GIT_REV_ADJ" || return 1
fi
fi
@ -3158,6 +3161,7 @@ install_ubuntu_git_deps() {
__apt_get_install_noinput ca-certificates
fi
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -ne 3 ]; then
@ -3615,6 +3619,7 @@ install_debian_git_deps() {
__apt_get_install_noinput ca-certificates
fi
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -ne 3 ]; then
@ -3963,6 +3968,7 @@ install_fedora_git_deps() {
__PACKAGES=""
fi
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
__PACKAGES="python${PY_PKG_VER}-devel python${PY_PKG_VER}-pip python${PY_PKG_VER}-setuptools gcc gcc-c++"
@ -4373,6 +4379,7 @@ install_centos_git_deps() {
__yum_install_noinput git || return 1
fi
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
__PACKAGES=""
@ -5418,6 +5425,7 @@ install_alpine_linux_git_deps() {
apk -U add git || return 1
fi
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
apk -U add python3 python3-dev py3-pip py3-setuptools g++ linux-headers zeromq-dev openrc || return 1
@ -5584,6 +5592,7 @@ install_amazon_linux_ami_2_git_deps() {
__yum_install_noinput git || return 1
fi
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
__PACKAGES="python${PY_PKG_VER}-pip python${PY_PKG_VER}-setuptools python${PY_PKG_VER}-devel gcc"
@ -5803,6 +5812,7 @@ install_amazon_linux_ami_2023_git_deps() {
__yum_install_noinput git || return 1
fi
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
__PACKAGES="python${PY_PKG_VER}-pip python${PY_PKG_VER}-setuptools python${PY_PKG_VER}-devel gcc"
@ -5990,6 +6000,7 @@ install_arch_linux_git_deps() {
pacman -Sy --noconfirm --needed git || return 1
fi
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 2 ]; then
@ -6373,6 +6384,7 @@ install_photon_git_deps() {
__PACKAGES=""
fi
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
__PACKAGES="python${PY_PKG_VER}-devel python${PY_PKG_VER}-pip python${PY_PKG_VER}-setuptools gcc glibc-devel linux-devel.x86_64 cython${PY_PKG_VER}"
@ -6732,6 +6744,7 @@ install_opensuse_git_deps() {
__zypper_install git || return 1
fi
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
# Check for Tumbleweed
@ -6966,6 +6979,7 @@ install_opensuse_15_git_deps() {
__zypper_install git || return 1
fi
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -ne 3 ]; then
@ -7221,6 +7235,7 @@ install_gentoo_git_deps() {
echoinfo "Running emerge -v1 setuptools"
__emerge -v1 setuptools || return 1
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
__gentoo_post_dep || return 1
}
@ -7589,6 +7604,7 @@ install_macosx_git_deps() {
# Install PIP
$_PYEXE /tmp/get-pip.py || return 1
# shellcheck disable=SC2119
__git_clone_and_checkout || return 1
return 0
@ -8125,6 +8141,7 @@ fi
if [ "${ITYPE}" = "git" ] && [ ${_NO_DEPS} -eq ${BS_TRUE} ]; then
# shellcheck disable=SC2119
if ! __git_clone_and_checkout; then
echo "Failed to clone and checkout git repository."
exit 1

View file

@ -29,10 +29,6 @@ def run_salt_call(cmd):
if platform.system() == "Windows":
cmd.append("--out=json")
result = subprocess.run(cmd, capture_output=True, text=True)
print(
f"DGM run_salt_call, cmd '{cmd}', result '{result}', stdout '{result.stdout}'",
flush=True,
)
if 0 == result.returncode:
json_data = json.loads(result.stdout)
else:
@ -43,10 +39,6 @@ def run_salt_call(cmd):
cmdl.extend(cmd)
cmdl.append("--out=json")
result = subprocess.run(cmdl, capture_output=True, text=True)
print(
f"DGM run_salt_call, cmdl '{cmdl}', result '{result}', stdout '{result.stdout}'",
flush=True,
)
if 0 == result.returncode:
json_data = json.loads(result.stdout)
else:
@ -74,10 +66,5 @@ def test_target_salt_version(path, target_salt_version):
pytest.skip(f"No target version specified")
cmd = ["salt-call", "--local", "grains.item", "saltversion", "--timeout=120"]
result = run_salt_call(cmd)
dgm_saltversion = result["saltversion"]
print(
f"DGM test_target_salt_version, target_salt_version '{target_salt_version}', result saltversion '{dgm_saltversion }', result '{result}'",
flush=True,
)
# Returns: {'saltversion': '3006.9+217.g53cfa53040'}
assert result["saltversion"] == target_salt_version