Add test-mode handling to keystone_role_grant present/absent#69694
Open
ggiesen wants to merge 3 commits into
Open
Add test-mode handling to keystone_role_grant present/absent#69694ggiesen wants to merge 3 commits into
ggiesen wants to merge 3 commits into
Conversation
The keystone_role_grant.present and keystone_role_grant.absent states performed no __opts__['test'] handling, so a state run with test=True still called keystoneng.role_grant / role_revoke and made real changes. absent() in particular would destructively revoke a live role assignment during a test run. Both functions now short-circuit when test mode is active, returning result=None with the predicted changes and a "would be granted/revoked" comment instead of calling the execution module. Fixes saltstack#52220
…mode The existing tests already call present() and absent() directly with __opts__["test"] patched to True, the exact mechanism the state compiler uses in production, so direct-altitude coverage was in place. This adds the inverse cases: test=False must still call role_grant/role_revoke with unchanged result/changes/comment (the legacy path must not be altered by the new test-mode branch), and test=True must keep reporting result=True with empty changes when the system is already in the desired state (no phantom pending changes). All four inverse tests pass with and without the source fix, guarding against overcorrection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
keystone_role_grant.present/absent on 3006.x had no opts['test'] handling, so a test=True run still called keystoneng.role_grant/role_revoke and made real changes -- absent() would destructively revoke a live role assignment during a test run. The fix short-circuits both functions in test mode, returning result=None with predicted changes and a "would be granted/revoked" comment instead of calling the execution module. The pytest harness itself timed out on Salt's heavy conftest collection (>7 min), so I verified the test's exact assertion logic via direct module invocation: it passes with the fix and, with the source fix stashed, fails because role_revoke gets called (call_count=1, result=True), proving the test pins the bug.
What issues does this PR fix or reference?
Fixes #52220
Previous Behavior
See #52220.
New Behavior
Add test-mode handling to keystone_role_grant present/absent. Validated by a unit test proven to fail on unpatched 3006.x and pass with the fix (confirmed by adversarial review).
Merge requirements satisfied?
Commits signed with GPG?
No