/
githubmirror
/
salt
Обзор
Документация
Войти
/
githubmirror
/
salt
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tests/integration/cli/test_custom_module.py
100 строк
3 KB
Daniel A. Wozniak
Skip ssh tests for bad openssh version
04 дек 2025, 03:18
04 дек 2025, 03:18
cb1341e
Код
Авторство
О чём код?
""" :codeauthor: Daniel Mizyrycki (mzdaniel@glidelink.net) tests.integration.cli.custom_module ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Test salt-ssh sls with a custom module work. $ cat srv/custom_module.sls custom-module: module.run: - name: test.recho - text: hello $ cat srv/_modules/override_test.py __virtualname__ = 'test' def __virtual__(): return __virtualname__ def recho(text): return text[::-1] $ salt-ssh localhost state.sls custom_module localhost: olleh """ import pytest from tests.support.case import SSHCase from tests.support.helpers import system_python_version pytestmark = [ pytest.mark.skip_on_windows, pytest.mark.skipif( 'grains["osfinger"].startswith(("Fedora Linux-40", "Ubuntu-24.04", "Arch Linux"))', reason="System ships with a version of python that is too recent for salt-ssh tests", # Actually, the problem is that the tornado we ship is not prepared for Python 3.12, # and it imports `ssl` and checks if the `match_hostname` function is defined, which # has been deprecated since Python 3.7, so, the logic goes into trying to import # backports.ssl-match-hostname which is not installed on the system. ), pytest.mark.skipif( system_python_version() < (3, 10), reason="System python too old for these tests", ), pytest.mark.skipif( """grains["osfinger"].startswith("VMware Photon OS-5") and __import__("subprocess").run(["rpm", "-q", "openssh-server"], capture_output=True, text=True).stdout.strip() in ["openssh-server-9.3p2-18.ph5.x86_64", "openssh-server-9.3p2-18.ph5.aarch64"]""", reason="Photon OS OpenSSH 9.3p2-18 has a bug that breaks salt-ssh", # This version causes "vdollar_percent_expand: NULL replacement for token n" errors # when using the User config option that salt-ssh depends on. ), ] class SSHCustomModuleTest(SSHCase): """ Test sls with custom module functionality using ssh """ @pytest.mark.slow_test def test_ssh_regular_module(self): """ Test regular module work using SSHCase environment """ expected = "hello" cmd = self.run_function("test.echo", arg=["hello"]) self.assertEqual(expected, cmd) @pytest.mark.slow_test @pytest.mark.timeout(120, func_only=True) def test_ssh_custom_module(self): """ Test custom module work using SSHCase environment """ expected = "hello"[::-1] cmd = self.run_function("test.recho", arg=["hello"]) self.assertEqual(expected, cmd) @pytest.mark.slow_test def test_ssh_sls_with_custom_module(self): """ Test sls with custom module work using SSHCase environment """ expected = { "module_|-regular-module_|-test.echo_|-run": "hello", "module_|-custom-module_|-test.recho_|-run": "olleh", } cmd = self.run_function("state.sls", arg=["custom_module"]) for key in cmd: if not isinstance(cmd, dict) or not isinstance(cmd[key], dict): raise AssertionError(f"{cmd} is not a proper state return") elif not cmd[key]["result"]: raise AssertionError(cmd[key]["comment"]) cmd_ret = cmd[key]["changes"].get("ret", None) self.assertEqual(cmd_ret, expected[key])