mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Randomize names and prefer salt_master.state_tree.base
This commit is contained in:
parent
62bea250ff
commit
da57d43cc0
1 changed files with 34 additions and 44 deletions
|
@ -4,6 +4,7 @@ import time
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from saltfactories.utils import random_string
|
||||
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
||||
|
@ -14,7 +15,7 @@ pytestmark = [
|
|||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def pillar_tree(base_env_pillar_tree_root_dir):
|
||||
def _pillar_tree(salt_master):
|
||||
top_file = """
|
||||
base:
|
||||
'localhost':
|
||||
|
@ -27,14 +28,9 @@ def pillar_tree(base_env_pillar_tree_root_dir):
|
|||
alot: many
|
||||
script: grail
|
||||
"""
|
||||
top_tempfile = pytest.helpers.temp_file(
|
||||
"top.sls", top_file, base_env_pillar_tree_root_dir
|
||||
)
|
||||
basic_tempfile = pytest.helpers.temp_file(
|
||||
"basic.sls", basic_pillar_file, base_env_pillar_tree_root_dir
|
||||
)
|
||||
|
||||
with top_tempfile, basic_tempfile:
|
||||
with salt_master.pillar_tree.base.temp_file(
|
||||
"top.sls", top_file
|
||||
), salt_master.pillar_tree.base.temp_file("basic.sls", basic_pillar_file):
|
||||
yield
|
||||
|
||||
|
||||
|
@ -94,7 +90,7 @@ def test_get_file(salt_ssh_cli, tmp_path, template, dst_is_dir, cachedir):
|
|||
|
||||
|
||||
def test_get_file_gzipped(salt_ssh_cli, caplog, tmp_path):
|
||||
tgt = tmp_path / "foo"
|
||||
tgt = tmp_path / random_string("foo-")
|
||||
res = salt_ssh_cli.run("cp.get_file", "salt://grail/scene33", str(tgt), gzip=5)
|
||||
assert res.returncode == 0
|
||||
assert res.data
|
||||
|
@ -578,7 +574,8 @@ def test_cache_file(salt_ssh_cli, suffix, cachedir):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def _cache_twice(base_env_state_tree_root_dir, request, salt_ssh_cli, cachedir):
|
||||
def _cache_twice(salt_master, request, salt_ssh_cli, cachedir):
|
||||
|
||||
# ensure the cache is clean
|
||||
tgt = cachedir / "extrn_files" / "base" / "repo.saltproject.io" / "index.html"
|
||||
tgt.unlink(missing_ok=True)
|
||||
|
@ -609,7 +606,7 @@ def _cache_twice(base_env_state_tree_root_dir, request, salt_ssh_cli, cachedir):
|
|||
{{%- set res2 = salt["cp.cache_file"]("{src}") %}}
|
||||
{{{{ res2 }}}}
|
||||
"""
|
||||
with pytest.helpers.temp_file(name, contents, base_env_state_tree_root_dir):
|
||||
with salt_master.state_tree.base.temp_file(name, contents):
|
||||
yield f"salt://{name}"
|
||||
|
||||
|
||||
|
@ -695,24 +692,22 @@ def test_cache_dir_nonexistent_source(salt_ssh_cli, caplog):
|
|||
assert not res.data
|
||||
|
||||
|
||||
def test_list_states(salt_ssh_cli, tmp_path, base_env_state_tree_root_dir):
|
||||
def test_list_states(salt_master, salt_ssh_cli, tmp_path):
|
||||
top_sls = """
|
||||
base:
|
||||
'*':
|
||||
- core
|
||||
"""
|
||||
tgt = tmp_path / "testfile"
|
||||
|
||||
core_state = f"""
|
||||
{tgt}/testfile:
|
||||
{tmp_path / "testfile"}/testfile:
|
||||
file.managed:
|
||||
- source: salt://testfile
|
||||
- makedirs: true
|
||||
"""
|
||||
|
||||
with pytest.helpers.temp_file(
|
||||
"top.sls", top_sls, base_env_state_tree_root_dir
|
||||
), pytest.helpers.temp_file("core.sls", core_state, base_env_state_tree_root_dir):
|
||||
with salt_master.state_tree.base.temp_file(
|
||||
"top.sls", top_sls
|
||||
), salt_master.state_tree.base.temp_file("core.sls", core_state):
|
||||
res = salt_ssh_cli.run(
|
||||
"cp.list_states",
|
||||
)
|
||||
|
@ -757,22 +752,19 @@ def test_list_master_dirs(salt_ssh_cli):
|
|||
assert path not in res.data
|
||||
|
||||
|
||||
def test_list_master_symlinks(salt_ssh_cli, base_env_state_tree_root_dir):
|
||||
def test_list_master_symlinks(salt_ssh_cli, salt_master):
|
||||
if salt_ssh_cli.config.get("fileserver_ignoresymlinks", False):
|
||||
pytest.skip("Fileserver is configured to ignore symlinks")
|
||||
with pytest.helpers.temp_file("foo", "", base_env_state_tree_root_dir) as tgt:
|
||||
with salt_master.state_tree.base.temp_file(random_string("foo-"), "") as tgt:
|
||||
sym = tgt.parent / "test_list_master_symlinks"
|
||||
try:
|
||||
sym.symlink_to(tgt)
|
||||
res = salt_ssh_cli.run("cp.list_master_symlinks")
|
||||
assert res.returncode == 0
|
||||
assert res.data
|
||||
assert isinstance(res.data, dict)
|
||||
assert res.data
|
||||
assert sym.name in res.data
|
||||
assert res.data[sym.name] == str(tgt)
|
||||
finally:
|
||||
sym.unlink()
|
||||
sym.symlink_to(tgt)
|
||||
res = salt_ssh_cli.run("cp.list_master_symlinks")
|
||||
assert res.returncode == 0
|
||||
assert res.data
|
||||
assert isinstance(res.data, dict)
|
||||
assert res.data
|
||||
assert sym.name in res.data
|
||||
assert res.data[sym.name] == str(tgt)
|
||||
|
||||
|
||||
@pytest.fixture(params=(False, "cached", "render_cached"))
|
||||
|
@ -857,9 +849,7 @@ def test_hash_file_local(salt_ssh_cli, caplog):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def state_tree_jinjaimport(base_env_state_tree_root_dir, tmp_path):
|
||||
tgt = tmp_path / "config.conf"
|
||||
base_path = base_env_state_tree_root_dir / "my"
|
||||
def state_tree_jinjaimport(tmp_path, salt_master):
|
||||
map_contents = """{%- set mapdata = {"foo": "bar"} %}"""
|
||||
managed_contents = """
|
||||
{%- from "my/map.jinja" import mapdata with context %}
|
||||
|
@ -870,18 +860,18 @@ def state_tree_jinjaimport(base_env_state_tree_root_dir, tmp_path):
|
|||
|
||||
Serialize config:
|
||||
file.managed:
|
||||
- name: {tgt}
|
||||
- name: {tmp_path / "config.conf"}
|
||||
- source: salt://my/files/config.conf.j2
|
||||
- template: jinja
|
||||
"""
|
||||
with pytest.helpers.temp_file(
|
||||
"file_managed_import.sls", state_contents, base_path
|
||||
) as state:
|
||||
with pytest.helpers.temp_file("map.jinja", map_contents, base_path):
|
||||
with pytest.helpers.temp_file(
|
||||
"config.conf.j2", managed_contents, base_path / "files"
|
||||
):
|
||||
yield f"my.{state.stem}"
|
||||
with salt_master.state_tree.base.temp_file(
|
||||
"my/file_managed_import.sls", state_contents
|
||||
) as state, salt_master.state_tree.base.temp_file(
|
||||
"my/map.jinja", map_contents
|
||||
), salt_master.state_tree.base.temp_file(
|
||||
"my/files/config.conf.j2", managed_contents
|
||||
):
|
||||
yield f"my.{state.stem}"
|
||||
|
||||
|
||||
def test_cp_cache_file_as_workaround_for_missing_map_file(
|
||||
|
|
Loading…
Add table
Reference in a new issue