Skip to content

libvirt/tests: add tests to virtual_network.iface_ovs - #6877

Open
aniket-sahu-ibmx wants to merge 1 commit into
autotest:masterfrom
aniket-sahu-ibmx:add-ovs-test
Open

aniket-sahu-ibmx wants to merge 1 commit into
autotest:masterfrom
aniket-sahu-ibmx:add-ovs-test

Conversation

@aniket-sahu-ibmx

@aniket-sahu-ibmx aniket-sahu-ibmx commented Jun 2, 2026

Copy link
Copy Markdown

Add attach-detach tests for ovs bridge interface with multiple options, i.e. testing with pings, stress testing attach-detach with all options configurable.

Summary by CodeRabbit

  • Tests
    • Added a Linux-only virtual network test that hotplugs and hot-unplugs an Open vSwitch–backed NIC on a VM.
    • Validates host-side attachment to the expected OVS bridge and, when enabled, guest-side IP configuration and connectivity via bridge ping.
    • Includes modes with/without guest verification and basic vs. stress iterations.
    • Improves reliability with idempotent OVS bridge setup and thorough restore/cleanup after each run.

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 4cf28bdf-d771-4300-a87c-8ced95526012

📥 Commits

Reviewing files that changed from the base of the PR and between 9a69213 and b1867bd.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/virtual_network/attach_detach_device/attach_detach_ovs_interface.cfg
  • libvirt/tests/src/virtual_network/attach_detach_device/attach_detach_ovs_interface.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • libvirt/tests/cfg/virtual_network/attach_detach_device/attach_detach_ovs_interface.cfg
  • libvirt/tests/src/virtual_network/attach_detach_device/attach_detach_ovs_interface.py

Walkthrough

Changes

This PR adds a new libvirt test configuration and a matching Python test module for hotplugging and hot-unplugging an OVS-backed network interface. The config defines OVS bridge and guest addressing, interface attributes, and guest-check/stress variants. The test module creates or reuses the OVS bridge, attaches the interface to a running VM, verifies the host tap attachment, optionally configures the guest and pings the bridge, detaches the interface, checks live XML removal, and performs teardown.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant run as run()
  participant ovs as OVS bridge
  participant virsh as virsh
  participant vm as VM live XML
  participant guest as Guest session
  run->>ovs: setup_ovs_bridge(bridge_name, bridge_ip, bridge_netmask)
  run->>virsh: attach_device(iface xml)
  run->>ovs: verify_ovs_port(iface_mac, bridge_name, vm_name)
  opt verify_guest_iface enabled
    run->>guest: verify_guest_iface_and_ping(iface_mac)
    guest->>ovs: ping bridge_ip
  end
  run->>virsh: detach_device(iface xml)
  run->>vm: check interface removed from live XML
  run->>vm: destroy VM and restore VMXML
  run->>ovs: delete bridge if created by test
Loading

Related issues: None found.

Related PRs: None found.

Suggested labels: virtual_network, test-addition

Suggested reviewers: None specified.

Poem

A rabbit hops onto the OVS bridge so fine,
Attaching and detaching interfaces in a line,
Ping the guest, check the tap, verify with glee,
Then tear it all down, tidy as can be,
Iterations counted, stress tests done —
Another network trick this rabbit's won! 🐇🔌

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main change: adding libvirt virtual network tests for an OVS interface.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 `@libvirt/tests/cfg/virtual_network/iface_ovs.cfg`:
- Around line 90-93: The netmask fields bridge_netmask and guest_netmask are set
as dotted decimals but the test harness uses them with the `ip addr add
<ip>/<netmask> dev ...` invocation which expects a CIDR prefix length (e.g. 24);
update bridge_netmask and guest_netmask in iface_ovs.cfg to use numeric prefix
lengths (e.g. "24") so the `ip addr add` calls in the test will succeed when
assigning bridge_ip and guest_ip.
- Around line 84-87: The hotplug=false variant leaves iface_attach_xml and
iface_xml uninitialized but later reuses them in the attach/detach stress loop;
move the creation of iface_attach_xml and iface_xml out of the hotplug-only
branch in libvirt/tests/src/virtual_network/iface_ovs.py (or initialize them
before the re-attach/detach loop) so they are always defined when the stress
attach/detach path runs, or alternatively guard the loop to skip
detach/re-attach when hotplug == "no".

