Skip to content

test: support an external proxy#266

Open
richm wants to merge 1 commit intolinux-system-roles:mainfrom
richm:test-support-external-proxy
Open

test: support an external proxy#266
richm wants to merge 1 commit intolinux-system-roles:mainfrom
richm:test-support-external-proxy

Conversation

@richm
Copy link
Contributor

@richm richm commented Mar 11, 2026

This PR allows to specify an external global proxy for testing purposes.
The format of SR_RHC_EXTERNAL_PROXY is scheme://hostname.port e.g.
http://my.hostname.com:3128

Signed-off-by: Rich Megginson rmeggins@redhat.com

Summary by Sourcery

Add support in the test playbooks for using an externally provided proxy via environment configuration.

New Features:

  • Allow tests to consume an external proxy definition from the SR_RHC_EXTERNAL_PROXY environment variable and expose it as rhc_proxy to the rhc role.

Enhancements:

  • Populate root shell proxy environment variables when an external proxy is configured, and default rhc_external_proxy to an empty structure when no proxy is set.
  • Skip the proxy-free registration test when an external proxy is defined so tests remain valid under proxied environments.
  • Tighten certain test failure conditions by explicitly checking non-zero match counts instead of relying on truthiness.

@richm richm requested a review from ptoscano as a code owner March 11, 2026 17:22
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 11, 2026

Reviewer's Guide

Adds support for using an externally specified HTTP(S) proxy during tests by parsing the SR_RHC_EXTERNAL_PROXY environment variable into a structured fact and wiring it through all role invocations, plus small fixes to test assertions and proxy-related test flow.

File-Level Changes

Change Details Files
Introduce parsing of SR_RHC_EXTERNAL_PROXY and expose it as rhc_external_proxy test fact, also exporting shell proxy vars.
  • Lookup SR_RHC_EXTERNAL_PROXY from the environment and conditionally execute a block when it is non-empty.
  • Use urlsplit filter to extract scheme, hostname, and port into rhc_external_proxy fact, defaulting port to an empty string when absent.
  • Append http_proxy and https_proxy export lines to /root/.bashrc using lineinfile so shell sessions inherit the external proxy.
  • Ensure rhc_external_proxy is explicitly set to an empty dict when SR_RHC_EXTERNAL_PROXY is unset to provide a consistent default.
tests/tasks/setup_test_data.yml
Thread rhc_external_proxy into all relevant test role invocations as rhc_proxy input.
  • Pass rhc_proxy: "{{ rhc_external_proxy
default({}) }}" into release-related test role invocations.
  • Pass the same rhc_proxy value into register/unregister, insights, environments, repositories, and remediation test roles so they honor the external proxy when set.
  • Use default({}) to keep existing behavior unchanged when SR_RHC_EXTERNAL_PROXY is not provided.
  • Adjust proxy-specific and insights tests for compatibility with the external proxy setting and Ansible return types.
    • Skip the "Register (without proxy)" test case in tests_proxy.yml whenever SR_RHC_EXTERNAL_PROXY is set to avoid conflicting expectations about proxy usage.
    • Update failed_when expressions that previously relied on truthiness of .found to explicitly compare against 0, aligning with the actual type/value returned by the lookup/check task.
    tests/tests_proxy.yml
    tests/tests_insights_ansible_host.yml
    tests/tests_insights_display_name.yml

    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

    Copy link

    @sourcery-ai sourcery-ai bot left a comment

    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:

    • The SR_RHC_EXTERNAL_PROXY environment variable is looked up and its length checked multiple times (including inside the block and again in the final set_fact); consider centralizing this into a single fact or variable to avoid redundant lookups and make the control flow easier to follow.
    • The lineinfile task that adds http_proxy/https_proxy to /root/.bashrc does not constrain matches with a regexp, so reruns can create duplicate export lines; consider using a regexp to update existing lines in place and keep the file idempotent.
    Prompt for AI Agents
    Please address the comments from this code review:
    
    ## Overall Comments
    - The `SR_RHC_EXTERNAL_PROXY` environment variable is looked up and its length checked multiple times (including inside the block and again in the final `set_fact`); consider centralizing this into a single fact or variable to avoid redundant lookups and make the control flow easier to follow.
    - The `lineinfile` task that adds `http_proxy`/`https_proxy` to `/root/.bashrc` does not constrain matches with a `regexp`, so reruns can create duplicate export lines; consider using a `regexp` to update existing lines in place and keep the file idempotent.

    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.

    @richm richm force-pushed the test-support-external-proxy branch from 71c4a2c to 46a0bb7 Compare March 11, 2026 20:07
    @richm
    Copy link
    Contributor Author

    richm commented Mar 11, 2026

    [citest]

    @richm
    Copy link
    Contributor Author

    richm commented Mar 12, 2026

    [citest]

    This PR allows to specify an external global proxy for testing purposes.
    The format of `SR_RHC_EXTERNAL_PROXY` is scheme://hostname.port e.g.
    `http://my.hostname.com:3128`
    
    Signed-off-by: Rich Megginson <rmeggins@redhat.com>
    @richm richm force-pushed the test-support-external-proxy branch from d946be8 to 19927f6 Compare March 13, 2026 17:11
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    None yet

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant