Skip to content

Conversation

@yanglei-rh
Copy link
Contributor

@yanglei-rh yanglei-rh commented Nov 19, 2025

Automate VIRT-95907 Jumbo Frame

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

Summary by CodeRabbit

  • Tests
    • Added a jumbo-frame validation suite for virtual network interfaces: boots VMs, adjusts MTUs on bridge and guest/host interfaces (Linux and Windows paths), adds temporary ARP entries, verifies MTU with progressive and large-frame pings plus stress floods, and includes cleanup to restore MTUs, remove temporary entries, and close VM sessions.

@coderabbitai
Copy link

coderabbitai bot commented Nov 19, 2025

Walkthrough

Adds a jumbo-frame test for libvirt virtual networks: a new config libvirt/tests/cfg/virtual_network/qemu/jumbo.cfg defining virtual_network.qemu_test.jumbo (MTU 9000, device-specific keys) and a new test module libvirt/tests/src/virtual_network/qemu/jumbo.py implementing run(test, params, env). The test boots a VM, adjusts MTUs on bridge/host/guest interfaces (Linux and Windows paths), injects an ARP entry, performs staged ICMP pings including large-frame and flood tests, and restores MTUs and cleanup on completion or error.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25–35 minutes

  • Heterogeneous changes: one config addition + one sizable test module with multi-phase logic.
  • Review focus:
    • libvirt/tests/src/virtual_network/qemu/jumbo.py — MTU change/restoration logic, ping size progression, flood phase, error handling and cleanup.
    • OS/device-specific branches (e1000e Linux-only, virtio_net Windows MTU key).
    • ARP injection/removal and VM session lifecycle.
    • OVS/bridge port and interface discovery logic.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title directly corresponds to the main changes—adding configuration and implementation for a jumbo frame test case for virtual networks in libvirt.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 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 (4)
libvirt/tests/cfg/virtual_network/qemu/jumbo.cfg (1)

1-13: Confirm Windows MTU registry command is defined somewhere in the config stack

This cfg provides mtu = 9000 and mtu_key = MTU for virtio_net on Windows, which matches how jumbo.py consumes mtu / mtu_key, but the test code also requires a reg_mtu_cmd parameter for Windows (reg_set_mtu_pattern = params.get("reg_mtu_cmd") and then reg_set_mtu_pattern % ...). Please confirm that reg_mtu_cmd is defined in a shared/base cfg or add it here to avoid runtime TypeError when running the Windows variant.

libvirt/tests/src/virtual_network/qemu/jumbo.py (3)

160-183: Avoid calling random.randrange in default argument and fix loss‑ratio message

size_increase_ping uses a default argument computed via random.randrange:

def size_increase_ping(step=random.randrange(90, 110)):

Default arguments are evaluated at import time, not at call time. This has two downsides:

  • The step is effectively fixed for the lifetime of the module, which is surprising.
  • It triggers the B008 warning (and static analysis here).

Refactor to compute step inside the function:

-def size_increase_ping(step=random.randrange(90, 110)):
+def size_increase_ping(step=None):
     test.log.info("Size increase ping")
+    if step is None:
+        step = random.randrange(90, 110)

Additionally, the failure message hard‑codes 50% even though fail_ratio is read from params:

fail_ratio = int(params.get("fail_ratio", 50))
if utils_test.get_loss_ratio(output) > fail_ratio:
    test.fail("Ping loss ratio is greater than 50% for size %s" % size)

Consider:

-            fail_ratio = int(params.get("fail_ratio", 50))
-            if utils_test.get_loss_ratio(output) > fail_ratio:
-                test.fail(
-                    "Ping loss ratio is greater than 50% for size %s" % size
-                )
+            fail_ratio = int(params.get("fail_ratio", 50))
+            loss = utils_test.get_loss_ratio(output)
+            if loss > fail_ratio:
+                test.fail(
+                    "Ping loss ratio %s is greater than %s%% for size %s"
+                    % (loss, fail_ratio, size)
+                )

