net: NAD live update VM info test#4962
Conversation
📝 WalkthroughWalkthroughAdds cloud-init runcmd support, a VM network patch API, VMI condition waiters, test helpers/fixtures for two-secondary-interface VMs, and tests that perform a live NAD reference swap asserting interface metadata is preserved. ChangesLinux Bridge NAD Reference Update Test Infrastructure
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Container Operations
Cherry-pick Operations
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
AI Features
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 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/l2_bridge/libl2bridge.py`:
- Around line 45-52: MULTI_IFACE_ARP_RUNCMD is missing an explicit type
annotation; add a typing annotation (e.g., List[str]) to the constant
declaration and ensure typing.List (or from typing import List) is imported at
the top of the module so static type checks pass; update the
MULTI_IFACE_ARP_RUNCMD constant definition to include the annotation (List[str])
while keeping the same string elements and semantics.
In `@tests/network/l2_bridge/nad_ref_change/lib_helpers.py`:
- Around line 70-73: Before constructing the list comprehension that zips
iface_names and nad_names into Network(...) entries, add a fail-fast length
validation that checks len(iface_names) == len(nad_names) and raise a clear
exception (e.g., ValueError or AssertionError) if they differ; locate the code
that builds the list of Network objects (the comprehension using iface_names,
nad_names, Network and Multus) and insert the check immediately above it so
mismatched lists fail loudly rather than being silently truncated.
In `@tests/network/l2_bridge/nad_ref_change/test_nad_ref_change.py`:
- Around line 89-95: Add an explicit assertion that the VM interface was updated
to the new NAD before checking invariants: after calling
update_nad_references(...) and waiting for readiness, inspect iface_after =
iface_info(under_test_vm_two_ifaces, VM_IFACE_1) and assert that the interface's
NAD reference field (e.g., the key holding the NetworkAttachmentDefinition name
such as 'nad' or 'network_attachment_definition') equals bridge_nad_b.name; only
then proceed to the existing equality/assertion comparing iface_before and
iface_after so the test fails if the patch was not applied.
In `@tests/network/libs/connectivity.py`:
- Around line 25-36: update_nad_references currently silently ignores update
keys that don't match any interface; change it to fail fast by collecting the
existing interface names from vm.instance.spec.template.spec.networks (the local
variable networks), compute missing = set(updates.keys()) - set(network["name"]
for network in networks), and if missing is non-empty raise a ValueError (or
appropriate exception) listing the missing interface names before performing the
network modifications and calling ResourceEditor(...).update(); keep the rest of
the logic (iterating networks, updating network["multus"]["networkName"], and
the atomic ResourceEditor patch) unchanged.
🪄 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: fe2510c4-b048-48f3-9584-5f15cdcdb2fa
📒 Files selected for processing (6)
tests/network/l2_bridge/libl2bridge.pytests/network/l2_bridge/nad_ref_change/conftest.pytests/network/l2_bridge/nad_ref_change/lib_helpers.pytests/network/l2_bridge/nad_ref_change/test_nad_ref_change.pytests/network/libs/cloudinit.pytests/network/libs/connectivity.py
|
Change: drop connectivity related changes - will implement in upcoming PRs |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Step 1: Get current head commit SHA
HEAD_SHA=$(gh pr view 4962 --repo RedHatQE/openshift-virtualization-tests --json headRefOid -q .headRefOid)
echo "HEAD SHA: $HEAD_SHA"
# Step 2: Get list of changed files
echo "=== Changed files ==="
gh pr diff 4962 --repo RedHatQE/openshift-virtualization-tests --name-only
# Step 3: Get diff to find first changed line of first file
echo "=== PR diff (first 120 lines) ==="
gh pr diff 4962 --repo RedHatQE/openshift-virtualization-tests | head -120Length of output: 5536 🏁 Script executed: #!/bin/bash
# Post inline review comment on libs/net/vmspec.py line 6 (first changed line, new import)
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
repos/RedHatQE/openshift-virtualization-tests/pulls/4962/comments \
-f body="**Test Execution Plan**
- **Run smoke tests: False** — No concrete dependency path exists from any smoke-marked test to the changed files. All changes are additive or backward-compatible (new exception classes, new watch helpers, optional \`runcmd\` field defaulting to \`None\`, new constants, import refactor with identical values).
- \`tests/network/l2_bridge/nad_ref_change/test_nad_ref_change.py::TestRunningVMLinuxBridgeVlanChange::test_vm_state_iface_info_preserved\` — newly enabled test; validates guest interface identity (MAC, name, IPs) is preserved after a live NAD reference update.
- \`tests/network/l2_bridge/vmi_interfaces_stability/test_interfaces_stability.py\` — \`LINUX_BRIDGE_IFACE_NAME_1\`/\`LINUX_BRIDGE_IFACE_NAME_2\` are now imported from \`libl2bridge\` instead of being locally defined; values are identical but the import refactor warrants a run." \
-f commit_id="3d2c619ee69e7ad94c5c195e9eeeba326a8f2a3d" \
-f path="libs/net/vmspec.py" \
-F line=6 \
-f side="RIGHT"
echo "Exit code: $?"Length of output: 4866 |
|
/approve |
|
My comments can be considered as nit and fixed in a follow-up (don't want to block the PR) |
Add Watch-API-based helpers for waiting on VMI status conditions, following the same resource-version-capture pattern as lookup_iface_status, to avoid missing transitions between the triggering action and the watch. Two separate helpers make the intent explicit: use wait_for_vmi_condition when a condition must be present with a given status, and wait_for_no_vmi_condition when it must have been cleared. Signed-off-by: Asia Khromov <azhivovk@redhat.com> Assisted-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Asia Khromov <azhivovk@redhat.com> Assisted-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Add test_vm_state_iface_info_preserved: verifies that updating the NAD reference on a running VM's secondary Linux bridge network does not alter the guest interface MAC address, name, or IP addresses. Introduces two_secondary_bridge_vm() — a shared VM factory for Linux bridge tests with multiple secondary interfaces — and the supporting fixtures. Update nad helper is saving the resource version of VMI, then updating NAD and then ensures the changes are applied by watching the conditions - MigrationRequired=True and then the condition disappears. Currently, this is the way of knowing the NAD live update was successfully applied. Signed-off-by: Asia Khromov <azhivovk@redhat.com> Assisted-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
Change: Remove empty list and avoid false "True" in all() |
There was a problem hiding this comment.
♻️ Duplicate comments (1)
libs/net/vmspec.py (1)
273-276:⚠️ Potential issue | 🟠 Major | ⚡ Quick winHIGH: Treat empty/None conditions as “not set” in
wait_for_no_vmi_conditionLine 274 and Line 284 currently require
existing_conditionsto be truthy before calling_vmi_condition_not_set(...). That blocks the success path when conditions areNone/[], even though this function is documented to succeed when the condition is absent, and can cause an unnecessary timeout.Suggested fix
- existing_conditions = vmi_instance.status.conditions - if existing_conditions and _vmi_condition_not_set( - existing_conditions=existing_conditions, required_condition=condition - ): + existing_conditions = vmi_instance.status.conditions + if _vmi_condition_not_set( + existing_conditions=existing_conditions or [], required_condition=condition + ): return @@ - existing_conditions = event["object"].status.conditions - if existing_conditions and _vmi_condition_not_set( - existing_conditions=existing_conditions, required_condition=condition - ): + existing_conditions = event["object"].status.conditions + if _vmi_condition_not_set( + existing_conditions=existing_conditions or [], required_condition=condition + ): returnAlso applies to: 283-286
🤖 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 `@libs/net/vmspec.py` around lines 273 - 276, In wait_for_no_vmi_condition, don't gate the check on existing_conditions being truthy — treat None or an empty list as "condition not set": remove the `if existing_conditions and _vmi_condition_not_set(...)` pattern and instead call `_vmi_condition_not_set(existing_conditions=existing_conditions, required_condition=condition)` unconditionally (or update `_vmi_condition_not_set` to explicitly return True for None/[]); reference `existing_conditions`, `_vmi_condition_not_set`, and `wait_for_no_vmi_condition` when making the change so the function succeeds immediately when conditions are absent.
🤖 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.
Duplicate comments:
In `@libs/net/vmspec.py`:
- Around line 273-276: In wait_for_no_vmi_condition, don't gate the check on
existing_conditions being truthy — treat None or an empty list as "condition not
set": remove the `if existing_conditions and _vmi_condition_not_set(...)`
pattern and instead call
`_vmi_condition_not_set(existing_conditions=existing_conditions,
required_condition=condition)` unconditionally (or update
`_vmi_condition_not_set` to explicitly return True for None/[]); reference
`existing_conditions`, `_vmi_condition_not_set`, and `wait_for_no_vmi_condition`
when making the change so the function succeeds immediately when conditions are
absent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1309aea9-7c2c-426f-a090-62b30f00b334
📒 Files selected for processing (6)
libs/net/vmspec.pytests/network/l2_bridge/libl2bridge.pytests/network/l2_bridge/nad_ref_change/conftest.pytests/network/l2_bridge/nad_ref_change/lib_helpers.pytests/network/l2_bridge/nad_ref_change/test_nad_ref_change.pytests/network/l2_bridge/vmi_interfaces_stability/lib_helpers.py
|
/verified |
Test execution plan request detailsCRITICAL: You MUST post an inline review comment on the first changed line of the first file. As an expert software testing engineer, analyze all modified files in this PR and create a targeted test execution plan. Analysis Requirements:
Your deliverable: Test Execution Plan
Guidelines:
Hardware-Related Checks (SR-IOV, GPU, DPDK): When PR modifies fixtures for hardware-specific resources:
CRITICAL WORKFLOW COMPLETION RULES: When responding to this test execution plan request, you MUST follow these rules EXACTLY:
ABSOLUTE PROHIBITIONS (violating these creates empty/meaningless reviews):
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: |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Get current HEAD SHA and first changed line
HEAD_SHA=$(gh pr view 4962 --repo RedHatQE/openshift-virtualization-tests --json headRefOid -q .headRefOid)
echo "HEAD SHA: $HEAD_SHA"
# Get first changed file
FIRST_FILE=$(gh pr diff 4962 --repo RedHatQE/openshift-virtualization-tests --name-only | head -1)
echo "First file: $FIRST_FILE"
# Get the diff for that file to find the first added line number
gh pr diff 4962 --repo RedHatQE/openshift-virtualization-tests | head -60Length of output: 2590 🏁 Script executed: #!/bin/bash
# Post inline review comment on libs/net/vmspec.py line 6 for the latest commit
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
repos/RedHatQE/openshift-virtualization-tests/pulls/4962/comments \
-f body="**Test Execution Plan**
- **Run smoke tests: False** — No concrete dependency path exists from any smoke-marked test to the changed files. All changes are additive or backward-compatible (new exception classes, new VMI watch helpers, optional \`runcmd\` field defaulting to \`None\`, new constants, import refactor with identical values).
- \`tests/network/l2_bridge/nad_ref_change/test_nad_ref_change.py::TestRunningVMLinuxBridgeVlanChange::test_vm_state_iface_info_preserved\` — newly enabled test; validates guest interface identity (MAC, name, IPs) is preserved after a live NAD reference update.
- \`tests/network/l2_bridge/vmi_interfaces_stability/test_interfaces_stability.py\` — \`LINUX_BRIDGE_IFACE_NAME_1\`/\`LINUX_BRIDGE_IFACE_NAME_2\` are now imported from \`libl2bridge\` instead of being locally defined; values are identical but the import refactor warrants a run." \
-f commit_id="2d48c5d0e94b01ff4a92b87459aac8fe786648a6" \
-f path="libs/net/vmspec.py" \
-F line=6 \
-f side="RIGHT"
echo "Exit code: $?"Length of output: 4863 |
|
/check-can-merge |
|
New container for quay.io/openshift-cnv/openshift-virtualization-tests:latest published |
What this PR does / why we need it:
Adds
test_vm_state_iface_info_preserved: verifies that live-updating a secondary Linux bridge network's NAD reference on a running VM does not alter the guest interface identity (MAC address, name,IP addresses). This is the first test in the NAD live-update series for Linux bridge: it establishes the shared infrastructure that subsequent PRs in
the series build on.
Which issue(s) this PR fixes: -
Special notes for reviewer:
The two connectivity tests and the non-migratable negative test are present as STD placeholders (test = False) they document the full planned test class but are not collected by pytest. They
will be implemented in follow-up PRs.
jira-ticket: https://redhat.atlassian.net/browse/CNV-80573
Summary by CodeRabbit
Tests
New Features