In `@libvirt/tests/src/virtual_network/iface_ovs.py`:
- Around line 245-247: The current branch only logs ping failures but does not
fail the test; change the block that runs session.cmd_status_output("ping -c 3
-W 5 %s" % ping_dest) (see variables test_ping, ping_dest and method
session.cmd_status_output) to assert the ping succeeded or raise a test failure
when status != 0 (e.g., replace the silent log of "FAILED" with an assertion or
explicit raise including the ping_dest and status), so any failed with_ping
connectivity check will stop the test rather than just logging.
- Around line 251-257: The loop currently detaches the interface on the last
iteration when detach is true and test_qos is false, and then the shared cleanup
also attempts a detach, causing a double-detach; modify the logic so the shared
cleanup only detaches if the interface is still attached—either by setting a
boolean flag (e.g., already_detached) when virsh.detach_interface or
virsh.detach_device is called inside the loop (using detach_type, iface_mac,
iface_xml), or by changing the shared cleanup condition to skip detach when
detach is true and iteration == attach_detach_iterations - 1 and not test_qos;
ensure the flag/condition is checked before calling virsh.detach_interface or
virsh.detach_device in the shared cleanup.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ddda4938-b7c7-4bd4-8725-e5d8c36cdc09

📥 Commits

Reviewing files that changed from the base of the PR and between c96ab65 and 2ae303f.

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

Comment thread libvirt/tests/cfg/virtual_network/iface_ovs.cfg Outdated
Comment thread libvirt/tests/cfg/virtual_network/iface_ovs.cfg Outdated
Comment thread libvirt/tests/src/virtual_network/iface_ovs.py Outdated
Comment thread libvirt/tests/src/virtual_network/iface_ovs.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@libvirt/tests/src/virtual_network/iface_ovs.py`:
- Around line 203-257: The loop always calls virsh.attach_device and later
references iface_xml (only set when attach_type == "device"), causing
UnboundLocalError and inconsistent API use across iterations; fix by computing
and preserving the chosen attach/detach mode and the corresponding prepared
payloads before the loop (use attach_type and detach_type to decide and create
iface_attach_xml or iface_xml once, or set flags like use_device_attach), then
inside the attach/detach loop call the matching API (e.g., call
virsh.attach_device with iface_attach_xml when attach_type == "device" or call
the interface-specific attach API when attach_type == "interface") and similarly
use iface_xml vs iface_attach_xml for virsh.detach_device/virsh.detach_interface
so the same mode and variables are used consistently across all
attach_detach_iterations.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1c61421a-945d-4f2d-8b84-b35a48a7cc7c

📥 Commits

Reviewing files that changed from the base of the PR and between 2ae303f and f7ea429.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/virtual_network/iface_ovs.cfg
  • libvirt/tests/src/virtual_network/iface_ovs.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • libvirt/tests/cfg/virtual_network/iface_ovs.cfg

Comment thread libvirt/tests/src/virtual_network/iface_ovs.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@libvirt/tests/src/virtual_network/iface_ovs.py`:
- Around line 212-214: The virsh.attach_interface call on line 212 (and
similarly on line 178) does not specify a MAC address parameter, causing virsh
to generate a random MAC. However, subsequent verifications reference iface_mac
which holds the original MAC from line 129, resulting in a mismatch. Fix this by
adding the --mac parameter to the virsh.attach_interface command options when
attach_type equals "interface", passing iface_mac as the value (e.g., add "--mac
%s" % iface_mac to the options string in both the attach_type == "interface"
block around line 212 and the similar attach block around line 178). This
ensures the MAC address used in the attach command matches the MAC being
verified in subsequent checks on lines 222, 226, and 241.
- Around line 251-255: The `ip addr add` command in the guest IP configuration
block fails on subsequent test iterations because the address persists from the
previous iteration when the interface is not detached. Before executing the
`session.cmd("ip addr add %s/%s dev %s"...)` command with the guest_ip and
guest_netmask values, first check if the IP address is already configured on the
interface using an `ip addr show` command, or alternatively flush existing
addresses on that interface using `ip addr flush dev %s` before adding the new
address. This prevents the "File exists" error on iterations greater than zero.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c11e961b-aebb-4376-a093-489bd6dafbd2

📥 Commits

Reviewing files that changed from the base of the PR and between f7ea429 and 18324b3.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/virtual_network/iface_ovs.cfg
  • libvirt/tests/src/virtual_network/iface_ovs.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • libvirt/tests/cfg/virtual_network/iface_ovs.cfg

Comment thread libvirt/tests/src/virtual_network/iface_ovs.py Outdated
Comment thread libvirt/tests/src/virtual_network/iface_ovs.py Outdated
@aniket-sahu-ibmx

Copy link
Copy Markdown
Author

