mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Updated package integration tests
This commit is contained in:
parent
c1a5e4e122
commit
c13bcb4597
10 changed files with 313 additions and 27 deletions
|
@ -5,11 +5,36 @@ pytestmark = [
|
|||
]
|
||||
|
||||
|
||||
def test_salt_api(salt_master, api_request):
|
||||
@pytest.fixture
|
||||
def salt_systemd_setup(
|
||||
salt_call_cli,
|
||||
install_salt,
|
||||
):
|
||||
"""
|
||||
Fixture to set systemd for salt packages to enabled and active
|
||||
Note: assumes Salt packages already installed
|
||||
"""
|
||||
install_salt.install()
|
||||
|
||||
# ensure known state, enabled and active
|
||||
test_list = ["salt-api", "salt-minion", "salt-master"]
|
||||
for test_item in test_list:
|
||||
test_cmd = f"systemctl enable {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
test_cmd = f"systemctl restart {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
|
||||
def test_salt_api(salt_systemd_setup, api_request):
|
||||
"""
|
||||
Test running a command against the salt api
|
||||
"""
|
||||
assert salt_master.is_running()
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ret = api_request.post(
|
||||
"/run",
|
||||
|
|
|
@ -4,6 +4,29 @@ import pytest
|
|||
from pytestskipmarkers.utils import platform
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def salt_systemd_setup(
|
||||
salt_call_cli,
|
||||
install_salt,
|
||||
):
|
||||
"""
|
||||
Fixture to set systemd for salt packages to enabled and active
|
||||
Note: assumes Salt packages already installed
|
||||
"""
|
||||
install_salt.install()
|
||||
|
||||
# ensure known state, enabled and active
|
||||
test_list = ["salt-api", "salt-minion", "salt-master"]
|
||||
for test_item in test_list:
|
||||
test_cmd = f"systemctl enable {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
test_cmd = f"systemctl restart {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
|
||||
def test_salt_call_local(salt_call_cli):
|
||||
"""
|
||||
Test salt-call --local test.ping
|
||||
|
@ -13,10 +36,14 @@ def test_salt_call_local(salt_call_cli):
|
|||
assert ret.data is True
|
||||
|
||||
|
||||
def test_salt_call(salt_call_cli):
|
||||
def test_salt_call(salt_systemd_setup, salt_call_cli):
|
||||
"""
|
||||
Test salt-call test.ping
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ret = salt_call_cli.run("test.ping")
|
||||
assert ret.returncode == 0
|
||||
assert ret.data is True
|
||||
|
@ -44,10 +71,14 @@ def state_name(salt_master):
|
|||
yield name
|
||||
|
||||
|
||||
def test_sls(salt_call_cli, state_name):
|
||||
def test_sls(salt_systemd_setup, salt_call_cli, state_name):
|
||||
"""
|
||||
Test calling a sls file
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ret = salt_call_cli.run("state.apply", state_name)
|
||||
assert ret.returncode == 0
|
||||
assert ret.data
|
||||
|
|
|
@ -5,37 +5,76 @@ pytestmark = [
|
|||
]
|
||||
|
||||
|
||||
def test_grains_items(salt_cli, salt_minion):
|
||||
@pytest.fixture
|
||||
def salt_systemd_setup(
|
||||
salt_call_cli,
|
||||
install_salt,
|
||||
):
|
||||
"""
|
||||
Fixture to set systemd for salt packages to enabled and active
|
||||
Note: assumes Salt packages already installed
|
||||
"""
|
||||
install_salt.install()
|
||||
|
||||
# ensure known state, enabled and active
|
||||
test_list = ["salt-api", "salt-minion", "salt-master"]
|
||||
for test_item in test_list:
|
||||
test_cmd = f"systemctl enable {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
test_cmd = f"systemctl restart {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
|
||||
def test_grains_items(salt_systemd_setup, salt_cli, salt_minion):
|
||||
"""
|
||||
Test grains.items
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ret = salt_cli.run("grains.items", minion_tgt=salt_minion.id)
|
||||
assert ret.data, ret
|
||||
assert "osrelease" in ret.data
|
||||
|
||||
|
||||
def test_grains_item_os(salt_cli, salt_minion):
|
||||
def test_grains_item_os(salt_systemd_setup, salt_cli, salt_minion):
|
||||
"""
|
||||
Test grains.item os
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ret = salt_cli.run("grains.item", "os", minion_tgt=salt_minion.id)
|
||||
assert ret.data, ret
|
||||
assert "os" in ret.data
|
||||
|
||||
|
||||
def test_grains_item_pythonversion(salt_cli, salt_minion):
|
||||
def test_grains_item_pythonversion(salt_systemd_setup, salt_cli, salt_minion):
|
||||
"""
|
||||
Test grains.item pythonversion
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ret = salt_cli.run("grains.item", "pythonversion", minion_tgt=salt_minion.id)
|
||||
assert ret.data, ret
|
||||
assert "pythonversion" in ret.data
|
||||
|
||||
|
||||
def test_grains_setval_key_val(salt_cli, salt_minion):
|
||||
def test_grains_setval_key_val(salt_systemd_setup, salt_cli, salt_minion):
|
||||
"""
|
||||
Test grains.setval key val
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ret = salt_cli.run("grains.setval", "key", "val", minion_tgt=salt_minion.id)
|
||||
assert ret.data, ret
|
||||
assert "key" in ret.data
|
||||
|
|
|
@ -5,20 +5,51 @@ pytestmark = [
|
|||
]
|
||||
|
||||
|
||||
def test_salt_minion_ping(salt_cli, salt_minion):
|
||||
@pytest.fixture
|
||||
def salt_systemd_setup(
|
||||
salt_call_cli,
|
||||
install_salt,
|
||||
):
|
||||
"""
|
||||
Fixture to set systemd for salt packages to enabled and active
|
||||
Note: assumes Salt packages already installed
|
||||
"""
|
||||
install_salt.install()
|
||||
|
||||
# ensure known state, enabled and active
|
||||
test_list = ["salt-api", "salt-minion", "salt-master"]
|
||||
for test_item in test_list:
|
||||
test_cmd = f"systemctl enable {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
test_cmd = f"systemctl restart {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
|
||||
def test_salt_minion_ping(salt_systemd_setup, salt_cli, salt_minion):
|
||||
"""
|
||||
Test running a command against a targeted minion
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ret = salt_cli.run("test.ping", minion_tgt=salt_minion.id)
|
||||
assert ret.returncode == 0
|
||||
assert ret.data is True
|
||||
|
||||
|
||||
def test_salt_minion_setproctitle(salt_cli, salt_minion):
|
||||
def test_salt_minion_setproctitle(salt_systemd_setup, salt_cli, salt_minion):
|
||||
"""
|
||||
Test that setproctitle is working
|
||||
for the running Salt minion
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ret = salt_cli.run(
|
||||
"ps.pgrep", "MinionProcessManager", full=True, minion_tgt=salt_minion.id
|
||||
)
|
||||
|
|
|
@ -5,11 +5,38 @@ pytestmark = [
|
|||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def salt_systemd_setup(
|
||||
salt_call_cli,
|
||||
install_salt,
|
||||
):
|
||||
"""
|
||||
Fixture to set systemd for salt packages to enabled and active
|
||||
Note: assumes Salt packages already installed
|
||||
"""
|
||||
install_salt.install()
|
||||
|
||||
# ensure known state, enabled and active
|
||||
test_list = ["salt-api", "salt-minion", "salt-master"]
|
||||
for test_item in test_list:
|
||||
test_cmd = f"systemctl enable {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
test_cmd = f"systemctl restart {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("output_fmt", ["yaml", "json"])
|
||||
def test_salt_output(salt_cli, salt_minion, output_fmt):
|
||||
def test_salt_output(salt_systemd_setup, salt_cli, salt_minion, output_fmt):
|
||||
"""
|
||||
Test --output
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ret = salt_cli.run(
|
||||
f"--output={output_fmt}", "test.fib", "7", minion_tgt=salt_minion.id
|
||||
)
|
||||
|
|
|
@ -8,6 +8,29 @@ pytestmark = [
|
|||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def salt_systemd_setup(
|
||||
salt_call_cli,
|
||||
install_salt,
|
||||
):
|
||||
"""
|
||||
Fixture to set systemd for salt packages to enabled and active
|
||||
Note: assumes Salt packages already installed
|
||||
"""
|
||||
install_salt.install()
|
||||
|
||||
# ensure known state, enabled and active
|
||||
test_list = ["salt-api", "salt-minion", "salt-master"]
|
||||
for test_item in test_list:
|
||||
test_cmd = f"systemctl enable {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
test_cmd = f"systemctl restart {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pillar_name(salt_master):
|
||||
name = "info"
|
||||
|
@ -35,10 +58,14 @@ def pillar_name(salt_master):
|
|||
yield name
|
||||
|
||||
|
||||
def test_salt_pillar(salt_cli, salt_minion, pillar_name):
|
||||
def test_salt_pillar(salt_systemd_setup, salt_cli, salt_minion, pillar_name):
|
||||
"""
|
||||
Test pillar.items
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ret = salt_cli.run("pillar.items", minion_tgt=salt_minion.id)
|
||||
assert ret.returncode == 0
|
||||
assert pillar_name in ret.data
|
||||
|
|
|
@ -10,6 +10,29 @@ pytestmark = [
|
|||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def salt_systemd_setup(
|
||||
salt_call_cli,
|
||||
install_salt,
|
||||
):
|
||||
"""
|
||||
Fixture to set systemd for salt packages to enabled and active
|
||||
Note: assumes Salt packages already installed
|
||||
"""
|
||||
install_salt.install()
|
||||
|
||||
# ensure known state, enabled and active
|
||||
test_list = ["salt-api", "salt-minion", "salt-master"]
|
||||
for test_item in test_list:
|
||||
test_cmd = f"systemctl enable {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
test_cmd = f"systemctl restart {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def files(tmp_path):
|
||||
return types.SimpleNamespace(
|
||||
|
@ -52,7 +75,7 @@ def state_name(files, salt_master):
|
|||
yield name
|
||||
|
||||
|
||||
def test_salt_state_file(salt_cli, salt_minion, state_name, files):
|
||||
def test_salt_state_file(salt_systemd_setup, salt_cli, salt_minion, state_name, files):
|
||||
"""
|
||||
Test state file
|
||||
"""
|
||||
|
@ -60,6 +83,10 @@ def test_salt_state_file(salt_cli, salt_minion, state_name, files):
|
|||
assert files.fpath_2.exists() is False
|
||||
assert files.fpath_3.exists() is False
|
||||
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ret = salt_cli.run("state.apply", state_name, minion_tgt=salt_minion.id)
|
||||
assert ret.returncode == 0
|
||||
assert ret.data
|
||||
|
|
|
@ -3,17 +3,41 @@ import pathlib
|
|||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def salt_systemd_setup(
|
||||
salt_call_cli,
|
||||
install_salt,
|
||||
):
|
||||
"""
|
||||
Fixture to set systemd for salt packages to enabled and active
|
||||
Note: assumes Salt packages already installed
|
||||
"""
|
||||
install_salt.install()
|
||||
|
||||
# ensure known state, enabled and active
|
||||
test_list = ["salt-api", "salt-minion", "salt-master"]
|
||||
for test_item in test_list:
|
||||
test_cmd = f"systemctl enable {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
test_cmd = f"systemctl restart {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
|
||||
@pytest.mark.skip_on_windows
|
||||
@pytest.mark.skip_if_binaries_missing("ufw")
|
||||
def test_salt_ufw(salt_master, salt_call_cli, install_salt):
|
||||
def test_salt_ufw(salt_systemd_setup, salt_call_cli, install_salt):
|
||||
"""
|
||||
Test salt.ufw for Debian/Ubuntu salt-master
|
||||
"""
|
||||
if install_salt.distro_id not in ("debian", "ubuntu"):
|
||||
pytest.skip("Only tests Debian / Ubuntu packages")
|
||||
|
||||
# check that the salt_master is running
|
||||
assert salt_master.is_running()
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
ufw_master_path = pathlib.Path("/etc/ufw/applications.d/salt.ufw")
|
||||
assert ufw_master_path.exists()
|
||||
|
|
|
@ -11,6 +11,29 @@ from saltfactories.utils.tempfiles import temp_directory
|
|||
pytestmark = [pytest.mark.skip_unless_on_linux]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def salt_systemd_setup(
|
||||
salt_call_cli,
|
||||
install_salt,
|
||||
):
|
||||
"""
|
||||
Fixture to set systemd for salt packages to enabled and active
|
||||
Note: assumes Salt packages already installed
|
||||
"""
|
||||
install_salt.install()
|
||||
|
||||
# ensure known state, enabled and active
|
||||
test_list = ["salt-api", "salt-minion", "salt-master"]
|
||||
for test_item in test_list:
|
||||
test_cmd = f"systemctl enable {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
test_cmd = f"systemctl restart {test_item}"
|
||||
ret = salt_call_cli.run("--local", "cmd.run", test_cmd)
|
||||
assert ret.returncode == 0
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pkg_paths():
|
||||
"""
|
||||
|
@ -64,10 +87,14 @@ def _skip_on_non_relenv(install_salt):
|
|||
pytest.skip("The salt user only exists on relenv versions of salt")
|
||||
|
||||
|
||||
def test_salt_user_master(salt_master, install_salt):
|
||||
def test_salt_user_master(salt_systemd_setup, salt_master, install_salt):
|
||||
"""
|
||||
Test the correct user is running the Salt Master
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
match = False
|
||||
for proc in psutil.Process(salt_master.pid).children():
|
||||
assert proc.username() == "salt"
|
||||
|
@ -76,10 +103,14 @@ def test_salt_user_master(salt_master, install_salt):
|
|||
assert match
|
||||
|
||||
|
||||
def test_salt_user_home(install_salt):
|
||||
def test_salt_user_home(isalt_systemd_setup, nstall_salt):
|
||||
"""
|
||||
Test the salt user's home is /opt/saltstack/salt
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
proc = subprocess.run(
|
||||
["getent", "passwd", "salt"], check=False, capture_output=True
|
||||
)
|
||||
|
@ -92,10 +123,14 @@ def test_salt_user_home(install_salt):
|
|||
assert home == "/opt/saltstack/salt"
|
||||
|
||||
|
||||
def test_salt_user_group(install_salt):
|
||||
def test_salt_user_group(salt_systemd_setup, install_salt):
|
||||
"""
|
||||
Test the salt user is in the salt group
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
proc = subprocess.run(["id", "salt"], check=False, capture_output=True)
|
||||
assert proc.returncode == 0
|
||||
in_group = False
|
||||
|
@ -108,10 +143,14 @@ def test_salt_user_group(install_salt):
|
|||
assert in_group is True
|
||||
|
||||
|
||||
def test_salt_user_shell(install_salt):
|
||||
def test_salt_user_shell(salt_systemd_setup, install_salt):
|
||||
"""
|
||||
Test the salt user's login shell
|
||||
"""
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
proc = subprocess.run(
|
||||
["getent", "passwd", "salt"], check=False, capture_output=True
|
||||
)
|
||||
|
@ -127,7 +166,11 @@ def test_salt_user_shell(install_salt):
|
|||
|
||||
|
||||
def test_pkg_paths(
|
||||
install_salt, pkg_paths, pkg_paths_salt_user, pkg_paths_salt_user_exclusions
|
||||
salt_systemd_setup,
|
||||
install_salt,
|
||||
pkg_paths,
|
||||
pkg_paths_salt_user,
|
||||
pkg_paths_salt_user_exclusions,
|
||||
):
|
||||
"""
|
||||
Test package paths ownership
|
||||
|
@ -136,6 +179,11 @@ def test_pkg_paths(
|
|||
"3006.4"
|
||||
):
|
||||
pytest.skip("Package path ownership was changed in salt 3006.4")
|
||||
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
salt_user_subdirs = []
|
||||
|
||||
for _path in pkg_paths:
|
||||
|
@ -175,7 +223,12 @@ def test_pkg_paths(
|
|||
|
||||
@pytest.mark.skip_if_binaries_missing("logrotate")
|
||||
def test_paths_log_rotation(
|
||||
salt_master, salt_minion, salt_call_cli, install_salt, pkg_tests_account
|
||||
salt_systemd_setup,
|
||||
salt_master,
|
||||
salt_minion,
|
||||
salt_call_cli,
|
||||
install_salt,
|
||||
pkg_tests_account,
|
||||
):
|
||||
"""
|
||||
Test the correct ownership is assigned when log rotation occurs
|
||||
|
@ -200,8 +253,10 @@ def test_paths_log_rotation(
|
|||
"Only tests RedHat family packages till logrotation paths are resolved on Ubuntu/Debian, see issue 65231"
|
||||
)
|
||||
|
||||
# check that the salt_master is running
|
||||
assert salt_master.is_running()
|
||||
# setup systemd to enabled and active for Salt packages
|
||||
# pylint: disable=pointless-statement
|
||||
salt_systemd_setup
|
||||
|
||||
match = False
|
||||
for proc in psutil.Process(salt_master.pid).children():
|
||||
assert proc.username() == "salt"
|
||||
|
|
|
@ -65,17 +65,17 @@ def test_salt_versions_report_minion(salt_cli, salt_call_cli, salt_minion):
|
|||
|
||||
# Make sure we can ping the minion ...
|
||||
ret = salt_cli.run(
|
||||
"--timeout=240", "test.ping", minion_tgt=salt_minion.id, _timeout=240
|
||||
"--timeout=300", "test.ping", minion_tgt=salt_minion.id, _timeout=300
|
||||
)
|
||||
assert ret.returncode == 0
|
||||
assert ret.data is True
|
||||
ret = salt_cli.run(
|
||||
"--hard-crash",
|
||||
"--failhard",
|
||||
"--timeout=240",
|
||||
"--timeout=300",
|
||||
"test.versions_report",
|
||||
minion_tgt=salt_minion.id,
|
||||
_timeout=240,
|
||||
_timeout=300,
|
||||
)
|
||||
ret.stdout.matcher.fnmatch_lines(["*Salt Version:*"])
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue