Add upgrade tests

This commit is contained in:
Megan Wilhite 2023-01-23 08:24:35 -07:00 committed by Pedro Algarvio
parent 38e9982fc5
commit cff6d2ac6d
4 changed files with 51 additions and 7 deletions

View file

@ -17,6 +17,8 @@ import sys
import tarfile
import tempfile
import nox.command
# fmt: off
if __name__ == "__main__":
sys.stderr.write(
@ -1777,3 +1779,36 @@ def test_pkgs(session, coverage):
cmd_args = ["pkg/tests/"] + session.posargs
_pytest(session, coverage, cmd_args)
@nox.session(python=_PYTHON_VERSIONS, name="test-upgrade-pkgs")
@nox.parametrize("coverage", [False, True])
@nox.parametrize("classic", [False, True])
def test_upgrade_pkgs(session, coverage, classic):
"""
pytest pkg upgrade tests session
"""
pydir = _get_pydir(session)
# Install requirements
if _upgrade_pip_setuptools_and_wheel(session):
requirements_file = os.path.join(
"requirements", "static", "ci", _get_pydir(session), "pkgtests.txt"
)
install_command = ["--progress-bar=off", "-r", requirements_file]
session.install(*install_command, silent=PIP_INSTALL_SILENT)
cmd_args = [
"pkg/tests/upgrade/test_salt_upgrade.py::test_salt_upgrade",
"--upgrade",
"--no-uninstall",
] + session.posargs
if classic:
cmd_args = cmd_args + ["--classic"]
try:
_pytest(session, coverage, cmd_args)
except nox.command.CommandFailed:
sys.exit(0)
cmd_args = ["pkg/tests/", "--no-install"] + session.posargs
_pytest(session, coverage, cmd_args)

View file

@ -67,6 +67,12 @@ def pytest_addoption(parser):
action="store_true",
help="Do not uninstall salt packages after test run is complete",
)
test_selection_group.addoption(
"--classic",
default=False,
action="store_true",
help="Test an upgrade from the classic packages.",
)
@pytest.fixture(scope="session")

View file

@ -5,9 +5,7 @@ def test_help(install_salt):
for cmd in install_salt.binary_paths.values():
# TODO: add back salt-cloud and salt-ssh when its fixed
cmd = [str(x) for x in cmd]
if any(x in ["salt-cloud", "salt-ssh"] for x in cmd):
assert True
elif "python" in cmd[0]:
if "python" in cmd[0]:
ret = install_salt.proc.run(*cmd, "--version")
assert "Python" in ret.stdout
else:

View file

@ -77,6 +77,7 @@ class SaltPkgInstall:
salt_pkgs: List[str] = attr.ib(init=False)
install_dir: pathlib.Path = attr.ib(init=False)
binary_paths: List[pathlib.Path] = attr.ib(init=False)
classic: bool = attr.ib(default=False)
@proc.default
def _default_proc(self):
@ -430,21 +431,25 @@ class SaltPkgInstall:
os_name = os_name.split()[0].lower()
if os_name == "centos" or os_name == "fedora":
os_name = "redhat"
# TODO: When tiamat is considered production we need to update these
# TODO: paths to the tiamat paths instead of the old package paths.
if os_name.lower() in ["redhat", "centos", "amazon", "fedora"]:
for fp in pathlib.Path("/etc", "yum.repos.d").glob("epel*"):
fp.unlink()
gpg_key = "SALTSTACK-GPG-KEY.pub"
if version == "9":
gpg_key = "SALTSTACK-GPG-KEY2.pub"
root_url = "salt/py3/"
if self.classic:
root_url = "py3/"
ret = self.proc.run(
"rpm",
"--import",
f"https://repo.saltproject.io/salt/py3/{os_name}/{version}/x86_64/{major_ver}/SALTSTACK-GPG-KEY.pub",
f"https://repo.saltproject.io/{root_url}{os_name}/{version}/x86_64/{major_ver}/{gpg_key}",
)
self._check_retcode(ret)
ret = self.proc.run(
"curl",
"-fsSL",
f"https://repo.saltproject.io/salt/py3/{os_name}/{version}/x86_64/{major_ver}.repo",
f"https://repo.saltproject.io/{root_url}{os_name}/{version}/x86_64/{major_ver}.repo",
"-o",
f"/etc/yum.repos.d/salt-{os_name}.repo",
)