Test Results:
--job-results-dir /home/stuff/tests/results --vt-only-filter "virtio_scsi virtio_net qcow2 SLES.16.1.ppc64le"
/usr/local/lib/python3.13/site-packages/avocado/core/init.py:18: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
import pkg_resources
No python imaging library installed. Screendump and Windows guest BSOD detection are disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
No python imaging library installed. PPM image conversion to JPEG disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
No python imaging library installed. Screendump and Windows guest BSOD detection are disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
No python imaging library installed. PPM image conversion to JPEG disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
JOB ID : 600372bc296bf938531d63f4c9c9180a57fc9e0e
JOB LOG : /home/stuff/tests/results/job-2026-06-18T08.12-600372b/job.log
(1/4) type_specific.io-github-autotest-libvirt.virtual_network.iface_ovs.attach_detach.without_ping.basic: STARTED
(1/4) type_specific.io-github-autotest-libvirt.virtual_network.iface_ovs.attach_detach.without_ping.basic: PASS (38.76 s)
(2/4) type_specific.io-github-autotest-libvirt.virtual_network.iface_ovs.attach_detach.without_ping.stress: STARTED
(2/4) type_specific.io-github-autotest-libvirt.virtual_network.iface_ovs.attach_detach.without_ping.stress: PASS (179.00 s)
(3/4) type_specific.io-github-autotest-libvirt.virtual_network.iface_ovs.attach_detach.with_ping.basic: STARTED
(3/4) type_specific.io-github-autotest-libvirt.virtual_network.iface_ovs.attach_detach.with_ping.basic: PASS (41.04 s)
(4/4) type_specific.io-github-autotest-libvirt.virtual_network.iface_ovs.attach_detach.with_ping.stress: STARTED
(4/4) type_specific.io-github-autotest-libvirt.virtual_network.iface_ovs.attach_detach.with_ping.stress: PASS (201.37 s)

@hholoubk

Copy link
Copy Markdown
Collaborator

I believe you are adding significant part of the needed test, the only issue is, the legacy way you unfortunately used.

Please check existing code in virtual_network/attach_detach_device/attach_iface_with*. there is much simplier way how to work with iface_parameters.

if you need to have it better parametrized .. you can use the approach used in virtual_network/attach_detach_device/attach_detach_nat_interface.cfg

instead of a lot of new parameters that has to be processed and passed, you will add one row

according cursorIDE AI I used to suggest the new approach structure (into .cfg)
iface_attrs = {
'type_name': 'bridge',
'source': {'bridge': 'ovsbr'},
'mac_address': '52:54:00:01:ab:cd',
'model': 'virtio',
'virtualport': {'type': 'openvswitch'},
}

in .py:
iface_attrs = eval(params.get('iface_attrs', '{}'))

iface = libvirt_vmxml.create_vm_device_by_type(
'interface', iface_attrs)

