Skip to content

Conversation

@BulaYoungR
Copy link

@BulaYoungR BulaYoungR commented Nov 10, 2025

Use wait_for_serial_login instead of regex to fix login prompt timeouts

Committer: Bolatbek Issakh [email protected]

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced VM reset and reboot test flows with improved serial console session management, ensuring proper cleanup and re-establishment of connections.
  • Tests

    • Updated serial console handling in lifecycle tests to maintain consistent session management across device operations.

@coderabbitai
Copy link

coderabbitai bot commented Nov 10, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request modifies the test file for iommu device lifecycle handling. It replaces the VM reset and reboot flow implementations by removing direct virsh command invocations and login prompt verification. Instead, the code now consistently closes the existing serial session, performs cleanup and recreation of the serial console, and re-establishes a new serial login session after reset or reboot operations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Serial session handling logic: Review the correctness of closing, cleaning up, and re-creating the serial console. Verify that the new session management properly replaces the functionality of the original virsh reset command and login verification.
  • Lifecycle consistency: Ensure that reopening the serial session after VM operations doesn't introduce timing or state issues, and that the session is properly established before subsequent test steps.
  • Test reliability: Verify that removing explicit login prompt checks doesn't cause race conditions or flaky test behavior during VM transitions.

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 accurately summarizes the main change: replacing VM reset/reboot flows with serial console recreation logic in the iommu_device_lifecycle test file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

@BulaYoungR BulaYoungR marked this pull request as draft November 10, 2025 15: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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 516ab17 and e88f413.

📒 Files selected for processing (1)
  • libvirt/tests/src/sriov/vIOMMU/iommu_device_lifecycle.py (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
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.
📚 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/sriov/vIOMMU/iommu_device_lifecycle.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.12
  • GitHub Check: Python 3.8
  • GitHub Check: Python 3.9

Comment on lines 64 to 72
test.log.info("TEST_STEP: Reset the VM.")
session = vm.wait_for_serial_login(
timeout=int(params.get('login_timeout')))
virsh.reset(vm.name, **VIRSH_ARGS)
_match, _text = session.read_until_last_line_matches(
[r"[Ll]ogin:\s*"], timeout=240, internal_timeout=0.5)
session.close()
vm.cleanup_serial_console()
vm.create_serial_console()
session = vm.wait_for_serial_login(
timeout=int(params.get('login_timeout')))
session.close()
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

Critical: Missing VM reset operation.

The test logs "Reset the VM" but no actual reset command is executed. The current code only recreates the serial console without performing a VM reset operation. The original virsh.reset(vm.name, **VIRSH_ARGS) call appears to have been removed.

The reset should be performed after the initial login and before recreating the console:

 if test_scenario == "reset":
     test.log.info("TEST_STEP: Reset the VM.")
     session = vm.wait_for_serial_login(
         timeout=int(params.get('login_timeout')))
     session.close()
+    virsh.reset(vm.name, **VIRSH_ARGS)
     vm.cleanup_serial_console()
     vm.create_serial_console()
     session = vm.wait_for_serial_login(
         timeout=int(params.get('login_timeout')))
     session.close()
📝 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
test.log.info("TEST_STEP: Reset the VM.")
session = vm.wait_for_serial_login(
timeout=int(params.get('login_timeout')))
virsh.reset(vm.name, **VIRSH_ARGS)
_match, _text = session.read_until_last_line_matches(
[r"[Ll]ogin:\s*"], timeout=240, internal_timeout=0.5)
session.close()
vm.cleanup_serial_console()
vm.create_serial_console()
session = vm.wait_for_serial_login(
timeout=int(params.get('login_timeout')))
session.close()
test.log.info("TEST_STEP: Reset the VM.")
session = vm.wait_for_serial_login(
timeout=int(params.get('login_timeout')))
session.close()
virsh.reset(vm.name, **VIRSH_ARGS)
vm.cleanup_serial_console()
vm.create_serial_console()
session = vm.wait_for_serial_login(
timeout=int(params.get('login_timeout')))
session.close()
🤖 Prompt for AI Agents
In libvirt/tests/src/sriov/vIOMMU/iommu_device_lifecycle.py around lines 64 to
72, the code logs "Reset the VM" but never executes the actual VM reset; restore
the removed virsh.reset(vm.name, **VIRSH_ARGS) call so the VM is reset after the
first serial login and before cleaning/recreating the serial console. Ensure
VIRSH_ARGS is available in scope (import or reference the existing constant) and
call virsh.reset(vm.name, **VIRSH_ARGS) between session.close() and
vm.cleanup_serial_console().

Comment on lines 74 to 82
for _ in range(int(params.get('loop_time', '5'))):
test.log.info("TEST_STEP: Reboot the VM.")
session = vm.wait_for_serial_login(
timeout=int(params.get('login_timeout')))
session.sendline(params.get("reboot_command"))
_match, _text = session.read_until_last_line_matches(
[r"[Ll]ogin:\s*"], timeout=240, internal_timeout=0.5)
session.close()
vm.cleanup_serial_console()
vm.create_serial_console()
session = vm.wait_for_serial_login(timeout=int(params.get('login_timeout')))
session.close()
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

Critical: Missing VM reboot operation.

The test logs "Reboot the VM" but no actual reboot command is executed. The current code only recreates the serial console without performing a VM reboot. The loop runs multiple times without actually rebooting the VM between iterations.

The reboot should be triggered after the initial login:

 for _ in range(int(params.get('loop_time', '5'))):
     test.log.info("TEST_STEP: Reboot the VM.")
     session = vm.wait_for_serial_login(
         timeout=int(params.get('login_timeout')))
+    session.cmd("reboot")
     session.close()
     vm.cleanup_serial_console()
     vm.create_serial_console()
     session = vm.wait_for_serial_login(timeout=int(params.get('login_timeout')))
     session.close()
📝 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
for _ in range(int(params.get('loop_time', '5'))):
test.log.info("TEST_STEP: Reboot the VM.")
session = vm.wait_for_serial_login(
timeout=int(params.get('login_timeout')))
session.sendline(params.get("reboot_command"))
_match, _text = session.read_until_last_line_matches(
[r"[Ll]ogin:\s*"], timeout=240, internal_timeout=0.5)
session.close()
vm.cleanup_serial_console()
vm.create_serial_console()
session = vm.wait_for_serial_login(timeout=int(params.get('login_timeout')))
session.close()
for _ in range(int(params.get('loop_time', '5'))):
test.log.info("TEST_STEP: Reboot the VM.")
session = vm.wait_for_serial_login(
timeout=int(params.get('login_timeout')))
session.cmd("reboot")
session.close()
vm.cleanup_serial_console()
vm.create_serial_console()
session = vm.wait_for_serial_login(timeout=int(params.get('login_timeout')))
session.close()
🤖 Prompt for AI Agents
In libvirt/tests/src/sriov/vIOMMU/iommu_device_lifecycle.py around lines 74 to
82, the loop logs "Reboot the VM" but never actually reboots; after the initial
login and session.close() insert a vm.reboot() call so the VM is restarted
before cleaning and recreating the serial console, then keep the subsequent
vm.cleanup_serial_console(), vm.create_serial_console(), and the
wait_for_serial_login() call to verify the VM came back up.

@BulaYoungR
Copy link
Author

Before fix

2025-11-04 05:20:50,978 avocado.job job              L0659 INFO | Test results available in /var/log/avocado/job-results/job-2025-11-04T05.14-f506216
2025-11-04 05:20:50,978 avocado.app human            L0146 INFO | RESULTS    : PASS 0 | ERROR 1 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0

After fix

JOB ID     : 0e1176ac25492031870f4132cf861eede8ff84c1
JOB LOG    : /var/log/avocado/job-results/job-2025-11-10T10.15-0e1176a/job.log
 (1/1) type_specific.io-github-autotest-libvirt.vIOMMU.iommu_device_lifecycle.reboot_many_times.virtio_muti_devices.vhost_on.virtio: STARTED
 (1/1) type_specific.io-github-autotest-libvirt.vIOMMU.iommu_device_lifecycle.reboot_many_times.virtio_muti_devices.vhost_on.virtio: PASS (252.45 s)
RESULTS    : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0

…se wait_for_serial_login instead of regex to fix login prompt timeouts

Committer: Bolatbek Issakh <[email protected]>
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