mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 17:50:20 +00:00
Stop using salt.config.DEFAULT_{MASTER,MINION}_CONFIG
on unit and functional tests
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
2f505e782a
commit
53a78e71fb
16 changed files with 102 additions and 98 deletions
|
@ -1,7 +1,3 @@
|
|||
"""
|
||||
tests.pytests.functional.cli.test_salt
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
"""
|
||||
import pytest
|
||||
|
||||
import salt.version
|
||||
|
|
|
@ -9,7 +9,7 @@ log = logging.getLogger(__name__)
|
|||
|
||||
@pytest.fixture(scope="package")
|
||||
def minion_id():
|
||||
return "func-tests-minion"
|
||||
return "func-tests-minion-opts"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
@ -78,6 +78,53 @@ def minion_opts(
|
|||
return factory.config.copy()
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def master_config_defaults():
|
||||
"""
|
||||
Functional test modules can provide this fixture to tweak the default configuration dictionary
|
||||
passed to the master factory
|
||||
"""
|
||||
return {}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def master_config_overrides():
|
||||
"""
|
||||
Functional test modules can provide this fixture to tweak the configuration
|
||||
overrides dictionary passed to the master factory
|
||||
"""
|
||||
return {}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def master_opts(
|
||||
salt_factories,
|
||||
state_tree,
|
||||
state_tree_prod,
|
||||
master_config_defaults,
|
||||
master_config_overrides,
|
||||
):
|
||||
master_config_overrides.update(
|
||||
{
|
||||
"file_client": "local",
|
||||
"file_roots": {
|
||||
"base": [
|
||||
str(state_tree),
|
||||
],
|
||||
"prod": [
|
||||
str(state_tree_prod),
|
||||
],
|
||||
},
|
||||
}
|
||||
)
|
||||
factory = salt_factories.salt_master_daemon(
|
||||
"func-tests-master-opts",
|
||||
defaults=master_config_defaults or None,
|
||||
overrides=master_config_overrides,
|
||||
)
|
||||
return factory.config.copy()
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def loaders(minion_opts):
|
||||
return Loaders(minion_opts, loaded_base_name="{}.loaded".format(__name__))
|
||||
|
|
|
@ -6,7 +6,6 @@ import psutil # pylint: disable=3rd-party-module-not-gated
|
|||
import pytest
|
||||
from pytestshellutils.utils.processes import terminate_process
|
||||
|
||||
import salt.config
|
||||
import salt.fileserver.hgfs as hgfs
|
||||
from tests.support.mock import patch
|
||||
|
||||
|
@ -19,13 +18,9 @@ except ImportError:
|
|||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def configure_loader_modules():
|
||||
opts = salt.config.DEFAULT_MASTER_OPTS.copy()
|
||||
cache = tempfile.TemporaryDirectory(dir="/tmp")
|
||||
opts["cachedir"] = cache.name
|
||||
opts["fileserver_backend"] = ["hgfs"]
|
||||
yield {hgfs: {"__opts__": opts}}
|
||||
cache.cleanup()
|
||||
def configure_loader_modules(master_opts):
|
||||
master_opts["fileserver_backend"] = ["hgfs"]
|
||||
yield {hgfs: {"__opts__": master_opts}}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import pytest
|
||||
|
||||
import salt.config
|
||||
import salt.fileserver.roots as roots
|
||||
from salt.utils.odict import OrderedDict
|
||||
from tests.support.mock import patch
|
||||
|
@ -11,21 +10,14 @@ pytestmark = [
|
|||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def configure_loader_modules(base_env_state_tree_root_dir, tmp_path):
|
||||
cachedir = tmp_path / "__salt_test_fileserver_roots_cache_dir"
|
||||
cachedir.mkdir(parents=True, exist_ok=True)
|
||||
opts = salt.config.DEFAULT_MINION_OPTS.copy()
|
||||
opts["cachedir"] = str(cachedir)
|
||||
opts["file_roots"]["base"] = [str(base_env_state_tree_root_dir)]
|
||||
return {roots: {"__opts__": opts}}
|
||||
def configure_loader_modules(minion_opts):
|
||||
return {roots: {"__opts__": minion_opts}}
|
||||
|
||||
|
||||
# nox -e pytest-zeromq-3.8(coverage=False) -- -vvv --run-slow --run-destructive tests\pytests\functional\fileserver\test_roots.py
|
||||
def test_symlink_list(base_env_state_tree_root_dir):
|
||||
with pytest.helpers.temp_file(
|
||||
"target", "data", base_env_state_tree_root_dir
|
||||
) as target:
|
||||
link = base_env_state_tree_root_dir / "link"
|
||||
def test_symlink_list(state_tree):
|
||||
with pytest.helpers.temp_file("target", "data", state_tree) as target:
|
||||
link = state_tree / "link"
|
||||
link.symlink_to(str(target))
|
||||
ret = roots.symlink_list({"saltenv": "base"})
|
||||
assert ret == {"link": str(target)}
|
||||
|
@ -35,15 +27,11 @@ def test_symlink_list(base_env_state_tree_root_dir):
|
|||
"env",
|
||||
("base", "something-else", "cool_path_123", "__env__"),
|
||||
)
|
||||
def test_fileserver_roots_find_file_envs_path_substitution(
|
||||
env, temp_salt_minion, tmp_path
|
||||
):
|
||||
def test_fileserver_roots_find_file_envs_path_substitution(env, minion_opts, tmp_path):
|
||||
"""
|
||||
Test fileserver access to a dynamic path using __env__
|
||||
"""
|
||||
fn = "test.txt"
|
||||
opts = temp_salt_minion.config.copy()
|
||||
|
||||
if env == "__env__":
|
||||
# __env__ saltenv will pass "dynamic" as saltenv and
|
||||
# expect to be routed to the "dynamic" directory
|
||||
|
@ -66,10 +54,10 @@ def test_fileserver_roots_find_file_envs_path_substitution(
|
|||
expected["path"] = str(filepath)
|
||||
|
||||
# Stop using OrderedDict once we drop Py3.5 support
|
||||
opts["file_roots"] = OrderedDict()
|
||||
opts["file_roots"][env] = [str(tmp_path / leaf_dir)]
|
||||
minion_opts["file_roots"] = OrderedDict()
|
||||
minion_opts["file_roots"][env] = [str(tmp_path / leaf_dir)]
|
||||
|
||||
with patch("salt.fileserver.roots.__opts__", opts, create=True):
|
||||
with patch("salt.fileserver.roots.__opts__", minion_opts, create=True):
|
||||
ret = roots.find_file(fn, saltenv=actual_env)
|
||||
ret.pop("stat")
|
||||
assert ret == expected
|
||||
|
@ -79,7 +67,7 @@ def test_fileserver_roots_find_file_envs_path_substitution(
|
|||
"saltenv", ("base", "something-else", "cool_path_123", "__env__")
|
||||
)
|
||||
def test_fileserver_roots__file_lists_envs_path_substitution(
|
||||
saltenv, temp_salt_minion, tmp_path
|
||||
saltenv, tmp_path, minion_opts
|
||||
):
|
||||
"""
|
||||
Test fileserver access to a dynamic path using __env__
|
||||
|
@ -89,7 +77,6 @@ def test_fileserver_roots__file_lists_envs_path_substitution(
|
|||
# It doesn't really matter what it is - expected saltenv and not expected
|
||||
# saltenv
|
||||
# The filenames should be different, because cache lists the filenames.
|
||||
opts = temp_salt_minion.config.copy()
|
||||
other_env = "something_completely_different"
|
||||
other_filename = "different.txt"
|
||||
expected_filename = "test.txt"
|
||||
|
@ -114,10 +101,10 @@ def test_fileserver_roots__file_lists_envs_path_substitution(
|
|||
(otherpath / other_filename).touch()
|
||||
|
||||
# Stop using OrderedDict once we drop Py3.5 support
|
||||
opts["file_roots"] = OrderedDict()
|
||||
opts["file_roots"]["__env__"] = [str(file_roots)]
|
||||
minion_opts["file_roots"] = OrderedDict()
|
||||
minion_opts["file_roots"]["__env__"] = [str(file_roots)]
|
||||
|
||||
with patch("salt.fileserver.roots.__opts__", opts, create=True):
|
||||
with patch("salt.fileserver.roots.__opts__", minion_opts, create=True):
|
||||
# actual_env is our target. The other env doesn't really matter, but
|
||||
# it should be different than our expected one and also contain its
|
||||
# own file(s)
|
||||
|
|
|
@ -4,7 +4,6 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
import salt.config
|
||||
import salt.pillar.hg_pillar as hg_pillar
|
||||
|
||||
try:
|
||||
|
@ -16,12 +15,8 @@ except ImportError:
|
|||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def configure_loader_modules():
|
||||
opts = salt.config.DEFAULT_MASTER_OPTS.copy()
|
||||
cache = tempfile.TemporaryDirectory(dir="/tmp")
|
||||
opts["cachedir"] = cache.name
|
||||
yield {hg_pillar: {"__opts__": opts}}
|
||||
cache.cleanup()
|
||||
def configure_loader_modules(master_opts):
|
||||
yield {hg_pillar: {"__opts__": master_opts}}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
@ -3,7 +3,6 @@ unit tests for the slack engine
|
|||
"""
|
||||
import pytest
|
||||
|
||||
import salt.config
|
||||
import salt.engines.slack as slack
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
|
@ -20,11 +19,10 @@ def configure_loader_modules():
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def slack_client():
|
||||
mock_opts = salt.config.DEFAULT_MINION_OPTS.copy()
|
||||
def slack_client(minion_opts):
|
||||
token = "xoxb-xxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
with patch.dict(slack.__opts__, mock_opts):
|
||||
with patch.dict(slack.__opts__, minion_opts):
|
||||
with patch("slackclient.SlackClient.rtm_connect", MagicMock(return_value=True)):
|
||||
slack_client = slack.SlackClient(token)
|
||||
yield slack_client
|
||||
|
|
|
@ -3,7 +3,6 @@ unit tests for the slack engine
|
|||
"""
|
||||
import pytest
|
||||
|
||||
import salt.config
|
||||
import salt.engines.slack_bolt_engine as slack_bolt_engine
|
||||
from tests.support.mock import MagicMock, call, patch
|
||||
|
||||
|
@ -94,7 +93,6 @@ def configure_loader_modules():
|
|||
|
||||
@pytest.fixture
|
||||
def slack_client(minion_opts):
|
||||
mock_opts = salt.config.DEFAULT_MINION_OPTS.copy()
|
||||
app_token = "xapp-x-xxxxxxxxxxx-xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
bot_token = "xoxb-xxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
trigger = "!"
|
||||
|
|
|
@ -36,22 +36,20 @@ def grains_dir(tmp_path):
|
|||
shutil.rmtree(tmp_path)
|
||||
|
||||
|
||||
def test_grains():
|
||||
def test_grains(minion_opts):
|
||||
"""
|
||||
Load grains.
|
||||
"""
|
||||
opts = salt.config.DEFAULT_MINION_OPTS.copy()
|
||||
grains = salt.loader.grains(opts, force_refresh=True)
|
||||
grains = salt.loader.grains(minion_opts, force_refresh=True)
|
||||
assert "saltversion" in grains
|
||||
|
||||
|
||||
def test_custom_grain_with_annotations(grains_dir):
|
||||
def test_custom_grain_with_annotations(minion_opts, grains_dir):
|
||||
"""
|
||||
Load custom grain with annotations.
|
||||
"""
|
||||
opts = salt.config.DEFAULT_MINION_OPTS.copy()
|
||||
opts["grains_dirs"] = [grains_dir]
|
||||
grains = salt.loader.grains(opts, force_refresh=True)
|
||||
minion_opts["grains_dirs"] = [grains_dir]
|
||||
grains = salt.loader.grains(minion_opts, force_refresh=True)
|
||||
assert grains.get("example") == "42"
|
||||
|
||||
|
||||
|
|
|
@ -5,9 +5,8 @@ import salt.loader
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def matchers():
|
||||
opts = salt.config.DEFAULT_MINION_OPTS.copy()
|
||||
return salt.loader.matchers(opts)
|
||||
def matchers(minion_opts):
|
||||
return salt.loader.matchers(minion_opts)
|
||||
|
||||
|
||||
def test_sanity(matchers):
|
||||
|
|
|
@ -26,7 +26,7 @@ def configure_loader_modules():
|
|||
None,
|
||||
],
|
||||
)
|
||||
def test_gen_xml_for_xen_default_profile(loader):
|
||||
def test_gen_xml_for_xen_default_profile(loader, minion_opts):
|
||||
"""
|
||||
Test virt._gen_xml(), XEN PV default profile case
|
||||
"""
|
||||
|
@ -68,7 +68,7 @@ def test_gen_xml_for_xen_default_profile(loader):
|
|||
disks = root.findall(".//disk")
|
||||
assert len(disks) == 1
|
||||
disk = disks[0]
|
||||
root_dir = salt.config.DEFAULT_MINION_OPTS.get("root_dir")
|
||||
root_dir = salt.syspaths.ROOT_DIR
|
||||
assert disk.find("source").attrib["file"].startswith(root_dir)
|
||||
assert "hello_system" in disk.find("source").attrib["file"]
|
||||
assert disk.find("target").attrib["dev"] == "xvda"
|
||||
|
|
|
@ -3,23 +3,22 @@ import re
|
|||
|
||||
import pytest
|
||||
|
||||
import salt.config
|
||||
import salt.output.highstate as highstate
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules():
|
||||
minion_opts = salt.config.DEFAULT_MINION_OPTS.copy()
|
||||
overrides = {
|
||||
"extension_modules": "",
|
||||
"optimization_order": [0, 1, 2],
|
||||
"color": False,
|
||||
"state_output_pct": True,
|
||||
"state_output": "terse",
|
||||
}
|
||||
minion_opts.update(overrides)
|
||||
def configure_loader_modules(minion_opts):
|
||||
minion_opts.update(
|
||||
{
|
||||
"extension_modules": "",
|
||||
"optimization_order": [0, 1, 2],
|
||||
"color": False,
|
||||
"state_output_pct": True,
|
||||
"state_output": "terse",
|
||||
}
|
||||
)
|
||||
return {highstate: {"__opts__": minion_opts}}
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ import importlib
|
|||
|
||||
import pytest
|
||||
|
||||
import salt.config
|
||||
import salt.exceptions
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
|
@ -11,10 +10,10 @@ pass_ = importlib.import_module("salt.renderers.pass")
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules():
|
||||
def configure_loader_modules(master_opts):
|
||||
return {
|
||||
pass_: {
|
||||
"__opts__": salt.config.DEFAULT_MASTER_OPTS.copy(),
|
||||
"__opts__": master_opts,
|
||||
"_get_pass_exec": MagicMock(return_value="/usr/bin/pass"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import pytest
|
||||
|
||||
import salt.config
|
||||
import salt.runners.saltutil as saltutil
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
|
@ -69,10 +68,8 @@ def module_sync_functions():
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules():
|
||||
opts = salt.config.DEFAULT_MASTER_OPTS.copy()
|
||||
|
||||
return {saltutil: {"opts": opts}}
|
||||
def configure_loader_modules(master_opts):
|
||||
return {saltutil: {"opts": master_opts}}
|
||||
|
||||
|
||||
def test_sync_all():
|
||||
|
|
|
@ -9,11 +9,10 @@ log = logging.getLogger(__name__)
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def minion_config():
|
||||
cfg = salt.config.DEFAULT_MINION_OPTS.copy()
|
||||
cfg["file_client"] = "local"
|
||||
cfg["id"] = "foo01"
|
||||
return cfg
|
||||
def minion_config(minion_opts):
|
||||
minion_opts["file_client"] = "local"
|
||||
minion_opts["id"] = "foo01"
|
||||
return minion_opts
|
||||
|
||||
|
||||
def test_global_state_conditions_unconfigured(minion_config):
|
||||
|
|
|
@ -2,7 +2,6 @@ import logging
|
|||
|
||||
import pytest
|
||||
|
||||
import salt.config
|
||||
import salt.modules.chocolatey as chocolatey_mod
|
||||
import salt.states.chocolatey as chocolatey
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
@ -16,16 +15,15 @@ def choco_path():
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules():
|
||||
opts = salt.config.DEFAULT_MINION_OPTS.copy()
|
||||
def configure_loader_modules(minion_opts):
|
||||
return {
|
||||
chocolatey: {
|
||||
"__opts__": opts,
|
||||
"__opts__": minion_opts,
|
||||
"__salt__": {},
|
||||
"__context__": {},
|
||||
},
|
||||
chocolatey_mod: {
|
||||
"__opts__": opts,
|
||||
"__opts__": minion_opts,
|
||||
"__context__": {},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1068,12 +1068,11 @@ def test_valid_ipv4_master_address_ipv6_enabled(minion_opts):
|
|||
assert salt.minion.resolve_dns(minion_opts) == expected
|
||||
|
||||
|
||||
async def test_master_type_disable():
|
||||
async def test_master_type_disable(minion_opts):
|
||||
"""
|
||||
Tests master_type "disable" to not even attempt connecting to a master.
|
||||
"""
|
||||
mock_opts = salt.config.DEFAULT_MINION_OPTS.copy()
|
||||
mock_opts.update(
|
||||
minion_opts.update(
|
||||
{
|
||||
"master_type": "disable",
|
||||
"master": None,
|
||||
|
@ -1083,11 +1082,11 @@ async def test_master_type_disable():
|
|||
}
|
||||
)
|
||||
|
||||
minion = salt.minion.Minion(mock_opts)
|
||||
minion = salt.minion.Minion(minion_opts)
|
||||
try:
|
||||
|
||||
try:
|
||||
minion_man = salt.minion.MinionManager(mock_opts)
|
||||
minion_man = salt.minion.MinionManager(minion_opts)
|
||||
minion_man._connect_minion(minion)
|
||||
except RuntimeError:
|
||||
pytest.fail("_connect_minion(minion) threw an error, This was not expected")
|
||||
|
|
Loading…
Add table
Reference in a new issue