Skip to content

Conversation

@nanli1
Copy link
Contributor

@nanli1 nanli1 commented Nov 22, 2025

   xxxx-95968 - [virtual network][virtual-nic-device] Migrate guest while scp files
   xxxx-296253 - [virtual network][virtual-nic-device] migrate guest with iommu_platform=on and different memory size

Signed-off-by: nanli nanli@redhat.com

VT_TYPE=libvirt python3 /home/kar/ConfigTest.py --testcase=virtual_network.qemu_test.migrate_with_file_transfer  --guestname=RHEL.10.1 --machines=q35 --nicmodel=virtio_net --platform=x86_64  --customsparams='netdst=switch'  --clone=no 

xxxx-95968 case:
 (1/6) qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.10.1.x86_64.io-github-autotest-libvirt.virtual_network.qemu_test.migrate_with_file_transfer.default_mem.default.q35: PASS (484.03 s)

xxxx-296253 
 (2/6) qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.10.1.x86_64.io-github-autotest-libvirt.virtual_network.qemu_test.migrate_with_file_transfer.default_mem.with_iommu.q35: PASS (513.28 s)
 (3/6) qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.10.1.x86_64.io-github-autotest-libvirt.virtual_network.qemu_test.migrate_with_file_transfer.default_mem.with_virtio_iommu.q35: PASS (596.79 s)
 (4/6) qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.10.1.x86_64.io-github-autotest-libvirt.virtual_network.qemu_test.migrate_with_file_transfer.minimum_mem.default.q35: PASS (486.03 s)
 (5/6) qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.10.1.x86_64.io-github-autotest-libvirt.virtual_network.qemu_test.migrate_with_file_transfer.minimum_mem.with_iommu.q35: PASS (400.47 s)
 (6/6) qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.10.1.x86_64.io-github-autotest-libvirt.virtual_network.qemu_test.migrate_with_file_transfer.minimum_mem.with_virtio_iommu.q35: PASS (400.03 s)



Summary by CodeRabbit

  • Tests
    • Added an automated test and configuration that validates VM migration with concurrent file transfer, host-to-host transfer, network reachability checks, optional reverse migration, and OS-specific transfer path handling.
  • Chores
    • Minor internal import/utility adjustment to support the new migration test.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 22, 2025

Walkthrough

Adds a new Libvirt QEMU migration test that performs file transfer during VM live migration. Introduces a configuration block migrate_with_file_transfer at libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg describing lifecycle actions, NFS-backed storage, disk/network/migration settings, file-transfer parameters (with a Windows guest_path override). Adds the test implementation libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py exposing run(test, params, env) which prepares migration state and URIs, establishes destination login, verifies connectivity, orchestrates migration (optionally migrating back), and ensures cleanup. Also adds an import of virttest.utils_test in provider/migration/migration_base.py.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py: parameter parsing, session/login handling, network reachability checks, migration invocation, error handling, and cleanup/finally branches.
  • Validate libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg for correct parameter names, types, and platform-specific overrides.
  • Verify the added virttest.utils_test import in provider/migration/migration_base.py for import-order or side-effect risks.

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 title 'virtual_network: add case for migrating guest while scp files' clearly and specifically describes the main change: adding a new test case for VM migration with concurrent SCP file transfers.
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

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

@nanli1 nanli1 force-pushed the add_case_for_migrating_guest_while_scp_files branch from 7b0e98b to 1e791de Compare November 22, 2025 14:10
@nanli1 nanli1 marked this pull request as draft November 22, 2025 14:11
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/virtual_network/qemu/migrate_with_file_transfer.py (1)

48-51: Flow for migrating the VM back looks good; please confirm required params exist.

The migrate_vm_back guard plus migration_obj.run_migration_back() is consistent with MigrationBase.run_migration_back() and the new cfg sets migrate_vm_back = "yes", so this path will execute.

That helper, however, relies on parameters like server_ip, server_user, server_pwd, client_ip, and client_pwd being present in params (often wired from migrate_source_host/migrate_dest_host in higher‑level cfg). They’re not visible in this snippet.

Can you double‑check that those fields are provided by the surrounding virtual_network/qemu configs for this test variant, so the “migrate back” step doesn’t fail due to missing connection info?

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a302a6f and 1e791de.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg (1 hunks)
  • libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (2)
provider/migration/base_steps.py (3)
  • setup_connection (343-364)
  • cleanup_connection (366-378)
  • MigrationBase (27-477)
provider/virtual_network/network_base.py (1)
  • ping_check (98-149)
⏰ 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). (2)
  • GitHub Check: Python 3.9
  • GitHub Check: Python 3.8

