Skip to content

Massive fix - #6915

Draft
BulaYoungR wants to merge 5 commits into
autotest:masterfrom
BulaYoungR:massive-fix
Draft

Massive fix#6915
BulaYoungR wants to merge 5 commits into
autotest:masterfrom
BulaYoungR:massive-fix

Conversation

@BulaYoungR

@BulaYoungR BulaYoungR commented Jul 23, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • Bug Fixes

    • Improved virtual network interface attach, detach, and update validation, including boot-order scenarios.
    • Corrected error detection for direct bridge VLAN network setup.
    • Enhanced compatibility with guest operating systems that provide either dhcpcd or dhcp-client.
  • Tests

    • Virtual network, migration, multi-VM, and SR-IOV tests now support a broader range of guest distributions.
    • Added clearer failures when no supported DHCP client can be installed.

Super User and others added 5 commits July 22, 2026 15:23
Libvirt now rejects VLAN tags on direct/bridge at define time
(virDomainNetDefValidate), so the negative test must use
define_error instead of start_error.
aarch64 EFI guests often already use per-device disk boot and lack
os/boot, so attach failed with a duplicate boot-order error instead of
the expected os/boot conflict. Prepare the domain like the newer
attach_iface_with_boot_order test.
CI guests are created with type=bridge (virbr0). Avocado drops an
iface_type cfg key, so set type=network in code when direct_net is
used. Otherwise update-device tries to change the interface type and
fails with "unable to change config on 'network' network type".
aarch64 EFI guests already have per-device disk boot, so update-device
with iface boot=1 failed with a duplicate boot-order error instead of
the expected os/boot conflict. Detect via expect_err_msg (avocado may
drop unknown cfg keys) and set os/boot like iface_attach_detach.
RHEL 10 no longer ships dhcp-client; install dhcpcd first and fall
back to dhcp-client for older guests.

Committer: Bolatbek Issakh <bissakh@redhat.com>
@BulaYoungR
BulaYoungR marked this pull request as draft July 23, 2026 14:24
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Virtual network tests now configure boot-order preconditions before interface modification and expect the macvtap VLAN failure during definition. Interface updates preserve type information and prepare boot and direct-network attributes before applying changes. Guest network setup in migration, multivm, and SR-IOV tests now accepts either dhcpcd or dhcp-client, failing only when both installations fail.

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is too vague to convey the main change in the patch. Use a concise, specific title that describes the primary update, such as the DHCP client/package handling change in virtual network tests.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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: 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/migration/migrate_network.py`:
- Around line 320-324: Update the post-migration DHCP handling around the
package_install fallback to retain which client was successfully installed, then
ensure the restart paths that currently invoke restart_dhclient use matching
dhcpcd logic or the client-agnostic utils_net.restart_guest_network helper.
Preserve the existing dhcp-client behavior while making dhcpcd-only guests
recover successfully.

In `@libvirt/tests/src/virtual_network/iface_update.py`:
- Around line 250-252: Replace the unsafe eval() call in the
update_driver_iommu_ast case with ast.literal_eval() when parsing
params.get('iommu_attrs', '{}'), and ensure the ast module is imported. Preserve
the resulting iommu_attrs value and the existing
libvirt_virtio.add_iommu_dev(vm, iommu_attrs) call.
🪄 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 Plus

Run ID: 80c08af1-3791-40e2-8d8e-625b06991c84

📥 Commits

Reviewing files that changed from the base of the PR and between c96ab65 and 47b5cc3.

📒 Files selected for processing (6)
  • libvirt/tests/cfg/virtual_network/iface_network.cfg
  • libvirt/tests/src/migration/migrate_network.py
  • libvirt/tests/src/virtual_network/iface_attach_detach.py
  • libvirt/tests/src/virtual_network/iface_update.py
  • libvirt/tests/src/virtual_network/virtual_network_multivms.py
  • provider/sriov/sriov_base.py

Comment on lines +320 to 324
# RHEL <= 9: dhcp-client; RHEL 10+: dhcpcd
if not (utils_package.package_install('dhcpcd', session=vm_session) or
utils_package.package_install('dhcp-client', session=vm_session)):
test.error("Failed to install dhcp client (dhcpcd/dhcp-client) on guest.")
utils_net.restart_guest_network(vm_session)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use the DHCP client that was actually installed after migration.

This fallback can select dhcpcd, but the later post-migration paths still execute restart_dhclient (defaulting to dhclient -r; dhclient at Lines 352 and 402). On a dhcpcd-only guest, network recovery can therefore fail even though installation succeeded. Retain the selected client and use matching restart logic, or call the client-agnostic network restart helper in those paths.

🤖 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 `@libvirt/tests/src/migration/migrate_network.py` around lines 320 - 324,
Update the post-migration DHCP handling around the package_install fallback to
retain which client was successfully installed, then ensure the restart paths
that currently invoke restart_dhclient use matching dhcpcd logic or the
client-agnostic utils_net.restart_guest_network helper. Preserve the existing
dhcp-client behavior while making dhcpcd-only guests recover successfully.

Comment on lines 250 to 252
if case == 'update_driver_iommu_ast':
iommu_attrs = eval(params.get('iommu_attrs', '{}'))
libvirt_virtio.add_iommu_dev(vm, iommu_attrs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C2 "iommu_attrs\s*=" libvirt/tests/cfg libvirt/tests/src

Repository: autotest/tp-libvirt

Length of output: 1682


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== file outline =="
ast-grep outline libvirt/tests/src/virtual_network/iface_update.py --view expanded | sed -n '1,220p' || true

echo "== top of iface_update.py =="
sed -n '1,40p' libvirt\Tests/src/virtual_network/iface_update.py 2>/dev/null || sed -n '1,40p' libvirt/tests/src/virtual_network/iface_update.py

echo "== cfg section around driver ast =="
sed -n '170,195p' libvirt/tests/cfg/virtual_network/iface_update.cfg

echo "== all eval()/literals parser related in target files =="
rg -n "\b(eval|literal_eval|params\.get|--cfg)\b" libvirt/tests/cfg/virtual_network/iface_update.cfg libvirt/tests/src/virtual_network/iface_update.py

Repository: autotest/tp-libvirt

Length of output: 8644


🌐 Web query:

Python ast.literal_eval security safe parsing literals eval arbitrary code execution documentation

💡 Result:

The function ast.literal_eval is designed to parse and evaluate strings containing only basic Python literal structures (e.g., strings, numbers, tuples, lists, dicts, sets, booleans, None, and Ellipsis) [1][2][3]. While it is fundamentally different from eval because it does not execute arbitrary Python code, it is not considered inherently "safe" for processing untrusted input [1][4]. Key security considerations include: 1. No Arbitrary Code Execution: Unlike eval, ast.literal_eval does not maintain a namespace, perform name lookups, or allow the invocation of functions or methods, which prevents direct arbitrary code execution [1][5]. 2. Denial of Service (DoS) Risks: The function is vulnerable to denial-of-service attacks when processing untrusted input [1]. A relatively small, specially crafted string can trigger excessive memory consumption, excessive CPU usage, or C stack exhaustion, leading to a crash of the Python interpreter [1][4][5]. 3. Documentation Updates: Historically, the Python documentation described ast.literal_eval as "safe," but this was determined to be misleading [1][6][3]. Official documentation has been updated to remove this guarantee and explicitly warns against using the function with untrusted sources [1][4]. For scenarios requiring the parsing of untrusted data, using a safer, non-executable format like JSON (via the json module) is generally recommended [7]. If ast.literal_eval must be used, input should be validated or restricted (e.g., by limiting the input length) to mitigate potential DoS risks [6].

Citations:


Do not execute iommu_attrs parameter text.

params is populated from test configuration, so eval() can execute arbitrary Python if the parameter is malformed or untrusted. Use ast.literal_eval() so only Python literals are accepted.

Proposed fix
+import ast
+
-            iommu_attrs = eval(params.get('iommu_attrs', '{}'))
+            iommu_attrs = ast.literal_eval(params.get('iommu_attrs', '{}'))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if case == 'update_driver_iommu_ast':
iommu_attrs = eval(params.get('iommu_attrs', '{}'))
libvirt_virtio.add_iommu_dev(vm, iommu_attrs)
import ast
if case == 'update_driver_iommu_ast':
iommu_attrs = ast.literal_eval(params.get('iommu_attrs', '{}'))
libvirt_virtio.add_iommu_dev(vm, iommu_attrs)
🧰 Tools
🪛 ast-grep (0.44.1)

[info] 250-250: use of eval can be insecure
Context: eval(params.get('iommu_attrs', '{}'))
Note: [CWE-94] Improper Control of Generation of Code ('Code Injection').

(no-eval-python)

🪛 Ruff (0.15.21)

[error] 251-251: Use of possibly insecure function; consider using ast.literal_eval

(S307)

🤖 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 `@libvirt/tests/src/virtual_network/iface_update.py` around lines 250 - 252,
Replace the unsafe eval() call in the update_driver_iommu_ast case with
ast.literal_eval() when parsing params.get('iommu_attrs', '{}'), and ensure the
ast module is imported. Preserve the resulting iommu_attrs value and the
existing libvirt_virtio.add_iommu_dev(vm, iommu_attrs) call.

Sources: Learnings, Linters/SAST tools

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.

1 participant