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 (#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]>
  • Loading branch information
meaksh and m-czernek committed Oct 29, 2024
1 parent f10bd0f commit 785b882
Show file tree
Hide file tree
Showing 10 changed files with 50 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 @@ -1051,11 +1051,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
6 changes: 6 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 Down Expand Up @@ -30,6 +31,11 @@
log = logging.getLogger(__name__)


@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 @@ -82,6 +82,10 @@ def _pip_successful_install(
@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(pip, 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 @@ -110,6 +110,10 @@ def _skip_if_pep8_installed(modules, pkg_name):
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(states, pkg_name):
"""
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 @@ -58,6 +58,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
5 changes: 5 additions & 0 deletions tests/pytests/integration/netapi/test_ssh_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import sys

import pytest

Expand All @@ -19,6 +20,10 @@
# backports.ssl-match-hostname which is not installed on the system.
),
pytest.mark.timeout_unless_on_windows(120),
pytest.mark.skipif(
"venv-salt-minion" in sys.executable,
reason="Skipping for Salt Bundle (tests are not compatible)",
),
]

log = logging.getLogger(__name__)
Expand Down
7 changes: 7 additions & 0 deletions tests/pytests/integration/ssh/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import sys

from tests.support.pytest.helpers import reap_stray_processes

Expand Down Expand Up @@ -93,3 +94,9 @@ def state_tree_dir(base_env_state_tree_root_dir):

with top_tempfile, map_tempfile, state_tempfile:
yield


@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 @@ -1441,6 +1441,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 785b882

Please sign in to comment.