Skip to content

net: adapt test helpers to Fedora 43#4873

Open
servolkov wants to merge 3 commits into
RedHatQE:mainfrom
servolkov:fix/fedora-43-fix-net
Open

net: adapt test helpers to Fedora 43#4873
servolkov wants to merge 3 commits into
RedHatQE:mainfrom
servolkov:fix/fedora-43-fix-net

Conversation

@servolkov
Copy link
Copy Markdown
Contributor

@servolkov servolkov commented May 15, 2026

What this PR does / why we need it:

Fix test failures caused by the Fedora 41 → 43 container image upgrade (PR #4322):

  1. Console output parsing broken — Fedora 43 (systemd 256+) emits OSC 8003
    session-tracking escape sequences. The ANSI regex in vm_console_run_commands
    only stripped CSI sequences, leaving OSC markers in parsed output. This caused
    json.loads() to fail in test_vm_is_started_with_successful_connectivity.

  2. IP lookup race conditionget_ip_from_vm_or_virt_handler_pod read
    vmi.interfaces[0]["ipAddresses"] once without waiting. Fedora 43's guest agent
    reports IPs slower than Fedora 41, so ipAddresses was still None right after
    AgentConnected became True, crashing test_connectivity_over_pod_network.

Which issue(s) this PR fixes:

failures from PR #4322

Special notes for reviewer:

Importing lookup_iface_status_ip from libs/net/vmspec into utilities/network.py was
blocked by the circular dependency caused by IfaceNotFound living in utilities/network.py.
IfaceNotFound was a single exception incorrectly covering both spec and status lookup
failures with a misleading "Interface not found for NAD" message. Replaced each usage
with the semantically correct exception.

Removing IfaceNotFound is a prerequisite for the race condition fix.

jira-ticket:

NONE

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved error handling for network interface lookups with clearer error messages
    • Enhanced VM console output display by filtering additional terminal escape sequences for better readability

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

📝 Walkthrough

Walkthrough

This PR consolidates NAD interface lookup exception handling by moving IfaceNotFound from utilities/network to libs/vm/spec, refactors VM IP resolution to use new lookup utilities from libs.net.vmspec, and enhances terminal escape sequence stripping in console output processing.

Changes

Exception Relocation and IP Resolution Refactoring

Layer / File(s) Summary
IfaceNotFound exception definition and wiring
libs/vm/spec.py, libs/vm/vm.py, utilities/network.py, tests/network/l2_bridge/libl2bridge.py, tests/network/l2_bridge/test_bridge_nic_hot_plug.py
New IfaceNotFound exception defined in libs/vm/spec.py with name storage and formatted message. All imports updated: added to libs/vm/vm.py, removed from utilities/network.py local definition, and test modules redirected to import from libs.vm.spec.
VM IP resolution refactoring
utilities/network.py
get_ip_from_vm_or_virt_handler_pod() refactored to extract interface name from vm.vmi.interfaces[0]["name"], call lookup_iface_status_ip() with derived ip_family parameter, and return None when IpNotFound is raised; imports updated to include IpNotFound and lookup_iface_status_ip from libs.net.vmspec.
Terminal output escape sequence handling
utilities/virt.py
ANSI regex pattern in vm_console_run_commands() extended to match OSC (operating system command) escape sequences in addition to existing CSI sequence stripping, broadening the set of terminal control codes removed from captured console output.

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
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 were added in this PR. The test file modified (test_bridge_nic_hot_plug.py) is pre-existing (+1/-1 import changes only). STP requirement applies only to NEW test files.
Title check ✅ Passed The title 'net: adapt test helpers to Fedora 43' clearly describes the main change (adapting network test helpers for Fedora 43 compatibility), relates directly to the PR objectives, meets the 120-character limit (36 chars), and accurately summarizes the essential purpose of the changeset.
Description check ✅ Passed The PR description covers all required template sections with substantial detail: problem statement (console parsing + race condition), specific fixes, file-level changes, and architectural decisions (circular dependency resolution).

✏️ 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-2
Copy link
Copy Markdown
Contributor

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
  • nirdothan
  • orelmisan
  • 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 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.67%. Comparing base (9b6c72f) to head (25c680a).
⚠️ Report is 64 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4873   +/-   ##
=======================================
  Coverage   98.67%   98.67%           
=======================================
  Files          25       25           
  Lines        2485     2487    +2     
=======================================
+ Hits         2452     2454    +2     
  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.

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 15, 2026
servolkov added 3 commits May 16, 2026 01:35
IfaceNotFound was a single exception incorrectly covering both spec
and status lookup failures with a misleading "Interface not found for
NAD" message. Replace each usage with the semantically correct
exception:

- VMInterfaceSpecNotFoundError for spec.domain.devices.interfaces
  lookups (libs/vm/vm.py)
- VMInterfaceStatusNotFoundError for vmi.status.interfaces lookups
  (utilities/network.py, tests/network/l2_bridge/)

This also eliminates the only libs/ -> utilities/network import,
breaking the circular dependency that prevented utilities/network.py
from importing libs/net/vmspec.

Signed-off-by: Sergei Volkov <sevolkov@redhat.com>
Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Fedora 43 (systemd 256+) emits OSC 8003 session-tracking escape
sequences in the terminal. The existing regex in vm_console_run_commands
only stripped CSI sequences (ESC[…), leaving OSC sequences (ESC]…) in
the parsed output. This broke any caller that parses console output,
e.g. json.loads() in ip_specification tests.

Extend the regex to also strip OSC sequences terminated by BEL or ST,
per ECMA-48 specification.

Signed-off-by: Sergei Volkov <sevolkov@redhat.com>
Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
The function read vm.vmi.interfaces[0]["ipAddresses"] once without
waiting. With Fedora 43 the guest agent reports IPs slower than
Fedora 41, so ipAddresses is still None right after AgentConnected
becomes True, causing TypeError on iteration.

Delegate the VM branch to lookup_iface_status_ip which polls the VMI
with a watcher until IPs are reported.

Signed-off-by: Sergei Volkov <sevolkov@redhat.com>
Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread libs/net/vmspec.py
from libs.vm.spec import Network
from libs.vm.vm import BaseVirtualMachine

if TYPE_CHECKING:
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.

IIUC, this is done to avoid the enforcement of circular imports.
The commit message says, from what I understand, that what was cirucalrly imported is IfaceNotFound, so why does the import of BaseVirtualMachine need this defense?
I am confused...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you are right to be confused. In reality a general crucially import issue is resolved by this PR - utilities use libs code and no libs that use utilities code. We are good here.

The current TYPE_CHECKING is for type annotations only, no real code is used. We could also use 'BaseVirtualMachine'(quotes) as type annotation to avoid this TYPE_CHECKING and real BaseVirtualMachine import, but I don't have strong opinion here.

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.

This is a workaround, why can't we just fix it?
Conditional imports is a smell, the dependency is there in a cycle even if you do not see it.
That network utility needs to be taken down.

Here is my attempt to help in this: #4906

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here is my attempt to help in this: #4906

@EdDev Could you explain how your PR relates to the current thread?

Comment thread libs/vm/vm.py
def set_interface_state(self, network_name: str, state: str) -> None:
if not self._spec.template.spec.domain.devices:
raise IfaceNotFound(name=network_name)
raise VMInterfaceSpecNotFoundError(f"Interface {network_name} not found in VM {self.name} spec")
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.

Nice catch!
Separating SpecNotFound from StatusNotFound sounds like the correct approach.
+1

@nestoracunablanco
Copy link
Copy Markdown
Contributor

Tested using #4759 , (rebased onto this changes)
This change fix the Fedora43 related errors.
Once merged, I would like to follow up on the discussion in #4322

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

/retest all

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

Overlapping files

utilities/virt.py

@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/libl2bridge.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.

9 participants