mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Migrate proxy tests to PyTest
This commit is contained in:
parent
ea0482296e
commit
3a510e541d
11 changed files with 252 additions and 273 deletions
|
@ -1,20 +0,0 @@
|
|||
@Library('salt@master-1.7') _
|
||||
|
||||
runTestSuite(
|
||||
ami_image_id: 'ami-018072d7ecddbe0b7',
|
||||
concurrent_builds: 1,
|
||||
distro_name: 'centos',
|
||||
distro_version: '7',
|
||||
env: env,
|
||||
extra_codecov_flags: ["proxy"],
|
||||
golden_images_branch: 'master',
|
||||
jenkins_slave_label: 'kitchen-slave',
|
||||
nox_env_name: 'runtests-zeromq',
|
||||
nox_passthrough_opts: '--proxy',
|
||||
python_version: 'py3',
|
||||
testrun_timeout: 6,
|
||||
force_run_full: true,
|
||||
disable_from_filenames: true,
|
||||
use_spot_instances: true)
|
||||
|
||||
// vim: ft=groovy
|
|
@ -1,20 +0,0 @@
|
|||
@Library('salt@master-1.7') _
|
||||
|
||||
runTestSuite(
|
||||
ami_image_id: 'ami-0271016d2ae2ec10f',
|
||||
concurrent_builds: 1,
|
||||
distro_name: 'ubuntu',
|
||||
distro_version: '1604',
|
||||
env: env,
|
||||
extra_codecov_flags: ["proxy"],
|
||||
golden_images_branch: 'master',
|
||||
jenkins_slave_label: 'kitchen-slave',
|
||||
nox_env_name: 'runtests-zeromq',
|
||||
nox_passthrough_opts: '--proxy',
|
||||
python_version: 'py3',
|
||||
testrun_timeout: 6,
|
||||
force_run_full: true,
|
||||
disable_from_filenames: true,
|
||||
use_spot_instances: true)
|
||||
|
||||
// vim: ft=groovy
|
|
@ -1306,8 +1306,12 @@ def reap_stray_processes():
|
|||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def grains(request):
|
||||
sminion = create_sminion()
|
||||
def sminion():
|
||||
return create_sminion()
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def grains(sminion):
|
||||
return sminion.opts["grains"].copy()
|
||||
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
|
@ -1,17 +0,0 @@
|
|||
"""
|
||||
tests.integration.proxy.conftest
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Proxy related fixtures
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pytest.fixture(scope="package", autouse=True)
|
||||
def salt_proxy(salt_proxy):
|
||||
return salt_proxy
|
|
@ -1,123 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Test salt-call --proxyid commands
|
||||
|
||||
tests.integration.proxy.test_shell
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
"""
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
|
||||
import salt.ext.six as six
|
||||
import salt.utils.json as json
|
||||
from tests.support.case import ShellCase
|
||||
from tests.support.helpers import slowTest
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProxyCallerSimpleTestCase(ShellCase):
|
||||
"""
|
||||
Test salt-call --proxyid <proxyid> commands
|
||||
"""
|
||||
|
||||
RUN_TIMEOUT = 300
|
||||
|
||||
@staticmethod
|
||||
def _load_return(ret):
|
||||
try:
|
||||
return json.loads("\n".join(ret))
|
||||
except ValueError:
|
||||
log.warning("Failed to JSON decode: '%s'", ret)
|
||||
six.reraise(*sys.exc_info())
|
||||
|
||||
@slowTest
|
||||
def test_can_it_ping(self):
|
||||
"""
|
||||
Ensure the proxy can ping
|
||||
"""
|
||||
ret = self._load_return(
|
||||
self.run_call(
|
||||
"--proxyid proxytest --out=json test.ping",
|
||||
config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
|
||||
)
|
||||
)
|
||||
self.assertEqual(ret["local"], True)
|
||||
|
||||
@slowTest
|
||||
def test_list_pkgs(self):
|
||||
"""
|
||||
Package test 1, really just tests that the virtual function capability
|
||||
is working OK.
|
||||
"""
|
||||
ret = self._load_return(
|
||||
self.run_call(
|
||||
"--proxyid proxytest --out=json pkg.list_pkgs",
|
||||
config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
|
||||
)
|
||||
)
|
||||
self.assertIn("coreutils", ret["local"])
|
||||
self.assertIn("apache", ret["local"])
|
||||
self.assertIn("redbull", ret["local"])
|
||||
|
||||
@slowTest
|
||||
def test_upgrade(self):
|
||||
ret = self._load_return(
|
||||
self.run_call(
|
||||
"--proxyid proxytest --out=json pkg.upgrade",
|
||||
config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
|
||||
)
|
||||
)
|
||||
self.assertEqual(ret["local"]["coreutils"]["new"], "2.0")
|
||||
self.assertEqual(ret["local"]["redbull"]["new"], "1000.99")
|
||||
|
||||
@slowTest
|
||||
def test_service_list(self):
|
||||
ret = self._load_return(
|
||||
self.run_call(
|
||||
"--proxyid proxytest --out=json service.list",
|
||||
config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
|
||||
)
|
||||
)
|
||||
self.assertIn("ntp", ret["local"])
|
||||
|
||||
@slowTest
|
||||
def test_service_start(self):
|
||||
ret = self._load_return(
|
||||
self.run_call(
|
||||
"--proxyid proxytest --out=json service.start samba",
|
||||
config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
|
||||
)
|
||||
)
|
||||
ret = self._load_return(
|
||||
self.run_call(
|
||||
"--proxyid proxytest --out=json service.status samba",
|
||||
config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
|
||||
)
|
||||
)
|
||||
self.assertTrue(ret)
|
||||
|
||||
@slowTest
|
||||
def test_service_get_all(self):
|
||||
ret = self._load_return(
|
||||
self.run_call(
|
||||
"--proxyid proxytest --out=json service.get_all",
|
||||
config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
|
||||
)
|
||||
)
|
||||
self.assertIn("samba", ret["local"])
|
||||
|
||||
@slowTest
|
||||
def test_grains_items(self):
|
||||
ret = self._load_return(
|
||||
self.run_call(
|
||||
"--proxyid proxytest --out=json grains.items",
|
||||
config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
|
||||
)
|
||||
)
|
||||
self.assertEqual(ret["local"]["kernel"], "proxy")
|
||||
self.assertEqual(ret["local"]["kernelrelease"], "proxy")
|
|
@ -1,90 +0,0 @@
|
|||
"""
|
||||
Simple Smoke Tests for Connected Proxy Minion
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from tests.support.case import ModuleCase
|
||||
from tests.support.helpers import PRE_PYTEST_SKIP_REASON, slowTest
|
||||
|
||||
|
||||
class ProxyMinionSimpleTestCase(ModuleCase):
|
||||
"""
|
||||
Test proxy minion functionality
|
||||
"""
|
||||
|
||||
def test_can_it_ping(self):
|
||||
"""
|
||||
Ensure the proxy can ping
|
||||
"""
|
||||
ret = self.run_function("test.ping", minion_tgt="proxytest")
|
||||
self.assertEqual(ret, True)
|
||||
|
||||
def test_list_pkgs(self):
|
||||
"""
|
||||
Package test 1, really just tests that the virtual function capability
|
||||
is working OK.
|
||||
"""
|
||||
ret = self.run_function("pkg.list_pkgs", minion_tgt="proxytest")
|
||||
self.assertIn("coreutils", ret)
|
||||
self.assertIn("apache", ret)
|
||||
self.assertIn("redbull", ret)
|
||||
|
||||
def test_install_pkgs(self):
|
||||
"""
|
||||
Package test 2, really just tests that the virtual function capability
|
||||
is working OK.
|
||||
"""
|
||||
ret = self.run_function("pkg.install", ["thispkg"], minion_tgt="proxytest")
|
||||
self.assertEqual(ret["thispkg"], "1.0")
|
||||
|
||||
ret = self.run_function("pkg.list_pkgs", minion_tgt="proxytest")
|
||||
|
||||
self.assertEqual(ret["apache"], "2.4")
|
||||
self.assertEqual(ret["redbull"], "999.99")
|
||||
self.assertEqual(ret["thispkg"], "1.0")
|
||||
|
||||
def test_remove_pkgs(self):
|
||||
ret = self.run_function("pkg.remove", ["apache"], minion_tgt="proxytest")
|
||||
self.assertNotIn("apache", ret)
|
||||
|
||||
def test_upgrade(self):
|
||||
ret = self.run_function("pkg.upgrade", minion_tgt="proxytest")
|
||||
self.assertEqual(ret["coreutils"]["new"], "2.0")
|
||||
self.assertEqual(ret["redbull"]["new"], "1000.99")
|
||||
|
||||
def test_service_list(self):
|
||||
ret = self.run_function("service.list", minion_tgt="proxytest")
|
||||
self.assertIn("ntp", ret)
|
||||
|
||||
def test_service_stop(self):
|
||||
ret = self.run_function("service.stop", ["ntp"], minion_tgt="proxytest")
|
||||
ret = self.run_function("service.status", ["ntp"], minion_tgt="proxytest")
|
||||
self.assertFalse(ret)
|
||||
|
||||
def test_service_start(self):
|
||||
ret = self.run_function("service.start", ["samba"], minion_tgt="proxytest")
|
||||
ret = self.run_function("service.status", ["samba"], minion_tgt="proxytest")
|
||||
self.assertTrue(ret)
|
||||
|
||||
def test_service_get_all(self):
|
||||
ret = self.run_function("service.get_all", minion_tgt="proxytest")
|
||||
self.assertTrue(ret)
|
||||
self.assertIn("samba", " ".join(ret))
|
||||
|
||||
def test_grains_items(self):
|
||||
ret = self.run_function("grains.items", minion_tgt="proxytest")
|
||||
self.assertEqual(ret["kernel"], "proxy")
|
||||
self.assertEqual(ret["kernelrelease"], "proxy")
|
||||
|
||||
@pytest.mark.skip_on_darwin(reason=PRE_PYTEST_SKIP_REASON)
|
||||
def test_state_apply(self):
|
||||
ret = self.run_function("state.apply", ["core"], minion_tgt="proxytest")
|
||||
for key, value in ret.items():
|
||||
self.assertTrue(value["result"])
|
||||
|
||||
@slowTest
|
||||
@pytest.mark.skip_on_darwin(reason=PRE_PYTEST_SKIP_REASON)
|
||||
def test_state_highstate(self):
|
||||
ret = self.run_function("state.highstate", minion_tgt="proxytest")
|
||||
for key, value in ret.items():
|
||||
self.assertTrue(value["result"])
|
0
tests/pytests/integration/proxy/__init__.py
Normal file
0
tests/pytests/integration/proxy/__init__.py
Normal file
12
tests/pytests/integration/proxy/conftest.py
Normal file
12
tests/pytests/integration/proxy/conftest.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
import pytest
|
||||
from tests.support.helpers import PRE_PYTEST_SKIP_REASON
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def skip_pre_pytest_platforms(grains):
|
||||
os = grains["os"]
|
||||
os_major_version = int(grains.get("osmajorrelease") or 0)
|
||||
centos_7 = os == "CentOS" and os_major_version == 7
|
||||
ubuntu_16 = os == "Ubuntu" and os_major_version == 16
|
||||
if not centos_7 and not ubuntu_16:
|
||||
pytest.skip(PRE_PYTEST_SKIP_REASON)
|
142
tests/pytests/integration/proxy/test_shell.py
Normal file
142
tests/pytests/integration/proxy/test_shell.py
Normal file
|
@ -0,0 +1,142 @@
|
|||
"""
|
||||
tests.integration.proxy.test_shell
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Test salt-call --proxyid <proxyid> commands
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
import salt.utils.path
|
||||
import salt.utils.platform
|
||||
from tests.support.helpers import slowTest
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def salt_call_cli(salt_proxy):
|
||||
return salt_proxy.get_salt_call_cli(default_timeout=120)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def package_name(grains):
|
||||
pkg = "figlet"
|
||||
if salt.utils.platform.is_windows():
|
||||
pkg = "putty"
|
||||
elif grains["os_family"] == "RedHat":
|
||||
pkg = "units"
|
||||
elif grains["os_family"] == "Arch":
|
||||
pkg = "xz"
|
||||
return pkg
|
||||
|
||||
|
||||
@slowTest
|
||||
def test_can_it_ping(salt_call_cli):
|
||||
"""
|
||||
Ensure the proxy can ping
|
||||
"""
|
||||
ret = salt_call_cli.run("test.ping")
|
||||
assert ret.exitcode == 0, ret
|
||||
assert ret.json is True
|
||||
|
||||
|
||||
@slowTest
|
||||
def test_list_pkgs(salt_call_cli, package_name):
|
||||
"""
|
||||
Package test 1, really just tests that the virtual function capability
|
||||
is working OK.
|
||||
"""
|
||||
ret = salt_call_cli.run("pkg.list_pkgs")
|
||||
assert ret.exitcode == 0, ret
|
||||
assert package_name in ret.json
|
||||
|
||||
|
||||
@slowTest
|
||||
@pytest.mark.skip_if_not_root
|
||||
@pytest.mark.destructive_test
|
||||
def test_upgrade(salt_call_cli):
|
||||
# Do we have any upgrades
|
||||
ret = salt_call_cli.run("pkg.list_upgrades")
|
||||
assert ret.exitcode == 0, ret
|
||||
if not ret.json:
|
||||
pytest.skip("No upgrades available to run test")
|
||||
ret = salt_call_cli.run("pkg.upgrade")
|
||||
assert ret.exitcode == 0, ret
|
||||
# Assert that something got upgraded
|
||||
assert ret.json
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def service_name(grains, sminion):
|
||||
_service_name = "cron"
|
||||
cmd_name = "crontab"
|
||||
os_family = grains["os_family"]
|
||||
os_release = grains["osrelease"]
|
||||
stopped = False
|
||||
running = True
|
||||
if os_family == "RedHat":
|
||||
_service_name = "crond"
|
||||
elif os_family == "Arch":
|
||||
_service_name = "sshd"
|
||||
cmd_name = "systemctl"
|
||||
elif os_family == "MacOS":
|
||||
_service_name = "org.ntp.ntpd"
|
||||
if int(os_release.split(".")[1]) >= 13:
|
||||
_service_name = "com.apple.AirPlayXPCHelper"
|
||||
stopped = ""
|
||||
running = "[0-9]"
|
||||
elif os_family == "Windows":
|
||||
_service_name = "Spooler"
|
||||
|
||||
ret = sminion.functions.service.get_enabled()
|
||||
pre_srv_enabled = _service_name in ret
|
||||
post_srv_disable = False
|
||||
if not pre_srv_enabled:
|
||||
ret = sminion.functions.service.enable(name=_service_name)
|
||||
assert ret is True
|
||||
post_srv_disable = True
|
||||
|
||||
if os_family != "Windows" and salt.utils.path.which(cmd_name) is None:
|
||||
pytest.skip("{} is not installed".format(cmd_name))
|
||||
|
||||
yield _service_name
|
||||
|
||||
if post_srv_disable:
|
||||
ret = sminion.functions.service.disable(name=_service_name)
|
||||
assert ret.exitcode == 0
|
||||
|
||||
|
||||
@slowTest
|
||||
@pytest.mark.skip_if_not_root
|
||||
def test_service_list(salt_call_cli, service_name):
|
||||
ret = salt_call_cli.run("service.list")
|
||||
assert ret.exitcode == 0, ret
|
||||
assert service_name in ret.json
|
||||
|
||||
|
||||
@slowTest
|
||||
@pytest.mark.skip_if_not_root
|
||||
def test_service_start(salt_call_cli, service_name):
|
||||
ret = salt_call_cli.run("service.start", service_name)
|
||||
assert ret.exitcode == 0, ret
|
||||
ret = salt_call_cli.run("service.status", service_name)
|
||||
assert ret.exitcode == 0, ret
|
||||
assert ret.json is True
|
||||
|
||||
|
||||
@slowTest
|
||||
@pytest.mark.skip_if_not_root
|
||||
def test_service_get_all(salt_call_cli, service_name):
|
||||
ret = salt_call_cli.run("service.get_all")
|
||||
assert ret.exitcode == 0, ret
|
||||
assert service_name in ret.json
|
||||
|
||||
|
||||
@slowTest
|
||||
def test_grains_items(salt_call_cli):
|
||||
ret = salt_call_cli.run("grains.items")
|
||||
assert ret.exitcode == 0, ret
|
||||
assert ret.json["kernel"] == "proxy"
|
||||
assert ret.json["kernelrelease"] == "proxy"
|
92
tests/pytests/integration/proxy/test_simple.py
Normal file
92
tests/pytests/integration/proxy/test_simple.py
Normal file
|
@ -0,0 +1,92 @@
|
|||
"""
|
||||
Simple Smoke Tests for Connected Proxy Minion
|
||||
"""
|
||||
|
||||
from tests.support.helpers import slowTest
|
||||
|
||||
|
||||
def test_can_it_ping(salt_cli, salt_proxy):
|
||||
"""
|
||||
Ensure the proxy can ping
|
||||
"""
|
||||
ret = salt_cli.run("test.ping", minion_tgt=salt_proxy.id)
|
||||
assert ret.json is True
|
||||
|
||||
|
||||
def test_list_pkgs(salt_cli, salt_proxy):
|
||||
"""
|
||||
Package test 1, really just tests that the virtual function capability
|
||||
is working OK.
|
||||
"""
|
||||
ret = salt_cli.run("pkg.list_pkgs", minion_tgt=salt_proxy.id)
|
||||
assert "coreutils" in ret.json
|
||||
assert "apache" in ret.json
|
||||
assert "redbull" in ret.json
|
||||
|
||||
|
||||
def test_install_pkgs(salt_cli, salt_proxy):
|
||||
"""
|
||||
Package test 2, really just tests that the virtual function capability
|
||||
is working OK.
|
||||
"""
|
||||
ret = salt_cli.run("pkg.install", "thispkg", minion_tgt=salt_proxy.id)
|
||||
assert ret.json["thispkg"] == "1.0"
|
||||
|
||||
ret = salt_cli.run("pkg.list_pkgs", minion_tgt=salt_proxy.id)
|
||||
|
||||
assert ret.json["apache"] == "2.4"
|
||||
assert ret.json["redbull"] == "999.99"
|
||||
assert ret.json["thispkg"] == "1.0"
|
||||
|
||||
|
||||
def test_remove_pkgs(salt_cli, salt_proxy):
|
||||
ret = salt_cli.run("pkg.remove", "apache", minion_tgt=salt_proxy.id)
|
||||
assert "apache" not in ret.json
|
||||
|
||||
|
||||
def test_upgrade(salt_cli, salt_proxy):
|
||||
ret = salt_cli.run("pkg.upgrade", minion_tgt=salt_proxy.id)
|
||||
assert ret.json["coreutils"]["new"] == "2.0"
|
||||
assert ret.json["redbull"]["new"] == "1000.99"
|
||||
|
||||
|
||||
def test_service_list(salt_cli, salt_proxy):
|
||||
ret = salt_cli.run("service.list", minion_tgt=salt_proxy.id)
|
||||
assert "ntp" in ret.json
|
||||
|
||||
|
||||
def test_service_stop(salt_cli, salt_proxy):
|
||||
ret = salt_cli.run("service.stop", "ntp", minion_tgt=salt_proxy.id)
|
||||
ret = salt_cli.run("service.status", "ntp", minion_tgt=salt_proxy.id)
|
||||
assert ret.json is False
|
||||
|
||||
|
||||
def test_service_start(salt_cli, salt_proxy):
|
||||
ret = salt_cli.run("service.start", "samba", minion_tgt=salt_proxy.id)
|
||||
ret = salt_cli.run("service.status", "samba", minion_tgt=salt_proxy.id)
|
||||
assert ret.json is True
|
||||
|
||||
|
||||
def test_service_get_all(salt_cli, salt_proxy):
|
||||
ret = salt_cli.run("service.get_all", minion_tgt=salt_proxy.id)
|
||||
assert ret.json
|
||||
assert "samba" in ret.json
|
||||
|
||||
|
||||
def test_grains_items(salt_cli, salt_proxy):
|
||||
ret = salt_cli.run("grains.items", minion_tgt=salt_proxy.id)
|
||||
assert ret.json["kernel"] == "proxy"
|
||||
assert ret.json["kernelrelease"] == "proxy"
|
||||
|
||||
|
||||
def test_state_apply(salt_cli, salt_proxy):
|
||||
ret = salt_cli.run("state.apply", "core", minion_tgt=salt_proxy.id)
|
||||
for value in ret.json.values():
|
||||
assert value["result"] is True
|
||||
|
||||
|
||||
@slowTest
|
||||
def test_state_highstate(salt_cli, salt_proxy):
|
||||
ret = salt_cli.run("state.highstate", minion_tgt=salt_proxy.id)
|
||||
for value in ret.json.values():
|
||||
assert value["result"] is True
|
Loading…
Add table
Reference in a new issue