Skip to content

Virtual disk: add different migration test cases#6755

Open
meinaLi wants to merge 1 commit intoautotest:masterfrom
meinaLi:blk_nbd_disk_migration
Open

Virtual disk: add different migration test cases#6755
meinaLi wants to merge 1 commit intoautotest:masterfrom
meinaLi:blk_nbd_disk_migration

Conversation

@meinaLi
Copy link
Contributor

@meinaLi meinaLi commented Jan 8, 2026

Automate:
RHEL-175001 - [Migration] Migrate vm with disk type= block - logical volume based on iscsi
VIRT-19098 - [Migration] Migrate with nbd disk defined in xml

Summary by CodeRabbit

  • Tests
    • Added a migration test configuration covering mixed disk scenarios (file, block, NBD) with precopy and postcopy presets.
    • Added test routines to exercise block and NBD migration paths, including remote block setup, NBD/firewall handling, migration execution, verification, and guaranteed cleanup.
  • Chores
    • NBD export options expanded to accept an additional shared identifier for exports.

@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

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

Walkthrough

Adds a new migration test configuration at libvirt/tests/cfg/migration/migration_with_disk/migration_with_different_disks.cfg and a new test implementation libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py. The Python test exposes setup_block_remote and run, prepares VM disks (file/NFS, iSCSI block, NBD), handles remote iSCSI and NBD setup, firewall adjustments, migration execution with precopy/postcopy options, verification, and cleanup. Also updates provider/virtual_disk/disk_base.py to read a new shared_num parameter and pass it to the NbdExport constructor.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 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 'Virtual disk: add different migration test cases' directly matches the main changes: two new test files for migration scenarios with block and NBD disks.
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. 🎉

🧹 Recent nitpick comments
libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py (1)

86-87: Consider adding firewall reload after removing the port.

For consistency with the setup (if the reload is added there), and to ensure the firewall state is fully restored, consider adding firewall_cmd.reload() after remove_port. While less critical during cleanup, it ensures the runtime configuration matches the permanent configuration.

🔧 Proposed fix
         if disk_type == "nbd":
             firewall_cmd.remove_port(nbd_server_port, "tcp", permanent=True)
+            firewall_cmd.reload()

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

@meinaLi
Copy link
Contributor Author

meinaLi commented Jan 8, 2026

# avocado run --vt-type libvirt --vt-omit-data-loss --vt-machine-type q35 migration.migration_with_disk.migration_with_different_disks
JOB ID     : 1d139becb184689ac78da89360ed7043f5941771
JOB LOG    : /var/log/avocado/job-results/job-2026-01-07T21.02-1d139be/job.log
 (1/4) type_specific.io-github-autotest-libvirt.migration.migration_with_disk.migration_with_different_disks.with_precopy.block_disk: STARTED
 (1/4) type_specific.io-github-autotest-libvirt.migration.migration_with_disk.migration_with_different_disks.with_precopy.block_disk: PASS (223.28 s)
 (2/4) type_specific.io-github-autotest-libvirt.migration.migration_with_disk.migration_with_different_disks.with_precopy.nbd_disk: STARTED
 (2/4) type_specific.io-github-autotest-libvirt.migration.migration_with_disk.migration_with_different_disks.with_precopy.nbd_disk: PASS (197.10 s)
 (3/4) type_specific.io-github-autotest-libvirt.migration.migration_with_disk.migration_with_different_disks.with_postcopy.block_disk: STARTED
 (3/4) type_specific.io-github-autotest-libvirt.migration.migration_with_disk.migration_with_different_disks.with_postcopy.block_disk: PASS (220.93 s)
 (4/4) type_specific.io-github-autotest-libvirt.migration.migration_with_disk.migration_with_different_disks.with_postcopy.nbd_disk: STARTED
 (4/4) type_specific.io-github-autotest-libvirt.migration.migration_with_disk.migration_with_different_disks.with_postcopy.nbd_disk: PASS (197.44 s)
RESULTS    : PASS 4 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB HTML   : /var/log/avocado/job-results/job-2026-01-07T21.02-1d139be/results.html
JOB TIME   : 842.39 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: 0

🧹 Nitpick comments (4)
libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py (4)

38-42: Consider logging the result of the device mapper cleanup command.

The clear_dm_dev command removes device mapper devices and the volume group directory. While ignore_status=True is appropriate for cleanup operations that may not have existing resources, it would be helpful to log the command output for debugging purposes. This can help identify issues if the cleanup partially succeeds or fails.

📝 Suggested improvement
+    status, output = remote.run_remote_cmd(clear_dm_dev, params, ignore_status=True)
-    remote.run_remote_cmd(clear_dm_dev, params, ignore_status=True)
+    test.log.debug("Device mapper cleanup result (status=%s): %s", status, output)

75-76: Add error handling for firewall port operations.

The firewall port addition should verify success before proceeding, as failure to open the port will cause the NBD migration to fail. Consider checking the return value or catching exceptions.

🔒 Suggested improvement for firewall operations
-        if disk_type == "nbd":
-            firewall_cmd.add_port(nbd_server_port, "tcp", permanent=True)
-            process.run('firewall-cmd --reload')
+        if disk_type == "nbd":
+            try:
+                firewall_cmd.add_port(nbd_server_port, "tcp", permanent=True)
+                result = process.run('firewall-cmd --reload', verbose=True)
+                test.log.debug("Firewall port %s opened successfully", nbd_server_port)
+            except process.CmdError as e:
+                test.error(f"Failed to open firewall port {nbd_server_port}: {e}")

86-86: Evaluate whether ignoring iSCSI logout errors is appropriate.

The iscsiadm -m session -u command logs out of all iSCSI sessions with ignore_status=True. If this command fails, it might indicate active iSCSI sessions that weren't properly cleaned up, which could affect subsequent test runs. Consider logging the result to aid debugging.

📝 Suggested logging improvement
-            remote.run_remote_cmd("iscsiadm -m session -u", params, ignore_status=True)
+            status, output = remote.run_remote_cmd("iscsiadm -m session -u", params, ignore_status=True)
+            if status != 0:
+                test.log.debug("iSCSI logout warning (status=%s): %s", status, output)

91-92: Mirror the error handling from setup for firewall cleanup.

The firewall port removal in cleanup should have similar error handling as suggested for the setup to ensure symmetric behavior and proper logging.

♻️ Suggested improvement for cleanup symmetry
-        if disk_type == "nbd":
-            firewall_cmd.remove_port(nbd_server_port, "tcp", permanent=True)
-            process.run('firewall-cmd --reload')
+        if disk_type == "nbd":
+            try:
+                firewall_cmd.remove_port(nbd_server_port, "tcp", permanent=True)
+                process.run('firewall-cmd --reload', verbose=True)
+                test.log.debug("Firewall port %s closed successfully", nbd_server_port)
+            except Exception as e:
+                test.log.warning("Failed to close firewall port %s: %s", nbd_server_port, e)
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b9e2f43 and 64ca542.

📒 Files selected for processing (3)
  • libvirt/tests/cfg/migration/migration_with_disk/migration_with_different_disks.cfg
  • libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py
  • provider/virtual_disk/disk_base.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-12T10:00:09.383Z
Learnt from: yanglei-rh
Repo: autotest/tp-libvirt PR: 6675
File: libvirt/tests/cfg/virtual_network/qemu/nic_bonding.cfg:16-16
Timestamp: 2025-12-12T10:00:09.383Z
Learning: In tp-libvirt test config files (*.cfg under libvirt/tests/cfg), the cartesian config parser supports variable substitution using the ${variable_name} syntax. Variables defined in the cfg (e.g., filesize = 4000) are substituted into strings that reference them (e.g., count=${filesize}) before the Python test code receives the parameters. Treat this as a general behavior for these cfg files: define variables early, reference them with ${var}, and verify substitutions in tests to avoid hard-coded literals.