@nanli1 nanli1 force-pushed the add_case_for_migrating_guest_while_scp_files branch from 1e791de to 053da21 Compare November 23, 2025 13:27
@nanli1 nanli1 marked this pull request as ready for review November 23, 2025 13:53
@nanli1 nanli1 changed the title add case for migrating guest while scp files Vvirtual_network: add case for migrating guest while scp files Nov 23, 2025
@nanli1
Copy link
Contributor Author

nanli1 commented Nov 23, 2025

Migrate when transfer file log


L0475 DEBUG| [stderr] Migration: [ 3.40 %]
[stdlog] 2025-11-23 14:32:46,672 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.42 %]
[stdlog] 2025-11-23 14:32:47,173 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.43 %]
[stdlog] 2025-11-23 14:32:47,194 aexpect.remote remote           L0653 DEBUG| The scp process terminated with status 0
[stdlog] 2025-11-23 14:32:47,202 aexpect.remote remote           L1385 INFO | Copy file from 10.37.158.122:/var/tmp/transferred-u8ax7_s5 to /var/tmp/avocado_8bopr2a5/tmp-_9txvv0a, estimated throughput: 1072.54 MB/s
[stdlog] 2025-11-23 14:32:47,673 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.44 %]
[stdlog] 2025-11-23 14:32:48,175 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.45 %]
[stdlog] 2025-11-23 14:32:48,676 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.46 %]
[stdlog] 2025-11-23 14:32:49,178 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.48 %]
[stdlog] 2025-11-23 14:32:49,678 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.49 %]
[stdlog] 2025-11-23 14:32:50,180 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.50 %]
[stdlog] 2025-11-23 14:32:50,680 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.51 %]
[stdlog] 2025-11-23 14:32:51,181 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.52 %]
[stdlog] 2025-11-23 14:32:51,681 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.54 %]
[stdlog] 2025-11-23 14:32:52,182 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.55 %]
[stdlog] 2025-11-23 14:32:52,683 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.57 %]
[stdlog] 2025-11-23 14:32:53,183 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.59 %]
[stdlog] 2025-11-23 14:32:53,252 avocado.virttest.utils_test error_context    L0084 INFO | Context: Compare md5sum between original file and transferred file
[stdlog] 2025-11-23 14:32:53,259 avocado.virttest.utils_test __init__         L0813 INFO | Cleaning temp file on guest
[stdlog] 2025-11-23 14:32:53,259 aexpect.client client           L1365 DEBUG| [10.37.158.122] Sending command: rm -f /var/tmp/transferred-u8ax7_s5
[stdlog] 2025-11-23 14:32:53,405 aexpect.client client           L1365 DEBUG| [10.37.158.122] Sending command: echo $?
[stdlog] 2025-11-23 14:32:53,551 avocado.virttest.migration migration        L0631 DEBUG| start_time:1763904742, eclipse_time:31
[stdlog] 2025-11-23 14:32:53,685 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.60 %]
[stdlog] 2025-11-23 14:32:54,185 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.62 %]
[stdlog] 2025-11-23 14:32:54,687 avocado.utils.process process          L0475 DEBUG| [stderr] Migration: [ 3.63 %]

@nanli1 nanli1 requested a review from cliping November 23, 2025 13:57
@nanli1 nanli1 changed the title Vvirtual_network: add case for migrating guest while scp files virtual_network: add case for migrating guest while scp files Nov 24, 2025
@nanli1 nanli1 force-pushed the add_case_for_migrating_guest_while_scp_files branch from 053da21 to 6f7fe9d Compare November 24, 2025 07:18
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/virtual_network/qemu/migrate_with_file_transfer.py (1)

34-36: Consider VM state validation before migration.

The is_alive() check is a basic safeguard, but it doesn't detect states like paused or crashed. If more robust pre-migration state validation isn't already handled by MigrationBase.run_migration(), consider using vm.wait_for_login() or checking vm.state() to ensure the VM is fully operational.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 053da21 and 6f7fe9d.

📒 Files selected for processing (3)
  • libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg (1 hunks)
  • libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (1 hunks)
  • provider/migration/migration_base.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-18T08:47:14.465Z
Learnt from: smitterl
Repo: autotest/tp-libvirt PR: 6072
File: libvirt/tests/src/passthrough/pci/libvirt_pci_passthrough_hotplug.py:239-241
Timestamp: 2025-11-18T08:47:14.465Z
Learning: In tp-libvirt tests, `utils_test.ping` is a valid function that exists in the avocado-vt framework (virttest.utils_test module). It is an alias to `utils_net.ping` and supports parameters including dest, count, interface, timeout, and session.

Applied to files:

  • provider/migration/migration_base.py
⏰ 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.12
  • GitHub Check: Python 3.11
  • GitHub Check: Python 3.8
