Skip to content

Conversation

@nanli1
Copy link
Contributor

@nanli1 nanli1 commented Oct 14, 2025

xxxx-298951:[network]change mtu settings of guest xml during migration
Signed-off-by: nanli [email protected]


avocado run --vt-type libvirt  --vt-machine-type q35  migration.xml_update.negative.update_interface_mtu

 (1/1) type_specific.io-github-autotest-libvirt.migration.xml_update.negative.update_interface_mtu: PASS (142.88 s)



Summary by CodeRabbit

  • New Features

    • Added ability to modify interface MTU in migration scenarios.
  • Tests

    • Added a negative migration test variant validating failures when interface MTU values differ.
    • Supports configurable original and updated MTU values for network interfaces.
    • Includes expected error matching for unsupported MTU mismatch configurations.

@coderabbitai
Copy link

coderabbitai bot commented Oct 14, 2025

Walkthrough

Adds a negative test variant that exercises updating a network interface MTU during migration and extends migration XML update logic to handle modify="mtu" by setting the interface mtu size to updated_mtu; test expects an error when MTU mismatch is unsupported.

Changes

Cohort / File(s) Summary of changes
Negative migration test variant (config)
libvirt/tests/cfg/migration/migration_xml_update.cfg
Adds update_interface_mtu variant: sets remove_all=interface, modify=mtu, status_error=yes; defines original_mtu and updated_mtu; adds add_device with network MTU from original_mtu; adds expected error pattern for unsupported MTU mismatch.
Migration XML update logic
libvirt/tests/src/migration/migration_xml_update.py
In create_migration_xml, adds branch for modify == "mtu" to locate the interface's mtu element and set its size attribute to updated_mtu.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant T as Test Runner
  participant CFG as migration_xml_update.cfg
  participant PY as migration_xml_update.py
  participant XML as Domain XML
  participant M as Migration Engine

  T->>CFG: Load variant "update_interface_mtu" (negative)
  T->>PY: run(modify="mtu", original_mtu, updated_mtu, status_error=yes)
  PY->>XML: create_migration_xml(modify="mtu")
  Note right of PY #EFEFEF: Find interface device -> mtu element\nSet `mtu/@size` = updated_mtu
  PY->>M: Attempt migration with modified XML
  M-->>T: Return error matching MTU mismatch pattern
  Note over T,M #FFF2CC: Test expects failure (status_error=yes)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Check XML element lookup and attribute set for mtu exists and handles missing element.
  • Verify test config values and the error regex/pattern match the runtime message.

Suggested labels

minorfix

Suggested reviewers

  • cliping

Poem

I nudged the MTU with a twitch and a hop,
Swapped one small size — then the packets did stop.
If migration balks and the logs shout "oh no!"
I'll hop to the XML and tweak it just so.
Carrots await when the tests finally flow. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Add case for updating interface mtu during migration" accurately and specifically describes the main change in the changeset. The modifications add a new test variant update_interface_mtu to the migration configuration and implement the corresponding logic to handle MTU updates during migration. The title is concise, clear, and uses descriptive terminology that conveys the primary objective of the PR, making it easy for a teammate to understand the change at a glance.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 002b190 and 8d285f5.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/migration/migration_xml_update.cfg (1 hunks)
  • libvirt/tests/src/migration/migration_xml_update.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libvirt/tests/cfg/migration/migration_xml_update.cfg
⏰ 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.12
  • GitHub Check: Python 3.11
  • GitHub Check: Python 3.8
  • GitHub Check: Python 3.9

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

🧹 Nitpick comments (1)
libvirt/tests/src/migration/migration_xml_update.py (1)

108-108: Verify trailing newline is required.

The added trailing newline appears to be a formatting preference. Confirm this aligns with the project's coding guidelines or was intentional.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 919ea51 and a9f3247.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/migration/migration_xml_update.cfg (1 hunks)
  • libvirt/tests/src/migration/migration_xml_update.py (2 hunks)
⏰ 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.12
  • GitHub Check: Python 3.9
  • GitHub Check: Python 3.11
  • GitHub Check: Python 3.8
🔇 Additional comments (1)
libvirt/tests/cfg/migration/migration_xml_update.cfg (1)

48-55: LGTM!

The test variant configuration is well-structured for a negative test case. The MTU values (5000 and 6000) are appropriate, and the error pattern correctly uses regex to match the expected failure message.

Comment on lines +58 to +61
elif modify == "mtu":
# Update MTU size for interface element
mtu_element = dev.find("mtu")
mtu_element.attrib['size'] = params.get("updated_mtu")
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Add null check for mtu_element.

The code assumes the mtu element exists in the device XML, but dev.find("mtu") returns None if not found. Accessing .attrib on None will raise an AttributeError.

Apply this diff to add a null check:

 elif modify == "mtu":
     # Update MTU size for interface element
     mtu_element = dev.find("mtu")
+    if mtu_element is None:
+        test.error("MTU element not found in device XML")
     mtu_element.attrib['size'] = params.get("updated_mtu")
📝 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
elif modify == "mtu":
# Update MTU size for interface element
mtu_element = dev.find("mtu")
mtu_element.attrib['size'] = params.get("updated_mtu")
elif modify == "mtu":
# Update MTU size for interface element
mtu_element = dev.find("mtu")
if mtu_element is None:
test.error("MTU element not found in device XML")
mtu_element.attrib['size'] = params.get("updated_mtu")
🤖 Prompt for AI Agents
In libvirt/tests/src/migration/migration_xml_update.py around lines 58 to 61,
the code assumes dev.find("mtu") returns an element and directly accesses
mtu_element.attrib which will raise if mtu is missing; add a null check: if
mtu_element is None, create a new 'mtu' element under dev (e.g., using
ElementTree.SubElement or equivalent) and set its 'size' attribute to
params.get("updated_mtu"), otherwise update the existing
mtu_element.attrib['size'] with params.get("updated_mtu"); ensure the value is
converted to a string and handle missing updated_mtu by skipping or raising as
appropriate.

@nanli1 nanli1 force-pushed the add_case_for_updating_interface_mtu_during_migration branch from a9f3247 to 002b190 Compare October 14, 2025 00:40
@nanli1 nanli1 requested review from chloerh, cliping and smitterl and removed request for chloerh and cliping October 14, 2025 00:54
Copy link
Contributor

@cliping cliping left a comment

Choose a reason for hiding this comment

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

LGTM

This commit adds test cases for updating network interface MTU settings
in guest XML configuration during live migration scenarios.

The motivation is to ensure network configuration integrity during
complex migration procedures, preventing connectivity issues that may
arise from inconsistent MTU settings. The approach involves modifying
MTU values at different migration stages and validating network
functionality post-migration.

Reference: xxxx-298951
Signed-off-by: nanli <[email protected]>
@nanli1 nanli1 force-pushed the add_case_for_updating_interface_mtu_during_migration branch from 002b190 to 8d285f5 Compare October 29, 2025 03:21
Copy link
Contributor

@smitterl smitterl left a comment

Choose a reason for hiding this comment

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

thanks

@smitterl smitterl merged commit d59fd82 into autotest:master Oct 29, 2025
6 checks passed
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.

3 participants