mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Move grain_opts to subdict to prevent overwriting core grains
This commit is contained in:
parent
ae1d3f3eb3
commit
6c3365f67c
2 changed files with 21 additions and 1 deletions
|
@ -11,5 +11,5 @@ def opts():
|
|||
if __opts__.get("grain_opts", False) or (
|
||||
isinstance(__pillar__, dict) and __pillar__.get("grain_opts", False)
|
||||
):
|
||||
return __opts__
|
||||
return {"opts": __opts__}
|
||||
return {}
|
||||
|
|
20
tests/pytests/unit/grains/test_opts.py
Normal file
20
tests/pytests/unit/grains/test_opts.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
"""
|
||||
tests.pytests.unit.grains.test_opts
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
"""
|
||||
|
||||
import salt.grains.opts as opts
|
||||
from tests.support.mock import patch
|
||||
|
||||
|
||||
def test_grain_opts_does_not_overwrite_core_grains(tmp_path):
|
||||
"""
|
||||
Tests that enabling grain_opts doesn't overwrite the core grains
|
||||
|
||||
See: https://github.com/saltstack/salt/issues/66784
|
||||
"""
|
||||
dunder_opts = {"grain_opts": True}
|
||||
|
||||
with patch.object(opts, "__opts__", dunder_opts, create=True):
|
||||
with patch.object(opts, "__pillar__", {}, create=True):
|
||||
assert opts.opts() == {"opts": dunder_opts}
|
Loading…
Add table
Reference in a new issue