Second issue is, that it would be better to enlarge the existing variant attach.detach with your code. (this is again suggestion of AI ... I didn't check how the code really works .. but from brief check it looks it is right)

But looking at the code overall ... it feels like you didn't check existing codes and methods and helpers either in tp-libvirt providers or avocado-vt...

e.g. whole block 237->263:
"The guest verify block" duplicates utils_net.set_guest_ip_addr() and utils_net.ping() / network_base.ping_check().

Check and follow the same approach as attach_detach_nat_interface.py and iface_options.py instead of raw serial session.cmd() calls.

Third issue I see is more general. The code is not following best practices...
You added a lot of new code that would in future become difficult to maintain.
I know you probably followed the way of coding .. but when we change the code it should become better than previously

At least put several part that do one logical thing to specific method. i.e. there will be just
if
one_method_with_descriptive_name
else
other_method_with_descriptive_name

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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
`@libvirt/tests/src/virtual_network/attach_detach_device/attach_detach_ovs_interface.py`:
- Around line 35-40: The teardown logic is deleting an OVS bridge
unconditionally even when setup_ovs_bridge() only reused an existing bridge.
Update the test to track whether setup_ovs_bridge() actually created the bridge
(for example with a flag set when utils_net.add_ovs_bridge() runs) and only
remove it in the matching teardown path; if the bridge pre-existed, leave it
untouched. Apply the same change wherever the bridge is torn down in this test
flow so shared host OVS networking is not disrupted.
- Line 112: The `attach_detach_ovs_interface` test is parsing cfg-driven
`iface_attrs` with `eval()`, which should not be used for configuration parsing.
Update the parsing logic in this test to use `ast.literal_eval()` instead, and
make sure the module imports `ast` so `iface_attrs` is still converted from the
config string safely.
- Around line 37-40: The bridge setup commands in attach_detach_ovs_interface
use shell=True with bridge_name, bridge_ip, and bridge_netmask, which leaves
privileged ip invocation vulnerable to shell injection. Update the setup logic
in the relevant test helper to avoid shell interpolation by passing arguments to
process.run as argv, or validate/quote the inputs before executing the commands.
Keep the fix localized around the bridge setup calls that bring the interface up
and add the address.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fa0a20cb-e3e5-483f-bf3c-f71f63631847

📥 Commits

Reviewing files that changed from the base of the PR and between 18324b3 and 9a69213.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/virtual_network/attach_detach_device/attach_detach_ovs_interface.cfg
  • libvirt/tests/src/virtual_network/attach_detach_device/attach_detach_ovs_interface.py
✅ Files skipped from review due to trivial changes (1)
  • libvirt/tests/cfg/virtual_network/attach_detach_device/attach_detach_ovs_interface.cfg

@aniket-sahu-ibmx

Copy link
Copy Markdown
Author

Hi @hholoubk

I have refactored the code according to your instructions using the existing utilities, and added the tests in new files under virtual_network/attach_detach_device. Although I don't think it is a good idea to enlarge the existing attach.detach variant, as the existing attach variant has hardcoded values for the interface source, and also it follows the legacy standards, as you mentioned before.

Please let me know if any other changes are required.

Add attach-detach tests for ovs bridge interface with multiple
options, i.e. testing with pings, stress testing attach-detach
with all options configurable.
@aniket-sahu-ibmx

Copy link
Copy Markdown
Author

Test results after rework:
06:47:26 INFO : Running: /usr/local/bin/avocado run --vt-type libvirt --vt-config /home/stuff/tests/data/avocado-vt/backends/libvirt/cfg/backuprestore.cfg --force-job-id cccaefe0b78f84ea71bca205032306ff49b7b0d7 --job-results-dir /home/stuff/tests/results --vt-only-filter "virtio_scsi virtio_net qcow2 SLES.16.1.ppc64le"
/usr/local/lib/python3.13/site-packages/avocado/core/init.py:18: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
import pkg_resources
No python imaging library installed. Screendump and Windows guest BSOD detection are disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
No python imaging library installed. PPM image conversion to JPEG disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
No python imaging library installed. Screendump and Windows guest BSOD detection are disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
No python imaging library installed. PPM image conversion to JPEG disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
JOB ID : cccaefe0b78f84ea71bca205032306ff49b7b0d7
JOB LOG : /home/stuff/tests/results/job-2026-07-08T06.47-cccaefe/job.log
(1/4) type_specific.io-github-autotest-libvirt.virtual_network.attach_detach_device.attach_detach_ovs_interface.without_guest_check.basic: STARTED
(1/4) type_specific.io-github-autotest-libvirt.virtual_network.attach_detach_device.attach_detach_ovs_interface.without_guest_check.basic: PASS (38.65 s)
(2/4) type_specific.io-github-autotest-libvirt.virtual_network.attach_detach_device.attach_detach_ovs_interface.without_guest_check.stress: STARTED
(2/4) type_specific.io-github-autotest-libvirt.virtual_network.attach_detach_device.attach_detach_ovs_interface.without_guest_check.stress: PASS (89.97 s)
(3/4) type_specific.io-github-autotest-libvirt.virtual_network.attach_detach_device.attach_detach_ovs_interface.with_guest_check.basic: STARTED
(3/4) type_specific.io-github-autotest-libvirt.virtual_network.attach_detach_device.attach_detach_ovs_interface.with_guest_check.basic: PASS (54.76 s)
(4/4) type_specific.io-github-autotest-libvirt.virtual_network.attach_detach_device.attach_detach_ovs_interface.with_guest_check.stress: STARTED
(4/4) type_specific.io-github-autotest-libvirt.virtual_network.attach_detach_device.attach_detach_ovs_interface.with_guest_check.stress: PASS (252.33 s)
RESULTS : PASS 4 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB HTML : /home/stuff/tests/results/job-2026-07-08T06.47-cccaefe/results.html
JOB TIME : 445.57 s
06:54:54 INFO :
06:54:54 INFO : Summary of test results can be found below:
TestSuite TestRun Summary

guest_backuprestore Run Successfully executed
/home/stuff/tests/results/job-2026-07-08T06.47-cccaefe/job.log
| PASS 4 || CANCEL 0 || ERRORS 0 || FAILURES 0 || SKIP 0 || WARN 0 || INTERRUPT 0 |

@aniket-sahu-ibmx

Copy link
Copy Markdown
Author

@harihare keeping you in loop for this

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