mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Update to saltfactories v0.7.14
This commit is contained in:
parent
982c506cc0
commit
ad95cd4c47
7 changed files with 38 additions and 239 deletions
|
@ -16,7 +16,6 @@ import logging
|
|||
import os
|
||||
import pprint
|
||||
import shutil
|
||||
import socket
|
||||
import stat
|
||||
import sys
|
||||
import tempfile
|
||||
|
@ -129,13 +128,8 @@ def pytest_addoption(parser):
|
|||
"""
|
||||
register argparse-style options and ini-style config values.
|
||||
"""
|
||||
parser.addoption(
|
||||
"--sysinfo",
|
||||
default=False,
|
||||
action="store_true",
|
||||
help="Print some system information.",
|
||||
)
|
||||
parser.addoption(
|
||||
test_selection_group = parser.getgroup("Tests Selection")
|
||||
test_selection_group.addoption(
|
||||
"--transport",
|
||||
default="zeromq",
|
||||
choices=("zeromq", "tcp"),
|
||||
|
@ -144,7 +138,6 @@ def pytest_addoption(parser):
|
|||
"zeromq or tcp. Default: %default"
|
||||
),
|
||||
)
|
||||
test_selection_group = parser.getgroup("Tests Selection")
|
||||
test_selection_group.addoption(
|
||||
"--ssh",
|
||||
"--ssh-tests",
|
||||
|
@ -163,23 +156,13 @@ def pytest_addoption(parser):
|
|||
default=False,
|
||||
help="Run proxy tests",
|
||||
)
|
||||
test_selection_group.addoption(
|
||||
"--run-destructive",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Run destructive tests. These tests can include adding "
|
||||
"or removing users from your system for example. "
|
||||
"Default: False",
|
||||
)
|
||||
test_selection_group.addoption(
|
||||
"--run-expensive",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Run expensive tests. These tests usually involve costs "
|
||||
"like for example bootstrapping a cloud VM. "
|
||||
"Default: False",
|
||||
)
|
||||
output_options_group = parser.getgroup("Output Options")
|
||||
output_options_group.addoption(
|
||||
"--sysinfo",
|
||||
default=False,
|
||||
action="store_true",
|
||||
help="Print some system information.",
|
||||
)
|
||||
output_options_group.addoption(
|
||||
"--output-columns",
|
||||
default=80,
|
||||
|
@ -228,25 +211,6 @@ def pytest_configure(config):
|
|||
config.addinivalue_line("norecursedirs", os.path.join(CODE_DIR, dirname))
|
||||
|
||||
# Expose the markers we use to pytest CLI
|
||||
config.addinivalue_line(
|
||||
"markers",
|
||||
"destructive_test: Run destructive tests. These tests can include adding "
|
||||
"or removing users from your system for example.",
|
||||
)
|
||||
config.addinivalue_line(
|
||||
"markers", "skip_if_not_root: Skip if the current user is not `root`."
|
||||
)
|
||||
config.addinivalue_line(
|
||||
"markers",
|
||||
"skip_if_binaries_missing(*binaries, check_all=False, message=None): Skip if "
|
||||
"any of the passed binaries are not found in path. If 'check_all' is "
|
||||
"'True', then all binaries must be found.",
|
||||
)
|
||||
config.addinivalue_line(
|
||||
"markers",
|
||||
"requires_network(only_local_network=False): Skip if no networking is set up. "
|
||||
"If 'only_local_network' is 'True', only the local network is checked.",
|
||||
)
|
||||
config.addinivalue_line(
|
||||
"markers",
|
||||
"requires_salt_modules(*required_module_names): Skip if at least one module is not available.",
|
||||
|
@ -477,139 +441,6 @@ def pytest_runtest_setup(item):
|
|||
item._skipped_by_mark = True
|
||||
pytest.skip(PRE_PYTEST_SKIP_REASON)
|
||||
|
||||
destructive_tests_marker = item.get_closest_marker("destructive_test")
|
||||
if destructive_tests_marker is not None or _has_unittest_attr(
|
||||
item, "__destructive_test__"
|
||||
):
|
||||
if item.config.getoption("--run-destructive") is False:
|
||||
item._skipped_by_mark = True
|
||||
pytest.skip("Destructive tests are disabled")
|
||||
os.environ[str("DESTRUCTIVE_TESTS")] = str(
|
||||
item.config.getoption("--run-destructive")
|
||||
)
|
||||
|
||||
expensive_tests_marker = item.get_closest_marker("expensive_test")
|
||||
if expensive_tests_marker is not None or _has_unittest_attr(
|
||||
item, "__expensive_test__"
|
||||
):
|
||||
if item.config.getoption("--run-expensive") is False:
|
||||
item._skipped_by_mark = True
|
||||
pytest.skip("Expensive tests are disabled")
|
||||
os.environ[str("EXPENSIVE_TESTS")] = str(item.config.getoption("--run-expensive"))
|
||||
|
||||
skip_if_not_root_marker = item.get_closest_marker("skip_if_not_root")
|
||||
if skip_if_not_root_marker is not None or _has_unittest_attr(
|
||||
item, "__skip_if_not_root__"
|
||||
):
|
||||
if not sys.platform.startswith("win"):
|
||||
if os.getuid() != 0:
|
||||
item._skipped_by_mark = True
|
||||
pytest.skip("You must be logged in as root to run this test")
|
||||
else:
|
||||
current_user = salt.utils.win_functions.get_current_user()
|
||||
if current_user != "SYSTEM":
|
||||
if not salt.utils.win_functions.is_admin(current_user):
|
||||
item._skipped_by_mark = True
|
||||
pytest.skip(
|
||||
"You must be logged in as an Administrator to run this test"
|
||||
)
|
||||
|
||||
skip_if_binaries_missing_marker = item.get_closest_marker(
|
||||
"skip_if_binaries_missing"
|
||||
)
|
||||
if skip_if_binaries_missing_marker is not None:
|
||||
binaries = skip_if_binaries_missing_marker.args
|
||||
if len(binaries) == 1:
|
||||
if isinstance(binaries[0], (list, tuple, set, frozenset)):
|
||||
binaries = binaries[0]
|
||||
check_all = skip_if_binaries_missing_marker.kwargs.get("check_all", False)
|
||||
message = skip_if_binaries_missing_marker.kwargs.get("message", None)
|
||||
if check_all:
|
||||
for binary in binaries:
|
||||
if salt.utils.path.which(binary) is None:
|
||||
item._skipped_by_mark = True
|
||||
pytest.skip(
|
||||
'{0}The "{1}" binary was not found'.format(
|
||||
message and "{0}. ".format(message) or "", binary
|
||||
)
|
||||
)
|
||||
elif salt.utils.path.which_bin(binaries) is None:
|
||||
item._skipped_by_mark = True
|
||||
pytest.skip(
|
||||
"{0}None of the following binaries was found: {1}".format(
|
||||
message and "{0}. ".format(message) or "", ", ".join(binaries)
|
||||
)
|
||||
)
|
||||
|
||||
requires_network_marker = item.get_closest_marker("requires_network")
|
||||
if requires_network_marker is not None:
|
||||
only_local_network = requires_network_marker.kwargs.get(
|
||||
"only_local_network", False
|
||||
)
|
||||
has_local_network = False
|
||||
# First lets try if we have a local network. Inspired in verify_socket
|
||||
try:
|
||||
pubsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
retsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
pubsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
pubsock.bind(("", 18000))
|
||||
pubsock.close()
|
||||
retsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
retsock.bind(("", 18001))
|
||||
retsock.close()
|
||||
has_local_network = True
|
||||
except socket.error:
|
||||
# I wonder if we just have IPV6 support?
|
||||
try:
|
||||
pubsock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||
retsock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||
pubsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
pubsock.bind(("", 18000))
|
||||
pubsock.close()
|
||||
retsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
retsock.bind(("", 18001))
|
||||
retsock.close()
|
||||
has_local_network = True
|
||||
except socket.error:
|
||||
# Let's continue
|
||||
pass
|
||||
|
||||
if only_local_network is True:
|
||||
if has_local_network is False:
|
||||
# Since we're only supposed to check local network, and no
|
||||
# local network was detected, skip the test
|
||||
item._skipped_by_mark = True
|
||||
pytest.skip("No local network was detected")
|
||||
|
||||
# We are using the google.com DNS records as numerical IPs to avoid
|
||||
# DNS lookups which could greatly slow down this check
|
||||
for addr in (
|
||||
"173.194.41.198",
|
||||
"173.194.41.199",
|
||||
"173.194.41.200",
|
||||
"173.194.41.201",
|
||||
"173.194.41.206",
|
||||
"173.194.41.192",
|
||||
"173.194.41.193",
|
||||
"173.194.41.194",
|
||||
"173.194.41.195",
|
||||
"173.194.41.196",
|
||||
"173.194.41.197",
|
||||
):
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(0.25)
|
||||
sock.connect((addr, 80))
|
||||
sock.close()
|
||||
# We connected? Stop the loop
|
||||
break
|
||||
except socket.error:
|
||||
# Let's check the next IP
|
||||
continue
|
||||
else:
|
||||
item._skipped_by_mark = True
|
||||
pytest.skip("No internet network connection was detected")
|
||||
|
||||
requires_salt_modules_marker = item.get_closest_marker("requires_salt_modules")
|
||||
if requires_salt_modules_marker is not None:
|
||||
required_salt_modules = requires_salt_modules_marker.args
|
||||
|
|
|
@ -15,15 +15,14 @@ import shutil
|
|||
import subprocess
|
||||
import time
|
||||
|
||||
import pytest
|
||||
import salt.ext.six as six
|
||||
from salt.utils.nb_popen import NonBlockingPopen
|
||||
from tests.support.case import TestCase
|
||||
from saltfactories.utils.ports import get_unused_localhost_port
|
||||
from saltfactories.utils.processes.helpers import terminate_process
|
||||
from tests.support.cli_scripts import ScriptPathMixin
|
||||
from tests.support.helpers import get_unused_localhost_port
|
||||
from tests.support.mixins import AdaptedConfigurationTestCaseMixin
|
||||
from tests.support.processes import terminate_process
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.unit import SkipTest, TestCase
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -48,7 +47,7 @@ class TestEventReturn(AdaptedConfigurationTestCaseMixin, ScriptPathMixin, TestCa
|
|||
cls.root_dir = temp_config["root_dir"]
|
||||
cls.config_dir = os.path.dirname(temp_config["conf_file"])
|
||||
if temp_config["transport"] == "tcp":
|
||||
pytest.skip("Test only applicable to the ZMQ transport")
|
||||
raise SkipTest("Test only applicable to the ZMQ transport")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
|
|
|
@ -29,9 +29,12 @@ import salt.utils.process
|
|||
import salt.utils.psutil_compat as psutils
|
||||
import salt.utils.yaml
|
||||
from salt.ext import six
|
||||
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
|
||||
from salt.ext.six.moves import range
|
||||
from saltfactories.utils.processes.helpers import (
|
||||
terminate_process,
|
||||
terminate_process_list,
|
||||
)
|
||||
from tests.support.cli_scripts import ScriptPathMixin
|
||||
from tests.support.processes import terminate_process, terminate_process_list
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
|
|
|
@ -26,14 +26,14 @@ from datetime import datetime, timedelta
|
|||
import salt.utils.files
|
||||
from salt.ext import six
|
||||
from salt.ext.six.moves import cStringIO
|
||||
from saltfactories.utils.processes.helpers import terminate_process
|
||||
from tests.support.cli_scripts import ScriptPathMixin
|
||||
from tests.support.helpers import RedirectStdStreams, requires_sshd_server
|
||||
from tests.support.mixins import (
|
||||
from tests.support.mixins import ( # pylint: disable=unused-import
|
||||
AdaptedConfigurationTestCaseMixin,
|
||||
SaltClientTestCaseMixin,
|
||||
SaltMultimasterClientTestCaseMixin,
|
||||
)
|
||||
from tests.support.processes import terminate_process
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ import salt.utils.yaml
|
|||
from salt.fileserver import gitfs
|
||||
from salt.pillar import git_pillar
|
||||
from saltfactories.utils.processes.bases import FactoryDaemonScriptBase
|
||||
from saltfactories.utils.processes.helpers import start_daemon as sf_start_daemon
|
||||
from saltfactories.utils.processes.helpers import terminate_process
|
||||
from saltfactories.utils.processes.helpers import start_daemon, terminate_process
|
||||
from saltfactories.utils.processes.sshd import SshdDaemon
|
||||
from tests.support.case import ModuleCase
|
||||
from tests.support.helpers import (
|
||||
get_unused_localhost_port,
|
||||
|
@ -44,7 +44,6 @@ try:
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
USERNAME = "gitpillaruser"
|
||||
|
@ -84,21 +83,6 @@ _OPTS = {
|
|||
PROC_TIMEOUT = 10
|
||||
|
||||
|
||||
def start_daemon(
|
||||
daemon_cli_script_name, daemon_class, config_dir=None, check_port=None
|
||||
):
|
||||
"""
|
||||
Returns a running process daemon
|
||||
"""
|
||||
return sf_start_daemon(
|
||||
None,
|
||||
daemon_cli_script_name,
|
||||
daemon_class,
|
||||
config_dir=config_dir,
|
||||
check_port=check_port,
|
||||
)
|
||||
|
||||
|
||||
class UwsgiDaemon(FactoryDaemonScriptBase):
|
||||
def __init__(self, *args, **kwargs):
|
||||
config_dir = kwargs.pop("config_dir")
|
||||
|
@ -106,7 +90,9 @@ class UwsgiDaemon(FactoryDaemonScriptBase):
|
|||
super(UwsgiDaemon, self).__init__(*args, **kwargs)
|
||||
self.config_dir = config_dir
|
||||
self.check_port = check_port
|
||||
self.log_prefix = "[uWSGI]"
|
||||
|
||||
def get_log_prefix(self):
|
||||
return "[uWSGI] "
|
||||
|
||||
def get_base_script_args(self):
|
||||
"""
|
||||
|
@ -128,7 +114,9 @@ class NginxDaemon(FactoryDaemonScriptBase):
|
|||
super(NginxDaemon, self).__init__(*args, **kwargs)
|
||||
self.config_dir = config_dir
|
||||
self.check_port = check_port
|
||||
self.log_prefix = "[Nginx]"
|
||||
|
||||
def get_log_prefix(self):
|
||||
return "[Nginx] "
|
||||
|
||||
def get_base_script_args(self):
|
||||
"""
|
||||
|
@ -143,28 +131,6 @@ class NginxDaemon(FactoryDaemonScriptBase):
|
|||
return [self.check_port]
|
||||
|
||||
|
||||
class SshdDaemon(FactoryDaemonScriptBase):
|
||||
def __init__(self, *args, **kwargs):
|
||||
config_dir = kwargs.pop("config_dir")
|
||||
check_port = kwargs.pop("check_port")
|
||||
super(SshdDaemon, self).__init__(*args, **kwargs)
|
||||
self.config_dir = config_dir
|
||||
self.check_port = check_port
|
||||
self.log_prefix = "[SSHD]"
|
||||
|
||||
def get_base_script_args(self):
|
||||
"""
|
||||
Returns any additional arguments to pass to the CLI script
|
||||
"""
|
||||
return ["-D", "-e", "-f", os.path.join(self.config_dir, "sshd_config")]
|
||||
|
||||
def get_check_ports(self):
|
||||
"""
|
||||
Return a list of ports to check against to ensure the daemon is running
|
||||
"""
|
||||
return [self.check_port]
|
||||
|
||||
|
||||
class SaltClientMixin(ModuleCase):
|
||||
|
||||
client = None
|
||||
|
@ -267,7 +233,7 @@ class SSHDMixin(SaltClientMixin, SaltReturnAssertsMixin):
|
|||
cls.sshd_bin,
|
||||
SshdDaemon,
|
||||
config_dir=cls.sshd_config_dir,
|
||||
check_port=cls.sshd_port,
|
||||
serve_port=cls.sshd_port,
|
||||
)
|
||||
log.info("%s: sshd started", cls.__name__)
|
||||
except AssertionError:
|
||||
|
@ -300,13 +266,13 @@ class SSHDMixin(SaltClientMixin, SaltReturnAssertsMixin):
|
|||
if cls.sshd_proc is not None:
|
||||
log.info(
|
||||
"[%s] Stopping %s",
|
||||
cls.sshd_proc.log_prefix,
|
||||
cls.sshd_proc.get_log_prefix(),
|
||||
cls.sshd_proc.__class__.__name__,
|
||||
)
|
||||
terminate_process(cls.sshd_proc.pid, kill_children=True, slow_stop=True)
|
||||
log.info(
|
||||
"[%s] %s stopped",
|
||||
cls.sshd_proc.log_prefix,
|
||||
cls.sshd_proc.get_log_prefix(),
|
||||
cls.sshd_proc.__class__.__name__,
|
||||
)
|
||||
cls.sshd_proc = None
|
||||
|
@ -457,26 +423,26 @@ class WebserverMixin(SaltClientMixin, SaltReturnAssertsMixin):
|
|||
if cls.nginx_proc is not None:
|
||||
log.info(
|
||||
"[%s] Stopping %s",
|
||||
cls.nginx_proc.log_prefix,
|
||||
cls.nginx_proc.get_log_prefix(),
|
||||
cls.nginx_proc.__class__.__name__,
|
||||
)
|
||||
terminate_process(cls.nginx_proc.pid, kill_children=True, slow_stop=True)
|
||||
log.info(
|
||||
"[%s] %s stopped",
|
||||
cls.nginx_proc.log_prefix,
|
||||
cls.nginx_proc.get_log_prefix(),
|
||||
cls.nginx_proc.__class__.__name__,
|
||||
)
|
||||
cls.nginx_proc = None
|
||||
if cls.uwsgi_proc is not None:
|
||||
log.info(
|
||||
"[%s] Stopping %s",
|
||||
cls.uwsgi_proc.log_prefix,
|
||||
cls.uwsgi_proc.get_log_prefix(),
|
||||
cls.uwsgi_proc.__class__.__name__,
|
||||
)
|
||||
terminate_process(cls.uwsgi_proc.pid, kill_children=True, slow_stop=True)
|
||||
log.info(
|
||||
"[%s] %s stopped",
|
||||
cls.uwsgi_proc.log_prefix,
|
||||
cls.uwsgi_proc.get_log_prefix(),
|
||||
cls.uwsgi_proc.__class__.__name__,
|
||||
)
|
||||
cls.uwsgi_proc = None
|
||||
|
|
|
@ -14,11 +14,11 @@ import salt.utils.platform
|
|||
import salt.utils.schedule
|
||||
from salt.modules.test import ping
|
||||
from salt.utils.process import SubprocessList
|
||||
from tests.support.case import TestCase
|
||||
from saltfactories.utils.processes.helpers import terminate_process
|
||||
from tests.support.mixins import SaltReturnAssertsMixin
|
||||
from tests.support.mock import MagicMock, patch
|
||||
from tests.support.processes import terminate_process
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@ import salt.utils.event
|
|||
import salt.utils.stringutils
|
||||
import zmq
|
||||
import zmq.eventloop.ioloop
|
||||
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
|
||||
from salt.ext.six.moves import range
|
||||
from salt.ext.tornado.testing import AsyncTestCase
|
||||
from saltfactories.utils.processes.helpers import terminate_process
|
||||
from tests.support.events import eventpublisher_process, eventsender_process
|
||||
from tests.support.helpers import slowTest
|
||||
from tests.support.processes import terminate_process
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.unit import TestCase, expectedFailure, skipIf
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue