Updated package integration tests

This commit is contained in:
David Murphy 2024-06-26 10:39:02 -06:00 committed by Daniel Wozniak
parent c13bcb4597
commit 1e4509fd7d
8 changed files with 32 additions and 236 deletions

View file

@ -5,36 +5,11 @@ 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
def test_salt_api(salt_systemd_setup, api_request):
def test_salt_api(api_request, salt_master):
"""
Test running a command against the salt api
"""
# setup systemd to enabled and active for Salt packages
# pylint: disable=pointless-statement
salt_systemd_setup
assert salt_master.is_running()
ret = api_request.post(
"/run",

View file

@ -4,29 +4,6 @@ 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
@ -36,13 +13,11 @@ def test_salt_call_local(salt_call_cli):
assert ret.data is True
def test_salt_call(salt_systemd_setup, salt_call_cli):
def test_salt_call(salt_call_cli, salt_master):
"""
Test salt-call test.ping
"""
# setup systemd to enabled and active for Salt packages
# pylint: disable=pointless-statement
salt_systemd_setup
assert salt_master.is_running()
ret = salt_call_cli.run("test.ping")
assert ret.returncode == 0
@ -71,13 +46,11 @@ def state_name(salt_master):
yield name
def test_sls(salt_systemd_setup, salt_call_cli, state_name):
def test_sls(salt_call_cli, salt_master, state_name):
"""
Test calling a sls file
"""
# setup systemd to enabled and active for Salt packages
# pylint: disable=pointless-statement
salt_systemd_setup
assert salt_master.is_running()
ret = salt_call_cli.run("state.apply", state_name)
assert ret.returncode == 0

View file

@ -5,75 +5,44 @@ 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
def test_grains_items(salt_systemd_setup, salt_cli, salt_minion):
def test_grains_items(salt_cli, salt_minion, salt_master):
"""
Test grains.items
"""
# setup systemd to enabled and active for Salt packages
# pylint: disable=pointless-statement
salt_systemd_setup
assert salt_master.is_running()
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_systemd_setup, salt_cli, salt_minion):
def test_grains_item_os(salt_cli, salt_minion, salt_master):
"""
Test grains.item os
"""
# setup systemd to enabled and active for Salt packages
# pylint: disable=pointless-statement
salt_systemd_setup
assert salt_master.is_running()
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_systemd_setup, salt_cli, salt_minion):
def test_grains_item_pythonversion(salt_cli, salt_minion, salt_master):
"""
Test grains.item pythonversion
"""
# setup systemd to enabled and active for Salt packages
# pylint: disable=pointless-statement
salt_systemd_setup
assert salt_master.is_running()
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_systemd_setup, salt_cli, salt_minion):
def test_grains_setval_key_val(salt_cli, salt_minion, salt_master):
"""
Test grains.setval key val
"""
# setup systemd to enabled and active for Salt packages
# pylint: disable=pointless-statement
salt_systemd_setup
assert salt_master.is_running()
ret = salt_cli.run("grains.setval", "key", "val", minion_tgt=salt_minion.id)
assert ret.data, ret

View file

@ -5,50 +5,23 @@ 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
def test_salt_minion_ping(salt_systemd_setup, salt_cli, salt_minion):
def test_salt_minion_ping(salt_cli, salt_minion, salt_master):
"""
Test running a command against a targeted minion
"""
# setup systemd to enabled and active for Salt packages
# pylint: disable=pointless-statement
salt_systemd_setup
assert salt_master.is_running()
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_systemd_setup, salt_cli, salt_minion):
def test_salt_minion_setproctitle(salt_cli, salt_minion, salt_master):
"""
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
assert salt_master.is_running()
ret = salt_cli.run(
"ps.pgrep", "MinionProcessManager", full=True, minion_tgt=salt_minion.id

View file

@ -5,37 +5,12 @@ 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_systemd_setup, salt_cli, salt_minion, output_fmt):
def test_salt_output(salt_cli, salt_minion, salt_master, output_fmt):
"""
Test --output
"""
# setup systemd to enabled and active for Salt packages
# pylint: disable=pointless-statement
salt_systemd_setup
assert salt_master.is_running()
ret = salt_cli.run(
f"--output={output_fmt}", "test.fib", "7", minion_tgt=salt_minion.id

View file

@ -8,29 +8,6 @@ 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"
@ -58,13 +35,11 @@ def pillar_name(salt_master):
yield name
def test_salt_pillar(salt_systemd_setup, salt_cli, salt_minion, pillar_name):
def test_salt_pillar(salt_cli, salt_minion, salt_master, pillar_name):
"""
Test pillar.items
"""
# setup systemd to enabled and active for Salt packages
# pylint: disable=pointless-statement
salt_systemd_setup
assert salt_master.is_running()
ret = salt_cli.run("pillar.items", minion_tgt=salt_minion.id)
assert ret.returncode == 0

View file

@ -10,29 +10,6 @@ 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(
@ -75,17 +52,14 @@ def state_name(files, salt_master):
yield name
def test_salt_state_file(salt_systemd_setup, salt_cli, salt_minion, state_name, files):
def test_salt_state_file(salt_cli, salt_minion, salt_master, state_name, files):
"""
Test state file
"""
assert files.fpath_1.exists() is False
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
assert salt_master.is_running()
ret = salt_cli.run("state.apply", state_name, minion_tgt=salt_minion.id)
assert ret.returncode == 0

View file

@ -87,13 +87,11 @@ 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_systemd_setup, salt_master, install_salt):
def test_salt_user_master(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
assert salt_master.is_running()
match = False
for proc in psutil.Process(salt_master.pid).children():
@ -103,13 +101,11 @@ def test_salt_user_master(salt_systemd_setup, salt_master, install_salt):
assert match
def test_salt_user_home(isalt_systemd_setup, nstall_salt):
def test_salt_user_home(install_salt, salt_master):
"""
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
assert salt_master.is_running()
proc = subprocess.run(
["getent", "passwd", "salt"], check=False, capture_output=True
@ -123,13 +119,11 @@ def test_salt_user_home(isalt_systemd_setup, nstall_salt):
assert home == "/opt/saltstack/salt"
def test_salt_user_group(salt_systemd_setup, install_salt):
def test_salt_user_group(install_salt, salt_master):
"""
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
assert salt_master.is_running()
proc = subprocess.run(["id", "salt"], check=False, capture_output=True)
assert proc.returncode == 0
@ -143,13 +137,11 @@ def test_salt_user_group(salt_systemd_setup, install_salt):
assert in_group is True
def test_salt_user_shell(salt_systemd_setup, install_salt):
def test_salt_user_shell(install_salt, salt_master):
"""
Test the salt user's login shell
"""
# setup systemd to enabled and active for Salt packages
# pylint: disable=pointless-statement
salt_systemd_setup
assert salt_master.is_running()
proc = subprocess.run(
["getent", "passwd", "salt"], check=False, capture_output=True
@ -166,7 +158,6 @@ def test_salt_user_shell(salt_systemd_setup, install_salt):
def test_pkg_paths(
salt_systemd_setup,
install_salt,
pkg_paths,
pkg_paths_salt_user,
@ -180,10 +171,6 @@ def test_pkg_paths(
):
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:
@ -223,7 +210,6 @@ def test_pkg_paths(
@pytest.mark.skip_if_binaries_missing("logrotate")
def test_paths_log_rotation(
salt_systemd_setup,
salt_master,
salt_minion,
salt_call_cli,
@ -253,10 +239,6 @@ def test_paths_log_rotation(
"Only tests RedHat family packages till logrotation paths are resolved on Ubuntu/Debian, see issue 65231"
)
# 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"