This keeps behavior predictable and messages accurate.


90-123: Check Windows‑specific parameters and close session_serial in cleanup

Within the Windows branch you rely on:

reg_set_mtu_pattern = params.get("reg_mtu_cmd")
mtu_key_word = params.get("mtu_key", "MTU")
reg_set_mtu = reg_set_mtu_pattern % (int(index), mtu_key_word, int(mtu))
guest_mtu_cmd = "%s " % reg_set_mtu
...
utils_net.restart_windows_guest_network(session_serial, connection_id, mode=mode)

Two minor points:

  1. If reg_mtu_cmd is missing from the combined cfg, reg_set_mtu_pattern will be None and this will raise a TypeError. Align this with the cfg (either ensure it’s always defined or guard with an explicit error).

  2. session_serial is opened but never closed in the finally block; only session is closed. To avoid leaking long‑lived serial connections during large test runs, consider also closing session_serial when present.

Example:

-    finally:
-        # Environment clean
-        if session:
-            session.close()
+    finally:
+        # Environment clean
+        if session:
+            session.close()
+        if 'session_serial' in locals() and session_serial:
+            session_serial.close()

36-44: Shell commands via shell=True – low risk here but worth constraining inputs

Several process.run / process.getoutput / process.system calls use shell=True with interpolated values (e.g. netdst, iface, ifname, guest_ip, iface_mac). In this test harness those inputs ultimately come from test config and libvirt/OS introspection, so the risk is low, but static analysis correctly flags them.

Where convenient, consider:

  • Switching to argument lists (shell=False) for simple commands like ip link, arp, grep, ovs-vsctl.
  • Or, at minimum, ensuring all interpolated values are validated (interface names/IPs match expected patterns), especially if any part can be influenced externally.

This will make the test more robust and quieter for security linters.

Also applies to: 78-89, 118-123, 187-190, 209-210, 215-215

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 875c970 and 3c8fede.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/virtual_network/qemu/jumbo.cfg (1 hunks)
  • libvirt/tests/src/virtual_network/qemu/jumbo.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-18T08:47:14.465Z
Learnt from: smitterl
Repo: autotest/tp-libvirt PR: 6072
File: libvirt/tests/src/passthrough/pci/libvirt_pci_passthrough_hotplug.py:239-241
Timestamp: 2025-11-18T08:47:14.465Z
Learning: In tp-libvirt tests, `utils_test.ping` is a valid function that exists in the avocado-vt framework (virttest.utils_test module). It is an alias to `utils_net.ping` and supports parameters including dest, count, interface, timeout, and session.

Applied to files:

  • libvirt/tests/src/virtual_network/qemu/jumbo.py
📚 Learning: 2025-09-24T08:01:27.899Z
Learnt from: hholoubk
Repo: autotest/tp-libvirt PR: 6579
File: libvirt/tests/src/sriov/vIOMMU/iommu_device_lifecycle.py:95-97
Timestamp: 2025-09-24T08:01:27.899Z
Learning: In the libvirt test framework used in tp-libvirt, VM cleanup including destroying running VMs is handled by the teardown method (test_obj.teardown_iommu_test()) called in the finally block, so explicit VM destroy calls on timeout are not necessary according to the maintainers.

Applied to files:

  • libvirt/tests/src/virtual_network/qemu/jumbo.py
🧬 Code graph analysis (1)
libvirt/tests/src/virtual_network/qemu/jumbo.py (1)
libvirt/tests/src/serial/serial_functional.py (1)
  • wait_for_login (235-258)
🪛 Ruff (0.14.5)
libvirt/tests/src/virtual_network/qemu/jumbo.py

43-43: Function call with shell=True parameter identified, security issue

(S604)


88-88: Function call with shell=True parameter identified, security issue

(S604)


118-118: Function call with shell=True parameter identified, security issue

(S604)


122-122: Function call with shell=True parameter identified, security issue

(S604)


160-160: Standard pseudo-random generators are not suitable for cryptographic purposes

(S311)


160-160: Do not perform function call random.randrange in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


187-187: Function call with shell=True parameter identified, security issue

(S604)


209-209: Function call with shell=True parameter identified, security issue

(S604)


210-210: Function call with shell=True parameter identified, security issue

(S604)


215-215: Function call with shell=True parameter identified, security issue

(S604)

@yanglei-rh
Copy link
Contributor Author

Tested pass from my side.

VT_TYPE=libvirt python3 ConfigTest.py --testcase=virtual_network.qemu_test.jumbo --guestname=RHEL.10.2,Win2025 --machines=q35 --nicmodel=virtio_net --platform=x86_64 --customsparams='netdst=switch\nnet_driver=vhost\nqueues=4' --clone=no
(1/1) Host_RHEL.m10.u2.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-libvirt.virtual_network.qemu_test.jumbo.q35: PASS (654.98 s)
(1/1) Host_RHEL.m10.u2.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-libvirt.virtual_network.qemu_test.jumbo.q35: PASS (654.98 s)

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: 1

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

57-60: Capture and restore original MTU values instead of hard-coding 1500

The test hard-codes mtu_default = 1500 (line 58) and restores all bridge NICs to this value during cleanup (lines 219-221). On systems where interfaces are intentionally configured with non-1500 MTUs, this corrupts the host configuration after the test completes.

Store each interface's original MTU before modification (lines 86-88):

+    orig_mtu = {}
     error_context.context("Change all Bridge NICs MTU to %s" % mtu, test.log.info)
     for iface in target_ifaces:
+        # Capture original MTU before changing
+        orig_mtu[iface] = int(process.getoutput(f"cat /sys/class/net/{iface}/mtu", shell=True))
         process.run(host_mtu_cmd % (iface, mtu), shell=True)

Then restore using captured values in cleanup (lines 219-221):

-    test.log.info("Change back Bridge NICs MTU to %s", mtu_default)
+    test.log.info("Restoring Bridge NIC MTUs to original values")
     for iface in target_ifaces:
-        process.run(host_mtu_cmd % (iface, mtu_default), shell=True)
+        original = orig_mtu.get(iface, mtu_default)
+        process.run(host_mtu_cmd % (iface, original), shell=True)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c8fede and 3a59ffd.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/virtual_network/qemu/jumbo.cfg (1 hunks)
  • libvirt/tests/src/virtual_network/qemu/jumbo.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-18T08:47:14.465Z
Learnt from: smitterl
Repo: autotest/tp-libvirt PR: 6072
File: libvirt/tests/src/passthrough/pci/libvirt_pci_passthrough_hotplug.py:239-241
Timestamp: 2025-11-18T08:47:14.465Z
Learning: In tp-libvirt tests, `utils_test.ping` is a valid function that exists in the avocado-vt framework (virttest.utils_test module). It is an alias to `utils_net.ping` and supports parameters including dest, count, interface, timeout, and session.

Applied to files:

  • libvirt/tests/src/virtual_network/qemu/jumbo.py
📚 Learning: 2025-09-24T08:01:27.899Z
Learnt from: hholoubk
Repo: autotest/tp-libvirt PR: 6579
File: libvirt/tests/src/sriov/vIOMMU/iommu_device_lifecycle.py:95-97
Timestamp: 2025-09-24T08:01:27.899Z
Learning: In the libvirt test framework used in tp-libvirt, VM cleanup including destroying running VMs is handled by the teardown method (test_obj.teardown_iommu_test()) called in the finally block, so explicit VM destroy calls on timeout are not necessary according to the maintainers.

Applied to files:

  • libvirt/tests/src/virtual_network/qemu/jumbo.py
🧬 Code graph analysis (1)
libvirt/tests/src/virtual_network/qemu/jumbo.py (1)
libvirt/tests/src/serial/serial_functional.py (1)
  • wait_for_login (235-258)
🪛 Ruff (0.14.5)
libvirt/tests/src/virtual_network/qemu/jumbo.py

43-43: Function call with shell=True parameter identified, security issue

(S604)


88-88: Function call with shell=True parameter identified, security issue

(S604)


118-118: Function call with shell=True parameter identified, security issue

(S604)


122-122: Function call with shell=True parameter identified, security issue

(S604)


163-163: Standard pseudo-random generators are not suitable for cryptographic purposes

(S311)


191-191: Function call with shell=True parameter identified, security issue

(S604)


215-215: Function call with shell=True parameter identified, security issue

(S604)


216-216: Function call with shell=True parameter identified, security issue

(S604)


221-221: Function call with shell=True parameter identified, security issue

(S604)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Python 3.9
  • GitHub Check: Python 3.12
  • GitHub Check: Python 3.11
  • GitHub Check: Python 3.8
🔇 Additional comments (6)
libvirt/tests/cfg/virtual_network/qemu/jumbo.cfg (1)

1-13: LGTM! Configuration structure is sound.

The jumbo frame test configuration is well-structured with appropriate parameters:

  • MTU 9000 is standard for jumbo frames
  • Device-specific variants correctly restrict e1000e to Linux and provide Windows-specific MTU registry key for virtio_net
  • VM lifecycle parameters align with the test implementation
libvirt/tests/src/virtual_network/qemu/jumbo.py (5)

1-34: LGTM! Well-structured test entry point.

Imports are appropriate, the @error_context.context_aware decorator enables helpful test logging, and the docstring clearly outlines the 10-step jumbo frame test sequence.


36-43: Helper function is straightforward and appropriate.

The get_ovs_ports function correctly retrieves OVS bridge interfaces. The use of shell=True is acceptable in test code where command inputs are controlled.


120-186: Test helpers implement comprehensive MTU validation.

The ARP entry addition and test helper functions provide thorough jumbo frame verification:

  • is_mtu_ok for readiness check
  • verify_mtu for path MTU validation with packet loss detection
  • flood_ping for stress testing
  • large_frame_ping for sustained large-frame transmission
  • size_increase_ping with progressive sizing and retry logic

The use of random.randrange at line 163 is appropriate for varying test step sizes (not cryptographic use).


187-206: LGTM! Test execution flow is well-structured.

The test properly waits for MTU readiness (with helpful debug output on timeout), executes comprehensive functional validation, and concludes with stress testing. The sequence matches the documented test steps.


208-218: Cleanup logic is sound.

The finally block ensures proper cleanup:

  • Sessions are closed with defensive checks
  • Temporary ARP entry is correctly removed (using proper integer comparison at line 215)
  • Helpful logging confirms ARP cleanup success

(Note: MTU restoration issue at lines 219-221 is addressed in a separate comment.)

Automate VIRT-95907 Jumbo Frame

Signed-off-by: Lei Yang <leiyang@redhat.com>
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/qemu/jumbo.py (1)

69-69: Consider conditional serial session creation for Windows only.

The serial session is created for all OS types at line 69, but it's only used for Windows (lines 113-115 for network restart). For Linux guests, this creates an unused resource.

Consider moving serial session creation into the Windows-specific block:

 session = vm.wait_for_login(timeout=timeout)
-session_serial = vm.wait_for_serial_login(timeout=timeout)
 
 iface_mac = vm.get_mac_address(0)
 ...
 else:
+    session_serial = vm.wait_for_serial_login(timeout=timeout)
     connection_id = utils_net.get_windows_nic_attribute(

Adjust the cleanup check at line 212 accordingly.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a59ffd and f0c45e1.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/virtual_network/qemu/jumbo.cfg (1 hunks)
  • libvirt/tests/src/virtual_network/qemu/jumbo.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-18T08:47:14.465Z
Learnt from: smitterl
Repo: autotest/tp-libvirt PR: 6072
File: libvirt/tests/src/passthrough/pci/libvirt_pci_passthrough_hotplug.py:239-241
Timestamp: 2025-11-18T08:47:14.465Z
Learning: In tp-libvirt tests, `utils_test.ping` is a valid function that exists in the avocado-vt framework (virttest.utils_test module). It is an alias to `utils_net.ping` and supports parameters including dest, count, interface, timeout, and session.

Applied to files:

  • libvirt/tests/src/virtual_network/qemu/jumbo.py
📚 Learning: 2025-09-24T08:01:27.899Z
Learnt from: hholoubk
Repo: autotest/tp-libvirt PR: 6579
File: libvirt/tests/src/sriov/vIOMMU/iommu_device_lifecycle.py:95-97
Timestamp: 2025-09-24T08:01:27.899Z
Learning: In the libvirt test framework used in tp-libvirt, VM cleanup including destroying running VMs is handled by the teardown method (test_obj.teardown_iommu_test()) called in the finally block, so explicit VM destroy calls on timeout are not necessary according to the maintainers.

Applied to files:

  • libvirt/tests/src/virtual_network/qemu/jumbo.py
🧬 Code graph analysis (1)
libvirt/tests/src/virtual_network/qemu/jumbo.py (1)
libvirt/tests/src/serial/serial_functional.py (1)
  • wait_for_login (235-258)
🪛 Ruff (0.14.5)
libvirt/tests/src/virtual_network/qemu/jumbo.py

43-43: Function call with shell=True parameter identified, security issue

(S604)


88-88: Function call with shell=True parameter identified, security issue

(S604)


118-118: Function call with shell=True parameter identified, security issue

(S604)


122-122: Function call with shell=True parameter identified, security issue

(S604)


163-163: Standard pseudo-random generators are not suitable for cryptographic purposes

(S311)


191-191: Function call with shell=True parameter identified, security issue

(S604)


215-215: Function call with shell=True parameter identified, security issue

(S604)


216-216: Function call with shell=True parameter identified, security issue

(S604)


221-221: Function call with shell=True parameter identified, security issue

(S604)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Python 3.11
  • GitHub Check: Python 3.12
  • GitHub Check: Python 3.9
  • GitHub Check: Python 3.8
🔇 Additional comments (5)
libvirt/tests/cfg/virtual_network/qemu/jumbo.cfg (1)

1-13: LGTM! Configuration is well-structured.

The jumbo frame test configuration is appropriate:

  • Root privileges and VM lifecycle settings are correctly specified
  • MTU 9000 is the standard jumbo frame size
  • Device restrictions (e1000e for Linux only) align with driver capabilities
  • Windows MTU configuration via registry key is properly defined
libvirt/tests/src/virtual_network/qemu/jumbo.py (4)

1-34: LGTM! Well-documented test function.

The imports are appropriate and the docstring clearly outlines the 10-step test flow for RX jumbo frame validation.


36-43: LGTM! Helper function is clear and correct.

The OVS port enumeration logic is straightforward. The shell=True parameter is acceptable in the libvirt test framework context.


117-118: LGTM! Typo fixed.

The log message now correctly reads "Changing the MTU of host tap" (previous review noted the typo "Chaning").


214-217: LGTM! ARP cleanup logic fixed.

The integer comparison == 0 at line 215 is now correct (previous review identified this was comparing to string "0"). The ARP entry cleanup will now work properly.

@yanglei-rh
Copy link
Contributor Author

Hi @qiankehan @nanli1 Please help review this patch which about test jumbo frame inside guest, thanks a lot. It's important to note that this differs from directly adding jumbo frames in the current XML; the two are designed for different customer needs.

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.

2 participants