2023-10-10 20:45:56 +01:00
|
|
|
import asyncio
|
|
|
|
|
2022-09-16 16:57:57 +01:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
import salt.config
|
2023-10-10 20:45:56 +01:00
|
|
|
import salt.transport.tcp
|
|
|
|
from tests.support.mock import MagicMock, patch
|
2022-09-16 16:57:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def minion_opts(tmp_path):
|
|
|
|
"""
|
|
|
|
Default minion configuration with relative temporary paths to not require root permissions.
|
|
|
|
"""
|
2022-09-16 17:05:09 +01:00
|
|
|
root_dir = tmp_path / "minion"
|
2022-09-16 16:57:57 +01:00
|
|
|
opts = salt.config.DEFAULT_MINION_OPTS.copy()
|
2022-09-16 17:05:09 +01:00
|
|
|
opts["__role"] = "minion"
|
|
|
|
opts["root_dir"] = str(root_dir)
|
2023-12-01 01:16:03 -07:00
|
|
|
opts["master_uri"] = "tcp://{ip}:{port}".format(
|
|
|
|
ip="127.0.0.1", port=opts["master_port"]
|
|
|
|
)
|
2022-09-16 16:57:57 +01:00
|
|
|
for name in ("cachedir", "pki_dir", "sock_dir", "conf_dir"):
|
2022-09-16 17:05:09 +01:00
|
|
|
dirpath = root_dir / name
|
|
|
|
dirpath.mkdir(parents=True)
|
2022-09-16 16:57:57 +01:00
|
|
|
opts[name] = str(dirpath)
|
|
|
|
opts["log_file"] = "logs/minion.log"
|
|
|
|
return opts
|
2022-09-16 17:05:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def master_opts(tmp_path):
|
|
|
|
"""
|
|
|
|
Default master configuration with relative temporary paths to not require root permissions.
|
|
|
|
"""
|
|
|
|
root_dir = tmp_path / "master"
|
2023-07-31 14:13:38 -07:00
|
|
|
opts = salt.config.master_config(None)
|
2022-09-16 17:05:09 +01:00
|
|
|
opts["__role"] = "master"
|
|
|
|
opts["root_dir"] = str(root_dir)
|
|
|
|
for name in ("cachedir", "pki_dir", "sock_dir", "conf_dir"):
|
|
|
|
dirpath = root_dir / name
|
|
|
|
dirpath.mkdir(parents=True)
|
|
|
|
opts[name] = str(dirpath)
|
|
|
|
opts["log_file"] = "logs/master.log"
|
|
|
|
return opts
|
2023-08-26 01:22:29 -07:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def syndic_opts(tmp_path):
|
|
|
|
"""
|
|
|
|
Default master configuration with relative temporary paths to not require root permissions.
|
|
|
|
"""
|
|
|
|
root_dir = tmp_path / "syndic"
|
|
|
|
opts = salt.config.DEFAULT_MINION_OPTS.copy()
|
|
|
|
opts["syndic_master"] = "127.0.0.1"
|
|
|
|
opts["__role"] = "minion"
|
|
|
|
opts["root_dir"] = str(root_dir)
|
|
|
|
for name in ("cachedir", "pki_dir", "sock_dir", "conf_dir"):
|
|
|
|
dirpath = root_dir / name
|
|
|
|
dirpath.mkdir(parents=True)
|
|
|
|
opts[name] = str(dirpath)
|
|
|
|
opts["log_file"] = "logs/syndic.log"
|
|
|
|
return opts
|
2023-10-10 20:45:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def mocked_tcp_pub_client():
|
|
|
|
transport = MagicMock(spec=salt.transport.tcp.TCPPubClient)
|
|
|
|
transport.connect = MagicMock()
|
|
|
|
future = asyncio.Future()
|
|
|
|
transport.connect.return_value = future
|
|
|
|
future.set_result(True)
|
|
|
|
with patch("salt.transport.tcp.TCPPubClient", transport):
|
|
|
|
yield
|