Skip to content

iface_update: Support new libvirt error message for boot order conflicts#6801

Open
BulaYoungR wants to merge 1 commit intoautotest:masterfrom
BulaYoungR:iface_update
Open

iface_update: Support new libvirt error message for boot order conflicts#6801
BulaYoungR wants to merge 1 commit intoautotest:masterfrom
BulaYoungR:iface_update

Conversation

@BulaYoungR
Copy link

@BulaYoungR BulaYoungR commented Feb 11, 2026

Fix negative test failure caused by libvirt error message format change in newer versions.

The test checks that libvirt correctly rejects setting boot order on a network interface when os/boot is already configured. However, libvirt changed the error message format between versions.

Changed file: libvirt/tests/src/virtual_network/iface_update.py
Changed lines: 283-302

Old libvirt error message:
"per-device boot elements cannot be used together with os/boot elements"

New libvirt error message:
"boot order 1 is already used by another device"

The test was checking only for the old message format, causing it to fail with newer libvirt versions even though the actual error was correct.

Fix: Modified error checking logic to accept both error message formats:

  • First check the expected message from test config (expect_err_msg)
  • If not matched, try alternative known patterns for boot order conflicts
  • This ensures compatibility with both old and new libvirt versions

The solution uses fallback patterns instead of updating test config files, making it work across different libvirt versions without needing separate test configurations.
Committer: Bolatbek Issakh bissakh@redhat.com

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for libvirt boot-order conflicts, recognizing both legacy and current error formats.
  • Refactor

    • Reworked interface update logic to use a generalized, dictionary-driven approach for broader and more maintainable attribute coverage.
  • Other

    • Added explicit network XML state logging around interface updates for better traceability.

@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

Walkthrough

Replaces per-attribute interface update code in libvirt/tests/src/virtual_network/iface_update.py with a generalized two-dictionary approach: iface_dict_bef and iface_dict_aft, populated from update_list_bef and update_list_aft via looped names() lookups. Expanded tracked attributes (lists include source, type, inbound, outbound, mtu, rom, driver_host, driver_guest, filter, model, boot, bandwidth, coalesce, alias, addr, teaming, filter_parameters; aft also includes link). Removed ROM path/file existence adjustment and ipxe-roms-qemu handling. Added network XML logging after bandwidth deletion and extended update-device error handling to match both old and new boot-order conflict messages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: enhancing error handling to support a new libvirt error message format for boot order conflicts, which is the primary focus of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

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

No actionable comments were generated in the recent review. 🎉


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

@BulaYoungR
Copy link
Author

Before fix

(.libvirt-ci-venv-ci-runtest-3tSibe) [root@ampere-mtsnow-altramax-62 libvirt-ci-latest-venv]# bin/avocado run --vt-type libvirt --vt-omit-data-loss --vt-machine-type arm64-mmio virtual_network.iface_update.negative_test.update_boot_order.vm_on.with_os_boot --job-timeout 1200 --vt-connect-uri qemu:///system
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     : e9c8b9f131a3ed173743a935b3facbb9e3f33416
JOB LOG    : /var/log/avocado/job-results/job-2026-02-11T10.24-e9c8b9f/job.log
 (1/1) type_specific.io-github-autotest-libvirt.virtual_network.iface_update.negative_test.update_boot_order.vm_on.with_os_boot: STARTED
 (1/1) type_specific.io-github-autotest-libvirt.virtual_network.iface_update.negative_test.update_boot_order.vm_on.with_os_boot: FAIL: The real error msg:'error: Failed to update device from /var/tmp/xml_utils_temp_35yau450.xml\nerror: unsupported configuration: boot order 1 is already used by another device' does not match expect one:per-device boot elements cannot be used together with ... (9.47 s)
RESULTS    : PASS 0 | ERROR 0 | FAIL 1 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB HTML   : /var/log/avocado/job-results/job-2026-02-11T10.24-e9c8b9f/results.html
JOB TIME   : 10.80 s

Test summary:
1-type_specific.io-github-autotest-libvirt.virtual_network.iface_update.negative_test.update_boot_order.vm_on.with_os_boot: FAIL

After fix

(.libvirt-ci-venv-ci-runtest-3tSibe) [root@ampere-mtsnow-altramax-62 libvirt-ci-latest-venv]# bin/avocado run --vt-type libvirt --vt-omit-data-loss --vt-machine-type arm64-mmio virtual_network.iface_update.negative_test.update_boot_order.vm_on.with_os_boot --job-timeout 1200 --vt-connect-uri qemu:///system
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     : 0f7e4db398d8a15a5120348bd9202d5755161f33
JOB LOG    : /var/log/avocado/job-results/job-2026-02-11T10.34-0f7e4db/job.log
 (1/1) type_specific.io-github-autotest-libvirt.virtual_network.iface_update.negative_test.update_boot_order.vm_on.with_os_boot: STARTED
 (1/1) type_specific.io-github-autotest-libvirt.virtual_network.iface_update.negative_test.update_boot_order.vm_on.with_os_boot: PASS (9.77 s)
RESULTS    : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB HTML   : /var/log/avocado/job-results/job-2026-02-11T10.34-0f7e4db/results.html
JOB TIME   : 10.87 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

🤖 Fix all issues with AI agents
In `@libvirt/tests/src/virtual_network/iface_update.py`:
- Around line 267-282: The code calls re.search(expect_err_msg, real_err_msg)
without guarding for expect_err_msg being None (params.get() may return None),
causing a TypeError; update the logic in the block that computes match_found
(around the variables expect_err_msg, real_err_msg, alternative_patterns) to
first check that expect_err_msg is a non-empty string (or compiled pattern)
before invoking re.search, e.g., only perform the initial re.search when
expect_err_msg is truthy and otherwise skip to trying alternative_patterns;
ensure match_found is a boolean after these checks so the existing test.fail
path remains valid.

Comment on lines +267 to 282
# Support both old and new libvirt error messages for boot order conflicts
# Old: "per-device boot elements cannot be used together with os/boot elements"
# New: "boot order X is already used by another device"
alternative_patterns = [
"boot order .* is already used by another device",
"per-device boot elements cannot be used together with os/boot elements"
]
match_found = re.search(expect_err_msg, real_err_msg, re.IGNORECASE)
if not match_found:
# Try alternative patterns for known cases where error message changed
match_found = any(re.search(pattern, real_err_msg, re.IGNORECASE)
for pattern in alternative_patterns)

if not match_found:
test.fail("The real error msg:'%s' does not match expect one:"
'%s' % (real_err_msg, expect_err_msg))
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Handle potential None value for expect_err_msg before regex matching.

If expect_err_msg is not set in test params (line 121 uses params.get() which returns None), re.search(expect_err_msg, ...) at line 274 will raise TypeError: first argument must be string or compiled pattern.

The fallback logic for supporting both old and new libvirt error messages is well-designed for cross-version compatibility.

🛡️ Proposed fix to guard against None
             alternative_patterns = [
                 "boot order .* is already used by another device",
                 "per-device boot elements cannot be used together with os/boot elements"
             ]
-            match_found = re.search(expect_err_msg, real_err_msg, re.IGNORECASE)
+            match_found = False
+            if expect_err_msg:
+                match_found = re.search(expect_err_msg, real_err_msg, re.IGNORECASE)
             if not match_found:
                 # Try alternative patterns for known cases where error message changed
                 match_found = any(re.search(pattern, real_err_msg, re.IGNORECASE) 
                                  for pattern in alternative_patterns)
🤖 Prompt for AI Agents
In `@libvirt/tests/src/virtual_network/iface_update.py` around lines 267 - 282,
The code calls re.search(expect_err_msg, real_err_msg) without guarding for
expect_err_msg being None (params.get() may return None), causing a TypeError;
update the logic in the block that computes match_found (around the variables
expect_err_msg, real_err_msg, alternative_patterns) to first check that
expect_err_msg is a non-empty string (or compiled pattern) before invoking
re.search, e.g., only perform the initial re.search when expect_err_msg is
truthy and otherwise skip to trying alternative_patterns; ensure match_found is
a boolean after these checks so the existing test.fail path remains valid.

Fix negative test failure caused by libvirt error message format change
in newer versions.

The test checks that libvirt correctly rejects setting boot order on a
network interface when os/boot is already configured. However, libvirt
changed the error message format between versions.

Changed file: libvirt/tests/src/virtual_network/iface_update.py
Changed lines: 283-302

Old libvirt error message:
    "per-device boot elements cannot be used together with os/boot elements"

New libvirt error message:
    "boot order 1 is already used by another device"

The test was checking only for the old message format, causing it to fail
with newer libvirt versions even though the actual error was correct.

Fix: Modified error checking logic to accept both error message formats:
- First check the expected message from test config (expect_err_msg)
- If not matched, try alternative known patterns for boot order conflicts
- This ensures compatibility with both old and new libvirt versions

The solution uses fallback patterns instead of updating test config files,
making it work across different libvirt versions without needing separate
test configurations.
Committer: Bolatbek Issakh <bissakh@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.

1 participant