mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Adjust some tests to get passing nightly builds again
This commit is contained in:
parent
16bead7bcc
commit
ebb02d6c3a
2 changed files with 93 additions and 88 deletions
|
@ -318,41 +318,35 @@ def test_listen_requisite_resolution_names(state, state_tree):
|
||||||
assert "test_|-listener_service_|-crond_|-mod_watch" in ret
|
assert "test_|-listener_service_|-crond_|-mod_watch" in ret
|
||||||
|
|
||||||
|
|
||||||
def test_onlyif_req(state, subtests):
|
@pytest.mark.parametrize(
|
||||||
onlyif = [{}]
|
"fun,onlyif,result,comment,assert_changes",
|
||||||
with subtests.test(onlyif=onlyif):
|
(
|
||||||
ret = state.single(
|
("test.succeed_with_changes", [{}], True, "Success!", None),
|
||||||
name="onlyif test", fun="test.succeed_with_changes", onlyif=onlyif
|
(
|
||||||
)
|
"test.succeed_without_changes",
|
||||||
assert ret.result is True
|
[{"fun": "test.true"}],
|
||||||
assert ret.comment == "Success!"
|
True,
|
||||||
|
"Success!",
|
||||||
onlyif = [{"fun": "test.true"}]
|
False,
|
||||||
with subtests.test(onlyif=onlyif):
|
),
|
||||||
ret = state.single(
|
(
|
||||||
name="onlyif test", fun="test.succeed_without_changes", onlyif=onlyif
|
"test.fail_with_changes",
|
||||||
)
|
[{"fun": "test.false"}],
|
||||||
assert ret.result is True
|
True,
|
||||||
assert not ret.changes
|
"onlyif condition is false",
|
||||||
assert ret.comment == "Success!"
|
False,
|
||||||
|
),
|
||||||
onlyif = [{"fun": "test.false"}]
|
("test.fail_with_changes", [{"fun": "test.true"}], False, "Failure!", True),
|
||||||
with subtests.test(onlyif=onlyif):
|
),
|
||||||
ret = state.single(
|
)
|
||||||
name="onlyif test", fun="test.fail_with_changes", onlyif=onlyif
|
def test_onlyif_req(state, fun, onlyif, result, comment, assert_changes):
|
||||||
)
|
ret = state.single(name="onlyif test", fun=fun, onlyif=onlyif)
|
||||||
assert ret.result is True
|
assert ret.result is result
|
||||||
assert not ret.changes
|
assert ret.comment == comment
|
||||||
assert ret.comment == "onlyif condition is false"
|
if assert_changes is True:
|
||||||
|
|
||||||
onlyif = [{"fun": "test.true"}]
|
|
||||||
with subtests.test(onlyif=onlyif):
|
|
||||||
ret = state.single(
|
|
||||||
name="onlyif test", fun="test.fail_with_changes", onlyif=onlyif
|
|
||||||
)
|
|
||||||
assert ret.result is False
|
|
||||||
assert ret.changes
|
assert ret.changes
|
||||||
assert ret.comment == "Failure!"
|
elif assert_changes is False:
|
||||||
|
assert not ret.changes
|
||||||
|
|
||||||
|
|
||||||
def test_listen_requisite_not_exist(state, state_tree):
|
def test_listen_requisite_not_exist(state, state_tree):
|
||||||
|
|
|
@ -6,6 +6,7 @@ user present with custom homedir
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -43,6 +44,11 @@ def username(sminion):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def guid():
|
||||||
|
return random.randint(60000, 61000)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def user_home(username, tmp_path):
|
def user_home(username, tmp_path):
|
||||||
if salt.utils.platform.is_windows():
|
if salt.utils.platform.is_windows():
|
||||||
|
@ -429,73 +435,78 @@ def test_user_present_change_optional_groups(
|
||||||
assert user_info["groups"] == [group_1.name]
|
assert user_info["groups"] == [group_1.name]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def user_present_groups(states):
|
||||||
|
groups = ["testgroup1", "testgroup2"]
|
||||||
|
try:
|
||||||
|
yield groups
|
||||||
|
finally:
|
||||||
|
for group in groups:
|
||||||
|
ret = states.group.absent(name=group)
|
||||||
|
assert ret.result is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip_unless_on_linux(reason="underlying functionality only runs on Linux")
|
@pytest.mark.skip_unless_on_linux(reason="underlying functionality only runs on Linux")
|
||||||
def test_user_present_no_groups(modules, states, username):
|
def test_user_present_no_groups(modules, states, username, user_present_groups, guid):
|
||||||
"""
|
"""
|
||||||
test user.present when groups arg is not
|
test user.present when groups arg is not
|
||||||
included by the group is created in another
|
included by the group is created in another
|
||||||
state. Re-run the states to ensure there are
|
state. Re-run the states to ensure there are
|
||||||
not changes and it is idempotent.
|
not changes and it is idempotent.
|
||||||
"""
|
"""
|
||||||
groups = ["testgroup1", "testgroup2"]
|
ret = states.group.present(name=username, gid=guid)
|
||||||
try:
|
assert ret.result is True
|
||||||
ret = states.group.present(name=username, gid=61121)
|
|
||||||
assert ret.result is True
|
|
||||||
|
|
||||||
ret = states.user.present(
|
ret = states.user.present(
|
||||||
name=username,
|
name=username,
|
||||||
uid=61121,
|
uid=guid,
|
||||||
gid=61121,
|
gid=guid,
|
||||||
)
|
)
|
||||||
assert ret.result is True
|
assert ret.result is True
|
||||||
assert ret.changes["groups"] == [username]
|
assert ret.changes["groups"] == [username]
|
||||||
assert ret.changes["name"] == username
|
assert ret.changes["name"] == username
|
||||||
|
|
||||||
ret = states.group.present(
|
ret = states.group.present(
|
||||||
name=groups[0],
|
name=user_present_groups[0],
|
||||||
members=[username],
|
members=[username],
|
||||||
)
|
)
|
||||||
assert ret.changes["members"] == [username]
|
assert ret.changes["members"] == [username]
|
||||||
|
|
||||||
ret = states.group.present(
|
ret = states.group.present(
|
||||||
name=groups[1],
|
name=user_present_groups[1],
|
||||||
members=[username],
|
members=[username],
|
||||||
)
|
)
|
||||||
assert ret.changes["members"] == [username]
|
assert ret.changes["members"] == [username]
|
||||||
|
|
||||||
user_info = modules.user.info(username)
|
user_info = modules.user.info(username)
|
||||||
assert user_info
|
assert user_info
|
||||||
assert user_info["groups"] == [username, groups[0], groups[1]]
|
assert user_info["groups"] == [username, *user_present_groups]
|
||||||
|
|
||||||
# run again, expecting no changes
|
# run again, expecting no changes
|
||||||
ret = states.group.present(name=username)
|
ret = states.group.present(name=username)
|
||||||
assert ret.result is True
|
assert ret.result is True
|
||||||
assert ret.changes == {}
|
assert ret.changes == {}
|
||||||
|
|
||||||
ret = states.user.present(
|
ret = states.user.present(
|
||||||
name=username,
|
name=username,
|
||||||
)
|
)
|
||||||
assert ret.result is True
|
assert ret.result is True
|
||||||
assert ret.changes == {}
|
assert ret.changes == {}
|
||||||
|
|
||||||
ret = states.group.present(
|
ret = states.group.present(
|
||||||
name=groups[0],
|
name=user_present_groups[0],
|
||||||
members=[username],
|
members=[username],
|
||||||
)
|
)
|
||||||
assert ret.result is True
|
assert ret.result is True
|
||||||
assert ret.changes == {}
|
assert ret.changes == {}
|
||||||
|
|
||||||
ret = states.group.present(
|
ret = states.group.present(
|
||||||
name=groups[1],
|
name=user_present_groups[1],
|
||||||
members=[username],
|
members=[username],
|
||||||
)
|
)
|
||||||
assert ret.result is True
|
assert ret.result is True
|
||||||
assert ret.changes == {}
|
assert ret.changes == {}
|
||||||
|
|
||||||
user_info = modules.user.info(username)
|
user_info = modules.user.info(username)
|
||||||
assert user_info
|
assert user_info
|
||||||
assert user_info["groups"] == [username, groups[0], groups[1]]
|
assert user_info["groups"] == [username, *user_present_groups]
|
||||||
finally:
|
|
||||||
for group in groups:
|
|
||||||
ret = states.group.absent(name=group)
|
|
||||||
assert ret.result is True
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue