Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions bootstrap-salt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,33 @@ __salt_version_string() {
echo "$1"
}

#--- FUNCTION -------------------------------------------------------------------------------------------------------
# NAME: __salt_repo_exclude_majors
# DESCRIPTION: Print the exclude= value for a salt.repo section that must
# stay on the major version of the Salt version in $1 (e.g.
# 3006.26 or 3008.1-1). The baseurl serves every major, so
# without it the first yum/dnf update moves to the newest
# Salt. Same list as the official salt.repo: 3006 through 3010
# minus the given major. For majors past 3008 the list runs to
# the major + 2, so the next two majors are still excluded.
#----------------------------------------------------------------------------------------------------------------------
__salt_repo_exclude_majors() {
_EXCLUDE_MAJOR=$(echo "$1" | cut -d '.' -f 1)
_EXCLUDE_LAST=3010
if [ "$_EXCLUDE_MAJOR" -gt 3008 ]; then
_EXCLUDE_LAST=$((_EXCLUDE_MAJOR + 2))
fi
_EXCLUDE_LIST=""
_EXCLUDE_REV=3006
while [ "$_EXCLUDE_REV" -le "$_EXCLUDE_LAST" ]; do
if [ "$_EXCLUDE_REV" -ne "$_EXCLUDE_MAJOR" ]; then
_EXCLUDE_LIST="${_EXCLUDE_LIST} *${_EXCLUDE_REV}*"
fi
_EXCLUDE_REV=$((_EXCLUDE_REV + 1))
done
echo "${_EXCLUDE_LIST# }"
}

# check if systemd is functional
__check_services_systemd_functional

