Skip to content

Add test-mode handling to keystone_role_grant present/absent#69694

Open
ggiesen wants to merge 3 commits into
saltstack:3006.xfrom
ggiesen:fix-52220-keystone-role-grant-test
Open

Add test-mode handling to keystone_role_grant present/absent#69694
ggiesen wants to merge 3 commits into
saltstack:3006.xfrom
ggiesen:fix-52220-keystone-role-grant-test

Conversation

@ggiesen

@ggiesen ggiesen commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

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?

  • Tests written/updated
  • Changelog

Commits signed with GPG?

No

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.
@dwoz dwoz added the test:full Run the full test suite label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants