Skip to content

Conversation

@hholoubk
Copy link
Contributor

@hholoubk hholoubk commented Sep 23, 2025

This change adds new test to verify virsh shutdown command is working as expected for VM with vIOMMU devices.
Also added the optional possibility to start the VM again after the shutdown.

Improving test coverage for RHEL-109504.

Summary by CodeRabbit

  • Tests
    • Added a new "shutdown" lifecycle scenario to vIOMMU SR-IOV device lifecycle tests.
    • Verifies VM clean shutdown with a configurable timeout and reports failure if shutdown does not complete in time.
    • Optional parameter to automatically restart the VM after shutdown and verify successful boot/login.
    • Existing scenarios (reboot, reset, save/restore, suspend/resume) remain unchanged.

…etter vIOMMU device coverage

This change adds new test to verify virsh shutdown command is working as expected for VM with vIOMMU devices.
Also added the optional possibility to start the VM again after the shutdown.

improving test coverage for RHEL-109504.
@coderabbitai
Copy link

coderabbitai bot commented Sep 23, 2025

Walkthrough

Adds a new "shutdown" test scenario and corresponding test logic: the VM is shut down, waited on (default 60s), and optionally restarted if start_after_shutdown is enabled; other lifecycle branches remain unchanged.

Changes

Cohort / File(s) Summary
Test config: add shutdown scenario
libvirt/tests/cfg/sriov/vIOMMU/iommu_device_lifecycle.cfg
Adds a test_scenario variant shutdown with parameters start_after_shutdown = yes and shutdown_timeout = 60.
Lifecycle logic: handle shutdown and optional restart
libvirt/tests/src/sriov/vIOMMU/iommu_device_lifecycle.py
Adds branch for test_scenario == "shutdown": issues shutdown, waits up to shutdown_timeout for VM to be dead, logs failure on timeout; if start_after_shutdown is yes, starts the VM, resets serial state, opens serial login, waits for login using login_timeout, then closes session. Positioned before save/restore and suspend/resume branches.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Runner as Test Runner
  participant Test as Test Case
  participant Libvirt as libvirt
  participant VM as Guest

  Runner->>Test: invoke "shutdown" scenario
  Test->>Libvirt: virDomainShutdown(domain)
  Note over Test,Libvirt #D3E4CD: initiate graceful shutdown
  Test->>Libvirt: poll state until "shut off" (≤ shutdown_timeout)
  alt shutdown completed
    Libvirt-->>Test: state = shut off
    alt start_after_shutdown == yes
      Test->>Libvirt: virDomainStart(domain)
      Libvirt-->>Test: domain started
      Test->>VM: open serial login, wait (login_timeout)
      VM-->>Test: login successful
      Note right of Test #FCE7C6: reset serial & close session
    end
  else timeout
    Libvirt-->>Test: still running
    Note right of Test #F8D7DA: log failure and abort branch
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I tipped my ears at shutdown’s sigh,
A gentle halt beneath the sky—
If carrots beckon, I start anew,
Booting bright with morning dew.
Hop—tests pass, the garden’s true. 🥕

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 succinctly and accurately describes the primary change—adding a VM shutdown test to iommu_device_lifecycle to improve vIOMMU device coverage—and includes the tracking ID for traceability, making it clear and relevant to the PR objectives. It is concise, specific, and directly related to the changes in the diff.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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 a106bab and 39ae585.

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

🧹 Nitpick comments (4)
libvirt/tests/cfg/sriov/vIOMMU/iommu_device_lifecycle.cfg (1)

44-46: Add a configurable shutdown timeout knob.

Hard-coding 60s in code makes tuning harder across environments. Add a shutdown_timeout param here to align with code usage.

         - shutdown:
             start_after_shutdown = yes
+            shutdown_timeout = 60
libvirt/tests/src/sriov/vIOMMU/iommu_device_lifecycle.py (3)

91-97: Make shutdown wait duration configurable.

Use a shutdown_timeout param (default 60) instead of a magic number for better portability.

-            if not utils_misc.wait_for(lambda: vm.is_dead(), 60):
+            shutdown_timeout = int(params.get("shutdown_timeout", "60"))
+            if not utils_misc.wait_for(lambda: vm.is_dead(), shutdown_timeout):
                 test.fail("VM failed to shutdown")

101-104: Close the login session to avoid leaks.

vm.wait_for_login() returns a session; not closing it can leak resources.

-                vm.start()
-                vm.wait_for_login(timeout=int(params.get('login_timeout', 240)))
-                test.log.info("VM successfully started after shutdown")
+                vm.start()
+                session = vm.wait_for_login(timeout=int(params.get('login_timeout', 240)))
+                session.close()
+                test.log.info("VM successfully started after shutdown")

101-104: Prefer serial login after restart to reduce network flakiness.

Aligns with the other lifecycle branches and avoids dependency on guest networking being up.

-                test.log.info("TEST_STEP: Starting VM after shutdown")
-                vm.start()
-                vm.wait_for_login(timeout=int(params.get('login_timeout', 240)))
-                test.log.info("VM successfully started after shutdown")
+                test.log.info("TEST_STEP: Starting VM after shutdown")
+                vm.cleanup_serial_console()
+                vm.create_serial_console()
+                vm.start()
+                session = vm.wait_for_serial_login(timeout=int(params.get('login_timeout')))
+                session.close()
+                test.log.info("VM successfully started after shutdown")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e9ec62 and a106bab.

📒 Files selected for processing (2)
  • libvirt/tests/cfg/sriov/vIOMMU/iommu_device_lifecycle.cfg (1 hunks)
  • libvirt/tests/src/sriov/vIOMMU/iommu_device_lifecycle.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
libvirt/tests/src/sriov/vIOMMU/iommu_device_lifecycle.py (1)
libvirt/tests/src/serial/serial_functional.py (1)
  • wait_for_login (235-258)
⏰ 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

@hholoubk hholoubk closed this Sep 24, 2025
@hholoubk hholoubk deleted the LIBVIRTAT-22036-add-VM-shutdown-new branch September 24, 2025 07:36
@hholoubk
Copy link
Contributor Author

Closed - and recreated a new one #6579

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