Expand Down Expand Up @@ -4220,6 +4247,7 @@ __install_saltstack_fedora_onedir_repository() {
echo "enabled=1" >> "${YUM_REPO_FILE}"
echo "enabled_metadata=1" >> "${YUM_REPO_FILE}"
echo "gpgcheck=1" >> "${YUM_REPO_FILE}"
echo "exclude=$(__salt_repo_exclude_majors "$ONEDIR_REV_DOT")" >> "${YUM_REPO_FILE}"
echo "gpgkey=https://${_REPO_URL}/api/security/keypair/SaltProjectKey/public" >> "${YUM_REPO_FILE}"
fi
else
Expand Down Expand Up @@ -4559,6 +4587,7 @@ __install_saltstack_rhel_onedir_repository() {
echo "enabled=1" >> "${YUM_REPO_FILE}"
echo "enabled_metadata=1" >> "${YUM_REPO_FILE}"
echo "gpgcheck=1" >> "${YUM_REPO_FILE}"
echo "exclude=$(__salt_repo_exclude_majors "$ONEDIR_REV_DOT")" >> "${YUM_REPO_FILE}"
echo "gpgkey=https://${_REPO_URL}/api/security/keypair/SaltProjectKey/public" >> "${YUM_REPO_FILE}"
fi
else
Expand Down Expand Up @@ -6041,6 +6070,7 @@ install_amazon_linux_ami_2_deps() {
echo "enabled=1" >> "${YUM_REPO_FILE}"
echo "enabled_metadata=1" >> "${YUM_REPO_FILE}"
echo "gpgcheck=1" >> "${YUM_REPO_FILE}"
echo "exclude=$(__salt_repo_exclude_majors "$STABLE_REV_DOT")" >> "${YUM_REPO_FILE}"
echo "gpgkey=https://${_REPO_URL}/api/security/keypair/SaltProjectKey/public" >> "${YUM_REPO_FILE}"
fi
else
Expand Down Expand Up @@ -6142,6 +6172,7 @@ install_amazon_linux_ami_2_onedir_deps() {
echo "enabled=1" >> "${YUM_REPO_FILE}"
echo "enabled_metadata=1" >> "${YUM_REPO_FILE}"
echo "gpgcheck=1" >> "${YUM_REPO_FILE}"
echo "exclude=$(__salt_repo_exclude_majors "$ONEDIR_REV_DOT")" >> "${YUM_REPO_FILE}"
echo "gpgkey=https://${_REPO_URL}/api/security/keypair/SaltProjectKey/public" >> "${YUM_REPO_FILE}"
fi
else
Expand Down Expand Up @@ -6335,6 +6366,7 @@ install_amazon_linux_ami_2023_onedir_deps() {
echo "enabled=1" >> "${YUM_REPO_FILE}"
echo "enabled_metadata=1" >> "${YUM_REPO_FILE}"
echo "gpgcheck=1" >> "${YUM_REPO_FILE}"
echo "exclude=$(__salt_repo_exclude_majors "$ONEDIR_REV_DOT")" >> "${YUM_REPO_FILE}"
echo "gpgkey=https://${_REPO_URL}/api/security/keypair/SaltProjectKey/public" >> "${YUM_REPO_FILE}"
fi
else
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/test_installation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import configparser
import json
import logging
import os
Expand Down Expand Up @@ -317,6 +318,40 @@ def test_rpm_repo_file_rewrite_custom_repo_url(tmp_path):
assert result.count("enabled=1") == 1 and result.count("enabled=0") == 1


def test_rpm_point_release_repo_excludes_other_majors():
"""
Regression test for https://github.com/saltstack/salt-bootstrap/issues/2147
For a point release (e.g. "stable 3006.24") bootstrap writes its own
salt.repo section. Its baseurl serves every major, so the section must
exclude the other majors or the next "dnf update" moves Salt to the newest
one in the repo.
"""
repo_file = "/etc/yum.repos.d/salt.repo"
if platform.system() != "Linux" or not os.path.exists(repo_file):
pytest.skip("No salt.repo file present")
if os.path.exists("/etc/photon-release"):
pytest.skip("tdnf doesn't read exclude= from a .repo file")

repo = configparser.ConfigParser(interpolation=None)
repo.read(repo_file)
# Only the point release path names the section after the full version,
# e.g. [salt-repo-3006.24-lts]
sections = []
for section in repo.sections():
match = re.match(r"salt-repo-(\d{4})\.\S+-lts$", section)
if match:
sections.append((section, int(match.group(1))))
if not sections:
pytest.skip("salt.repo was not written for a point release")

for section, major in sections:
exclude = repo[section].get("exclude", "").split()
assert f"*{major}*" not in exclude, f"[{section}] excludes its own major"
for other in range(3006, 3011):
if other != major:
assert f"*{other}*" in exclude, f"[{section}] does not exclude {other}"


DETECTION_FUNCTIONS = [
"__gather_linux_system_info",
"__sort_release_files",
Expand Down
43 changes: 43 additions & 0 deletions tests/shell/point_release_repo_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# shellcheck shell=sh

# Regression test for #2147: for a point release the RPM repository functions
# write their own salt.repo section, and its baseurl serves every major. Without
# an exclude= line the first yum/dnf update moves to the newest Salt.
Describe 'point release salt.repo'
Include "$(bootstrap_functions __salt_version_string __salt_repo_exclude_majors __rewrite_repo_url __install_saltstack_rhel_onedir_repository __install_saltstack_fedora_onedir_repository)"

BS_TRUE=1
BS_FALSE=0
_FORCE_OVERWRITE=$BS_FALSE
_PY_EXE="python3"
_PY_MAJOR_VERSION=3
_REPO_URL="packages.broadcom.com/artifactory"

# Mocks: no network, no package manager
__fetch_url() { printf '[salt-repo-latest]\n' > "$1"; }
yum() { :; }
dnf() { :; }
echodebug() { :; }

setup() {
WORK=$(mktemp -d)
YUM_REPO_FILE="$WORK/salt.repo"
}
cleanup() { rm -rf "$WORK"; }
BeforeEach setup
AfterEach cleanup

Parameters
__install_saltstack_rhel_onedir_repository "3006.26" "*3007* *3008* *3009* *3010*"
__install_saltstack_fedora_onedir_repository "3007.15" "*3006* *3008* *3009* *3010*"
__install_saltstack_rhel_onedir_repository "3008.1-1" "*3006* *3007* *3009* *3010*"
End

It "$1 keeps $2 on its major"
ONEDIR_REV="$2"
When call "$1"
The status should be success
The contents of file "$YUM_REPO_FILE" should include "[salt-repo-$2-lts]"
The contents of file "$YUM_REPO_FILE" should include "exclude=$3"
End
End
19 changes: 18 additions & 1 deletion tests/shell/version_helpers_spec.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# shellcheck shell=sh

Describe 'version and string helpers'
Include "$(bootstrap_functions __parse_version_string __unquote_string __camelcase_split __derive_debian_numeric_version)"
Include "$(bootstrap_functions __parse_version_string __unquote_string __camelcase_split __derive_debian_numeric_version __salt_repo_exclude_majors)"

Describe '__parse_version_string'
Parameters
Expand Down Expand Up @@ -57,4 +57,21 @@ Describe 'version and string helpers'
The output should eq ""
End
End

Describe '__salt_repo_exclude_majors'
# 3006 to 3008 match the exclude= lines in the official salt.repo
Parameters
"3006" "*3007* *3008* *3009* *3010*"
"3006.26" "*3007* *3008* *3009* *3010*"
"3007.15" "*3006* *3008* *3009* *3010*"
"3008.1-1" "*3006* *3007* *3009* *3010*"
"3009.2" "*3006* *3007* *3008* *3010* *3011*"
"3012.1" "*3006* *3007* *3008* *3009* *3010* *3011* *3013* *3014*"
End

It "excludes every major but the one in $1"
When call __salt_repo_exclude_majors "$1"
The output should eq "$2"
End
End
End
Loading