Skip to content

Improve virtual_network.iface_bridge cases to adapt to new testing tool#6816

Open
yanglei-rh wants to merge 1 commit intoautotest:masterfrom
yanglei-rh:LIBVIRTAT-22326
Open

Improve virtual_network.iface_bridge cases to adapt to new testing tool#6816
yanglei-rh wants to merge 1 commit intoautotest:masterfrom
yanglei-rh:LIBVIRTAT-22326

Conversation

@yanglei-rh
Copy link
Contributor

@yanglei-rh yanglei-rh commented Mar 4, 2026

1.Add some parameters to allow the framework provide guest xml
2.Add "only Linux" to limit guest type
3.Add a check about host bridge type

ID: LIBVIRTAT-22326
Signed-off-by: Lei Yang leiyang@redhat.com

Summary by CodeRabbit

  • Bug Fixes
    • Tests now skip when an Open vSwitch-type bridge is detected to avoid unsupported operations.
    • Bridge selection improved: configuration-aware resolution and sensible defaults to pick the correct interface.
    • Interface and MAC assignment adapt to whether an external network destination is used, preventing incorrect assignments.
    • Bridge creation and teardown made more conservative to avoid unintended changes to the host network.

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0a3c7e40-2f54-4137-817b-2b8e5f2926ea

📥 Commits

Reviewing files that changed from the base of the PR and between 849ac36 and 26c0549.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/virtual_network/iface_bridge.cfg
  • libvirt/tests/src/virtual_network/iface_bridge.py

Walkthrough

The PR modifies virtual_network iface_bridge config and test behavior: new config options were added and some hardcoded iface_source entries removed. The test now prefers netdst for bridge resolution (falling back to bridge_name defaulting to "test_br0"), aborts early if the host bridge is an OVS bridge, and only creates or deletes a host Linux bridge when bridge_name is provided and netdst is not set. VM2 MAC assignment, bridge existence checks, and cleanup paths are adjusted to follow the resolved bridge selection and skip host-bridge operations when netdst is used.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: improving iface_bridge test cases to work with a new testing tool that provides guest XML and adapts to host bridge type checks.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Copy link

@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: 2

🧹 Nitpick comments (1)
libvirt/tests/src/virtual_network/iface_bridge.py (1)

116-116: Normalize netdst to a single bridge token before use.

If netdst is comma-separated, this can produce an invalid bridge name downstream. Prefer taking the first entry explicitly.

