Skip to content

Fix automatic vault login - #21126

Merged
Gauravtalreja1 merged 1 commit into
SatelliteQE:masterfrom
lpramuk:fix_auto_vault_login
Mar 30, 2026
Merged

Fix automatic vault login#21126
Gauravtalreja1 merged 1 commit into
SatelliteQE:masterfrom
lpramuk:fix_auto_vault_login

Conversation

@lpramuk

@lpramuk lpramuk commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Problem Statement

Automatic vault login when running tests or collecting tests is now broken

$ make vault-logout
$ pytest --co tests/foreman/api/test_ping.py
ImportError while loading conftest '/home/lpramuk/git/SatelliteQE/robottelo/conftest.py'.
conftest.py:5: in <module>
    from robottelo.config import settings
robottelo/config/__init__.py:48: in <module>
    settings = get_settings()
               ^^^^^^^^^^^^^^
robottelo/config/__init__.py:37: in get_settings
    settings.validators.register(**VALIDATORS)
    ^^^^^^^^^^^^^^^^^^^
../../../.virtualenvs/r/lib/python3.13/site-packages/dynaconf/base.py:121: in __getattr__
    self._setup()
../../../.virtualenvs/r/lib/python3.13/site-packages/dynaconf/base.py:180: in _setup
    self._wrapped = self._wrapper_class(
../../../.virtualenvs/r/lib/python3.13/site-packages/dynaconf/base.py:270: in __init__
    self.execute_loaders()
../../../.virtualenvs/r/lib/python3.13/site-packages/dynaconf/base.py:1203: in execute_loaders
    core_loader.load(self, env, silent=silent, key=key)
../../../.virtualenvs/r/lib/python3.13/site-packages/dynaconf/loaders/vault_loader.py:86: in load
    client = get_client(obj)
             ^^^^^^^^^^^^^^^
../../../.virtualenvs/r/lib/python3.13/site-packages/dynaconf/loaders/vault_loader.py:69: in get_client
    assert client.is_authenticated(), (
           ^^^^^^^^^^^^^^^^^^^^^^^^^
E   AssertionError: Vault authentication error: is VAULT_TOKEN_FOR_DYNACONF or VAULT_ROLE_ID_FOR_DYNACONF defined?

Solution

Move recent conftest.py changes (#20339) to appropriate location in tests/foreman/conftest.py

Related Issues

SAT-43736

Summary by Sourcery

Enhancements:

  • Move the pytest_runtest_protocol hook from the global conftest to tests/foreman/conftest.py so version source changes apply only to Foreman tests.

@lpramuk lpramuk self-assigned this Mar 26, 2026
@lpramuk
lpramuk requested a review from a team as a code owner March 26, 2026 10:17
@lpramuk lpramuk added Bug This is an issue with the robottelo framework No-CherryPick PR doesnt need CherryPick to previous branches Stream Introduced in or relating directly to Satellite Stream/Master labels Mar 26, 2026
@sourcery-ai

sourcery-ai Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Moves a pytest hook that manipulates the vault/Foreman version source from the global conftest to the Foreman-specific test conftest, so that automatic vault login/version handling only applies to relevant Foreman tests.

Sequence diagram for pytest runtest protocol with Foreman foremanctl marker

sequenceDiagram
    participant Pytest as PytestRunner
    participant ForemanConftest as tests_foreman_conftest
    participant AutoVault as pytest_plugins_auto_vault
    participant Settings as settings
    participant Test as ForemanTest

    Pytest->>ForemanConftest: discover pytest_runtest_protocol hook
    Pytest->>AutoVault: initialize auto_vault plugin

    Pytest->>Test: start test execution
    Pytest->>ForemanConftest: pytest_runtest_protocol(item, nextitem)
    alt item has foremanctl marker
        ForemanConftest->>Settings: set(server.version.source, upstream)
        ForemanConftest->>Pytest: yield to next hook
        Pytest->>AutoVault: perform auto vault login using upstream
        AutoVault-->>Pytest: login complete
        Pytest-->>ForemanConftest: resume hook
        ForemanConftest->>Settings: set(server.version.source, internal)
    else item has no foremanctl marker
        ForemanConftest->>Pytest: yield to next hook
        Pytest->>AutoVault: perform normal behavior
        AutoVault-->>Pytest: complete
        Pytest-->>ForemanConftest: resume hook
    end

    Pytest->>Test: run test body
    Test-->>Pytest: result
Loading

File-Level Changes

Change Details Files
Scope the pytest_runtest_protocol hook to Foreman tests instead of applying it globally.
  • Remove pytest_runtest_protocol hook and settings dependency from the root-level conftest so it no longer affects all tests.
  • Add pytest_runtest_protocol hook implementation under tests/foreman/conftest.py to apply version source switching only when running Foreman tests marked with the foremanctl marker.
conftest.py
tests/foreman/conftest.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In pytest_runtest_protocol, rename the unused nextitem parameter to _nextitem (or remove it if not required by the hook signature) to make it clear it’s intentionally unused and avoid linter warnings.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `pytest_runtest_protocol`, rename the unused `nextitem` parameter to `_nextitem` (or remove it if not required by the hook signature) to make it clear it’s intentionally unused and avoid linter warnings.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@lpramuk

lpramuk commented Mar 26, 2026

Copy link
Copy Markdown
Contributor Author

trigger: test-robottelo
pytest: tests/foreman/installer/test_install_foremanctl.py

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14885
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/installer/test_install_foremanctl.py --external-logging
Test Result : ================= 14 passed, 66 warnings in 1863.70s (0:31:03) =================

@Satellite-QE Satellite-QE added the PRT-Passed Indicates that latest PRT run is passed for the PR label Mar 26, 2026

@ogajduse ogajduse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. I want @Gauravtalreja1 to take a look as well.

@ogajduse
ogajduse requested a review from Gauravtalreja1 March 26, 2026 21:48

@Gauravtalreja1 Gauravtalreja1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, thanks @lpramuk for fixing it.

@Gauravtalreja1
Gauravtalreja1 merged commit 07c349c into SatelliteQE:master Mar 30, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug This is an issue with the robottelo framework No-CherryPick PR doesnt need CherryPick to previous branches PRT-Passed Indicates that latest PRT run is passed for the PR Stream Introduced in or relating directly to Satellite Stream/Master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants