Skip to content

net, libs: Refactor modules and add new lib helper#5072

Open
azhivovk wants to merge 3 commits into
RedHatQE:mainfrom
azhivovk:net-refactor-shared-libs
Open

net, libs: Refactor modules and add new lib helper#5072
azhivovk wants to merge 3 commits into
RedHatQE:mainfrom
azhivovk:net-refactor-shared-libs

Conversation

@azhivovk
Copy link
Copy Markdown
Contributor

@azhivovk azhivovk commented May 31, 2026

What this PR does / why we need it:

Upcoming NAD live update metric test requires usage of existing network setup (NNCP, NAD).
This change promotes shared network infrastructure from test-specific locations to the shared libs layer so any test suite can use them without cross-package imports.

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

Network tests which use existing VLAN fixtures will be adjusted to the new cluster.py VLAN helper in a follow-up, as this PR is planned to be backported to 4.22 and will affect network tests.
New VLAN fixture will be used in the upcoming NAD live update metric test.

Exception ticket to backport to 4.22: https://redhat.atlassian.net/browse/CNV-88886

jira-ticket: -

Summary by CodeRabbit

  • New Features

    • Added VLAN iterator functionality for efficient VLAN management.
    • Introduced new test fixture for VLAN index consumption in test suite.
  • Chores

    • Reorganized internal module imports and consolidated shared utilities.
    • Updated type annotations for consistency and clarity.

@qodo-code-review
Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

PR consolidates test-local library imports to shared libs/net/ modules across multiple test configurations, introduces a VLAN iterator for cluster configuration management, updates type annotations for VMI condition functions from BaseVirtualMachine to VirtualMachine, and connects the VLAN iterator to test fixtures.

Changes

Network library consolidation and VLAN iterator

Layer / File(s) Summary
VLAN iterator feature and test fixture
libs/net/cluster.py, tests/conftest.py
New cluster_vlan_iterator() generator yields VLAN IDs from cluster config via cached _cluster_vlans() helper that normalizes comma-separated or list-formatted VLAN configs. New module-scoped next_vlan_index_number pytest fixture wraps the iterator for test injection.
VMI condition function parameter type narrowing
libs/net/vmspec.py
Parameter type for vm in wait_for_vmi_condition_status() and wait_for_no_vmi_condition() narrowed from BaseVirtualMachine to VirtualMachine; function behavior unchanged.
Shared library import consolidation
libs/net/nodenetworkconfigurationpolicy.py, tests/network/libs/cloudinit.py, tests/network/libs/cluster_user_defined_network.py, tests/network/bgp/conftest.py, tests/network/l2_bridge/conftest.py, tests/network/l2_bridge/bandwidth/conftest.py, tests/network/l2_bridge/migration_stuntime/conftest.py, tests/network/l2_bridge/nad_ref_change/conftest.py, tests/network/localnet/conftest.py, tests/network/localnet/ipam/conftest.py, tests/network/localnet/liblocalnet.py
Migrates dict_normalization_for_dataclass imports from tests.network.libs.apimachinery to production libs.net.apimachinery in utility modules; migrates NodeNetworkConfigurationPolicy (aliased libnncp) from test-local tests.network.libs.nodenetworkconfigurationpolicy to shared libs.net.nodenetworkconfigurationpolicy across all test conftest.py files. All downstream fixture and type annotation usage remains unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

The PR consists primarily of repetitive import path migrations (13 files following an identical pattern) paired with one small new VLAN iterator feature and two straightforward type annotation updates. Imports are low-risk structural changes with no logic mutations; the iterator is modest in complexity (caching, normalization, yielding); type narrowing is a simple signature adjustment. Homogeneous refactoring across many files reduces per-file review effort.

Possibly related PRs

  • RedHatQE/openshift-virtualization-tests#4962: Introduced the wait_for_vmi_condition_status() and wait_for_no_vmi_condition() functions with BaseVirtualMachine parameter types that are now being narrowed to VirtualMachine in this PR.

Suggested reviewers

  • orelmisan
  • yossisegev
  • Anatw
  • dshchedr
  • nirdothan
  • servolkov
  • EdDev
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly describes the main change: refactoring network modules to a shared libs layer and adding a new VLAN helper utility.
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 (test_.py) or test functions (def test_) added. Only library, config, fixture, and helper modules modified, not subject to STP requirement.
Description check ✅ Passed The pull request description covers all required template sections with clear explanations of what the PR does, its rationale, special reviewer notes, and relevant context.

✏️ 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
  • 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.

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

Clean rebase detected — no code changes compared to previous head (f44793f).

@azhivovk
Copy link
Copy Markdown
Contributor Author

Change: rebase and fix checks errors

@azhivovk
Copy link
Copy Markdown
Contributor Author

Change: refactor imports as suggested by coderabbit

Copy link
Copy Markdown
Contributor

@Anatw Anatw left a comment

Choose a reason for hiding this comment

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

Thank you Asia!

@azhivovk
Copy link
Copy Markdown
Contributor Author

azhivovk commented May 31, 2026

