Skip to content

Commit

Permalink
fixes #61478 state_aggregate minion option not respected
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasmhughes committed Jan 20, 2022
1 parent eb8bd12 commit c9a6217
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/61478.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix state_aggregate minion option not respected
4 changes: 2 additions & 2 deletions salt/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3534,8 +3534,8 @@ def __gen_opts(self, opts):
opts["env_order"] = mopts.get("env_order", opts.get("env_order", []))
opts["default_top"] = mopts.get("default_top", opts.get("default_top"))
opts["state_events"] = mopts.get("state_events")
opts["state_aggregate"] = mopts.get(
"state_aggregate", opts.get("state_aggregate", False)
opts["state_aggregate"] = (
opts.get("state_aggregate") or mopts.get("state_aggregate") or False
)
opts["jinja_env"] = mopts.get("jinja_env", {})
opts["jinja_sls_env"] = mopts.get("jinja_sls_env", {})
Expand Down
68 changes: 68 additions & 0 deletions tests/pytests/unit/state/test_state_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import itertools

import pytest
import salt.config
import salt.state


@pytest.fixture
def master_opts():
"""
Return a subset of master options to the minion
"""
opts = salt.config.DEFAULT_MASTER_OPTS.copy()
mopts = {}
mopts["file_roots"] = opts["file_roots"]
mopts["top_file_merging_strategy"] = opts["top_file_merging_strategy"]
mopts["env_order"] = opts["env_order"]
mopts["default_top"] = opts["default_top"]
mopts["renderer"] = opts["renderer"]
mopts["failhard"] = opts["failhard"]
mopts["state_top"] = opts["state_top"]
mopts["state_top_saltenv"] = opts["state_top_saltenv"]
mopts["nodegroups"] = opts["nodegroups"]
mopts["state_auto_order"] = opts["state_auto_order"]
mopts["state_events"] = opts["state_events"]
mopts["state_aggregate"] = opts["state_aggregate"]
mopts["jinja_env"] = opts["jinja_env"]
mopts["jinja_sls_env"] = opts["jinja_sls_env"]
mopts["jinja_lstrip_blocks"] = opts["jinja_lstrip_blocks"]
mopts["jinja_trim_blocks"] = opts["jinja_trim_blocks"]
return mopts


class MockBaseHighStateClient:
def __init__(self, opts):
self.opts = opts

def master_opts(self):
return self.opts


def test_state_aggregate_option_behavior(master_opts):
"""
Ensure state_aggregate can be overridden on the minion
"""
minion_opts = salt.config.DEFAULT_MINION_OPTS.copy()
possible = [None, True, False, ["pkg"]]
expected_result = [
True,
False,
["pkg"],
True,
True,
["pkg"],
False,
True,
["pkg"],
["pkg"],
True,
["pkg"],
]

for idx, combo in enumerate(itertools.permutations(possible, 2)):
master_opts["state_aggregate"], minion_opts["state_aggregate"] = combo
state_obj = salt.state.BaseHighState
state_obj.client = MockBaseHighStateClient(master_opts)
return_result = state_obj(minion_opts)._BaseHighState__gen_opts(minion_opts)
assert expected_result[idx] == return_result["state_aggregate"]

0 comments on commit c9a6217

Please sign in to comment.