🔇 Additional comments (4)
provider/migration/migration_base.py (1)

15-15: LGTM: Import supports dynamic function execution.

The utils_test import enables dynamic function calls through eval() in parse_funcs (used for action_during_mig parameters). Based on the PR context, the test configuration references utils_test.run_file_transfer as an action during migration.

libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (3)

11-14: LGTM: Imports are appropriate and used.

All imports are utilized in the test implementation and follow standard conventions.


58-68: Parameter extraction follows framework patterns.

The parameter extraction uses appropriate type-safe methods (get_boolean, get_numeric) with sensible defaults. Line 66 adds a self-reference (params["params"] = params) which enables nested functions called via action_during_mig to access the test context objects—this aligns with the pattern used in migration_base.py's parse_funcs.


70-73: LGTM: Proper cleanup with try/finally pattern.

The try/finally block ensures cleanup_connection() is always called, even if the test fails. This follows best practices for resource management in test frameworks.

Comment on lines +38 to +65
test.log.info("TEST_STEP 3: Testing network connectivity on destination host")
backup_uri = vm.connect_uri
vm.connect_uri = dest_uri

session = vm.wait_for_login(timeout=login_timeout)
ips = {'outside_ip': outside_ip}
network_base.ping_check(params, ips, session)
session.close()
vm.connect_uri = backup_uri
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Wrap URI switch in try/finally to ensure restoration.

If wait_for_login or ping_check raises an exception, line 46 won't execute and vm.connect_uri won't be restored. This could leave the VM object in an inconsistent state for subsequent operations or cleanup.

Apply this diff to ensure the URI is always restored:

         test.log.info("TEST_STEP 3: Testing network connectivity on destination host")
         backup_uri = vm.connect_uri
         vm.connect_uri = dest_uri
-
-        session = vm.wait_for_login(timeout=login_timeout)
-        ips = {'outside_ip': outside_ip}
-        network_base.ping_check(params, ips, session)
-        session.close()
-        vm.connect_uri = backup_uri
+        try:
+            session = vm.wait_for_login(timeout=login_timeout)
+            ips = {'outside_ip': outside_ip}
+            network_base.ping_check(params, ips, session)
+            session.close()
+        finally:
+            vm.connect_uri = backup_uri
🤖 Prompt for AI Agents
In libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py around
lines 38 to 46, the code switches vm.connect_uri then calls wait_for_login and
ping_check but if those raise the vm.connect_uri is never restored; wrap the URI
switch and subsequent operations in a try/finally: save backup_uri, set
vm.connect_uri = dest_uri, then in a finally block restore vm.connect_uri =
backup_uri; also ensure any opened session is closed in the finally (check
session was set) so both the VM URI and the session are reliably cleaned up.

@nanli1 nanli1 force-pushed the add_case_for_migrating_guest_while_scp_files branch from 6f7fe9d to 64c5e25 Compare November 24, 2025 07:29
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

♻️ Duplicate comments (1)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (1)

38-46: Wrap URI switch in try/finally to ensure restoration.

If wait_for_login or ping_check raises an exception, line 46 won't execute and vm.connect_uri won't be restored, leaving the VM object in an inconsistent state for subsequent operations or cleanup.

Apply this diff to ensure the URI is always restored:

         test.log.info("TEST_STEP 3: Testing network connectivity on destination host")
         backup_uri = vm.connect_uri
         vm.connect_uri = dest_uri
-
-        session = vm.wait_for_login(timeout=login_timeout)
-        ips = {'outside_ip': outside_ip}
-        network_base.ping_check(params, ips, session)
-        session.close()
-        vm.connect_uri = backup_uri
+        try:
+            session = vm.wait_for_login(timeout=login_timeout)
+            ips = {'outside_ip': outside_ip}
+            network_base.ping_check(params, ips, session)
+            session.close()
+        finally:
+            vm.connect_uri = backup_uri
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f7fe9d and 64c5e25.

📒 Files selected for processing (3)
  • libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg (1 hunks)
  • libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (1 hunks)
  • provider/migration/migration_base.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg
  • provider/migration/migration_base.py
🧰 Additional context used
🧬 Code graph analysis (1)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (2)
provider/migration/base_steps.py (3)
  • setup_connection (343-364)
  • cleanup_connection (366-378)
  • MigrationBase (27-477)
provider/virtual_network/network_base.py (1)
  • ping_check (98-149)
⏰ 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.8
  • GitHub Check: Python 3.12
  • GitHub Check: Python 3.9
  • GitHub Check: Python 3.11
🔇 Additional comments (4)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (4)

11-14: LGTM!

The imports are minimal, necessary, and correctly used throughout the test.


26-36: LGTM!

The migration setup sequence is correct: logs guest XML for debugging, prepares connections, ensures the VM is running, and then executes migration. Good defensive check on VM state before migration.


58-68: LGTM!

The parameter extraction uses appropriate methods (get, get_boolean, get_numeric) with sensible defaults. The MigrationBase initialization follows the expected pattern from the migration framework.


70-73: LGTM!

The try/finally structure ensures cleanup happens even if the test raises an exception. This is the correct pattern for resource management in test code.

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.


test.log.info("TEST_STEP 2: Starting migration with file transfers")
migration_obj.setup_connection()
if not vm.is_alive():
Copy link
Contributor

Choose a reason for hiding this comment

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

If start_vm = "yes" is set in the cfg, the VM will be started in migration_obj.setup_connection(). So maybe we can remove lines 34-35.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks dear, Updated

migrate_main_vm = "${main_vm}"
login_timeout = "360"
migrate_speed = 15
iterations = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

May I ask where this parameter is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks your patience liping, I remove them except migration_speed, I would like it could be added to control my migration speed.

@nanli1 nanli1 force-pushed the add_case_for_migrating_guest_while_scp_files branch from 64c5e25 to 776662d Compare November 26, 2025 03:33
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

♻️ Duplicate comments (2)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (2)

36-44: Make URI switch and session handling exception‑safe.

If vm.wait_for_login() or network_base.ping_check() raises, vm.connect_uri is never restored and the session may remain open, leaving the vm object in an inconsistent state for later steps/teardown.

Wrap the URI switch and session use in a try/finally so both the URI and any opened session are always cleaned up, e.g.:

-        test.log.info("TEST_STEP 3: Testing network connectivity on destination host")
-        backup_uri = vm.connect_uri
-        vm.connect_uri = dest_uri
-
-        session = vm.wait_for_login(timeout=login_timeout)
-        ips = {'outside_ip': outside_ip}
-        network_base.ping_check(params, ips, session)
-        session.close()
-        vm.connect_uri = backup_uri
+        test.log.info("TEST_STEP 3: Testing network connectivity on destination host")
+        backup_uri = vm.connect_uri
+        vm.connect_uri = dest_uri
+        session = None
+        try:
+            session = vm.wait_for_login(timeout=login_timeout)
+            ips = {'outside_ip': outside_ip}
+            network_base.ping_check(params, ips, session)
+        finally:
+            if session is not None:
+                session.close()
+            vm.connect_uri = backup_uri

46-48: Fix TEST_STEP 4 log message formatting for consistency.

Other steps use "TEST_STEP N: ...", but this one is missing the space after STEP.

-        if migrate_vm_back:
-            test.log.info("TEST_STEP4: Migrating VM back to source host")
+        if migrate_vm_back:
+            test.log.info("TEST_STEP 4: Migrating VM back to source host")
             migration_obj.run_migration_back()
🧹 Nitpick comments (1)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (1)

30-30: Align TEST_STEP 1 message formatting with other steps (optional).

For readability and consistency with steps 2–3, consider adding a space after the colon:

-        test.log.info("TEST_STEP 1:Guest xml is: %s\n", VMXML.new_from_dumpxml(vm_name))
+        test.log.info("TEST_STEP 1: Guest xml is: %s", VMXML.new_from_dumpxml(vm_name))

(The explicit \n is unnecessary because the logger already appends newlines.)

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64c5e25 and 776662d.

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

66-71: Good use of try/finally around migration lifecycle.

Wrapping run_test() in a try/finally that always calls teardown_test() (and thus migration_obj.cleanup_connection()) gives robust cleanup even on failures; this structure looks solid.

@nanli1 nanli1 force-pushed the add_case_for_migrating_guest_while_scp_files branch from 776662d to 5327266 Compare November 26, 2025 03:43
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)
provider/migration/migration_base.py (1)

15-15: Import of utils_test is correct to support eval-based action_during_mig hooks

Bringing virttest.utils_test into the module namespace is necessary so that parse_funcs can successfully eval strings like "utils_test.run_file_transfer" coming from action_during_mig config. This aligns with existing patterns in this file and the new migration-with-file-transfer test; no functional issues here.

If you want to future‑proof this against “unused import” cleanup, consider adding a short comment such as “needed for eval('utils_test.*') in action_during_mig hooks” above the import.

Based on learnings, virttest.utils_test is the right place for these helpers.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 776662d and 5327266.

📒 Files selected for processing (3)
  • libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg (1 hunks)
  • libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (1 hunks)
  • provider/migration/migration_base.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py
  • libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-18T08:47:14.465Z
Learnt from: smitterl
Repo: autotest/tp-libvirt PR: 6072
File: libvirt/tests/src/passthrough/pci/libvirt_pci_passthrough_hotplug.py:239-241
Timestamp: 2025-11-18T08:47:14.465Z
Learning: In tp-libvirt tests, `utils_test.ping` is a valid function that exists in the avocado-vt framework (virttest.utils_test module). It is an alias to `utils_net.ping` and supports parameters including dest, count, interface, timeout, and session.

Applied to files:

  • provider/migration/migration_base.py
⏰ 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.11
  • GitHub Check: Python 3.9
  • GitHub Check: Python 3.12
  • GitHub Check: Python 3.8

@nanli1
Copy link
Contributor Author

nanli1 commented Nov 26, 2025

(1/1) qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.10.1.x86_64.io-github-autotest-libvirt.virtual_network.qemu_test.migrate_with_file_transfer.q35: PASS (605.60 s)

@nanli1 nanli1 requested a review from cliping November 26, 2025 03:58
@nanli1 nanli1 force-pushed the add_case_for_migrating_guest_while_scp_files branch 2 times, most recently from ba91d77 to 061964e Compare November 30, 2025 05:09
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: 3

♻️ Duplicate comments (1)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (1)

57-65: Wrap URI switch in try/finally to ensure restoration.

If wait_for_login or ping_check raises an exception, vm.connect_uri won't be restored, leaving the VM object in an inconsistent state for cleanup operations.

         test.log.info("TEST_STEP 3: Testing network connectivity on destination host")
         backup_uri = vm.connect_uri
         vm.connect_uri = dest_uri
-
-        session = vm.wait_for_login(timeout=login_timeout)
-        ips = {'outside_ip': outside_ip}
-        network_base.ping_check(params, ips, session)
-        session.close()
-        vm.connect_uri = backup_uri
+        try:
+            session = vm.wait_for_login(timeout=login_timeout)
+            ips = {'outside_ip': outside_ip}
+            network_base.ping_check(params, ips, session)
+            session.close()
+        finally:
+            vm.connect_uri = backup_uri
🧹 Nitpick comments (2)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (2)

80-81: Consider using ast.literal_eval instead of eval for safer parsing.

eval() can execute arbitrary code if the config values are compromised. Since these parameters contain dictionary literals, ast.literal_eval provides the same functionality with better security.

+import ast
+
 from virttest.libvirt_xml.vm_xml import VMXML
-    iommu_dict = eval(params.get('iommu_dict', '{}'))
-    iface_iommu_driver = eval(params.get('iface_iommu_driver', '{}'))
+    iommu_dict = ast.literal_eval(params.get('iommu_dict', '{}'))
+    iface_iommu_driver = ast.literal_eval(params.get('iface_iommu_driver', '{}'))

53-54: Redundant VM start check.

Lines 53-54 check vm.is_alive() and start the VM, but there's already a similar check at lines 47-48 (which has a bug). Once the bug at line 47 is fixed, consider whether both checks are necessary or if one can be removed.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5327266 and 061964e.

📒 Files selected for processing (3)
  • libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg (1 hunks)
  • libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (1 hunks)
  • provider/migration/migration_base.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • provider/migration/migration_base.py
🧰 Additional context used
🧬 Code graph analysis (1)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (3)
libvirt/tests/src/passthrough/robustness/passthrough_robustness.py (1)
  • start (176-225)
provider/migration/base_steps.py (3)
  • setup_connection (343-364)
  • cleanup_connection (366-378)
  • MigrationBase (27-477)
libvirt/tests/src/serial/serial_functional.py (1)
  • wait_for_login (235-258)
🪛 Ruff (0.14.6)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py

80-80: Use of possibly insecure function; consider using ast.literal_eval

(S307)


81-81: Use of possibly insecure function; consider using ast.literal_eval

(S307)

⏰ 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). (3)
  • GitHub Check: Python 3.8
  • GitHub Check: Python 3.11
  • GitHub Check: Python 3.9
🔇 Additional comments (5)
libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg (2)

1-30: Configuration setup looks correct for migration with file transfer.

The base configuration properly sets up NFS storage, SSH-based migration with P2P and live options, and includes reasonable defaults for file transfer testing (500MB file, 240s timeout, 15 MB/s migration speed to ensure overlap).


31-31: Verify action_during_mig parameter format is valid for the migration framework.

The action_during_mig uses params.get('test'), params.get('params'), and params.get('env') directly in the config file. This assumes the config parser evaluates these expressions at runtime. Confirm this syntax is supported by the test framework's config parsing mechanism, as config files typically use variable substitution (${var}) rather than Python method calls.

libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (3)

96-96: Circular reference: params["params"] = params.

This creates a self-referential dictionary which could cause issues with serialization, deep copies, or debugging. If the migration framework requires params to be accessible via params.get('params'), this pattern works but be aware of potential side effects.

Is the circular reference params["params"] = params intentional for the action_during_mig callback? If so, consider adding a comment explaining why this is needed.


34-41: IOMMU setup function looks correct.

The setup_test function properly gates IOMMU configuration behind test_iommu flag and uses appropriate library functions for interface and IOMMU device modification.


71-75: Teardown correctly placed in finally block.

The teardown_test function properly calls cleanup_connection() and is invoked from the finally block, ensuring cleanup happens regardless of test outcome.

s390x:
iface_iommu_driver = {'name':'vhost','iommu': 'on'}
- with_virtio_iommu:
required_qemu= [7.0.0,)
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

Fix syntax: missing space before = in required_qemu.

The config parameter required_qemu= [7.0.0,) is missing a space before the equals sign, which may cause parsing issues depending on the config parser's strictness.

-            required_qemu= [7.0.0,)
+            required_qemu = [7.0.0,)
📝 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
required_qemu= [7.0.0,)
required_qemu = [7.0.0,)
🤖 Prompt for AI Agents
In libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg around
line 62, the assignment for required_qemu lacks a space before the equals sign
which can break strict parsers; update the line to include a space before and
after the '=' so it reads with proper spacing (e.g., required_qemu = [7.0.0,))
and keep spacing consistent with other config entries.

@nanli1 nanli1 force-pushed the add_case_for_migrating_guest_while_scp_files branch from 061964e to fec97d8 Compare November 30, 2025 05:15
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

♻️ Duplicate comments (4)
libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg (2)

47-51: Fix indentation for HostCpuVendor.intel and RHEL.7.9 blocks.

HostCpuVendor.intel: and RHEL.7.9: are over‑indented under iface_iommu_driver, so their iommu_dict overrides may not apply as intended for x86_64, i386. They should be siblings of iface_iommu_driver under the x86_64, i386: block.

Suggested fix:

-                iface_iommu_driver =  {'name':'vhost','iommu': 'on', 'ats': 'on', 'disable-legacy':'on', 'disable-modern':'off'}
-                    HostCpuVendor.intel:
-                    iommu_dict = {'model': 'intel', 'driver': {'intremap': 'on', 'caching_mode': 'on'}}
-                    RHEL.7.9:
-                        # For RHEL 7.9 compatibility - disable device IOTLB
-                        iommu_dict = {'model': 'intel', 'driver': {'intremap': 'on', 'caching_mode': 'on', 'device-iotlb': 'off'}}
+                iface_iommu_driver =  {'name':'vhost','iommu': 'on', 'ats': 'on', 'disable-legacy':'on', 'disable-modern':'off'}
+                HostCpuVendor.intel:
+                    iommu_dict = {'model': 'intel', 'driver': {'intremap': 'on', 'caching_mode': 'on'}}
+                    RHEL.7.9:
+                        # For RHEL 7.9 compatibility - disable device IOTLB
+                        iommu_dict = {'model': 'intel', 'driver': {'intremap': 'on', 'caching_mode': 'on', 'device-iotlb': 'off'}}

62-62: Add spacing around = in required_qemu for proper parsing.

required_qemu= [7.0.0,) is missing a space before the equals sign. For consistency and to avoid parser quirks, use spaces around =:

-            required_qemu= [7.0.0,)
+            required_qemu = [7.0.0,)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (2)

47-48: Call vm.is_alive() instead of referencing the method.

if not vm.is_alive: checks the method object, which is always truthy, so this branch never runs and the VM is never started here.

Update to call the method:

-        if not vm.is_alive:
+        if not vm.is_alive():
             vm.start()

57-65: Guard vm.connect_uri and session cleanup with try/finally.

If wait_for_login or ping_check raises, vm.connect_uri stays pointed at dest_uri and the session may remain open, leaving the VM object in an inconsistent state for later steps/cleanup.

Wrapping in try/finally keeps the URI and session handling robust:

-        test.log.info("TEST_STEP 3: Testing network connectivity on destination host")
-        backup_uri = vm.connect_uri
-        vm.connect_uri = dest_uri
-
-        session = vm.wait_for_login(timeout=login_timeout)
-        ips = {'outside_ip': outside_ip}
-        network_base.ping_check(params, ips, session)
-        session.close()
-        vm.connect_uri = backup_uri
+        test.log.info("TEST_STEP 3: Testing network connectivity on destination host")
+        backup_uri = vm.connect_uri
+        vm.connect_uri = dest_uri
+
+        session = None
+        try:
+            session = vm.wait_for_login(timeout=login_timeout)
+            ips = {'outside_ip': outside_ip}
+            network_base.ping_check(params, ips, session)
+        finally:
+            if session is not None:
+                session.close()
+            vm.connect_uri = backup_uri
🧹 Nitpick comments (2)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (2)

