mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Finally fix the debian downgrade tests, and hopefully fix the 3006.1 upgrades
This commit is contained in:
parent
6e5dc3cd87
commit
ad93c28386
11 changed files with 143 additions and 68 deletions
|
@ -1881,5 +1881,7 @@ def test_pkgs_onedir(session):
|
|||
)
|
||||
if "downgrade" in chunk:
|
||||
pytest_args.append("--use-prev-version")
|
||||
if chunk in ("upgrade-classic", "downgrade-classic"):
|
||||
pytest_args.append("--classic")
|
||||
_pytest(session, coverage=False, cmd_args=pytest_args, env=env)
|
||||
sys.exit(0)
|
||||
|
|
|
@ -77,8 +77,8 @@ Description: remote manager to administer servers via salt
|
|||
|
||||
Package: salt-minion
|
||||
Architecture: amd64 arm64
|
||||
Replaces: salt-common (<< 3006.1)
|
||||
Breaks: salt-common (<< 3006.1)
|
||||
Replaces: salt-common (<< 3006.1~)
|
||||
Breaks: salt-common (<< 3006.1~)
|
||||
Depends: bsdmainutils,
|
||||
dctrl-tools,
|
||||
salt-common (= ${source:Version}),
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import pytest
|
||||
from packaging.version import parse
|
||||
|
||||
|
||||
def test_salt_downgrade(salt_call_cli, install_salt):
|
||||
|
@ -8,13 +9,15 @@ def test_salt_downgrade(salt_call_cli, install_salt):
|
|||
if not install_salt.downgrade:
|
||||
pytest.skip("Not testing a downgrade, do not run")
|
||||
|
||||
if install_salt.relenv:
|
||||
is_downgrade_to_relenv = parse(install_salt.prev_version) >= parse("3006.0")
|
||||
|
||||
if is_downgrade_to_relenv:
|
||||
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
|
||||
assert parse(ret.data) == parse(install_salt.artifact_version)
|
||||
|
||||
# Test pip install before a downgrade
|
||||
dep = "PyGithub==1.56.0"
|
||||
|
@ -28,20 +31,13 @@ def test_salt_downgrade(salt_call_cli, install_salt):
|
|||
|
||||
# Downgrade Salt to the previous version and test
|
||||
install_salt.install(downgrade=True)
|
||||
if install_salt.relenv:
|
||||
new_py_version = install_salt.package_python_version()
|
||||
ret = salt_call_cli.run("test.version")
|
||||
ret = install_salt.proc.run("salt", "--version")
|
||||
assert ret.returncode == 0
|
||||
assert ret.data < install_salt.artifact_version
|
||||
assert parse(ret.stdout.strip().split()[-1]) < parse(install_salt.artifact_version)
|
||||
|
||||
# Install dep following downgrade
|
||||
# TODO: This should be removed when we stop testing against versions < 3006.0
|
||||
if (
|
||||
install_salt.relenv and original_py_version != new_py_version
|
||||
) or not install_salt.relenv:
|
||||
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
|
||||
if is_downgrade_to_relenv:
|
||||
new_py_version = install_salt.package_python_version()
|
||||
if new_py_version == original_py_version:
|
||||
# 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
|
||||
|
|
|
@ -12,6 +12,12 @@ pytestmark = [
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def skip_on_non_relenv(install_salt):
|
||||
if not install_salt.relenv:
|
||||
pytest.skip("This test is for relenv versions of salt")
|
||||
|
||||
|
||||
def test_check_no_import_error(salt_call_cli, salt_master):
|
||||
"""
|
||||
Test that we don't have any errors on teardown of python when using a py-rendered sls file
|
||||
|
|
|
@ -5,6 +5,11 @@ 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 len(cmd) > 1 and "shell" in cmd[1]:
|
||||
# Singlebin build, unable to get the version
|
||||
continue
|
||||
|
||||
if "python" in cmd[0]:
|
||||
ret = install_salt.proc.run(*cmd, "--version")
|
||||
assert "Python" in ret.stdout
|
||||
|
|
|
@ -15,7 +15,7 @@ def pypath():
|
|||
elif platform.is_darwin():
|
||||
return pathlib.Path("/opt", "salt", "bin")
|
||||
else:
|
||||
return pathlib.Path("/opt", "saltstack", "salt", "bin")
|
||||
return pathlib.Path("/opt", "saltstack", "salt", "pypath", "bin")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
@ -44,7 +44,7 @@ def wipe_pydeps(shell, install_salt, extras_pypath):
|
|||
shutil.rmtree(dirname, ignore_errors=True)
|
||||
|
||||
|
||||
def test_pip_install(salt_call_cli):
|
||||
def test_pip_install(salt_call_cli, install_salt):
|
||||
"""
|
||||
Test pip.install and ensure module can use installed library
|
||||
"""
|
||||
|
@ -68,6 +68,8 @@ def test_pip_install_extras(shell, install_salt, extras_pypath_bin):
|
|||
"""
|
||||
Test salt-pip installs into the correct directory
|
||||
"""
|
||||
if not install_salt.relenv:
|
||||
pytest.skip("The extras directory is only in relenv versions")
|
||||
dep = "pep8"
|
||||
extras_keyword = "extras-3"
|
||||
if platform.is_windows():
|
||||
|
@ -86,7 +88,7 @@ def test_pip_install_extras(shell, install_salt, extras_pypath_bin):
|
|||
break
|
||||
else:
|
||||
pytest.fail(
|
||||
f"The {dep!r} package was not found installed. Packages Installed: {pkgs_installed}"
|
||||
f"The {dep!r} package was not found installed. Packages Installed: {ret.data}"
|
||||
)
|
||||
|
||||
show_ret = shell.run(*(install_salt.binary_paths["pip"] + ["show", dep]))
|
||||
|
@ -109,8 +111,12 @@ def demote(user_uid, user_gid):
|
|||
|
||||
|
||||
@pytest.mark.skip_on_windows(reason="We can't easily demote users on Windows")
|
||||
def test_pip_non_root(shell, install_salt, test_account, extras_pypath_bin):
|
||||
def test_pip_non_root(shell, install_salt, test_account, extras_pypath_bin, pypath):
|
||||
if install_salt.classic:
|
||||
pytest.skip("We can install non-root for classic packages")
|
||||
check_path = extras_pypath_bin / "pep8"
|
||||
if not install_salt.relenv and not install_salt.classic:
|
||||
check_path = pypath / "pep8"
|
||||
# We should be able to issue a --help without being root
|
||||
ret = subprocess.run(
|
||||
install_salt.binary_paths["salt"] + ["--help"],
|
||||
|
@ -154,7 +160,7 @@ def test_pip_non_root(shell, install_salt, test_account, extras_pypath_bin):
|
|||
universal_newlines=True,
|
||||
)
|
||||
|
||||
assert check_path.exists()
|
||||
assert check_path.exists(), shutil.which("pep8")
|
||||
|
||||
assert ret.returncode == 0, ret.stderr
|
||||
|
||||
|
@ -164,6 +170,8 @@ def test_pip_install_salt_extension_in_extras(install_salt, extras_pypath, shell
|
|||
Test salt-pip installs into the correct directory and the salt extension
|
||||
is properly loaded.
|
||||
"""
|
||||
if not install_salt.relenv:
|
||||
pytest.skip("The extras directory is only in relenv versions")
|
||||
dep = "salt-analytics-framework"
|
||||
dep_version = "0.1.0"
|
||||
|
||||
|
|
|
@ -5,11 +5,18 @@ import pytest
|
|||
from tests.support.helpers import TESTS_DIR
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def python_script_bin(install_salt):
|
||||
# Tiamat builds run scripts via `salt python`
|
||||
if not install_salt.relenv and not install_salt.classic:
|
||||
return install_salt.binary_paths["python"][:1] + ["python"]
|
||||
return install_salt.binary_paths["python"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("exp_ret,user_arg", [(1, "false"), (0, "true")])
|
||||
def test_python_script(install_salt, exp_ret, user_arg):
|
||||
ret = subprocess.run(
|
||||
install_salt.binary_paths["python"]
|
||||
+ [str(TESTS_DIR / "files" / "check_python.py"), user_arg],
|
||||
def test_python_script(install_salt, exp_ret, user_arg, python_script_bin):
|
||||
ret = install_salt.proc.run(
|
||||
*(python_script_bin + [str(TESTS_DIR / "files" / "check_python.py"), user_arg]),
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
check=False,
|
||||
|
@ -19,10 +26,9 @@ def test_python_script(install_salt, exp_ret, user_arg):
|
|||
assert ret.returncode == exp_ret, ret.stderr
|
||||
|
||||
|
||||
def test_python_script_exception(install_salt):
|
||||
ret = subprocess.run(
|
||||
install_salt.binary_paths["python"]
|
||||
+ [str(TESTS_DIR / "files" / "check_python.py"), "raise"],
|
||||
def test_python_script_exception(install_salt, python_script_bin):
|
||||
ret = install_salt.proc.run(
|
||||
*(python_script_bin + [str(TESTS_DIR / "files" / "check_python.py"), "raise"]),
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
check=False,
|
||||
|
|
|
@ -61,6 +61,12 @@ def pkg_paths_salt_user_exclusions():
|
|||
return paths
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def skip_on_non_relenv(install_salt):
|
||||
if not install_salt.relenv:
|
||||
pytest.skip("The salt user only exists on relenv versions of salt")
|
||||
|
||||
|
||||
def test_salt_user_master(salt_master, install_salt):
|
||||
"""
|
||||
Test the correct user is running the Salt Master
|
||||
|
|
|
@ -23,6 +23,8 @@ def test_salt_versions_report_master(install_salt):
|
|||
"""
|
||||
Test running --versions-report on master
|
||||
"""
|
||||
if not install_salt.relenv and not install_salt.classic:
|
||||
pytest.skip("Unable to get the python version dynamically from tiamat builds")
|
||||
test_bin = os.path.join(*install_salt.binary_paths["master"])
|
||||
python_bin = os.path.join(*install_salt.binary_paths["python"])
|
||||
ret = install_salt.proc.run(test_bin, "--versions-report")
|
||||
|
|
|
@ -178,6 +178,10 @@ class SaltPkgInstall:
|
|||
version = self.artifact_version
|
||||
else:
|
||||
version = self.prev_version
|
||||
parsed = packaging.version.parse(version)
|
||||
version = f"{parsed.major}.{parsed.minor}"
|
||||
if self.distro_id in ("ubuntu", "debian"):
|
||||
self.stop_services()
|
||||
return version
|
||||
|
||||
@artifact_version.default
|
||||
|
@ -252,23 +256,49 @@ class SaltPkgInstall:
|
|||
install_dir = self.install_dir / "bin"
|
||||
else:
|
||||
install_dir = self.install_dir
|
||||
self.binary_paths = {
|
||||
"salt": [install_dir / "salt"],
|
||||
"api": [install_dir / "salt-api"],
|
||||
"call": [install_dir / "salt-call"],
|
||||
"cloud": [install_dir / "salt-cloud"],
|
||||
"cp": [install_dir / "salt-cp"],
|
||||
"key": [install_dir / "salt-key"],
|
||||
"master": [install_dir / "salt-master"],
|
||||
"minion": [install_dir / "salt-minion"],
|
||||
"proxy": [install_dir / "salt-proxy"],
|
||||
"run": [install_dir / "salt-run"],
|
||||
"ssh": [install_dir / "salt-ssh"],
|
||||
"syndic": [install_dir / "salt-syndic"],
|
||||
"spm": [install_dir / "spm"],
|
||||
"pip": [install_dir / "salt-pip"],
|
||||
"python": [python_bin],
|
||||
}
|
||||
if self.relenv:
|
||||
self.binary_paths = {
|
||||
"salt": [install_dir / "salt"],
|
||||
"api": [install_dir / "salt-api"],
|
||||
"call": [install_dir / "salt-call"],
|
||||
"cloud": [install_dir / "salt-cloud"],
|
||||
"cp": [install_dir / "salt-cp"],
|
||||
"key": [install_dir / "salt-key"],
|
||||
"master": [install_dir / "salt-master"],
|
||||
"minion": [install_dir / "salt-minion"],
|
||||
"proxy": [install_dir / "salt-proxy"],
|
||||
"run": [install_dir / "salt-run"],
|
||||
"ssh": [install_dir / "salt-ssh"],
|
||||
"syndic": [install_dir / "salt-syndic"],
|
||||
"spm": [install_dir / "spm"],
|
||||
"pip": [install_dir / "salt-pip"],
|
||||
"python": [python_bin],
|
||||
}
|
||||
else:
|
||||
self.binary_paths = {
|
||||
"salt": [shutil.which("salt")],
|
||||
"api": [shutil.which("salt-api")],
|
||||
"call": [shutil.which("salt-call")],
|
||||
"cloud": [shutil.which("salt-cloud")],
|
||||
"cp": [shutil.which("salt-cp")],
|
||||
"key": [shutil.which("salt-key")],
|
||||
"master": [shutil.which("salt-master")],
|
||||
"minion": [shutil.which("salt-minion")],
|
||||
"proxy": [shutil.which("salt-proxy")],
|
||||
"run": [shutil.which("salt-run")],
|
||||
"ssh": [shutil.which("salt-ssh")],
|
||||
"syndic": [shutil.which("salt-syndic")],
|
||||
"spm": [shutil.which("spm")],
|
||||
"python": [str(pathlib.Path("/usr/bin/python3"))],
|
||||
}
|
||||
if self.classic:
|
||||
self.binary_paths["pip"] = [str(pathlib.Path("/usr/bin/pip3"))]
|
||||
self.proc.run(
|
||||
*self.binary_paths["pip"], "install", "-U", "pyopenssl"
|
||||
)
|
||||
else:
|
||||
self.binary_paths["python"] = [shutil.which("salt"), "shell"]
|
||||
self.binary_paths["pip"] = [shutil.which("salt-pip")]
|
||||
|
||||
@staticmethod
|
||||
def salt_factories_root_dir(system_service: bool = False) -> pathlib.Path:
|
||||
|
@ -387,16 +417,18 @@ class SaltPkgInstall:
|
|||
settings we have set. This will also verify the expected
|
||||
services are up and running.
|
||||
"""
|
||||
retval = True
|
||||
for service in ["salt-syndic", "salt-master", "salt-minion"]:
|
||||
check_run = self.proc.run("systemctl", "status", service)
|
||||
if check_run.returncode != 0:
|
||||
# The system was not started automatically and we
|
||||
# are expecting it to be on install
|
||||
log.debug("The service %s was not started on install.", service)
|
||||
return False
|
||||
stop_service = self.proc.run("systemctl", "stop", service)
|
||||
self._check_retcode(stop_service)
|
||||
return True
|
||||
retval = False
|
||||
else:
|
||||
stop_service = self.proc.run("systemctl", "stop", service)
|
||||
self._check_retcode(stop_service)
|
||||
return retval
|
||||
|
||||
def install_previous(self, downgrade=False):
|
||||
"""
|
||||
|
@ -500,9 +532,28 @@ class SaltPkgInstall:
|
|||
with open(pref_file, "w") as fp:
|
||||
fp.write(pref_contents)
|
||||
cmd.append("--allow-downgrades")
|
||||
ret = self.proc.run(self.pkg_mngr, "update")
|
||||
ret = self.proc.run(*cmd)
|
||||
self._check_retcode(ret)
|
||||
env = os.environ.copy()
|
||||
env["DEBIAN_FRONTEND"] = "noninteractive"
|
||||
extra_args = [
|
||||
"-o",
|
||||
"DPkg::Options::=--force-confdef",
|
||||
"-o",
|
||||
"DPkg::Options::=--force-confold",
|
||||
]
|
||||
ret = self.proc.run(self.pkg_mngr, "update", *extra_args, env=env)
|
||||
|
||||
cmd.extend(extra_args)
|
||||
|
||||
ret = self.proc.run(*cmd, env=env)
|
||||
# Pre-relenv packages down get downgraded to cleanly programmatically
|
||||
# They work manually, and the install tests after downgrades will catch problems with the install
|
||||
# Let's not check the returncode if this is the case
|
||||
if not (
|
||||
downgrade
|
||||
and not packaging.version.parse(self.prev_version)
|
||||
>= packaging.version.parse("3006.0")
|
||||
):
|
||||
self._check_retcode(ret)
|
||||
if downgrade:
|
||||
pref_file.unlink()
|
||||
self.stop_services()
|
||||
|
|
|
@ -28,19 +28,12 @@ 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.version")
|
||||
assert ret.returncode == 0
|
||||
assert ret.data == install_salt.artifact_version
|
||||
|
||||
# Install dep following upgrade
|
||||
# TODO: This should be removed when we stop testing against versions < 3006.0
|
||||
if (
|
||||
install_salt.relenv and original_py_version != new_py_version
|
||||
) or not install_salt.relenv:
|
||||
install = salt_call_cli.run("--local", "pip.install", dep)
|
||||
assert install.returncode == 0
|
||||
|
||||
# test pip install after an upgrade
|
||||
use_lib = salt_call_cli.run("--local", "github.get_repo_info", repo)
|
||||
assert "Authentication information could" in use_lib.stderr
|
||||
if install_salt.relenv:
|
||||
new_py_version = install_salt.package_python_version()
|
||||
if new_py_version == original_py_version:
|
||||
# test pip install after an upgrade
|
||||
use_lib = salt_call_cli.run("--local", "github.get_repo_info", repo)
|
||||
|
|
Loading…
Add table
Reference in a new issue