Skip to content

Commit

Permalink
Fix "status.diskusage" and exclude some tests to run when testing Sal…
Browse files Browse the repository at this point in the history
…t Bundle (saltstack#659)

* Show warning instead of crashing when stats cannot be fetched

* Skip tests that are not compatible with Salt Bundle

* test_syndic_eauth: do not produce error if docker service is not running

* test_cmdmod: assert properly in case of DeprecationsWarnings

* Include path as part of output in case of errors

Co-authored-by: Marek Czernek <[email protected]>

---------

Co-authored-by: Marek Czernek <[email protected]>

BACKPORT-UPSTREAM=saltstack#66647
  • Loading branch information
meaksh authored and agraul committed Jan 27, 2025
1 parent ee8ad29 commit 33b1446
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 6 deletions.
14 changes: 9 additions & 5 deletions salt/modules/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,11 +1053,15 @@ def diskusage(*args):
ret = {}
for path in selected:
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}
try:
fsstats = os.statvfs(path)
blksz = fsstats.f_bsize
available = fsstats.f_bavail * blksz
total = fsstats.f_blocks * blksz
ret[path] = {"available": available, "total": total}
except OSError as exc:
log.warning("Cannot get stats from '{}': {}".format(path, exc))
ret[path] = {"available": None, "total": None}
return ret


Expand Down
5 changes: 5 additions & 0 deletions tests/integration/modules/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pprint
import re
import shutil
import sys
import tempfile

import pytest
Expand All @@ -16,6 +17,10 @@


@pytest.mark.skip_if_binaries_missing(*KNOWN_BINARY_NAMES, check_all=False)
@pytest.mark.skipif(
"venv-salt-minion" in sys.executable,
reason="Skipping for Salt Bundle (tests are not compatible)",
)
@pytest.mark.windows_whitelisted
class PipModuleTest(ModuleCase):
def setUp(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/ssh/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import shutil
import sys
import threading
import time

Expand All @@ -18,6 +19,10 @@


@pytest.mark.slow_test
@pytest.mark.skipif(
"venv-salt-minion" in sys.executable,
reason="Skipping for Salt Bundle (tests are not compatible)",
)
class SSHStateTest(SSHCase):
"""
testing the state system with salt-ssh
Expand Down
4 changes: 4 additions & 0 deletions tests/pytests/functional/modules/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
@pytest.mark.requires_network
@pytest.mark.slow_test
@pytest.mark.skip_if_binaries_missing("virtualenv", reason="Needs virtualenv binary")
@pytest.mark.skipif(
"venv-salt-minion" in sys.executable,
reason="Skipping for Salt Bundle (tests are not compatible)",
)
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
5 changes: 5 additions & 0 deletions tests/pytests/functional/modules/test_virtualenv_mod.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import shutil
import sys

import pytest

Expand Down Expand Up @@ -68,6 +69,10 @@ def test_clear(virtualenv, venv_dir, modules):
bool(salt.utils.path.which("transactional-update")),
reason="Skipping on transactional systems",
)
@pytest.mark.skipif(
"venv-salt-minion" in sys.executable,
reason="Skipping for Salt Bundle (tests are not compatible)",
)
def test_virtualenv_ver(virtualenv, venv_dir):
ret = virtualenv.create(str(venv_dir))
assert ret
Expand Down
4 changes: 4 additions & 0 deletions tests/pytests/functional/states/test_pip_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def run_command(path, **kwargs):
bool(salt.utils.path.which("transactional-update")),
reason="Skipping on transactional systems",
)
@pytest.mark.skipif(
"venv-salt-minion" in sys.executable,
reason="Skipping for Salt Bundle (tests are not compatible)",
)
def test_pip_installed_removed(modules, states):
"""
Tests installed and removed states
Expand Down
3 changes: 3 additions & 0 deletions tests/pytests/integration/cli/test_syndic_eauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def syndic_network():
try:
network = client.networks.create(name="syndic_test_net", ipam=ipam_config)
yield network.name
except Exception as e:
# Docker failed, it's gonna be an environment issue, let's just skip
pytest.skip(f"Docker failed with error {e}")
finally:
if network is not None:
network.remove()
Expand Down
4 changes: 3 additions & 1 deletion tests/pytests/integration/modules/test_cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def test_blacklist_glob(salt_call_cli):
)

assert (
ret.stderr.rstrip()
ret.stderr.rstrip().split("\n")[
-1
] # Taking only the last line in case of DeprecationWarnings
== "Error running 'cmd.run': The shell command \"bad_command --foo\" is not permitted"
)

Expand Down
6 changes: 6 additions & 0 deletions tests/pytests/integration/netapi/test_ssh_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

import pytest

import salt.netapi
Expand All @@ -8,6 +10,10 @@
pytestmark = [
pytest.mark.slow_test,
pytest.mark.requires_sshd_server,
pytest.mark.skipif(
"venv-salt-minion" in sys.executable,
reason="Skipping for Salt Bundle (tests are not compatible)",
),
]


Expand Down
9 changes: 9 additions & 0 deletions tests/pytests/integration/ssh/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys

import pytest


@pytest.fixture(scope="package", autouse=True)
def _auto_skip_on_salt_bundle():
if "venv-salt-minion" in sys.executable:
pytest.skip("Skipping for Salt Bundle (tests are not compatible)")
4 changes: 4 additions & 0 deletions tests/unit/utils/test_thin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,10 @@ def test_pack_alternatives_empty_dependencies(self):
"virtualenv", reason="Needs virtualenv binary"
)
@pytest.mark.skip_on_windows(reason="salt-ssh does not deploy to/from windows")
@pytest.mark.skipif(
"venv-salt-minion" in sys.executable,
reason="Skipping for Salt Bundle (tests are not compatible)",
)
def test_thin_dir(self):
"""
Test the thin dir to make sure salt-call can run
Expand Down

0 comments on commit 33b1446

Please sign in to comment.