/verified
verified correct collection due to move of imports
uv run pytest --verbose -rs -s -o log_cli=true --leftovers-collector --tb=native --skip-deprecated-api-test --cluster-sanity-skip-storage-check --collect-only tests/network/bgp/ tests/network/l2_bridge/ tests/network/l2_bridge/nad_ref_change/ tests/network/localnet/
61/62 tests collected (1 deselected) in 0.07s (deprecated api test is skipped)

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

@coderabbitai

Test execution plan request details

CRITICAL: You MUST post an inline review comment on the first changed line of the first file.
The inline comment should contain the Test Execution Plan with the smoke tests recommendation.
Do NOT submit a formal review - just post the inline comment directly.

As an expert software testing engineer, analyze all modified files in this PR and create a targeted test execution plan.
You will post an inline review comment with the test execution plan on the first changed file.
If you fail to run or post a comment, retry.

Analysis Requirements:

  1. Examine code changes in each modified file
  2. Identify affected code paths, functions, and classes
  3. Analyze pytest-specific elements: fixtures (scope, dependencies), parametrization, markers, conftest changes
  4. Trace test dependencies through imports, shared utilities, and fixture inheritance
  5. Detect new tests introduced in the PR
  6. Smoke Test Impact Analysis: Determine if any changes could affect smoke tests by checking:
    • Changes to files/functions used by tests marked with @pytest.mark.smoke
    • Changes to fixtures or utilities imported by smoke tests
    • Changes to conftest.py files that may affect smoke test execution
    • Changes to core infrastructure code (utilities/, libs/) that smoke tests depend on

Your deliverable:
Your change request comment will be based on the following requirements:

Test Execution Plan

  • Run smoke tests: True / False (Based on your smoke test impact analysis - True if any changes may affect smoke tests)
  • path/to/test_file.py - When the entire test file needs verification
  • path/to/test_file.py::TestClass::test_method - When specific test(s) needed
  • path/to/test_file.py::test_function - When specific test(s) needed
  • -m marker - When specific marker(s) can be used to cover multiple cases.

Guidelines:

  • Include only tests directly affected by the changes
  • Use a full file path only if ALL tests in that file require verification
  • Use file path + test name if only specific tests are needed
  • If a test marker can cover multiple files/tests, provide the marker
  • Balance coverage vs over-testing - Keep descriptions minimal

Hardware-Related Checks (SR-IOV, GPU, DPDK):

When PR modifies fixtures for hardware-specific resources:

  • Collection Safety: Fixtures MUST have existence checks (return None when hardware unavailable)
  • Test Plan: MUST verify both WITH and WITHOUT hardware:
    • Run affected tests on cluster WITH hardware
    • Verify collection succeeds on cluster WITHOUT hardware

CRITICAL WORKFLOW COMPLETION RULES:

When responding to this test execution plan request, you MUST follow these rules EXACTLY:

  1. YOUR ONLY DELIVERABLE: Post an inline review comment containing the test execution plan on the first changed line
  2. THEN STOP IMMEDIATELY - Do NOT generate any additional response
  3. FALLBACK ONLY: If submitting the review fails after retrying, post as a regular PR comment
  4. SILENCE = SUCCESS: After successfully submitting the review, your task is complete. No confirmation needed.

ABSOLUTE PROHIBITIONS (violating these creates empty/meaningless reviews):

  • ❌ Do NOT post acknowledgment messages like "Test execution plan posted", "Review posted successfully", "I've successfully posted"
  • ❌ Do NOT mention review IDs, URLs, or confirmation of posting in the PR thread
  • ❌ Do NOT add any follow-up comments after submitting the review
  • ❌ Do NOT reply to confirm task completion
  • ❌ Do NOT explain what you did - just do it and stop

Remember: The pull request review is visible to users. Additional comments are redundant noise.

CRITICAL: Before setting "Run smoke tests: True", you MUST use shell scripts to:
- Trace the actual fixture dependency chain from smoke tests to changed fixtures
- Verify that smoke tests actually import/use changed utilities or functions
- Confirm the dependency path exists; do NOT assume based on scope or semantics
- Be conservative: Session-scoped fixtures or infrastructure-sounding names do NOT
automatically mean smoke test impact. Only flag smoke test impact when you can
demonstrate a concrete dependency path.
WRONG: "This session-scoped storage fixture might affect smoke tests"
RIGHT: "Smoke test X uses fixture Y, which depends on the changed fixture Z"

Comment thread libs/net/cluster.py
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check smoke test usage of changed files/functions
echo "=== Smoke tests using nodenetworkconfigurationpolicy ==="
rg -l "smoke" tests/network/ --include="*.py" | head -20

echo "=== Files with smoke marker that import changed modules ==="
rg -l "`@pytest.mark.smoke`" tests/ --include="*.py" | xargs grep -l "nodenetworkconfigurationpolicy\|cluster_vlan_iterator\|wait_for_vmi_condition\|apimachinery" 2>/dev/null | head -20

echo "=== Smoke tests in network ==="
rg "`@pytest.mark.smoke`" tests/network/ -l --include="*.py" | head -20

echo "=== Check if tests/conftest.py next_vlan_index_number is used anywhere ==="
rg "next_vlan_index_number" tests/ --include="*.py" -n | head -20

echo "=== BGP tests using smoke ==="
rg "`@pytest.mark.smoke`" tests/network/bgp/ --include="*.py" -n | head -20

echo "=== l2_bridge tests using smoke ==="
rg "`@pytest.mark.smoke`" tests/network/l2_bridge/ --include="*.py" -n | head -20

echo "=== localnet tests using smoke ==="
rg "`@pytest.mark.smoke`" tests/network/localnet/ --include="*.py" -n | head -20

Length of output: 4568


🏁 Script executed:

#!/bin/bash
# Get the first changed file in the PR diff via GitHub API and find the first changed line
gh pr view 5072 --json files --jq '.files[0].path'
echo "---"
gh api repos/RedHatQE/openshift-virtualization-tests/pulls/5072/files --jq '.[0] | {path: .filename, patch: .patch}' | head -50

Length of output: 467


🏁 Script executed:

#!/bin/bash
# Find first file with an actual patch
gh api repos/RedHatQE/openshift-virtualization-tests/pulls/5072/files --jq '.[] | select(.patch != null) | {path: .filename, first_line: (.patch | split("\n")[0])}' | head -60

Length of output: 1467


🏁 Script executed:

#!/bin/bash
# Check smoke test usage with correct rg syntax
echo "=== Smoke tests in network dir ==="
rg "`@pytest.mark.smoke`" tests/network/ -l | head -20

echo "=== next_vlan_index_number usage ==="
rg "next_vlan_index_number" tests/ -n | head -20

echo "=== Smoke tests importing changed modules ==="
rg "`@pytest.mark.smoke`" tests/ -l | xargs grep -l "nodenetworkconfigurationpolicy\|cluster_vlan_iterator\|wait_for_vmi_condition\|apimachinery" 2>/dev/null | head -20

echo "=== vmspec wait_for_vmi usages ==="
rg "wait_for_vmi_condition" tests/ -n | head -20

Length of output: 1189


🏁 Script executed:

#!/bin/bash
# Get PR head SHA
gh api repos/RedHatQE/openshift-virtualization-tests/pulls/5072 --jq '.head.sha'

Length of output: 248


🏁 Script executed:

#!/bin/bash
BODY="**Test Execution Plan**

- **Run smoke tests: False** _(No smoke tests found in the network test suite; no dependency chain from \`@pytest.mark.smoke\` tests to any changed fixture or utility was detected.)_

**Changed files and affected tests:**

- \`tests/network/bgp/\` — conftest import path changed (\`libnncp\`); verify collection and fixture resolution:
  - \`-m bgp\`
- \`tests/network/l2_bridge/\` — conftest import paths changed across all sub-packages; verify collection:
  - \`-m l2_bridge\`
- \`tests/network/l2_bridge/nad_ref_change/\` — additionally uses \`wait_for_vmi_condition_status\` / \`wait_for_no_vmi_condition\` (type widened to \`VirtualMachine\`):
  - \`tests/network/l2_bridge/nad_ref_change/\`
- \`tests/network/localnet/\` — conftest import paths changed; verify collection:
  - \`-m localnet\`
- \`tests/conftest.py::next_vlan_index_number\` — new fixture, not yet consumed by any test; no execution required now."

gh api \
  repos/RedHatQE/openshift-virtualization-tests/pulls/5072/comments \
  -X POST \
  -f commit_id="fcc50e711b6393bae1924f1d47fbb80f9f0cc080" \
  -f path="libs/net/cluster.py" \
  -f side="RIGHT" \
  -F line=1 \
  -f body="$BODY"

Length of output: 4689



@servolkov
Copy link
Copy Markdown
Contributor

@azhivovk both the helper and the fixture are dead code right now, it contradicts the repo rule. I think we are in trouble here.

@azhivovk
Copy link
Copy Markdown
Contributor Author

azhivovk commented Jun 1, 2026

@servolkov
This fixture is net infra for upcoming NAD live update metric test

@servolkov
Copy link
Copy Markdown
Contributor

@servolkov This fixture is net infra for upcoming NAD live update metric test

Yes, I read the description, I see. But I can only repeat myself - the code is dead. If fixture is used in that PR, what is the problem to introduce it there?

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

/retest all

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

Overlapping files

tests/network/localnet/liblocalnet.py

@azhivovk
Copy link
Copy Markdown
Contributor Author

azhivovk commented Jun 2, 2026

@servolkov
I wanted to create a dedicated PR of refactoring and infra for the metric test
Is it okay if the implementation PR will be merged as is and I'll close this one?

@servolkov
Copy link
Copy Markdown
Contributor

@servolkov I wanted to create a dedicated PR of refactoring and infra for the metric test Is it okay if the implementation PR will be merged as is and I'll close this one?

Sure. To avoid "dead code" PRs it must be there.

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

/retest all

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

Overlapping files

tests/conftest.py

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

/retest all

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

Overlapping files

tests/network/localnet/liblocalnet.py

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

/retest all

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

Overlapping files

tests/network/l2_bridge/migration_stuntime/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.

9 participants