Skip to content

Comments

fix: el7 interface functionality requires NetworkManager#323

Merged
richm merged 1 commit intolinux-system-roles:mainfrom
richm:fix-need-nm-el7
Feb 18, 2026
Merged

fix: el7 interface functionality requires NetworkManager#323
richm merged 1 commit intolinux-system-roles:mainfrom
richm:fix-need-nm-el7

Conversation

@richm
Copy link
Contributor

@richm richm commented Feb 17, 2026

Cause: NetworkManager is not installed on some EL7 systems by default.

Consequence: The interface_pci_id could not be found.

Fix: Ensure NetworkManager is installed on EL7.

Result: The interface_pci_id can be used on EL7.

Also - module.warn is deprecated - use warnings instead if module.warn is
not supported.

Fix the interface pci test to ensure NetworkManager is running before the test.

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

Summary by Sourcery

Ensure interface_pci_id functionality works reliably on EL7 systems and surface deprecation warnings without relying on module.warn support.

Bug Fixes:

  • Ensure NetworkManager is installed and running on EL7 so interface_pci_id lookups succeed.
  • Return interface_pci_id lookup warnings via the module result when module.warn is unavailable.
  • Gate nftables ruleset checks in the interface PCI test on nftables backend availability.

Enhancements:

  • Pass accumulated warning messages through the firewall module’s exit_json payload for consumers to inspect.
  • Refine interface PCI ID parsing to return both interface names and an optional warning message.

Tests:

  • Update the interface PCI integration test to install/start NetworkManager on EL7 and to use shared distro vars for backend detection.

Chores:

  • Adjust package defaults to include NetworkManager and python-ipaddress on EL7 to support interface_pci_id and ipaddress usage.

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 17, 2026

Reviewer's Guide

Ensures NetworkManager is installed and running on EL7 for interface_pci_id support, refactors PCI ID parsing and warning handling to work without module.warn, and updates tests and vars to match the new behavior and EL7 requirements.

Class diagram for updated firewall_lib PCI ID parsing and warnings

classDiagram
  class FirewallLibModule {
    +parse_pci_id(module, item) tuple
    +main() void
  }

  class AnsibleModule {
    +params dict
    +warn(message)
    +fail_json(msg)
    +exit_json(changed, __firewall_changed, warnings)
  }

  class ParsePciIdResult {
    +interface_names list
    +warning string
  }

  FirewallLibModule ..> AnsibleModule : uses
  FirewallLibModule ..> ParsePciIdResult : returns

  %% Details of parse_pci_id behavior
  class parse_pci_id_behavior {
    +validate_online_mode()
    +match_pci_regex(item)
    +get_interface_pci()
    +handle_found_interface()
    +handle_missing_interface_with_warn()
    +handle_invalid_format()
  }

  FirewallLibModule ..> parse_pci_id_behavior : implements

  %% Details inside main related to warnings and interface_pci_id
  class main_behavior {
    +warnings list
    +handle_allow_zone_drifting_deprecated()
    +iterate_interface_pci_ids()
    +append_interfaces(interface_names)
    +collect_warnings(warning)
    +exit_with_warnings()
  }

  FirewallLibModule ..> main_behavior : implements

  class AllowZoneDriftingHandling {
    +check_firewalld_conf()
    +check_version()
    +call_module_warn_or_collect_warning()
  }

  main_behavior ..> AllowZoneDriftingHandling : uses
  AllowZoneDriftingHandling ..> AnsibleModule : uses warn()

  class InterfacePciIdHandling {
    +call_parse_pci_id()
    +extend_interface_param()
    +collect_pci_warnings()
  }

  main_behavior ..> InterfacePciIdHandling : uses
  InterfacePciIdHandling ..> FirewallLibModule : calls parse_pci_id()
  InterfacePciIdHandling ..> AnsibleModule : uses params
Loading

File-Level Changes

Change Details Files
Refactor PCI ID parsing to return both interface names and an optional warning, and to only use module.warn when available.
  • Initialize a local warning accumulator in parse_pci_id and change its return value from just a list to a tuple of (interface_names, warning).
  • On successful PCI match, look up interface names from cached PCI IDs and return them with an empty warning if found.
  • When no interface is found, build a warning string and call module.warn only if it is available and callable; otherwise preserve the warning string to be handled by the caller.
  • Ensure parse_pci_id always returns a tuple, returning ([], warning) on error paths instead of just an empty list.