Applied to files:

  • libvirt/tests/cfg/migration/migration_with_disk/migration_with_different_disks.cfg
🧬 Code graph analysis (1)
libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py (2)
libvirt/tests/src/migration/migrate_vm.py (1)
  • run_remote_cmd (759-776)
provider/migration/base_steps.py (3)
  • setup_connection (343-364)
  • cleanup_connection (366-378)
  • sync_cpu_for_mig (550-570)
⏰ 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.8
  • GitHub Check: Python 3.11
🔇 Additional comments (4)
libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py (1)

107-112: LGTM: Proper cleanup handling with try-finally.

The use of try-finally ensures that cleanup is always executed regardless of test success or failure, which is essential for preventing resource leaks and maintaining a clean test environment.

libvirt/tests/cfg/migration/migration_with_disk/migration_with_different_disks.cfg (2)

38-38: No action needed.

The disk_dict syntax is valid Python dictionary literal syntax and will be properly handled by the test framework. The cartesian config parser performs variable substitution (e.g., ${check_disk_kname_after_mig}"sda" or "vdb") before the resulting string reaches ast.literal_eval() in the test code, ensuring correct parsing.


44-44: No type conversion needed for shared_num.

The shared_num parameter follows the same pattern as other numeric configuration parameters like nbd_server_port, which are also retrieved as strings via self.params.get() and passed directly to NbdExport() without explicit conversion. The consistent handling across the codebase indicates that NbdExport handles string-to-appropriate-type conversion internally or accepts both string and numeric types.

Likely an incorrect or invalid review comment.

provider/virtual_disk/disk_base.py (1)

203-203: Verify that NbdExport handles None for shared_num parameter.

The shared_num parameter is retrieved using get() without a default value (line 203), which means it will be None if not present in params. While other code paths in the repository omit the shared_num parameter entirely when calling NbdExport, this code explicitly passes it even when None. Verify that the NbdExport constructor gracefully handles None for this parameter, or consider providing a sensible default value here to align with the pattern used for other similar parameters (e.g., enable_tls, export_name).

@meinaLi meinaLi force-pushed the blk_nbd_disk_migration branch from 64ca542 to e91b585 Compare January 8, 2026 02:35
@meinaLi
Copy link
Contributor Author

meinaLi commented Jan 8, 2026

This PR depends on avocado-framework/avocado-vt#4300.

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

🧹 Nitpick comments (3)
libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py (3)

73-75: Consider adding explicit error handling for firewall reload.

The firewall-cmd --reload command on line 75 doesn't specify error handling. While the default behavior will raise an exception on failure (which is appropriate for setup), being explicit improves clarity.

♻️ Optional: Add explicit error handling
         if disk_type == "nbd":
             firewall_cmd.add_port(nbd_server_port, "tcp", permanent=True)
-            process.run('firewall-cmd --reload')
+            process.run('firewall-cmd --reload', shell=True, verbose=True)

89-91: Make firewall cleanup more defensive.

In the cleanup path, the firewall-cmd --reload on line 91 should use ignore_status=True to prevent cleanup failures from masking the actual test results or blocking subsequent cleanup steps.

♻️ Recommended: Add ignore_status for cleanup robustness
         if disk_type == "nbd":
             firewall_cmd.remove_port(nbd_server_port, "tcp", permanent=True)
-            process.run('firewall-cmd --reload')
+            process.run('firewall-cmd --reload', shell=True, ignore_status=True)

96-96: Minor: Fix formatting with double space.

Line 96 has a double space before the assignment operator.

♻️ Formatting fix
-    client_ip  = params.get("client_ip")
+    client_ip = params.get("client_ip")
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64ca542 and e91b585.

📒 Files selected for processing (3)
  • libvirt/tests/cfg/migration/migration_with_disk/migration_with_different_disks.cfg
  • libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py
  • provider/virtual_disk/disk_base.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • libvirt/tests/cfg/migration/migration_with_disk/migration_with_different_disks.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.9
  • GitHub Check: Python 3.11
  • GitHub Check: Python 3.8
  • GitHub Check: Python 3.12
🔇 Additional comments (3)
libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py (2)

17-48: LGTM!

The remote iSCSI setup logic is well-structured. The defensive cleanup of existing device mapper devices before creating new ones (lines 37-41) helps prevent conflicts from previous test runs.


106-111: LGTM!

The try/finally pattern ensures cleanup runs regardless of test outcome, which is essential for preventing resource leaks in test infrastructure.

provider/virtual_disk/disk_base.py (1)

203-209: Verify that NbdExport accepts the shared_num parameter.

The shared_num parameter is not used in any other NbdExport instantiation throughout the codebase, and the virttest.utils_nbd module source is not available in the repository or public documentation. Confirm that the NbdExport constructor in virttest.utils_nbd supports the shared_num parameter and properly handles None values when the parameter is not configured.

@meinaLi meinaLi force-pushed the blk_nbd_disk_migration branch from e91b585 to 9423258 Compare January 8, 2026 02:40
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: 0

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

65-68: Consider using try/finally for session cleanup.

If an exception occurs in get_non_root_disk_name or dd_data_to_vm_disk, the session won't be closed properly.

♻️ Suggested improvement
         vm_session = vm.wait_for_login()
-        source_disk_name, _ = libvirt_disk.get_non_root_disk_name(vm_session)
-        utils_disk.dd_data_to_vm_disk(vm_session, source_disk_name)
-        vm_session.close()
+        try:
+            source_disk_name, _ = libvirt_disk.get_non_root_disk_name(vm_session)
+            utils_disk.dd_data_to_vm_disk(vm_session, source_disk_name)
+        finally:
+            vm_session.close()
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e91b585 and 9423258.

📒 Files selected for processing (3)
  • libvirt/tests/cfg/migration/migration_with_disk/migration_with_different_disks.cfg
  • libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py
  • provider/virtual_disk/disk_base.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • provider/virtual_disk/disk_base.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-12T10:00:09.383Z
Learnt from: yanglei-rh
Repo: autotest/tp-libvirt PR: 6675
File: libvirt/tests/cfg/virtual_network/qemu/nic_bonding.cfg:16-16
Timestamp: 2025-12-12T10:00:09.383Z
Learning: In tp-libvirt test config files (*.cfg under libvirt/tests/cfg), the cartesian config parser supports variable substitution using the ${variable_name} syntax. Variables defined in the cfg (e.g., filesize = 4000) are substituted into strings that reference them (e.g., count=${filesize}) before the Python test code receives the parameters. Treat this as a general behavior for these cfg files: define variables early, reference them with ${var}, and verify substitutions in tests to avoid hard-coded literals.

Applied to files:

  • libvirt/tests/cfg/migration/migration_with_disk/migration_with_different_disks.cfg
🧬 Code graph analysis (1)
libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py (2)
provider/migration/base_steps.py (4)
  • setup_connection (343-364)
  • cleanup_connection (366-378)
  • MigrationBase (27-477)
  • verify_default (309-324)
provider/virtual_disk/disk_base.py (3)
  • add_vm_disk (95-112)
  • cleanup_disk_preparation (269-302)
  • DiskBase (25-637)
⏰ 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.8
  • GitHub Check: Python 3.12
  • GitHub Check: Python 3.11
🔇 Additional comments (6)
libvirt/tests/cfg/migration/migration_with_disk/migration_with_different_disks.cfg (2)

1-29: LGTM - Base migration configuration is well-structured.

The base configuration correctly sets up NFS storage, migration parameters, and post-migration verification flags. Variable substitutions for migration hosts/credentials follow established patterns.


30-50: LGTM - Test variants are well-defined.

The block_disk and nbd_disk variants correctly specify distinct parameters, and the migration option variants (precopy/postcopy) provide appropriate virsh options. The shared_num = "2" parameter aligns with the NBD export constructor changes in disk_base.py.

libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py (4)

1-14: LGTM - Imports are appropriate.

All imported modules are utilized in the test implementation.


17-48: LGTM - iSCSI remote setup logic is correct.

The function correctly sets up a local iSCSI target, performs remote login, clears stale device mappings, and creates the LVM structure on the remote host. The cleanup command properly handles existing VG remnants before recreation.


77-91: LGTM - Cleanup logic correctly handles both disk types.

The cleanup properly sequences iSCSI operations (remote logout before local target teardown) and handles firewall port removal for NBD. The disk_obj.cleanup_disk_preparation handles the local disk resources created by add_vm_disk.


93-111: LGTM - Main test flow is well-structured.

The parameter extraction, object initialization, and try/finally pattern ensure proper resource management. Using ast.literal_eval for parsing disk_dict is appropriate for safely evaluating the configuration string.

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.

Others LGTM.


if disk_type == "nbd":
firewall_cmd.add_port(nbd_server_port, "tcp", permanent=True)
process.run('firewall-cmd --reload')
Copy link
Contributor

Choose a reason for hiding this comment

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

'firewall-cmd --reload' is already included in add_port(), so this line can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it now, thanks.

portal_ip=client_ip)
if disk_type == "nbd":
firewall_cmd.remove_port(nbd_server_port, "tcp", permanent=True)
process.run('firewall-cmd --reload')
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

@meinaLi meinaLi force-pushed the blk_nbd_disk_migration branch from 9423258 to 3f09072 Compare February 10, 2026 06:09
Automate:
RHEL-175001 - [Migration] Migrate vm with disk type= block - logical volume based on iscsi
VIRT-19098 - [Migration] Migrate with nbd disk defined in xml

Signed-off-by: Meina Li <meili@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: 1

🤖 Fix all issues with AI agents
In
`@libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py`:
- Around line 73-74: After adding the NBD port with
firewall_cmd.add_port(nbd_server_port, "tcp", permanent=True) when disk_type ==
"nbd", ensure the runtime firewall is updated so the port is actually open: call
the firewall reload (or follow the project pattern by sleeping briefly)
immediately after add_port to apply the change at runtime (mirror the behavior
in provider/migration/base_steps.py where they wait/reload after add_port).
Modify the block handling disk_type == "nbd" to invoke the firewall reload or a
short time.sleep(2) right after firewall_cmd.add_port so the NBD server port
becomes accessible at runtime.
🧹 Nitpick comments (3)
libvirt/tests/cfg/migration/migration_with_disk/migration_with_different_disks.cfg (1)

46-50: Consider increasing postcopy timeout for stability.

The --timeout 10 in postcopy migration may be tight for slower environments or larger memory guests, potentially causing premature postcopy triggers or test flakiness.

libvirt/tests/src/migration/migration_with_disk/migration_with_different_disks.py (2)

3-3: Remove unused import.

The process module from avocado.utils is imported but never used in this file.

🧹 Proposed fix
-from avocado.utils import process
-
 from virttest import remote

88-89: Match firewall reload in cleanup for consistency.

Similar to the setup, if reload is added after add_port, it should also be added after remove_port to ensure the port is closed at runtime.

🔧 Proposed fix
         if disk_type == "nbd":
             firewall_cmd.remove_port(nbd_server_port, "tcp", permanent=True)
+            firewall_cmd.reload()

@meinaLi meinaLi force-pushed the blk_nbd_disk_migration branch from 3f09072 to d5cdc6a Compare February 10, 2026 06:13
@meinaLi meinaLi requested a review from cliping February 10, 2026 07:11
@meinaLi
Copy link
Contributor Author

meinaLi commented Feb 26, 2026

@iccaszhulili Can you help review this PR? Thanks.

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