Skip to content

test: allow test to work with external proxy#263

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

test: allow test to work with external proxy#263
richm wants to merge 1 commit intolinux-system-roles:mainfrom
richm:proxy

Conversation

@richm
Copy link
Contributor

@richm richm commented Mar 2, 2026

SR_RHC_EXTERNAL_PROXY is the host:port of an external proxy that does not
require authentication.

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

Summary by Sourcery

Adjust proxy-related tests to support running with or without an external unauthenticated proxy configured via environment variables.

Tests:

  • Gate authenticated proxy test blocks and no-proxy registration tests on the absence of the SR_RHC_EXTERNAL_PROXY environment variable.
  • Add test setup that configures system and RHSM service-wide HTTP/HTTPS proxy settings when SR_RHC_EXTERNAL_PROXY is set.
  • Update SELinux port cleanup to exclude the standard Squid port from removal when managing proxy-related ports.

`SR_RHC_EXTERNAL_PROXY` is the host:port of an external proxy that does not
require authentication.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
@richm richm requested a review from ptoscano as a code owner March 2, 2026 22:31
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 2, 2026

Reviewer's Guide

Updates proxy-related tests to optionally use an externally-provided non-authenticating proxy via SR_RHC_EXTERNAL_PROXY, while keeping authenticated-proxy negative tests gated to the internal Squid setup, and adds host/systemd configuration to route rhsm traffic through the external proxy when provided.

File-Level Changes

Change Details Files
Gate authenticated-proxy negative tests on absence of an external proxy and encapsulate them in a higher-level block.
  • Wrap setup of authenticated Squid and all negative registration attempts (missing credentials, wrong username/password variants) in a parent block that only runs when SR_RHC_EXTERNAL_PROXY is unset or empty.
  • Retain existing include_role calls and rescue/assert logic for each negative test case, just changing their indentation and grouping under the conditional block.
tests/tests_proxy.yml
Make certain tests conditional when an external proxy is in use and adjust SELinux port removal to avoid removing the standard Squid port when it may be externally managed.
  • Add a when condition to the 'Register (without proxy)' task so it only runs when SR_RHC_EXTERNAL_PROXY is unset or empty.
  • Introduce an intermediate remove_port_list variable that filters out port 3128 from __proxy_port_list before passing it to the selinux_ports list used to remove ports.
tests/tests_proxy.yml
Add external proxy setup tasks that configure environment and rhsm systemd service to use an externally provided proxy from SR_RHC_EXTERNAL_PROXY.
  • Read SR_RHC_EXTERNAL_PROXY into a __proxy variable and derive http_proxy/https_proxy URLs, running the block only when the variable is non-empty.
  • Ensure /root/.bashrc exports http_proxy and https_proxy, creating the file if necessary.
  • Create /etc/systemd/system/rhsm.service.d and write a proxy.conf drop-in with http_proxy/https_proxy environment settings for rhsm.service.
  • Restart rhsm.service with daemon_reload when the proxy configuration changes and verify service status without marking it as changed.
tests/tasks/setup_test_data.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:

  • You repeat the lookup('env', 'SR_RHC_EXTERNAL_PROXY') | length == 0 condition in multiple places; consider setting a fact once (e.g. __external_proxy_present) and reusing it to simplify the play and avoid multiple env lookups.
  • Instead of directly restarting rhsm.service in the same block where you manage /etc/systemd/system/rhsm.service.d/proxy.conf, consider using a handler notified by the copy task, which will better align with Ansible’s handler semantics and avoid the need for # noqa no-handler.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- You repeat the `lookup('env', 'SR_RHC_EXTERNAL_PROXY') | length == 0` condition in multiple places; consider setting a fact once (e.g. `__external_proxy_present`) and reusing it to simplify the play and avoid multiple env lookups.
- Instead of directly restarting `rhsm.service` in the same block where you manage `/etc/systemd/system/rhsm.service.d/proxy.conf`, consider using a handler notified by the copy task, which will better align with Ansible’s handler semantics and avoid the need for `# noqa no-handler`.

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.

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