mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Initial attempt at downgrades on RPMS and DEBS
This commit is contained in:
parent
1a5d1a0fc5
commit
d986874ab0
5 changed files with 112 additions and 44 deletions
|
@ -1865,6 +1865,7 @@ def test_pkgs_onedir(session):
|
|||
+ session.posargs
|
||||
)
|
||||
_pytest(session, coverage=False, cmd_args=pytest_args, env=env)
|
||||
|
||||
if chunk not in ("install", "download-pkgs"):
|
||||
cmd_args = chunks["install"]
|
||||
pytest_args = (
|
||||
|
@ -1878,5 +1879,7 @@ def test_pkgs_onedir(session):
|
|||
]
|
||||
+ session.posargs
|
||||
)
|
||||
if "downgrade" in chunk:
|
||||
pytest_args.append("--use-prev-version")
|
||||
_pytest(session, coverage=False, cmd_args=pytest_args, env=env)
|
||||
sys.exit(0)
|
||||
|
|
|
@ -26,12 +26,12 @@ from tests.support.sminion import create_sminion
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
@pytest.fixture
|
||||
def version(install_salt):
|
||||
"""
|
||||
get version number from artifact
|
||||
"""
|
||||
return install_salt.get_version(version_only=True)
|
||||
return install_salt.version
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
|
@ -116,6 +116,11 @@ def pytest_addoption(parser):
|
|||
action="store",
|
||||
help="Test an upgrade from the version specified.",
|
||||
)
|
||||
test_selection_group.addoption(
|
||||
"--use-prev-version",
|
||||
action="store_true",
|
||||
help="Tells the test suite to validate the version using the previous version (for downgrades)",
|
||||
)
|
||||
test_selection_group.addoption(
|
||||
"--download-pkgs",
|
||||
default=False,
|
||||
|
@ -179,6 +184,7 @@ def install_salt(request, salt_factories_root_dir):
|
|||
no_install=request.config.getoption("--no-install"),
|
||||
classic=request.config.getoption("--classic"),
|
||||
prev_version=request.config.getoption("--prev-version"),
|
||||
use_prev_version=request.config.getoption("--use_prev-version"),
|
||||
) as fixture:
|
||||
yield fixture
|
||||
|
||||
|
|
43
pkg/tests/downgrade/test_salt_downgrade.py
Normal file
43
pkg/tests/downgrade/test_salt_downgrade.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
import pytest
|
||||
|
||||
|
||||
def test_salt_downgrade(salt_call_cli, install_salt):
|
||||
"""
|
||||
Test an upgrade of Salt.
|
||||
"""
|
||||
if not install_salt.downgrade:
|
||||
pytest.skip("Not testing a downgrade, do not run")
|
||||
|
||||
original_py_version = install_salt.package_python_version()
|
||||
|
||||
# Verify current install version is setup correctly and works
|
||||
ret = salt_call_cli.run("test.version")
|
||||
assert ret.returncode == 0
|
||||
assert ret.data == install_salt.artifact_version
|
||||
|
||||
# Test pip install before a downgrade
|
||||
dep = "PyGithub==1.56.0"
|
||||
install = salt_call_cli.run("--local", "pip.install", dep)
|
||||
assert install.returncode == 0
|
||||
|
||||
# Verify we can use the module dependent on the installed package
|
||||
repo = "https://github.com/saltstack/salt.git"
|
||||
use_lib = salt_call_cli.run("--local", "github.get_repo_info", repo)
|
||||
assert "Authentication information could" in use_lib.stderr
|
||||
|
||||
# Downgrade Salt to the previous version and test
|
||||
install_salt.install(downgrade=True)
|
||||
new_py_version = install_salt.package_python_version()
|
||||
ret = salt_call_cli.run("test.version")
|
||||
assert ret.returncode == 0
|
||||
assert ret.data == install_salt.prev_version
|
||||
|
||||
# Install dep following downgrade
|
||||
# TODO: This should be removed when we stop testing against versions < 3006.0
|
||||
if not install_salt.relenv or original_py_version != new_py_version:
|
||||
install = salt_call_cli.run("--local", "pip.install", dep)
|
||||
assert install.returncode == 0
|
||||
|
||||
# test pip install after a downgrade
|
||||
use_lib = salt_call_cli.run("--local", "github.get_repo_info", repo)
|
||||
assert "Authentication information could" in use_lib.stderr
|
|
@ -88,8 +88,9 @@ class SaltPkgInstall:
|
|||
|
||||
# Version information
|
||||
prev_version: str = attr.ib()
|
||||
major: str = attr.ib(init=False)
|
||||
minor: str = attr.ib(init=False)
|
||||
use_prev_version: str = attr.ib()
|
||||
artifact_version: str = attr.ib(init=False)
|
||||
version: str = attr.ib(init=False)
|
||||
|
||||
@proc.default
|
||||
def _default_proc(self):
|
||||
|
@ -168,38 +169,41 @@ class SaltPkgInstall:
|
|||
config_path = pathlib.Path("/etc", "salt")
|
||||
return config_path
|
||||
|
||||
@version.default
|
||||
def _default_version(self):
|
||||
"""
|
||||
The version to be installed at the start
|
||||
"""
|
||||
if not self.upgrade and not self.use_prev_version:
|
||||
version = self.artifact_version
|
||||
else:
|
||||
version = self.prev_version
|
||||
return version
|
||||
|
||||
@artifact_version.default
|
||||
def _default_artifact_version(self):
|
||||
"""
|
||||
The version of the local salt artifacts being tested, based on regex matching
|
||||
"""
|
||||
version = ""
|
||||
for artifact in ARTIFACTS_DIR.glob("**/*.*"):
|
||||
version = re.search(
|
||||
r"([0-9].*)(\-[0-9].fc|\-[0-9].el|\+ds|\_all|\_any|\_amd64|\_arm64|\-[0-9].am|(\-[0-9]-[a-z]*-[a-z]*[0-9_]*.|\-[0-9]*.*)(exe|msi|pkg|rpm|deb))",
|
||||
artifact.name,
|
||||
)
|
||||
if version:
|
||||
version = version.groups()[0].replace("_", "-").replace("~", "")
|
||||
version = version.split("-")[0]
|
||||
break
|
||||
return version
|
||||
|
||||
def update_process_path(self):
|
||||
# The installer updates the path for the system, but that doesn't
|
||||
# make it to this python session, so we need to update that
|
||||
os.environ["PATH"] = ";".join([str(self.install_dir), os.getenv("path")])
|
||||
|
||||
def get_version(self, version_only=False):
|
||||
"""
|
||||
Return the version information needed to install a previous version of Salt.
|
||||
"""
|
||||
if not self.upgrade:
|
||||
# Parse the version from a local artifact (regular or downgrade tests)
|
||||
version = ""
|
||||
for artifact in ARTIFACTS_DIR.glob("**/*.*"):
|
||||
version = re.search(
|
||||
r"([0-9].*)(\-[0-9].fc|\-[0-9].el|\+ds|\_all|\_any|\_amd64|\_arm64|\-[0-9].am|(\-[0-9]-[a-z]*-[a-z]*[0-9_]*.|\-[0-9]*.*)(exe|msi|pkg|rpm|deb))",
|
||||
artifact.name,
|
||||
)
|
||||
if version:
|
||||
version = version.groups()[0].replace("_", "-").replace("~", "")
|
||||
version = version.split("-")[0]
|
||||
break
|
||||
major, minor = version.split(".", 1)
|
||||
else:
|
||||
# This is an upgrade, start on the previous version
|
||||
major, minor = self.prev_version.split(".", 1)
|
||||
if version_only:
|
||||
return version
|
||||
return major, minor
|
||||
|
||||
def __attrs_post_init__(self):
|
||||
self.major, self.minor = self.get_version()
|
||||
self.relenv = packaging.version.parse(self.major) >= packaging.version.parse(
|
||||
self.relenv = packaging.version.parse(self.version) >= packaging.version.parse(
|
||||
"3006.0"
|
||||
)
|
||||
|
||||
|
@ -286,7 +290,10 @@ class SaltPkgInstall:
|
|||
assert ret.returncode == 0
|
||||
return True
|
||||
|
||||
def _install_pkgs(self, upgrade=False):
|
||||
def _install_pkgs(self, upgrade=False, downgrade=False):
|
||||
if downgrade:
|
||||
self.install_previous(downgrade=downgrade)
|
||||
return True
|
||||
pkg = self.pkgs[0]
|
||||
if platform.is_windows():
|
||||
if upgrade:
|
||||
|
@ -368,8 +375,8 @@ class SaltPkgInstall:
|
|||
"import sys; print('{}.{}'.format(*sys.version_info))",
|
||||
).stdout.strip()
|
||||
|
||||
def install(self, upgrade=False):
|
||||
self._install_pkgs(upgrade=upgrade)
|
||||
def install(self, upgrade=False, downgrade=False):
|
||||
self._install_pkgs(upgrade=upgrade, downgrade=downgrade)
|
||||
if self.distro_id in ("ubuntu", "debian"):
|
||||
self.stop_services()
|
||||
|
||||
|
@ -391,12 +398,12 @@ class SaltPkgInstall:
|
|||
self._check_retcode(stop_service)
|
||||
return True
|
||||
|
||||
def install_previous(self):
|
||||
def install_previous(self, downgrade=False):
|
||||
"""
|
||||
Install previous version. This is used for
|
||||
upgrade tests.
|
||||
"""
|
||||
major_ver = self.major
|
||||
major_ver = packaging.version.parse(self.prev_version).major
|
||||
distro_name = self.distro_name
|
||||
if distro_name == "centos" or distro_name == "fedora":
|
||||
distro_name = "redhat"
|
||||
|
@ -430,9 +437,10 @@ class SaltPkgInstall:
|
|||
)
|
||||
ret = self.proc.run(self.pkg_mngr, "clean", "expire-cache")
|
||||
self._check_retcode(ret)
|
||||
cmd_action = "downgrade" if downgrade else "install"
|
||||
ret = self.proc.run(
|
||||
self.pkg_mngr,
|
||||
"install",
|
||||
cmd_action,
|
||||
*self.salt_pkgs,
|
||||
"-y",
|
||||
)
|
||||
|
@ -444,7 +452,7 @@ class SaltPkgInstall:
|
|||
ret = self.proc.run(self.pkg_mngr, "install", "apt-transport-https", "-y")
|
||||
self._check_retcode(ret)
|
||||
## only classic 3005 has arm64 support
|
||||
if self.major >= "3006" and platform.is_aarch64():
|
||||
if self.relenv and platform.is_aarch64():
|
||||
arch = "arm64"
|
||||
elif platform.is_aarch64() and self.classic:
|
||||
arch = "arm64"
|
||||
|
@ -469,12 +477,20 @@ class SaltPkgInstall:
|
|||
)
|
||||
ret = self.proc.run(self.pkg_mngr, "update")
|
||||
self._check_retcode(ret)
|
||||
ret = self.proc.run(
|
||||
pkgs_to_install = self.salt_pkgs
|
||||
if downgrade:
|
||||
pkgs_to_install = [
|
||||
f"{pkg}={self.prev_version}" for pkg in self.salt_pkgs
|
||||
]
|
||||
cmd = [
|
||||
self.pkg_mngr,
|
||||
"install",
|
||||
*self.salt_pkgs,
|
||||
*pkgs_to_install,
|
||||
"-y",
|
||||
)
|
||||
]
|
||||
if downgrade:
|
||||
cmd.append("--allow-downgrades")
|
||||
ret = self.proc.run(*cmd)
|
||||
self._check_retcode(ret)
|
||||
self.stop_services()
|
||||
elif platform.is_windows():
|
||||
|
|
|
@ -11,9 +11,9 @@ def test_salt_upgrade(salt_call_cli, install_salt):
|
|||
original_py_version = install_salt.package_python_version()
|
||||
|
||||
# Verify previous install version is setup correctly and works
|
||||
ret = salt_call_cli.run("test.ping")
|
||||
ret = salt_call_cli.run("test.version")
|
||||
assert ret.returncode == 0
|
||||
assert ret.data
|
||||
assert ret.data == install_salt.prev_version
|
||||
|
||||
# Test pip install before an upgrade
|
||||
dep = "PyGithub==1.56.0"
|
||||
|
@ -28,9 +28,9 @@ def test_salt_upgrade(salt_call_cli, install_salt):
|
|||
# Upgrade Salt from previous version and test
|
||||
install_salt.install(upgrade=True)
|
||||
new_py_version = install_salt.package_python_version()
|
||||
ret = salt_call_cli.run("test.ping")
|
||||
ret = salt_call_cli.run("test.version")
|
||||
assert ret.returncode == 0
|
||||
assert ret.data
|
||||
assert ret.data == install_salt.artifact_version
|
||||
|
||||
# Install dep following upgrade
|
||||
# TODO: This should be removed when we stop testing against versions < 3006.0
|
||||
|
|
Loading…
Add table
Reference in a new issue