Skip to content

network: remove VMI MAC lookup helper from utilities/network#4906

Open
EdDev wants to merge 1 commit into
RedHatQE:mainfrom
EdDev:network/replace-get-vmi-mac-with-lookup-iface-status
Open

network: remove VMI MAC lookup helper from utilities/network#4906
EdDev wants to merge 1 commit into
RedHatQE:mainfrom
EdDev:network/replace-get-vmi-mac-with-lookup-iface-status

Conversation

@EdDev
Copy link
Copy Markdown
Contributor

@EdDev EdDev commented May 18, 2026

What this PR does / why we need it:

Callers of utilities/network should not depend on it for MAC address lookups when libs/net/vmspec already provides the right abstraction. This removes get_vmi_mac_address_by_iface_name and replaces all call sites with lookup_iface_status using a no-op predicate and a short timeout (1s).

Which issue(s) this PR fixes:
Special notes for reviewer:
jira-ticket:

Summary by CodeRabbit

  • Tests

    • Updated network connectivity test suite including kubemacpool, L2 bridge, and network upgrade scenarios to use improved interface status lookup mechanism for MAC address verification and validation.
  • Refactor

    • Removed legacy MAC address lookup utility function from core network utilities, streamlining the codebase.

Review Change Stack

Callers of utilities/network should not depend on it for MAC address
lookups when libs/net/vmspec already provides the right abstraction.

Replace get_vmi_mac_address_by_iface_name with lookup_iface_status
using a no-op predicate and a short timeout (1s), reading .mac from
the VMI status interface.

Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Edward Haas <edwardh@redhat.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

📝 Walkthrough

Walkthrough

This PR replaces all calls to the deprecated get_vmi_mac_address_by_iface_name() helper with lookup_iface_status() across kubemacpool, l2_bridge, and upgrade test modules, then removes the old helper function from utilities. The refactoring standardizes MAC address retrieval to use the vmspec interface status API.

Changes

MAC Lookup Refactoring

Layer / File(s) Summary
Remove deprecated helper and update utility signatures
utilities/network.py, tests/network/kubemacpool/utils.py
get_vmi_mac_address_by_iface_name() is removed from utilities. Kubemacpool test utilities assert_macs_preseved and assert_manual_mac_configured are refactored to call lookup_iface_status() with timeout=1 and extract .mac from the returned status object.
Update kubemacpool test cases
tests/network/kubemacpool/test_kubemacpool.py
All six test cases (pod masquerade, default auto-MAC, tuning auto-MAC, label-enabled namespace, label-absent namespace, and disabled assignment namespace) now call lookup_iface_status(..., predicate=lambda _: True, timeout=1).mac instead of the old VMI-based lookup.
Update l2_bridge and upgrade test files
tests/network/l2_bridge/conftest.py, tests/network/upgrade/test_upgrade_network.py
DHCP server config and kubemacpool before/after upgrade tests import lookup_iface_status and apply the same refactored MAC retrieval pattern, removing references to the old helper.

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and directly summarizes the main change: removing a VMI MAC lookup helper from utilities/network and is well under the 120 character limit.
Description check ✅ Passed The PR description adequately addresses the template's main sections with clear explanation of changes and rationale, though jira-ticket field is incomplete.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stp Link Required ✅ Passed No new test files or functions added. All changes are modifications to existing tests. Check requirement does not apply to this PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-virtualization-qe-bot-4
Copy link
Copy Markdown

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: A tracking issue is created for this PR and will be closed when the PR is merged or closed
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified
  • Labels: Enabled categories: branch, can-be-merged, cherry-pick, has-conflicts, hold, needs-rebase, size, verified, wip

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status
  • /reprocess - Trigger complete PR workflow reprocessing (useful if webhook failed or configuration changed)
  • /regenerate-welcome - Regenerate this welcome message

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest build-container - Rebuild and test container image
  • /retest verify-bugs-are-open - verify-bugs-are-open
  • /retest all - Run all available tests

Container Operations

  • /build-and-push-container - Build and push container image (tagged with PR number)
    • Supports additional build arguments: /build-and-push-container --build-arg KEY=value

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. LGTM Count: Minimum 2 /lgtm from reviewers
  3. Status Checks: All required status checks must pass
  4. No Blockers: No wip, hold, has-conflicts labels and PR must be mergeable (no conflicts)
  5. Verified: PR must be marked as verified

📊 Review Process

Approvers and Reviewers

Approvers:

  • EdDev
  • dshchedr
  • myakove
  • rnetser
  • vsibirsk

Reviewers:

  • Anatw
  • EdDev
  • RoniKishner
  • azhivovk
  • dshchedr
  • frenzyfriday
  • geetikakay
  • hmeir
  • nirdothan
  • orelmisan
  • rlobillo
  • rnetser
  • servolkov
  • vsibirsk
  • yossisegev
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
AI Features
  • Cherry-Pick Conflict Resolution: Enabled (claude/claude-opus-4-6[1m])

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is removed on new commits unless the push is detected as a clean rebase
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Container Builds: Container images are automatically tagged with the PR number
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.67%. Comparing base (d8d6ae3) to head (0524123).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4906      +/-   ##
==========================================
- Coverage   98.68%   98.67%   -0.01%     
==========================================
  Files          25       25              
  Lines        2504     2487      -17     
==========================================
- Hits         2471     2454      -17     
  Misses         33       33              
Flag Coverage Δ
utilities 98.67% <ø> (-0.01%) ⬇️

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/network/kubemacpool/test_kubemacpool.py`:
- Around line 47-51: The assert calling mac_pool.mac_is_within_range using
lookup_iface_status(...).mac should include a descriptive failure message;
update the assertion (and other similar asserts in this file) to pass a message
that includes VM identity and interface name (use vm.name or vm identifier and
vm.default_masquerade_iface_config.name) so test failures show which
VM/interface and MAC were out of range; locate uses of
mac_pool.mac_is_within_range and lookup_iface_status in this test and append an
f-string message describing vm, iface and the MAC value.

In `@tests/network/kubemacpool/utils.py`:
- Around line 148-151: The test assertions comparing MAC addresses lack failure
messages, making CI failures hard to triage; update the asserts around the MAC
checks (the one comparing iface.macAddress with lookup_iface_status(vm=vm,
iface_name=iface.name, ...) and the similar assert at the other block) to
include descriptive pytest failure messages that embed identifying context such
as vm (name/UID/namespace), iface.name, the expected value (iface.macAddress)
and the actual value returned by lookup_iface_status(). Use the same unique
symbols seen in the diff (iface.macAddress, iface.name, lookup_iface_status, vm)
so failures clearly show which VM/interface and what expected vs actual MAC
failed.

In `@tests/network/upgrade/test_upgrade_network.py`:
- Around line 86-90: The mac range assertions using mac_pool.mac_is_within_range
and lookup_iface_status(vm=vm, iface_name=upgrade_bridge_marker_nad.name, ...)
lack descriptive failure messages; update those assertions (including the
similar ones around the later block) to pass a clear pytest failure message that
includes VM identity (e.g., vm.name or vm.metadata.name), the interface name
(upgrade_bridge_marker_nad.name), and the observed MAC so that failures show
which VM/interface and which MAC fell outside the pool.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b6fea538-a825-4d42-8769-5d8bb2f54750

📥 Commits

Reviewing files that changed from the base of the PR and between 33ecd81 and 0524123.

📒 Files selected for processing (5)
  • tests/network/kubemacpool/test_kubemacpool.py
  • tests/network/kubemacpool/utils.py
  • tests/network/l2_bridge/conftest.py
  • tests/network/upgrade/test_upgrade_network.py
  • utilities/network.py
💤 Files with no reviewable changes (1)
  • utilities/network.py

Comment on lines 47 to 51
assert mac_pool.mac_is_within_range(
mac=get_vmi_mac_address_by_iface_name(vmi=vm.vmi, iface_name=vm.default_masquerade_iface_config.name),
mac=lookup_iface_status(
vm=vm, iface_name=vm.default_masquerade_iface_config.name, predicate=lambda _: True, timeout=1
).mac,
)
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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

MEDIUM: Include failure message in MAC-range assertions

Please add a descriptive message to this assert (and the same pattern in similar updated checks in this file) so failures report VM/interface context directly.

As per coding guidelines: tests/**/*.py: include assertion failure messages in pytest asserts.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/network/kubemacpool/test_kubemacpool.py` around lines 47 - 51, The
assert calling mac_pool.mac_is_within_range using lookup_iface_status(...).mac
should include a descriptive failure message; update the assertion (and other
similar asserts in this file) to pass a message that includes VM identity and
interface name (use vm.name or vm identifier and
vm.default_masquerade_iface_config.name) so test failures show which
VM/interface and MAC were out of range; locate uses of
mac_pool.mac_is_within_range and lookup_iface_status in this test and append an
f-string message describing vm, iface and the MAC value.

