Skip to content

Commit

Permalink
Several fixes for tests to avoid errors and failures in some OSes
Browse files Browse the repository at this point in the history
* test_pip_state: skip tests which requires virtualenv CLI

* test_syndic_eauth: skip when using an incompatible Docker version

* test_pip: skip tests which requires virtualenv CLI

* Some more extra fixes for tests

* Enhance paths to look for 'sftp-server'

* Do trigger errors on newer docker-py version

* Make test_search_not_found to not fail on transactional systems

* Add `@pytest.mark.flaky_jail` to `tests/pytests/integration/ssh/test_ssh_setup.py::test_setup`

Signed-off-by: Pedro Algarvio <[email protected]>

* Prevent crashing if mountpoint does not exist anymore

* Skip failing tests on transactional systems

* test_consul.py: do not produce error if consul is not available

* Redefine max retries for some flaky tests

* test_virt.py: skip as CI containers are not compatible with Salt 3006

* test_schema.py: Adjust expectations to newer jsonschema versions

* Apply suggestions from code review

Co-authored-by: Pedro Algarvio <[email protected]>

---------

Signed-off-by: Pedro Algarvio <[email protected]>
Co-authored-by: Pedro Algarvio <[email protected]>
Co-authored-by: Pedro Algarvio <[email protected]>
  • Loading branch information
3 people authored May 27, 2024
1 parent a7e578b commit 30fd274
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 25 deletions.
11 changes: 6 additions & 5 deletions salt/modules/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,11 +1052,12 @@ def diskusage(*args):
# query the filesystems disk usage
ret = {}
for path in selected:
fsstats = os.statvfs(path)
blksz = fsstats.f_bsize
available = fsstats.f_bavail * blksz
total = fsstats.f_blocks * blksz
ret[path] = {"available": available, "total": total}
if os.path.exists(path):
fsstats = os.statvfs(path)
blksz = fsstats.f_bsize
available = fsstats.f_bavail * blksz
total = fsstats.f_blocks * blksz
ret[path] = {"available": available, "total": total}
return ret


Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,8 @@ def sshd_server(salt_factories, sshd_config_dir, salt_master, grains):
"/usr/libexec/openssh/sftp-server",
# Arch Linux
"/usr/lib/ssh/sftp-server",
# openSUSE Tumbleweed and SL Micro 6.0
"/usr/libexec/ssh/sftp-server",
]
sftp_server_path = None
for path in sftp_server_paths:
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/modules/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ def test_pip_install_multiple_editables_and_pkgs(self):
@pytest.mark.skip_initial_gh_actions_failure(
reason="This was skipped on older golden images and is failing on newer."
)
@pytest.mark.skipif(
bool(salt.utils.path.which("transactional-update")),
reason="Skipping on transactional systems",
)
def test_system_pip3(self):