Suggested adjustment
-    bridge_name = params.get("netdst") or params.get("bridge_name", "test_br0")
+    netdst = params.get("netdst", "")
+    bridge_name = netdst.split(",")[0] if netdst else params.get("bridge_name", "test_br0")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libvirt/tests/src/virtual_network/iface_bridge.py` at line 116, Normalize the
netdst value before assigning bridge_name: if params.get("netdst") returns a
comma-separated string, split it on ',' and take the first token (trim
whitespace) as the bridge token, otherwise fall back to
params.get("bridge_name", "test_br0"); update the bridge_name assignment (the
variable bridge_name and its use of params.get("netdst") /
params.get("bridge_name")) to perform this normalization so downstream code
receives a single valid bridge name.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@libvirt/tests/src/virtual_network/iface_bridge.py`:
- Around line 174-179: The current logic cancels the test whenever
libvirt.check_iface(...) reports the bridge exists, which wrongly affects
non-self-managed bridges; change the condition so that test.cancel("The bridge
%s already exist" % bridge_name) only runs when bridge_name == "test_br0" and
check_iface(...) returns true; keep the existing create path using
create_linux_bridge_tmux(bridge_name, iface_name) and its failure handling for
the test_br0 branch (i.e., call test.fail on non-zero s), but do not cancel for
other bridge names if they already exist.
- Line 128: Replace the unsafe eval call that sets iface_source with
ast.literal_eval: parse params.get("iface_source", "{'bridge':'%s'}" %
bridge_name) using ast.literal_eval, then validate the result is a dict (and
optionally that it contains the expected 'bridge' key) before using it; update
the code that references iface_source accordingly (symbols: iface_source,
params.get, bridge_name, ast.literal_eval).

---

Nitpick comments:
In `@libvirt/tests/src/virtual_network/iface_bridge.py`:
- Line 116: Normalize the netdst value before assigning bridge_name: if
params.get("netdst") returns a comma-separated string, split it on ',' and take
the first token (trim whitespace) as the bridge token, otherwise fall back to
params.get("bridge_name", "test_br0"); update the bridge_name assignment (the
variable bridge_name and its use of params.get("netdst") /
params.get("bridge_name")) to perform this normalization so downstream code
receives a single valid bridge name.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9d27283f-ccd5-441e-a394-4c571d2ead03

📥 Commits

Reviewing files that changed from the base of the PR and between 5a1710f and e91280e.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/virtual_network/iface_bridge.cfg
  • libvirt/tests/src/virtual_network/iface_bridge.py

Copy link

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

♻️ Duplicate comments (1)
libvirt/tests/src/virtual_network/iface_bridge.py (1)

128-128: ⚠️ Potential issue | 🟠 Major

Replace unsafe eval for iface_source parsing.

Line 128 executes arbitrary input from params. Use ast.literal_eval plus a dict type check before use.

Suggested fix
-    iface_source = eval(params.get("iface_source", "{'bridge':'%s'}" % bridge_name))
+    try:
+        iface_source = ast.literal_eval(
+            params.get("iface_source", "{'bridge':'%s'}" % bridge_name)
+        )
+    except (ValueError, SyntaxError) as err:
+        test.cancel("Invalid iface_source literal: %s" % err)
+    if not isinstance(iface_source, dict):
+        test.cancel("Invalid iface_source, expected dict-like literal")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libvirt/tests/src/virtual_network/iface_bridge.py` at line 128, Replace the
unsafe eval usage that sets iface_source by parsing params.get("iface_source",
...) with ast.literal_eval and validate the result is a dict: call
ast.literal_eval on the string value for iface_source (fall back to the existing
default string when missing), catch ValueError/SyntaxError/TypeError, and if
successful ensure isinstance(iface_source, dict) before using it; if parsing
fails or the type check fails, log/raise an appropriate error or revert to the
default dict so code using iface_source (the variable set where the current line
uses eval) never executes untrusted code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@libvirt/tests/src/virtual_network/iface_bridge.py`:
- Line 128: Replace the unsafe eval usage that sets iface_source by parsing
params.get("iface_source", ...) with ast.literal_eval and validate the result is
a dict: call ast.literal_eval on the string value for iface_source (fall back to
the existing default string when missing), catch
ValueError/SyntaxError/TypeError, and if successful ensure
isinstance(iface_source, dict) before using it; if parsing fails or the type
check fails, log/raise an appropriate error or revert to the default dict so
code using iface_source (the variable set where the current line uses eval)
never executes untrusted code.

ℹ️ Review info
Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6758631b-75a4-4709-8a78-5ceb0c98ed54

📥 Commits

Reviewing files that changed from the base of the PR and between e91280e and 849ac36.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/virtual_network/iface_bridge.cfg
  • libvirt/tests/src/virtual_network/iface_bridge.py

@yanglei-rh
Copy link
Contributor Author

Test pass.

 (01/12) Host_RHEL.m9.u8.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.9.8.0.x86_64.io-github-autotest-libvirt.virtual_network.iface_bridge.default.shared_physical_network.q35: PASS (139.95 s)
 (02/12) Host_RHEL.m9.u8.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.9.8.0.x86_64.io-github-autotest-libvirt.virtual_network.iface_bridge.hotplug_iface.shared_physical_network.q35: PASS (87.13 s)
 (03/12) Host_RHEL.m9.u8.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.9.8.0.x86_64.io-github-autotest-libvirt.virtual_network.iface_bridge.hotplug_device.shared_physical_network.q35: PASS (90.89 s)
 (04/12) Host_RHEL.m9.u8.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.9.8.0.x86_64.io-github-autotest-libvirt.virtual_network.iface_bridge.update_with_diff_type.shared_physical_network.q35: PASS (92.58 s)
 (05/12) Host_RHEL.m9.u8.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.9.8.0.x86_64.io-github-autotest-libvirt.virtual_network.iface_bridge.multiqueues.start.shared_physical_network.q35: PASS (59.78 s)
 (06/12) Host_RHEL.m9.u8.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.9.8.0.x86_64.io-github-autotest-libvirt.virtual_network.iface_bridge.multiqueues.hotplug_device.shared_physical_network.q35: PASS (89.00 s)
 (07/12) Host_RHEL.m9.u8.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.9.8.0.x86_64.io-github-autotest-libvirt.virtual_network.iface_bridge.reconnect_tap.bridge_restart_libvirt.shared_physical_network.q35: PASS (107.48 s)
 (08/12) Host_RHEL.m9.u8.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.9.8.0.x86_64.io-github-autotest-libvirt.virtual_network.iface_bridge.reconnect_tap.net.restart_libvirt.shared_physical_network.q35: PASS (100.96 s)
 (09/12) Host_RHEL.m9.u8.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.9.8.0.x86_64.io-github-autotest-libvirt.virtual_network.iface_bridge.reconnect_tap.net.restart_net.shared_physical_network.q35: PASS (62.26 s)
 (10/12) Host_RHEL.m9.u8.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.9.8.0.x86_64.io-github-autotest-libvirt.virtual_network.iface_bridge.test_qos.start.shared_physical_network.q35: PASS (64.46 s)
 (11/12) Host_RHEL.m9.u8.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.9.8.0.x86_64.io-github-autotest-libvirt.virtual_network.iface_bridge.test_qos.hotplug_iface.shared_physical_network.q35: PASS (91.23 s)
 (12/12) Host_RHEL.m9.u8.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.9.8.0.x86_64.io-github-autotest-libvirt.virtual_network.iface_bridge.test_qos.network.shared_physical_network.q35: PASS (63.62 s)

1.Add some parameters to allow the framework provide guest xml
2.Add "only Linux" to limit guest type
3.Add a check about host bridge type

Signed-off-by: Lei Yang <leiyang@redhat.com>
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.

2 participants