library/firewall_lib.py
Introduce centralized warnings collection in main(), propagating warnings from PCI parsing and deprecation messages into the module result.
  • Create a warnings list in main() to aggregate messages that cannot be emitted via module.warn.
  • Wrap existing AllowZoneDrifting deprecation warning with a check for module.warn; fall back to appending the message to the warnings list when module.warn is unavailable.
  • Consume the (interface_names, warning) tuple from parse_pci_id, appending any non-empty warning string to the warnings list while still extending the interface list.
  • Include the aggregated warnings list in module.exit_json so callers can see warnings even when module.warn is not supported.
library/firewall_lib.py
Update interface_pci tests to ensure NetworkManager is installed and running on EL7 and to gate nftables-specific steps on nftables availability.
  • Run the test play with become: true, enable fact gathering, and load common distro vars from vars/rh_distros_vars.yml.
  • Simplify nftables_backend computation using __firewall_is_rh_distro and distribution_major_version, and guard nft dump/compare tasks with this flag.
  • Add an EL7-specific setup block that installs and starts NetworkManager when running on RHEL-compatible distributions with major version less than 8.
  • Keep the role invocation for adding a PCI device ethernet controller but rely on the updated environment and facts.
tests/tests_interface_pci.yml
Ensure NetworkManager and python-ipaddress are installed as extra packages on EL7 and earlier.
  • Document that NetworkManager is required for interface_pci_id and python-ipaddress is required for the ipaddress module, and that these are built-in on EL8+.
  • Update __firewall_packages_extra to include both NetworkManager and python-ipaddress for RHEL-like systems with major version less than 8, and no extras otherwise.
vars/main.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:

  • Installing NetworkManager unconditionally in __firewall_packages_extra for all RHEL/CentOS < 8 may be heavier than necessary; consider scoping this dependency to cases where interface_pci_id functionality is actually used (e.g., via a separate variable or conditional include) to avoid forcing it on all consumers.
  • The pattern callable(getattr(module, 'warn', None)) is now repeated in several places; consider extracting a small helper (e.g., _emit_warning(module, msg, warnings_list)) to centralize the logic for using module.warn vs. accumulating in the warnings list.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Installing `NetworkManager` unconditionally in `__firewall_packages_extra` for all RHEL/CentOS < 8 may be heavier than necessary; consider scoping this dependency to cases where `interface_pci_id` functionality is actually used (e.g., via a separate variable or conditional include) to avoid forcing it on all consumers.
- The pattern `callable(getattr(module, 'warn', None))` is now repeated in several places; consider extracting a small helper (e.g., `_emit_warning(module, msg, warnings_list)`) to centralize the logic for using `module.warn` vs. accumulating in the `warnings` list.

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.

@codecov
Copy link

codecov bot commented Feb 17, 2026

Codecov Report

❌ Patch coverage is 61.11111% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.20%. Comparing base (2d7c4ba) to head (ed321a9).
⚠️ Report is 131 commits behind head on main.

Files with missing lines Patch % Lines
library/firewall_lib.py 61.11% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #323      +/-   ##
==========================================
- 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.

@richm
Copy link
Contributor Author

richm commented Feb 17, 2026

[citest]

@richm
Copy link
Contributor Author

richm commented Feb 17, 2026

[citest]

Cause: NetworkManager is not installed on some EL7 systems by default.

Consequence: The interface_pci_id could not be found.

Fix: Ensure NetworkManager is installed on EL7.

Result: The interface_pci_id can be used on EL7.

Also - `module.warn` is deprecated - use `warnings` instead if `module.warn` is
not supported.

Fix the interface pci test to ensure NetworkManager is running before the test.

add warnings parameter for tests

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
@richm
Copy link
Contributor Author

richm commented Feb 17, 2026

[citest]

@richm
Copy link
Contributor Author

richm commented Feb 17, 2026

[citest_bad]

1 similar comment
@richm
Copy link
Contributor Author

richm commented Feb 17, 2026

[citest_bad]

@richm richm merged commit 608ccc9 into linux-system-roles:main Feb 18, 2026
38 of 39 checks passed
@richm richm deleted the fix-need-nm-el7 branch February 18, 2026 18:36
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