mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Fix get_policy KeyError on some policies
Some policies with throw a KeyError when getting the policy setting using the get_policy function.
This commit is contained in:
parent
34c243d026
commit
55cb0257ec
3 changed files with 55 additions and 1 deletions
1
changelog/61860.fixed
Normal file
1
changelog/61860.fixed
Normal file
|
@ -0,0 +1 @@
|
||||||
|
win_lgpo: Fixed intermittent KeyError when getting policy setting using lgpo.get_policy
|
|
@ -9705,7 +9705,7 @@ def _get_policy_adm_setting(
|
||||||
full_name
|
full_name
|
||||||
] = policy_item
|
] = policy_item
|
||||||
# go back and remove any "unpathed" policies that need a full path
|
# go back and remove any "unpathed" policies that need a full path
|
||||||
for path_needed in unpathed_dict[policy_namespace]:
|
for path_needed in unpathed_dict.get(policy_namespace, {}):
|
||||||
# remove the item with the same full name and re-add it w/a path'd version
|
# remove the item with the same full name and re-add it w/a path'd version
|
||||||
full_path_list = hierarchy[policy_namespace][
|
full_path_list = hierarchy[policy_namespace][
|
||||||
unpathed_dict[policy_namespace][path_needed]
|
unpathed_dict[policy_namespace][path_needed]
|
||||||
|
|
53
tests/pytests/functional/modules/win_lgpo/test_get_policy.py
Normal file
53
tests/pytests/functional/modules/win_lgpo/test_get_policy.py
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
pytestmark = [
|
||||||
|
pytest.mark.windows_whitelisted,
|
||||||
|
pytest.mark.skip_unless_on_windows,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def lgpo(modules):
|
||||||
|
return modules.lgpo
|
||||||
|
|
||||||
|
|
||||||
|
def test_hierarchical_return(lgpo):
|
||||||
|
result = lgpo.get_policy(
|
||||||
|
policy_name="Calculator",
|
||||||
|
policy_class="Machine",
|
||||||
|
hierarchical_return=True,
|
||||||
|
)
|
||||||
|
result = result["Administrative Templates"]
|
||||||
|
result = result["Windows Components"]
|
||||||
|
result = result["Microsoft User Experience Virtualization"]
|
||||||
|
result = result["Applications"]
|
||||||
|
result = result["Calculator"]
|
||||||
|
assert result in ("Enabled", "Disabled", "Not Configured")
|
||||||
|
|
||||||
|
|
||||||
|
def test_return_value_only_false(lgpo):
|
||||||
|
result = lgpo.get_policy(
|
||||||
|
policy_name="Calculator",
|
||||||
|
policy_class="Machine",
|
||||||
|
return_value_only=False,
|
||||||
|
)
|
||||||
|
assert result[
|
||||||
|
r"Windows Components\Microsoft User Experience Virtualization\Applications\Calculator"
|
||||||
|
] in ("Enabled", "Disabled", "Not Configured")
|
||||||
|
|
||||||
|
|
||||||
|
def test_return_full_policy_names_false(lgpo):
|
||||||
|
result = lgpo.get_policy(
|
||||||
|
policy_name="Calculator",
|
||||||
|
policy_class="Machine",
|
||||||
|
return_full_policy_names=False,
|
||||||
|
return_value_only=False,
|
||||||
|
)
|
||||||
|
assert result["Calculator"] in ("Enabled", "Disabled", "Not Configured")
|
||||||
|
|
||||||
|
|
||||||
|
def test_61860_calculator(lgpo):
|
||||||
|
result = lgpo.get_policy(policy_name="Calculator", policy_class="Machine")
|
||||||
|
# Any of the following are valid settings. We're only making sure it doesn't
|
||||||
|
# throw a stacktrace
|
||||||
|
assert result in ("Enabled", "Disabled", "Not Configured")
|
Loading…
Add table
Reference in a new issue