self.run_function(
Expand Down
4 changes: 4 additions & 0 deletions tests/pytests/functional/cache/test_consul.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
from salt.utils.versions import Version
from tests.pytests.functional.cache.helpers import run_common_cache_tests

pytest.importorskip(
"consul",
reason="Please install python-consul package to use consul data cache driver",
)
docker = pytest.importorskip("docker")

log = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions tests/pytests/functional/modules/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
@pytest.mark.requires_network
@pytest.mark.slow_test
@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
def test_list_available_packages(modules, pip_version, tmp_path):
with VirtualEnv(venv_dir=tmp_path, pip_requirement=pip_version) as virtualenv:
virtualenv.install("-U", pip_version)
Expand Down
11 changes: 11 additions & 0 deletions tests/pytests/functional/states/test_pip_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def test_pip_installed_removed(modules, states):


@pytest.mark.slow_test
@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
def test_pip_installed_removed_venv(tmp_path, create_virtualenv, states):
venv_dir = tmp_path / "pip_installed_removed"
create_virtualenv(str(venv_dir))
Expand All @@ -105,6 +106,7 @@ def test_pip_installed_removed_venv(tmp_path, create_virtualenv, states):


@pytest.mark.slow_test
@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
def test_pip_installed_errors(tmp_path, modules, state_tree):
venv_dir = tmp_path / "pip-installed-errors"
# Since we don't have the virtualenv created, pip.installed will
Expand Down Expand Up @@ -141,6 +143,7 @@ def test_pip_installed_errors(tmp_path, modules, state_tree):
assert state_return.result is True


@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
def test_pip_installed_name_test_mode(tmp_path, create_virtualenv, states):
"""
Test pip.installed state while test=true
Expand All @@ -154,6 +157,7 @@ def test_pip_installed_name_test_mode(tmp_path, create_virtualenv, states):
assert name in ret.comment


@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
def test_pip_installed_pkgs_test_mode(tmp_path, create_virtualenv, states):
"""
Test pip.installed state while test=true
Expand All @@ -168,6 +172,7 @@ def test_pip_installed_pkgs_test_mode(tmp_path, create_virtualenv, states):


@pytest.mark.slow_test
@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
def test_issue_2028_pip_installed_state(
tmp_path, modules, state_tree, get_python_executable
):
Expand Down Expand Up @@ -226,6 +231,7 @@ def test_issue_2028_pip_installed_state(


@pytest.mark.slow_test
@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
def test_issue_2087_missing_pip(tmp_path, create_virtualenv, modules):
venv_dir = tmp_path / "issue-2087-missing-pip"

Expand Down Expand Up @@ -271,6 +277,7 @@ def test_issue_2087_missing_pip(tmp_path, create_virtualenv, modules):
@pytest.mark.destructive_test
@pytest.mark.slow_test
@pytest.mark.skip_if_not_root
@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
def test_issue_6912_wrong_owner(tmp_path, create_virtualenv, modules, states):
# Setup virtual environment directory to be used throughout the test
venv_dir = tmp_path / "6912-wrong-owner"
Expand Down Expand Up @@ -338,6 +345,7 @@ def test_issue_6912_wrong_owner(tmp_path, create_virtualenv, modules, states):
@pytest.mark.skip_on_darwin(reason="Test is flaky on macosx")
@pytest.mark.slow_test
@pytest.mark.skip_if_not_root
@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
def test_issue_6912_wrong_owner_requirements_file(
tmp_path, create_virtualenv, state_tree, modules, states
):
Expand Down Expand Up @@ -409,6 +417,7 @@ def test_issue_6912_wrong_owner_requirements_file(

@pytest.mark.destructive_test
@pytest.mark.slow_test
@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
def test_issue_6833_pip_upgrade_pip(tmp_path, create_virtualenv, modules, states):
# Create the testing virtualenv
if sys.platform == "win32":
Expand Down Expand Up @@ -465,6 +474,7 @@ def test_issue_6833_pip_upgrade_pip(tmp_path, create_virtualenv, modules, states


@pytest.mark.slow_test
@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
def test_pip_installed_specific_env(
tmp_path, state_tree_prod, states, create_virtualenv
):
Expand Down Expand Up @@ -514,6 +524,7 @@ def test_pip_installed_specific_env(


@pytest.mark.slow_test
@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
def test_22359_pip_installed_unless_does_not_trigger_warnings(
create_virtualenv, tmp_path, states
):
Expand Down
4 changes: 4 additions & 0 deletions tests/pytests/functional/states/test_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
pytest.mark.slow_test,
pytest.mark.skip_if_not_root,
pytest.mark.destructive_test,
pytest.mark.skipif(
bool(salt.utils.path.which("transactional-update")),
reason="Skipping on transactional systems",
),
]


Expand Down
4 changes: 3 additions & 1 deletion tests/pytests/integration/cli/test_syndic_eauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import pytest

docker = pytest.importorskip("docker")
from tests.conftest import CODE_DIR

docker = pytest.importorskip("docker", minversion="4.0.0")

INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"

Expand Down
2 changes: 1 addition & 1 deletion tests/pytests/integration/daemons/test_memory_leak.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def file_add_delete_sls(testfile_path, base_env_state_tree_root_dir):

@pytest.mark.skip_on_darwin(reason="MacOS is a spawning platform, won't work")
@pytest.mark.skipif(GITHUB_ACTIONS, reason="Test is failing in GitHub Actions")
@pytest.mark.flaky(max_runs=4)
@pytest.mark.flaky(max_runs=10)
def test_memory_leak(salt_cli, salt_minion, file_add_delete_sls):
max_usg = None

Expand Down
1 change: 1 addition & 0 deletions tests/pytests/integration/modules/test_cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def test_avoid_injecting_shell_code_as_root(


@pytest.mark.slow_test
@pytest.mark.flaky(max_runs=4)
def test_blacklist_glob(salt_call_cli):
"""
cmd_blacklist_glob
Expand Down
4 changes: 4 additions & 0 deletions tests/pytests/integration/modules/test_virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
Version(docker.__version__) < Version("4.0.0"),
reason="Test does not work in this version of docker-py",
),
pytest.mark.skipif(
salt.version.__saltstack_version__.major <= 3006,
reason="CI containers are not compatible with this Salt version",
),
]


Expand Down
4 changes: 4 additions & 0 deletions tests/pytests/integration/ssh/test_pre_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ def result():


@pytest.mark.slow_test
@pytest.mark.skipif(
bool(salt.utils.path.which("transactional-update")),
reason="Skipping on transactional systems",
)
def test_ssh_pre_flight_perms(salt_ssh_cli, caplog, _create_roster, account):
"""
Test to ensure standard user cannot run pre flight script
Expand Down
1 change: 1 addition & 0 deletions tests/pytests/integration/ssh/test_ssh_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def salt_ssh_cli(
)


@pytest.mark.flaky_jail
def test_setup(salt_ssh_cli, ssh_container_name, ssh_sub_container_name, ssh_password):
"""
Test salt-ssh setup works
Expand Down
6 changes: 6 additions & 0 deletions tests/pytests/scenarios/setup/test_man.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@

import salt.utils.platform
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
from tests.conftest import CODE_DIR

MISSING_SETUP_PY_FILE = not CODE_DIR.joinpath("setup.py").exists()

pytestmark = [
pytest.mark.core_test,
pytest.mark.skip_on_windows,
pytest.mark.skip_on_aix,
pytest.mark.skip_initial_onedir_failure,
pytest.mark.skip_if_binaries_missing(*KNOWN_BINARY_NAMES, check_all=False),
pytest.mark.skipif(
MISSING_SETUP_PY_FILE, reason="This test only work if setup.py is available"
),
]


Expand Down
20 changes: 10 additions & 10 deletions tests/pytests/unit/modules/dockermod/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def config_get_enabled(val, default):


@pytest.mark.skipif(
docker_mod.docker.version_info < (1, 5, 0),
docker_mod._get_docker_py_versioninfo() < (1, 5, 0),
reason="docker module must be installed to run this test or is too old. >=1.5.0",
)
def test_list_networks():
Expand All @@ -381,7 +381,7 @@ def test_list_networks():


@pytest.mark.skipif(
docker_mod.docker.version_info < (1, 5, 0),
docker_mod._get_docker_py_versioninfo() < (1, 5, 0),
reason="docker module must be installed to run this test or is too old. >=1.5.0",
)
def test_create_network():
Expand Down Expand Up @@ -425,7 +425,7 @@ def test_create_network():


@pytest.mark.skipif(
docker_mod.docker.version_info < (1, 5, 0),
docker_mod._get_docker_py_versioninfo() < (1, 5, 0),
reason="docker module must be installed to run this test or is too old. >=1.5.0",
)
def test_remove_network():
Expand All @@ -447,7 +447,7 @@ def test_remove_network():


@pytest.mark.skipif(
docker_mod.docker.version_info < (1, 5, 0),
docker_mod._get_docker_py_versioninfo() < (1, 5, 0),
reason="docker module must be installed to run this test or is too old. >=1.5.0",
)
def test_inspect_network():
Expand All @@ -469,7 +469,7 @@ def test_inspect_network():


@pytest.mark.skipif(
docker_mod.docker.version_info < (1, 5, 0),
docker_mod._get_docker_py_versioninfo() < (1, 5, 0),
reason="docker module must be installed to run this test or is too old. >=1.5.0",
)
def test_connect_container_to_network():
Expand All @@ -494,7 +494,7 @@ def test_connect_container_to_network():


@pytest.mark.skipif(
docker_mod.docker.version_info < (1, 5, 0),
docker_mod._get_docker_py_versioninfo() < (1, 5, 0),
reason="docker module must be installed to run this test or is too old. >=1.5.0",
)
def test_disconnect_container_from_network():
Expand All @@ -516,7 +516,7 @@ def test_disconnect_container_from_network():


@pytest.mark.skipif(
docker_mod.docker.version_info < (1, 5, 0),
docker_mod._get_docker_py_versioninfo() < (1, 5, 0),
reason="docker module must be installed to run this test or is too old. >=1.5.0",
)
def test_list_volumes():
Expand All @@ -542,7 +542,7 @@ def test_list_volumes():


@pytest.mark.skipif(
docker_mod.docker.version_info < (1, 5, 0),
docker_mod._get_docker_py_versioninfo() < (1, 5, 0),
reason="docker module must be installed to run this test or is too old. >=1.5.0",
)
def test_create_volume():
Expand Down Expand Up @@ -572,7 +572,7 @@ def test_create_volume():


@pytest.mark.skipif(
docker_mod.docker.version_info < (1, 5, 0),
docker_mod._get_docker_py_versioninfo() < (1, 5, 0),
reason="docker module must be installed to run this test or is too old. >=1.5.0",
)
def test_remove_volume():
Expand All @@ -594,7 +594,7 @@ def test_remove_volume():


@pytest.mark.skipif(
docker_mod.docker.version_info < (1, 5, 0),
docker_mod._get_docker_py_versioninfo() < (1, 5, 0),
reason="docker module must be installed to run this test or is too old. >=1.5.0",
)
def test_inspect_volume():
Expand Down
1 change: 1 addition & 0 deletions tests/unit/modules/test_zypperpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,7 @@ def test_search(self):
zypp_mock.assert_called_with(root=None, ignore_not_found=True)
xml_mock.nolock.noraise.xml.call.assert_called_with("search", "emacs")

@patch("salt.utils.files.is_fcntl_available", MagicMock(return_value=False))
def test_search_not_found(self):
"""Test zypperpkg.search()"""
ret = {
Expand Down
Loading

0 comments on commit 30fd274

Please sign in to comment.