mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Use system configs if user is salt
This commit is contained in:
parent
35ddf6319f
commit
4013d4e9a5
5 changed files with 51 additions and 15 deletions
|
@ -3,6 +3,7 @@ import pathlib
|
|||
import shutil
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
from pytestskipmarkers.utils import platform
|
||||
from saltfactories.utils import random_string
|
||||
from saltfactories.utils.tempfiles import SaltPillarTree, SaltStateTree
|
||||
|
@ -282,14 +283,31 @@ def salt_master(salt_factories, install_salt, state_tree, pillar_tree):
|
|||
"rest_cherrypy": {"port": 8000, "disable_ssl": True},
|
||||
"netapi_enable_clients": ["local"],
|
||||
"external_auth": {"auto": {"saltdev": [".*"]}},
|
||||
"user": "salt",
|
||||
"log_file": salt.config.DEFAULT_MASTER_OPTS.get("log_file"),
|
||||
"root_dir": salt.config.DEFAULT_MASTER_OPTS.get("root_dir"),
|
||||
"key_logfile": salt.config.DEFAULT_MASTER_OPTS.get("key_logfile"),
|
||||
"pki_dir": salt.config.DEFAULT_MASTER_OPTS.get("pki_dir"),
|
||||
"api_logfile": salt.config.DEFAULT_API_OPTS.get("api_logfile"),
|
||||
"api_pidfile": salt.config.DEFAULT_API_OPTS.get("api_pidfile"),
|
||||
}
|
||||
master_config = install_salt.config_path / "master"
|
||||
with open(master_config) as fp:
|
||||
data = yaml.safe_load(fp)
|
||||
if "user" in data:
|
||||
# We are testing a different user, so we need to test the system
|
||||
# configs, or else permissions will not be correct.
|
||||
config_overrides["user"] = data["user"]
|
||||
config_overrides["log_file"] = salt.config.DEFAULT_MASTER_OPTS.get(
|
||||
"log_file"
|
||||
)
|
||||
config_overrides["root_dir"] = salt.config.DEFAULT_MASTER_OPTS.get(
|
||||
"root_dir"
|
||||
)
|
||||
config_overrides["key_logfile"] = salt.config.DEFAULT_MASTER_OPTS.get(
|
||||
"key_logfile"
|
||||
)
|
||||
config_overrides["pki_dir"] = salt.config.DEFAULT_MASTER_OPTS.get("pki_dir")
|
||||
config_overrides["api_logfile"] = salt.config.DEFAULT_API_OPTS.get(
|
||||
"api_logfile"
|
||||
)
|
||||
config_overrides["api_pidfile"] = salt.config.DEFAULT_API_OPTS.get(
|
||||
"api_pidfile"
|
||||
)
|
||||
|
||||
if (platform.is_windows() or platform.is_darwin()) and install_salt.singlebin:
|
||||
start_timeout = 240
|
||||
# For every minion started we have to accept it's key.
|
||||
|
|
|
@ -1,19 +1,27 @@
|
|||
import psutil
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.skip_on_windows,
|
||||
]
|
||||
|
||||
|
||||
def test_salt_user_master(salt_master):
|
||||
def test_salt_user_master(salt_master, install_salt):
|
||||
"""
|
||||
Test the correct user is running the Salt Master
|
||||
"""
|
||||
user = "salt"
|
||||
master_conf = install_salt.config_path / "master"
|
||||
with open(master_conf) as fp:
|
||||
data = yaml.safe_load(fp)
|
||||
if "user" not in data:
|
||||
pytest.skip("Package does not have user set. Not testing user")
|
||||
user = data["user"]
|
||||
match = False
|
||||
for _proc in psutil.process_iter(["username", "cmdline", "name"]):
|
||||
if any([x for x in _proc.info["cmdline"] if "salt-master" in x]):
|
||||
assert _proc.info["username"] == user
|
||||
match = True
|
||||
for proc in psutil.process_iter(["username", "cmdline", "name"]):
|
||||
if any([x for x in proc.info["cmdline"] if "salt-master" in x]):
|
||||
for child_proc in psutil.Process(proc.ppid()).children(recursive=True):
|
||||
if child_proc.is_running():
|
||||
assert child_proc.username() == user
|
||||
match = True
|
||||
assert match
|
||||
|
|
|
@ -96,6 +96,7 @@ class SaltPkgInstall:
|
|||
minor: str = attr.ib(init=False)
|
||||
relenv: bool = attr.ib(default=True)
|
||||
file_ext: bool = attr.ib(default=None)
|
||||
config_path: str = attr.ib(init=False)
|
||||
|
||||
@proc.default
|
||||
def _default_proc(self):
|
||||
|
@ -171,6 +172,17 @@ class SaltPkgInstall:
|
|||
install_dir = pathlib.Path("/opt", "saltstack", "salt")
|
||||
return install_dir
|
||||
|
||||
@config_path.default
|
||||
def _default_config_path(self):
|
||||
"""
|
||||
Default location for salt configurations
|
||||
"""
|
||||
if platform.is_windows():
|
||||
config_path = pathlib.Path("C://salt", "etc", "salt")
|
||||
else:
|
||||
config_path = pathlib.Path("/etc", "salt")
|
||||
return config_path
|
||||
|
||||
@repo_data.default
|
||||
def _default_repo_data(self):
|
||||
"""
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
cherrypy
|
||||
pytest-salt-factories==1.0.0rc17
|
||||
docker
|
||||
psutil
|
||||
|
|
|
@ -89,7 +89,6 @@ portend==3.1.0
|
|||
psutil==5.9.4
|
||||
# via
|
||||
# -r requirements/base.txt
|
||||
# -r requirements/static/ci/pkgtests.in
|
||||
# pytest-salt-factories
|
||||
# pytest-shell-utilities
|
||||
# pytest-system-statistics
|
||||
|
|
Loading…
Add table
Reference in a new issue