mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 17:50:20 +00:00
Fix tests, return res dict
This commit is contained in:
parent
c76fdd638a
commit
fceb58d543
2 changed files with 35 additions and 13 deletions
|
@ -49,11 +49,11 @@ def compound_matches(expr, minion_id):
|
|||
log.warning(
|
||||
"Minion data cache is disabled. Cannot evaluate compound matcher expression."
|
||||
)
|
||||
return False
|
||||
# Ensure the passed minion ID is valid and exists.
|
||||
return {"res": False}
|
||||
# Ensure the passed minion ID is valid.
|
||||
if not salt.utils.verify.valid_id(__opts__, minion_id):
|
||||
log.warning("Got invalid minion ID.")
|
||||
return False
|
||||
return {"res": False}
|
||||
log.debug("Evaluating if minion '%s' is matched by '%s'.", minion_id, expr)
|
||||
ckminions = salt.utils.minions.CkMinions(__opts__)
|
||||
# Compound expressions are usually evaluated in greedy mode since you
|
||||
|
@ -67,7 +67,7 @@ def compound_matches(expr, minion_id):
|
|||
expr, DEFAULT_TARGET_DELIM, greedy=False
|
||||
)
|
||||
if minion_id in minions["minions"]:
|
||||
return minion_id
|
||||
return {"res": minion_id}
|
||||
except Exception: # pylint: disable=broad-except
|
||||
pass
|
||||
return False
|
||||
return {"res": False}
|
||||
|
|
|
@ -170,11 +170,15 @@ class TestMatchCompoundRunner:
|
|||
],
|
||||
)
|
||||
def test_match_compound_matches(self, match_salt_run_cli, expr, expected):
|
||||
if expected:
|
||||
expected = "match-minion-alice"
|
||||
ret = match_salt_run_cli.run(
|
||||
"match.compound_matches", expr, "match-minion-alice"
|
||||
)
|
||||
assert ret.returncode == 0
|
||||
assert bool(ret.data) is expected
|
||||
assert ret.data
|
||||
assert "res" in ret.data
|
||||
assert ret.data["res"] == expected
|
||||
|
||||
@pytest.mark.usefixtures("eve_cached")
|
||||
def test_match_compound_matches_only_allows_exact_pillar_matching(
|
||||
|
@ -188,7 +192,9 @@ class TestMatchCompoundRunner:
|
|||
"match.compound_matches", "I@name:alic*", "match-minion-eve"
|
||||
)
|
||||
assert ret.returncode == 0
|
||||
assert ret.data is False
|
||||
assert ret.data
|
||||
assert "res" in ret.data
|
||||
assert ret.data["res"] is False
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"expr,expected",
|
||||
|
@ -207,11 +213,15 @@ class TestMatchCompoundRunner:
|
|||
def test_match_compound_matches_with_uncached_minion_data(
|
||||
self, match_salt_run_cli, expr, expected
|
||||
):
|
||||
if expected:
|
||||
expected = "match-minion-alice"
|
||||
ret = match_salt_run_cli.run(
|
||||
"match.compound_matches", expr, "match-minion-alice"
|
||||
)
|
||||
assert ret.returncode == 0
|
||||
assert bool(ret.data) is expected
|
||||
assert ret.data
|
||||
assert "res" in ret.data
|
||||
assert ret.data["res"] == expected
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"expr,expected",
|
||||
|
@ -228,18 +238,22 @@ class TestMatchCompoundRunner:
|
|||
def test_match_compound_matches_when_minion_is_down(
|
||||
self, match_salt_run_cli, expr, expected
|
||||
):
|
||||
if expected:
|
||||
expected = "match-minion-alice"
|
||||
ret = match_salt_run_cli.run(
|
||||
"match.compound_matches", expr, "match-minion-alice"
|
||||
)
|
||||
assert ret.returncode == 0
|
||||
assert bool(ret.data) is expected
|
||||
assert ret.data
|
||||
assert "res" in ret.data
|
||||
assert ret.data["res"] == expected
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"minion_id",
|
||||
[
|
||||
"hi\\there",
|
||||
"my/minion",
|
||||
"nonexistent",
|
||||
"../../../../../../../../../etc/shadow",
|
||||
],
|
||||
)
|
||||
def test_match_compound_matches_with_invalid_minion_id(
|
||||
|
@ -247,7 +261,9 @@ class TestMatchCompoundRunner:
|
|||
):
|
||||
ret = match_salt_run_cli.run("match.compound_matches", "*", minion_id)
|
||||
assert ret.returncode == 0
|
||||
assert ret.data is False
|
||||
assert ret.data
|
||||
assert "res" in ret.data
|
||||
assert ret.data["res"] is False
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"expr,expected",
|
||||
|
@ -263,11 +279,15 @@ class TestMatchCompoundRunner:
|
|||
def test_match_compound_matches_as_peer_run(
|
||||
self, match_salt_call_cli, expr, expected
|
||||
):
|
||||
if expected:
|
||||
expected = "match-minion-alice"
|
||||
ret = match_salt_call_cli.run(
|
||||
"publish.runner", "match.compound_matches", [expr, "match-minion-alice"]
|
||||
)
|
||||
assert ret.returncode == 0
|
||||
assert bool(ret.data) is expected
|
||||
assert ret.data
|
||||
assert "res" in ret.data
|
||||
assert ret.data["res"] == expected
|
||||
|
||||
|
||||
class TestMatchCompoundRunnerWithoutMinionDataCache:
|
||||
|
@ -293,4 +313,6 @@ class TestMatchCompoundRunnerWithoutMinionDataCache:
|
|||
"match.compound_matches", expr, "match-minion-alice"
|
||||
)
|
||||
assert ret.returncode == 0
|
||||
assert ret.data is False
|
||||
assert ret.data
|
||||
assert "res" in ret.data
|
||||
assert ret.data["res"] is False
|
||||
|
|
Loading…
Add table
Reference in a new issue