mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix up tests
This commit is contained in:
parent
bee018c0e5
commit
738bbbbbc4
2 changed files with 54 additions and 58 deletions
|
@ -65,6 +65,8 @@ def test_dynamic_pillarenv():
|
||||||
},
|
},
|
||||||
"file_roots": {"base": ["/srv/salt/base"], "__env__": ["/srv/salt/__env__"]},
|
"file_roots": {"base": ["/srv/salt/base"], "__env__": ["/srv/salt/__env__"]},
|
||||||
"extension_modules": "",
|
"extension_modules": "",
|
||||||
|
"fileserver_backend": "roots",
|
||||||
|
"cachedir": "",
|
||||||
}
|
}
|
||||||
pillar = salt.pillar.Pillar(opts, {}, "mocked-minion", "base", pillarenv="dev")
|
pillar = salt.pillar.Pillar(opts, {}, "mocked-minion", "base", pillarenv="dev")
|
||||||
assert pillar.opts["pillar_roots"] == {
|
assert pillar.opts["pillar_roots"] == {
|
||||||
|
@ -87,6 +89,8 @@ def test_ignored_dynamic_pillarenv():
|
||||||
},
|
},
|
||||||
"file_roots": {"base": ["/srv/salt/base"], "dev": ["/svr/salt/dev"]},
|
"file_roots": {"base": ["/srv/salt/base"], "dev": ["/svr/salt/dev"]},
|
||||||
"extension_modules": "",
|
"extension_modules": "",
|
||||||
|
"fileserver_backend": "roots",
|
||||||
|
"cachedir": "",
|
||||||
}
|
}
|
||||||
pillar = salt.pillar.Pillar(opts, {}, "mocked-minion", "base", pillarenv="base")
|
pillar = salt.pillar.Pillar(opts, {}, "mocked-minion", "base", pillarenv="base")
|
||||||
assert pillar.opts["pillar_roots"] == {"base": ["/srv/pillar/base"]}
|
assert pillar.opts["pillar_roots"] == {"base": ["/srv/pillar/base"]}
|
||||||
|
|
|
@ -58,9 +58,9 @@ class MockFileclient:
|
||||||
# pylint: enable=unused-argument,no-method-argument,method-hidden
|
# pylint: enable=unused-argument,no-method-argument,method-hidden
|
||||||
|
|
||||||
|
|
||||||
def _setup_test_topfile_sls_pillar_match(tempdir):
|
def _setup_test_topfile_sls_pillar_match(tmp_path):
|
||||||
# Write a simple topfile and two pillar state files
|
# Write a simple topfile and two pillar state files
|
||||||
top_file = tempfile.NamedTemporaryFile(dir=tempdir, delete=False)
|
top_file = tempfile.NamedTemporaryFile(dir=str(tmp_path), delete=False)
|
||||||
s = """
|
s = """
|
||||||
base:
|
base:
|
||||||
'phase:alpha':
|
'phase:alpha':
|
||||||
|
@ -69,7 +69,7 @@ base:
|
||||||
"""
|
"""
|
||||||
top_file.write(salt.utils.stringutils.to_bytes(s))
|
top_file.write(salt.utils.stringutils.to_bytes(s))
|
||||||
top_file.flush()
|
top_file.flush()
|
||||||
generic_file = tempfile.NamedTemporaryFile(dir=tempdir, delete=False)
|
generic_file = tempfile.NamedTemporaryFile(dir=str(tmp_path), delete=False)
|
||||||
generic_file.write(
|
generic_file.write(
|
||||||
b"""
|
b"""
|
||||||
generic:
|
generic:
|
||||||
|
@ -106,9 +106,9 @@ def test_pillarenv_from_saltenv():
|
||||||
assert pillar.opts["pillarenv"] == "dev"
|
assert pillar.opts["pillarenv"] == "dev"
|
||||||
|
|
||||||
|
|
||||||
def _setup_test_topfile_sls(tempdir, nodegroup_order, glob_order):
|
def _setup_test_topfile_sls(tmp_path, nodegroup_order, glob_order):
|
||||||
# Write a simple topfile and two pillar state files
|
# Write a simple topfile and two pillar state files
|
||||||
top_file = tempfile.NamedTemporaryFile(dir=tempdir, delete=False)
|
top_file = tempfile.NamedTemporaryFile(dir=str(tmp_path), delete=False)
|
||||||
s = """
|
s = """
|
||||||
base:
|
base:
|
||||||
group:
|
group:
|
||||||
|
@ -127,7 +127,7 @@ base:
|
||||||
)
|
)
|
||||||
top_file.write(salt.utils.stringutils.to_bytes(s))
|
top_file.write(salt.utils.stringutils.to_bytes(s))
|
||||||
top_file.flush()
|
top_file.flush()
|
||||||
ssh_file = tempfile.NamedTemporaryFile(dir=tempdir, delete=False)
|
ssh_file = tempfile.NamedTemporaryFile(dir=str(tmp_path), delete=False)
|
||||||
ssh_file.write(
|
ssh_file.write(
|
||||||
b"""
|
b"""
|
||||||
ssh:
|
ssh:
|
||||||
|
@ -135,7 +135,7 @@ ssh:
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
ssh_file.flush()
|
ssh_file.flush()
|
||||||
ssh_minion_file = tempfile.NamedTemporaryFile(dir=tempdir, delete=False)
|
ssh_minion_file = tempfile.NamedTemporaryFile(dir=str(tmp_path), delete=False)
|
||||||
ssh_minion_file.write(
|
ssh_minion_file.write(
|
||||||
b"""
|
b"""
|
||||||
ssh:
|
ssh:
|
||||||
|
@ -143,7 +143,7 @@ ssh:
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
ssh_minion_file.flush()
|
ssh_minion_file.flush()
|
||||||
generic_file = tempfile.NamedTemporaryFile(dir=tempdir, delete=False)
|
generic_file = tempfile.NamedTemporaryFile(dir=str(tmp_path), delete=False)
|
||||||
generic_file.write(
|
generic_file.write(
|
||||||
b"""
|
b"""
|
||||||
generic:
|
generic:
|
||||||
|
@ -155,7 +155,7 @@ generic:
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
generic_file.flush()
|
generic_file.flush()
|
||||||
generic_minion_file = tempfile.NamedTemporaryFile(dir=tempdir, delete=False)
|
generic_minion_file = tempfile.NamedTemporaryFile(dir=str(tmp_path), delete=False)
|
||||||
generic_minion_file.write(
|
generic_minion_file.write(
|
||||||
b"""
|
b"""
|
||||||
generic:
|
generic:
|
||||||
|
@ -503,9 +503,7 @@ def test_ext_pillar_with_extra_minion_data_val_elem():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# @patch("salt.channel.client.ReqChannel.factory", MagicMock())
|
def test_ext_pillar_first(tmp_path):
|
||||||
# @patch("salt.channel.client.AsyncReqChannel.factory", MagicMock())
|
|
||||||
def test_ext_pillar_first():
|
|
||||||
"""
|
"""
|
||||||
test when using ext_pillar and ext_pillar_first
|
test when using ext_pillar and ext_pillar_first
|
||||||
"""
|
"""
|
||||||
|
@ -532,31 +530,27 @@ def test_ext_pillar_first():
|
||||||
"kernel": "Linux",
|
"kernel": "Linux",
|
||||||
}
|
}
|
||||||
|
|
||||||
tempdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
|
sls_files = _setup_test_topfile_sls_pillar_match(
|
||||||
try:
|
str(tmp_path),
|
||||||
sls_files = _setup_test_topfile_sls_pillar_match(
|
)
|
||||||
tempdir,
|
fc_mock = MockFileclient(
|
||||||
)
|
cache_file=sls_files["top"]["dest"],
|
||||||
fc_mock = MockFileclient(
|
list_states=["top", "ssh", "ssh.minion", "generic", "generic.minion"],
|
||||||
cache_file=sls_files["top"]["dest"],
|
get_state=sls_files,
|
||||||
list_states=["top", "ssh", "ssh.minion", "generic", "generic.minion"],
|
)
|
||||||
get_state=sls_files,
|
with patch.object(
|
||||||
)
|
salt.fileclient, "get_file_client", MagicMock(return_value=fc_mock)
|
||||||
with patch.object(
|
), patch(
|
||||||
salt.fileclient, "get_file_client", MagicMock(return_value=fc_mock)
|
"salt.pillar.Pillar.ext_pillar",
|
||||||
), patch(
|
MagicMock(
|
||||||
"salt.pillar.Pillar.ext_pillar",
|
return_value=(
|
||||||
MagicMock(
|
{"id": "minion", "phase": "alpha", "role": "database"},
|
||||||
return_value=(
|
[],
|
||||||
{"id": "minion", "phase": "alpha", "role": "database"},
|
)
|
||||||
[],
|
),
|
||||||
)
|
):
|
||||||
),
|
pillar = salt.pillar.Pillar(opts, grains, "mocked-minion", "base")
|
||||||
):
|
assert pillar.compile_pillar()["generic"]["key1"] == "value1"
|
||||||
pillar = salt.pillar.Pillar(opts, grains, "mocked-minion", "base")
|
|
||||||
assert pillar.compile_pillar()["generic"]["key1"] == "value1"
|
|
||||||
finally:
|
|
||||||
shutil.rmtree(tempdir, ignore_errors=True)
|
|
||||||
|
|
||||||
|
|
||||||
@patch("salt.fileclient.Client.list_states")
|
@patch("salt.fileclient.Client.list_states")
|
||||||
|
@ -784,9 +778,9 @@ def test_topfile_order():
|
||||||
_run_test(nodegroup_order=2, glob_order=1, expected="foo")
|
_run_test(nodegroup_order=2, glob_order=1, expected="foo")
|
||||||
|
|
||||||
|
|
||||||
def test_relative_include(tempdir):
|
def test_relative_include(tmp_path):
|
||||||
join = os.path.join
|
join = os.path.join
|
||||||
with fopen(join(tempdir.tempdir, "top.sls"), "w") as f:
|
with fopen(join(str(tmp_path), "top.sls"), "w") as f:
|
||||||
print(
|
print(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
|
@ -799,7 +793,7 @@ def test_relative_include(tempdir):
|
||||||
),
|
),
|
||||||
file=f,
|
file=f,
|
||||||
)
|
)
|
||||||
includer_dir = join(tempdir.tempdir, "includer")
|
includer_dir = str(tmp_path / "includer")
|
||||||
os.makedirs(includer_dir)
|
os.makedirs(includer_dir)
|
||||||
with fopen(join(includer_dir, "init.sls"), "w") as f:
|
with fopen(join(includer_dir, "init.sls"), "w") as f:
|
||||||
print(
|
print(
|
||||||
|
@ -833,7 +827,7 @@ def test_relative_include(tempdir):
|
||||||
file=f,
|
file=f,
|
||||||
)
|
)
|
||||||
|
|
||||||
with fopen(join(tempdir.tempdir, "simple_includer.sls"), "w") as simpleincluder:
|
with fopen(str(tmp_path / "simple_includer.sls"), "w") as simpleincluder:
|
||||||
print(
|
print(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
|
@ -844,7 +838,7 @@ def test_relative_include(tempdir):
|
||||||
),
|
),
|
||||||
file=simpleincluder,
|
file=simpleincluder,
|
||||||
)
|
)
|
||||||
with fopen(join(tempdir.tempdir, "simple.sls"), "w") as f:
|
with fopen(str(tmp_path / "simple.sls"), "w") as f:
|
||||||
print(
|
print(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
|
@ -854,7 +848,7 @@ def test_relative_include(tempdir):
|
||||||
),
|
),
|
||||||
file=f,
|
file=f,
|
||||||
)
|
)
|
||||||
with fopen(join(tempdir.tempdir, "super_simple.sls"), "w") as f:
|
with fopen(str(tmp_path / "super_simple.sls"), "w") as f:
|
||||||
print(
|
print(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
|
@ -865,9 +859,9 @@ def test_relative_include(tempdir):
|
||||||
file=f,
|
file=f,
|
||||||
)
|
)
|
||||||
|
|
||||||
depth_dir = join(tempdir.tempdir, "includes", "with", "more")
|
depth_dir = tmp_path / "includes" / "with" / "more"
|
||||||
os.makedirs(depth_dir)
|
os.makedirs(str(depth_dir))
|
||||||
with fopen(join(depth_dir, "depth.sls"), "w") as f:
|
with fopen(str(depth_dir / "depth.sls"), "w") as f:
|
||||||
print(
|
print(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
|
@ -882,7 +876,7 @@ def test_relative_include(tempdir):
|
||||||
file=f,
|
file=f,
|
||||||
)
|
)
|
||||||
|
|
||||||
with fopen(join(depth_dir, "ramble.sls"), "w") as f:
|
with fopen(str(depth_dir / "ramble.sls"), "w") as f:
|
||||||
print(
|
print(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
|
@ -893,7 +887,7 @@ def test_relative_include(tempdir):
|
||||||
file=f,
|
file=f,
|
||||||
)
|
)
|
||||||
|
|
||||||
with fopen(join(depth_dir, "doors.sls"), "w") as f:
|
with fopen(str(depth_dir / "doors.sls"), "w") as f:
|
||||||
print(
|
print(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
|
@ -909,7 +903,7 @@ def test_relative_include(tempdir):
|
||||||
"renderer_blacklist": [],
|
"renderer_blacklist": [],
|
||||||
"renderer_whitelist": [],
|
"renderer_whitelist": [],
|
||||||
"state_top": "top.sls",
|
"state_top": "top.sls",
|
||||||
"pillar_roots": {"base": [tempdir.tempdir]},
|
"pillar_roots": {"base": [str(tmp_path)]},
|
||||||
"extension_modules": "",
|
"extension_modules": "",
|
||||||
"saltenv": "base",
|
"saltenv": "base",
|
||||||
"file_roots": [],
|
"file_roots": [],
|
||||||
|
@ -943,14 +937,14 @@ def test_relative_include(tempdir):
|
||||||
assert compiled_pillar["mojo"] == "bad risin'"
|
assert compiled_pillar["mojo"] == "bad risin'"
|
||||||
|
|
||||||
|
|
||||||
def test_missing_include(tempdir):
|
def test_missing_include(tmp_path):
|
||||||
opts = {
|
opts = {
|
||||||
"optimization_order": [0, 1, 2],
|
"optimization_order": [0, 1, 2],
|
||||||
"renderer": "yaml",
|
"renderer": "yaml",
|
||||||
"renderer_blacklist": [],
|
"renderer_blacklist": [],
|
||||||
"renderer_whitelist": [],
|
"renderer_whitelist": [],
|
||||||
"state_top": "top.sls",
|
"state_top": "top.sls",
|
||||||
"pillar_roots": {"base": [tempdir.tempdir]},
|
"pillar_roots": {"base": [str(tmp_path)]},
|
||||||
"extension_modules": "",
|
"extension_modules": "",
|
||||||
"saltenv": "base",
|
"saltenv": "base",
|
||||||
"file_roots": [],
|
"file_roots": [],
|
||||||
|
@ -968,8 +962,7 @@ def test_missing_include(tempdir):
|
||||||
"kernel": "Linux",
|
"kernel": "Linux",
|
||||||
}
|
}
|
||||||
|
|
||||||
join = os.path.join
|
with fopen(str(tmp_path / "top.sls"), "w") as f:
|
||||||
with fopen(join(tempdir.tempdir, "top.sls"), "w") as f:
|
|
||||||
print(
|
print(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
|
@ -980,9 +973,9 @@ def test_missing_include(tempdir):
|
||||||
),
|
),
|
||||||
file=f,
|
file=f,
|
||||||
)
|
)
|
||||||
include_dir = join(tempdir.tempdir, "simple_include")
|
include_dir = tmp_path / "simple_include"
|
||||||
os.makedirs(include_dir)
|
os.makedirs(include_dir)
|
||||||
with fopen(join(include_dir, "init.sls"), "w") as f:
|
with fopen(str(include_dir / "init.sls"), "w") as f:
|
||||||
print(
|
print(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
|
@ -1132,8 +1125,7 @@ def test_pillar_send_extra_minion_data_from_config(tmp_pki, grains):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_include(tempdir):
|
def test_include(tmp_path):
|
||||||
print(dir(tempdir))
|
|
||||||
opts = {
|
opts = {
|
||||||
"optimization_order": [0, 1, 2],
|
"optimization_order": [0, 1, 2],
|
||||||
"renderer": "yaml",
|
"renderer": "yaml",
|
||||||
|
@ -1155,7 +1147,7 @@ def test_include(tempdir):
|
||||||
"osrelease": "13.04",
|
"osrelease": "13.04",
|
||||||
"kernel": "Linux",
|
"kernel": "Linux",
|
||||||
}
|
}
|
||||||
sls_files = _setup_test_include_sls(tempdir.tempdir)
|
sls_files = _setup_test_include_sls(str(tmp_path))
|
||||||
fc_mock = MockFileclient(
|
fc_mock = MockFileclient(
|
||||||
cache_file=sls_files["top"]["dest"],
|
cache_file=sls_files["top"]["dest"],
|
||||||
get_state=sls_files,
|
get_state=sls_files,
|
||||||
|
|
Loading…
Add table
Reference in a new issue