80-81: Avoid eval on config values; prefer ast.literal_eval or typed params.

Using eval on iommu_dict / iface_iommu_driver is unnecessary and flagged by static analysis (S307). These values appear to be simple literals in the cfg, so ast.literal_eval (or direct dict parsing) would be safer and clearer.

One possible improvement:

+import ast
@@
-    iommu_dict = eval(params.get('iommu_dict', '{}'))
-    iface_iommu_driver = eval(params.get('iface_iommu_driver', '{}'))
+    raw_iommu = params.get('iommu_dict', '{}')
+    raw_iface = params.get('iface_iommu_driver', '{}')
+    iommu_dict = ast.literal_eval(raw_iommu) if isinstance(raw_iommu, str) else raw_iommu
+    iface_iommu_driver = ast.literal_eval(raw_iface) if isinstance(raw_iface, str) else raw_iface

Please verify that all callers provide literal-compatible values before switching, to avoid breaking any non-literal usages. Based on static analysis hints (S307).


94-95: Avoid making params self-referential for action hooks.

params.update({"params": params, "test": test, "env": env}) makes params["params"] point back to the same dict, creating a recursive structure that can be surprising and harder to inspect or serialize.

If the goal is just to expose test, env, and the original params to action_during_mig, consider a separate wrapper object instead of self-reference, e.g.:

-    # Add required objects to params for action_during_mig
-    params.update({"params": params, "test": test, "env": env})
+    # Add required objects for action_during_mig without self-referential params
+    hook_ctx = {"test": test, "env": env, "params": params}
+    params["action_hook_ctx"] = hook_ctx

and adjust the cfg / migration_base hook to read from action_hook_ctx instead of params.get('params'). This keeps the dictionary acyclic and easier to reason about.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 061964e and fec97d8.

📒 Files selected for processing (3)
  • libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg (1 hunks)
  • libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (1 hunks)
  • provider/migration/migration_base.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • provider/migration/migration_base.py
🧰 Additional context used
🪛 Ruff (0.14.6)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py

80-80: Use of possibly insecure function; consider using ast.literal_eval

(S307)


81-81: Use of possibly insecure function; consider using ast.literal_eval

(S307)

⏰ 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.9
  • GitHub Check: Python 3.8

   xxxx-95968 - [virtual network][virtual-nic-device] Migrate guest while scp files
   xxxx-296253 - [virtual network][virtual-nic-device] migrate guest with iommu_platform=on and different memory size
Signed-off-by: nanli <nanli@redhat.com>
@nanli1 nanli1 force-pushed the add_case_for_migrating_guest_while_scp_files branch from fec97d8 to 03f62d2 Compare December 1, 2025 08:55
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

♻️ Duplicate comments (4)
libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg (2)

44-49: Fix indentation for HostCpuVendor.intel and nested blocks.

The HostCpuVendor.intel: block (line 45) and its children are over-indented. They should be siblings/children of x86_64, i386:, not children of iface_iommu_driver. Current indentation will cause these settings to be ignored or misapplied.

                 iface_iommu_driver =  {'name':'vhost','iommu': 'on', 'ats': 'on', 'disable-legacy':'on', 'disable-modern':'off'}
-                    HostCpuVendor.intel:
-                    iommu_dict = {'model': 'intel', 'driver': {'intremap': 'on', 'caching_mode': 'on'}}
-                    RHEL.7.9:
-                        # For RHEL 7.9 compatibility - disable device IOTLB
-                        iommu_dict = {'model': 'intel', 'driver': {'intremap': 'on', 'caching_mode': 'on', 'device-iotlb': 'off'}}
+                HostCpuVendor.intel:
+                    iommu_dict = {'model': 'intel', 'driver': {'intremap': 'on', 'caching_mode': 'on'}}
+                    RHEL.7.9:
+                        # For RHEL 7.9 compatibility - disable device IOTLB
+                        iommu_dict = {'model': 'intel', 'driver': {'intremap': 'on', 'caching_mode': 'on', 'device-iotlb': 'off'}}

58-58: Fix spacing: missing space before =.

For consistency with other config parameters, add a space before the equals sign.

-            required_qemu= [7.0.0,)
+            required_qemu = [7.0.0,)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (2)

57-65: Wrap URI switch in try/finally to ensure restoration.

If wait_for_login or ping_check raises an exception, vm.connect_uri won't be restored, leaving the VM object in an inconsistent state for subsequent operations or cleanup.

         test.log.info("TEST_STEP 3: Testing network connectivity on destination host")
         backup_uri = vm.connect_uri
         vm.connect_uri = dest_uri