Comment on lines +148 to +151
assert (
iface.macAddress
== lookup_iface_status(vm=vm, iface_name=iface.name, predicate=lambda _: True, timeout=1).mac
)
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

HIGH: Add assertion failure context for MAC validation

These asserts currently fail without resource/interface context, which makes failures harder to triage in CI. Please add explicit failure messages.

Proposed patch
 def assert_macs_preseved(vm):
     for iface in vm.get_interfaces():
         assert (
             iface.macAddress
             == lookup_iface_status(vm=vm, iface_name=iface.name, predicate=lambda _: True, timeout=1).mac
-        )
+        ), f"MAC mismatch on VM {vm.name}, interface {iface.name}: expected {iface.macAddress}"

 def assert_manual_mac_configured(vm, iface_config):
     assert (
         iface_config.mac_address
         == lookup_iface_status(vm=vm, iface_name=iface_config.name, predicate=lambda _: True, timeout=1).mac
-    )
+    ), f"Manual MAC mismatch on VM {vm.name}, interface {iface_config.name}: expected {iface_config.mac_address}"

As per coding guidelines: tests/**/*.py: Use pytest assertions with failure messages (assert condition, 'descriptive message explaining failure').

Also applies to: 155-158

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/network/kubemacpool/utils.py` around lines 148 - 151, The test
assertions comparing MAC addresses lack failure messages, making CI failures
hard to triage; update the asserts around the MAC checks (the one comparing
iface.macAddress with lookup_iface_status(vm=vm, iface_name=iface.name, ...) and
the similar assert at the other block) to include descriptive pytest failure
messages that embed identifying context such as vm (name/UID/namespace),
iface.name, the expected value (iface.macAddress) and the actual value returned
by lookup_iface_status(). Use the same unique symbols seen in the diff
(iface.macAddress, iface.name, lookup_iface_status, vm) so failures clearly show
which VM/interface and what expected vs actual MAC failed.

Comment on lines 86 to 90
assert mac_pool.mac_is_within_range(
mac=get_vmi_mac_address_by_iface_name(vmi=vm.vmi, iface_name=upgrade_bridge_marker_nad.name)
mac=lookup_iface_status(
vm=vm, iface_name=upgrade_bridge_marker_nad.name, predicate=lambda _: True, timeout=1
).mac
)
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

HIGH: Add descriptive messages to kubemacpool range assertions

Both updated assertions should include failure messages with VM/interface details to make upgrade-failure triage actionable.

As per coding guidelines: tests/**/*.py: pytest assertions must include failure messages.

Also applies to: 195-199

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/network/upgrade/test_upgrade_network.py` around lines 86 - 90, The mac
range assertions using mac_pool.mac_is_within_range and
lookup_iface_status(vm=vm, iface_name=upgrade_bridge_marker_nad.name, ...) lack
descriptive failure messages; update those assertions (including the similar
ones around the later block) to pass a clear pytest failure message that
includes VM identity (e.g., vm.name or vm.metadata.name), the interface name
(upgrade_bridge_marker_nad.name), and the observed MAC so that failures show
which VM/interface and which MAC fell outside the pool.

@openshift-virtualization-qe-bot-3
Copy link
Copy Markdown
Contributor

/retest all

Auto-triggered: Files in this PR were modified by merged PR #4772.

Overlapping files

tests/network/l2_bridge/conftest.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants