mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Simplify the state to run
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
d9299a2498
commit
cf1971850e
1 changed files with 38 additions and 27 deletions
|
@ -1,36 +1,39 @@
|
|||
import subprocess
|
||||
import types
|
||||
|
||||
import pytest
|
||||
from pytestskipmarkers.utils import platform
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.skip_on_windows,
|
||||
]
|
||||
from saltfactories.utils.functional import MultiStateResult
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def state_name(salt_master):
|
||||
def files(tmp_path):
|
||||
return types.SimpleNamespace(
|
||||
fpath_1=tmp_path / "fpath_1.txt",
|
||||
fpath_2=tmp_path / "fpath_2.txt",
|
||||
fpath_3=tmp_path / "fpath_3.txt",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def state_name(files, salt_master):
|
||||
name = "some-state"
|
||||
if platform.is_windows():
|
||||
sls_contents = """
|
||||
create_empty_file:
|
||||
sls_contents = f"""
|
||||
create-fpath-1-file:
|
||||
file.managed:
|
||||
- name: C://salt/test/txt
|
||||
salt_dude:
|
||||
user.present:
|
||||
- name: dude
|
||||
- fullname: Salt Dude
|
||||
"""
|
||||
else:
|
||||
sls_contents = """
|
||||
update:
|
||||
pkg.installed:
|
||||
- name: bash
|
||||
salt_dude:
|
||||
user.present:
|
||||
- name: dude
|
||||
- fullname: Salt Dude
|
||||
- name: {files.fpath_1}
|
||||
|
||||
create-fpath-2-file:
|
||||
file.managed:
|
||||
- name: {files.fpath_2}
|
||||
|
||||
create-fpath-3-file:
|
||||
file.managed:
|
||||
- name: {files.fpath_3}
|
||||
"""
|
||||
assert files.fpath_1.exists() is False
|
||||
assert files.fpath_2.exists() is False
|
||||
assert files.fpath_3.exists() is False
|
||||
with salt_master.state_tree.base.temp_file(f"{name}.sls", sls_contents):
|
||||
if not platform.is_windows() and not platform.is_darwin():
|
||||
subprocess.run(
|
||||
|
@ -45,15 +48,23 @@ def state_name(salt_master):
|
|||
yield name
|
||||
|
||||
|
||||
def test_salt_state_file(salt_cli, salt_minion, state_name):
|
||||
def test_salt_state_file(salt_cli, salt_minion, state_name, files):
|
||||
"""
|
||||
Test state file
|
||||
"""
|
||||
assert files.fpath_1.exists() is False
|
||||
assert files.fpath_2.exists() is False
|
||||
assert files.fpath_3.exists() is False
|
||||
|
||||
ret = salt_cli.run("state.apply", state_name, minion_tgt=salt_minion.id)
|
||||
assert ret.returncode == 0
|
||||
assert ret.data
|
||||
if ret.stdout and "Minion did not return" in ret.stdout:
|
||||
pytest.skip("Skipping test, state took too long to apply")
|
||||
sls_ret = ret.data[next(iter(ret.data))]
|
||||
assert "changes" in sls_ret
|
||||
assert "name" in sls_ret
|
||||
|
||||
for state_return in MultiStateResult(ret.data):
|
||||
assert state_return.result is True
|
||||
|
||||
assert files.fpath_1.exists() is True
|
||||
assert files.fpath_2.exists() is True
|
||||
assert files.fpath_3.exists() is True
|
||||
|
|
Loading…
Add table
Reference in a new issue