Skip to content

Comments

test: ensure interface chosen is managed by NetworkManager#326

Merged
richm merged 1 commit intolinux-system-roles:mainfrom
richm:test-find-interface-managed-by-nm
Feb 20, 2026
Merged

test: ensure interface chosen is managed by NetworkManager#326
richm merged 1 commit intolinux-system-roles:mainfrom
richm:test-find-interface-managed-by-nm

Conversation

@richm
Copy link
Contributor

@richm richm commented Feb 19, 2026

NetworkManager must be running for this test to work, so ensure it.

Ensure that the interface chosen is an active connected device managed by NM.

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

Summary by Sourcery

Ensure the firewall interface PCI test targets an active NetworkManager-managed PCI ethernet device and improves visibility of firewall ruleset changes.

Bug Fixes:

  • Select an active, connected ethernet interface backed by a real PCI device that is managed by NetworkManager before running firewall tests.
  • Guard the PCI interface test to only run when suitable PCI-backed interfaces are present.

Enhancements:

  • Unify NetworkManager installation and startup across supported distributions for the test environment.
  • Add detailed debugging of NetworkManager-managed devices and iptables ruleset changes around the test execution.
  • Refine assertions to use explicit interface paths and cached PCI IDs, and clean up temporary files after the test.

Tests:

  • Extend the interface discovery logic to handle multiple PCI-backed ethernet interfaces and match them to NetworkManager devices via UDI paths.

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 19, 2026

Reviewer's Guide

Test playbook is updated to select a PCI-backed ethernet interface that is actively managed and connected via NetworkManager, ensure NetworkManager is present and running across supported distros, wire that interface’s PCI ID and name into assertions, and add more robust debugging and cleanup around iptables/nftables and temp dirs.

File-Level Changes

Change Details Files
Revise interface discovery to collect all PCI-backed ethernet interfaces and select one that is connected and managed by NetworkManager, capturing both interface path and PCI ID for later use.
  • Replace single-interface discovery with a loop over /sys/class/net matching e* that have both vendor and device files, registering all candidate interface paths.
  • Introduce a shell task that, using nmcli, finds the first NetworkManager-managed device in connected state whose GENERAL.UDI resolves to the same device path as one of the discovered interfaces and extracts its vendor/product IDs.
  • Store the chosen interface path and PCI VID:PID pair from the nmcli-based selection task and expose them via iface_path and pci_id variables instead of using pci_id.stdout and find_iface.stdout.
tests/tests_interface_pci.yml
Ensure NetworkManager is installed and started for the test on all relevant platforms and simplify/eliminate EL7-specific setup.
  • Add generic package and service tasks to ensure NetworkManager is installed and running before nmcli is used.
  • Remove the EL7-only block that conditionally installed and started NetworkManager, relying instead on the unified tasks.
tests/tests_interface_pci.yml
Adjust firewall role invocations and assertions to use the new iface_path/pci_id variables and add stronger debugging and cleanup around iptables/nftables.
  • Update firewall role calls to pass interface_pci_id via the pci_id variable instead of pci_id.stdout.
  • Update nftables and iptables assertions to assert on iface_path
basename and pci_id (trimmed) instead of the prior find_iface/pci_id stdout variables.
  • Add pre- and post-test iptables ruleset capture with diff output when not using nftables, and ensure temporary directories are removed in the always block.
  • Refine changed_when conditions to keep diagnostic tasks from marking the play as changed while preserving debug output including nmcli device dumps.

  • 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 vars defined on the Test interfaces with PCI ids block (iface_path and pci_id) reference pci_id_result.stdout_lines[...] before pci_id_result is registered, which will fail at runtime; consider moving these into a separate set_fact task after the pci_id_result task.
    • The shell task that finds the first interface managed by NetworkManager uses the bash-specific [[ ... ]] test operator but does not specify executable: /bin/bash, which can break on systems where /bin/sh is not bash; either declare the bash executable or use POSIX-compliant [ ... ] syntax.
    Prompt for AI Agents
    Please address the comments from this code review:
    
    ## Overall Comments
    - The `vars` defined on the `Test interfaces with PCI ids` block (`iface_path` and `pci_id`) reference `pci_id_result.stdout_lines[...]` before `pci_id_result` is registered, which will fail at runtime; consider moving these into a separate `set_fact` task after the `pci_id_result` task.
    - The shell task that finds the first interface managed by NetworkManager uses the bash-specific `[[ ... ]]` test operator but does not specify `executable: /bin/bash`, which can break on systems where `/bin/sh` is not bash; either declare the bash executable or use POSIX-compliant `[ ... ]` syntax.

    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
    Copy link
    Contributor Author

    richm commented Feb 19, 2026

    [citest]

    @codecov
    Copy link

    codecov bot commented Feb 19, 2026

    Codecov Report

    ✅ All modified and coverable lines are covered by tests.
    ✅ Project coverage is 58.20%. Comparing base (2d7c4ba) to head (a85cd09).
    ⚠️ Report is 133 commits behind head on main.

    Additional details and impacted files
    @@            Coverage Diff             @@
    ##             main     #326      +/-   ##
    ==========================================
    - Coverage   61.09%   58.20%   -2.90%     
    ==========================================
      Files           2        2              
      Lines         910     1304     +394     
    ==========================================
    + Hits          556      759     +203     
    - Misses        354      545     +191     
    Flag Coverage Δ
    sanity ?

    Flags with carried forward coverage won't be shown. Click here to find out more.

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    🚀 New features to boost your workflow:
    • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
    • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

    NetworkManager must be running for this test to work, so ensure it.
    
    Ensure that the interface chosen is an active connected device managed by NM.
    
    Signed-off-by: Rich Megginson <rmeggins@redhat.com>
    @richm richm force-pushed the test-find-interface-managed-by-nm branch from 1ba7e9a to a85cd09 Compare February 19, 2026 22:32
    @richm
    Copy link
    Contributor Author

    richm commented Feb 19, 2026

    [citest]

    Copy link
    Contributor

    @spetrosi spetrosi left a comment

    Choose a reason for hiding this comment

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

    Bravo!

    @richm richm merged commit 868f4f0 into linux-system-roles:main Feb 20, 2026
    38 of 39 checks passed
    @richm richm deleted the test-find-interface-managed-by-nm branch February 20, 2026 13:57
    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.

    2 participants