-
-        session = vm.wait_for_login(timeout=login_timeout)
-        ips = {'outside_ip': outside_ip}
-        network_base.ping_check(params, ips, session)
-        session.close()
-        vm.connect_uri = backup_uri
+        try:
+            session = vm.wait_for_login(timeout=login_timeout)
+            ips = {'outside_ip': outside_ip}
+            network_base.ping_check(params, ips, session)
+            session.close()
+        finally:
+            vm.connect_uri = backup_uri

47-48: Critical bug: Missing parentheses on vm.is_alive method call.

Line 47 uses vm.is_alive without parentheses, which references the method object itself (always truthy) instead of calling it to check VM state. This means the condition if not vm.is_alive: will always be False, and the VM will never be started here.

Note: Line 53 correctly uses vm.is_alive() with parentheses.

-        if not vm.is_alive:
+        if not vm.is_alive():
             vm.start()
🧹 Nitpick comments (1)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (1)

80-81: Consider using ast.literal_eval instead of eval for safer parsing.

While eval() is common in this codebase and the input comes from trusted config files, ast.literal_eval() would be safer as it only evaluates Python literals (strings, numbers, dicts, lists, etc.) and cannot execute arbitrary code.

+import ast
+
 from virttest.libvirt_xml.vm_xml import VMXML
-    iommu_dict = eval(params.get('iommu_dict', '{}'))
-    iface_iommu_driver = eval(params.get('iface_iommu_driver', '{}'))
+    iommu_dict = ast.literal_eval(params.get('iommu_dict', '{}'))
+    iface_iommu_driver = ast.literal_eval(params.get('iface_iommu_driver', '{}'))
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fec97d8 and 03f62d2.

📒 Files selected for processing (3)
  • libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg (1 hunks)
  • libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (1 hunks)
  • provider/migration/migration_base.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-18T08:47:14.465Z
Learnt from: smitterl
Repo: autotest/tp-libvirt PR: 6072
File: libvirt/tests/src/passthrough/pci/libvirt_pci_passthrough_hotplug.py:239-241
Timestamp: 2025-11-18T08:47:14.465Z
Learning: In tp-libvirt tests, `utils_test.ping` is a valid function that exists in the avocado-vt framework (virttest.utils_test module). It is an alias to `utils_net.ping` and supports parameters including dest, count, interface, timeout, and session.

Applied to files:

  • provider/migration/migration_base.py
📚 Learning: 2025-09-24T08:01:27.899Z
Learnt from: hholoubk
Repo: autotest/tp-libvirt PR: 6579
File: libvirt/tests/src/sriov/vIOMMU/iommu_device_lifecycle.py:95-97
Timestamp: 2025-09-24T08:01:27.899Z
Learning: In the libvirt test framework used in tp-libvirt, VM cleanup including destroying running VMs is handled by the teardown method (test_obj.teardown_iommu_test()) called in the finally block, so explicit VM destroy calls on timeout are not necessary according to the maintainers.

Applied to files:

  • libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py
🧬 Code graph analysis (1)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (4)
provider/migration/base_steps.py (3)
  • setup_connection (343-364)
  • cleanup_connection (366-378)
  • MigrationBase (27-477)
libvirt/tests/src/serial/serial_functional.py (1)
  • wait_for_login (235-258)
provider/virtual_network/network_base.py (1)
  • ping_check (98-149)
provider/guest_os_booting/guest_os_booting_base.py (1)
  • get_vm (18-56)
🪛 Ruff (0.14.6)
libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py

80-80: Use of possibly insecure function; consider using ast.literal_eval

(S307)


81-81: Use of possibly insecure function; consider using ast.literal_eval

(S307)

⏰ 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.9
  • GitHub Check: Python 3.8
🔇 Additional comments (3)
provider/migration/migration_base.py (1)

15-15: LGTM!

The import follows the existing pattern in this file and is required for eval() to resolve utils_test.run_file_transfer in the action_during_mig configuration. The pylint: disable=W0611 comment is appropriate since this module is accessed dynamically.

libvirt/tests/cfg/virtual_network/qemu/migrate_with_file_transfer.cfg (1)

1-34: LGTM!

The core migration configuration parameters are well-structured. The action_during_mig hook correctly references utils_test.run_file_transfer with the required parameter structure that will be resolved at runtime through params updates in the test file.

libvirt/tests/src/virtual_network/qemu/migrate_with_file_transfer.py (1)

99-103: LGTM!

The try/finally pattern correctly ensures teardown_test() is called even if an exception occurs during setup or test execution. Based on tp-libvirt patterns, VM cleanup including destroying running VMs is handled by the migration object's cleanup methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants