Skip to content

Conversation

@zhentang-tz
Copy link
Contributor

@zhentang-tz zhentang-tz commented Sep 26, 2025

The --live flag was removed from virsh dump upstream, so any positive test that still use it now fails immediately. ref: https://gitlab.com/libvirt/libvirt/-/issues/646

Delete all test cases that relied on --live, and add a negative test to make sure the command rejects the obsolete option.

Additionally, fix an unstable race by using utils_misc.wait_for(). Preventing the race condition where the log file had not yet been fully generated when the first check occurred.

Summary by CodeRabbit

  • Tests

    • Removed deprecated “--live” dump variants from relevant suites.
    • Added a negative test validating rejection of the “--live” option.
    • Improved reliability by waiting up to 30s for log verification before asserting.
    • Enhanced cleanup logic with safer backup handling and environment restoration.
  • Bug Fixes

    • Prevented false positives by explicitly checking for the expected error on invalid dump image formats and exiting early when matched.
    • Avoided teardown errors by guarding backup synchronization when no backup exists.

@coderabbitai
Copy link

coderabbitai bot commented Sep 26, 2025

Walkthrough

This change removes --live-related dump options from specific config variants and adds a negative test for invalid --live usage. In code, it adds asynchronous waiting for logfile checks, introduces safer backup_xml handling, and refines error-handling flow to restore config, restart services, and early-return on expected errors.

Changes

Cohort / File(s) Summary
Config: remove --live dump options
libvirt/tests/cfg/guest_kernel_debugging/virsh_dump.cfg, libvirt/tests/cfg/virsh_cmd/monitor/virsh_domstate.cfg
Removed live dump options/variants; added a negative-test variant using dump_options = "--live" under negative_test.
Source: error handling and async wait
libvirt/tests/src/guest_kernel_debugging/virsh_dump.py
Added backup_xml = None; check_logfile now uses utils_misc.wait_for with 30s timeout; on invalid dump_image_format, compute err_msg_found, restore qemu config, restart libvirtd socket, and early-return if expected error seen; guard backup_xml.sync() with truthy check.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Tester
  participant Test as virsh_dump.py
  participant Log as check_logfile()
  participant Wait as utils_misc.wait_for()
  participant QEMU as QEMU Config
  participant Libvirtd as libvirtd

  Tester->>Test: Run virsh_dump test
  alt invalid dump_image_format
    Test->>Log: check_logfile(format)
    Log->>Wait: wait_for(predicate, 30s)
    Wait-->>Log: result (found/not found)
    Log-->>Test: err_msg_found
    Test->>QEMU: restore config
    Test->>Libvirtd: restart socket
    alt expected error found
      Test-->>Tester: return (test passes this negative case)
    else not found
      Test-->>Tester: fail test
    end
  else valid path
    Test->>Log: check_logfile(...) (async wait used)
    Note right of Test: backup_xml.sync() only if backup_xml is set
    Test-->>Tester: continue/complete
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • xiaodwan

Poem

A nibble of logs, a hop through time,
I wait 30 seconds—precision sublime.
No more “live” carrots in config rows,
Restore, restart, see how it goes.
If errors appear as planned, I cheer—
Thump-thump, the test is clear! 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title “virsh_dump: drop --live option support” accurately and concisely reflects the main change of removing support for the --live flag in virsh_dump tests, directly matching the described updates.
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.

@zhentang-tz zhentang-tz force-pushed the guest_kernel_debugging_fix branch 2 times, most recently from 8e3ae3e to 12ed210 Compare October 9, 2025 03:58
The --live flag was removed from virsh dump upstream, so any positive test that still use it now fails immediately.
ref: https://gitlab.com/libvirt/libvirt/-/issues/646

Delete all test cases that relied on --live, and add a negative test to make sure the command rejects the obsolete option.

Additionally, fix an unstable race by using utils_misc.wait_for(). Preventing the race condition where the log file had not yet been fully generated when the first check occurred.

Also fix an unstable teardown issue

Signed-off-by: zhentang-tz <[email protected]>
@zhentang-tz zhentang-tz force-pushed the guest_kernel_debugging_fix branch from 12ed210 to c310b8d Compare October 10, 2025 09:24
@zhentang-tz
Copy link
Contributor Author

JOB ID : de3026c2b931917a63af1bcf516d6864c9e07a2e
JOB LOG : /var/log/avocado/job-results/job-2025-10-11T03.24-de3026c/job.log
(1/2) type_specific.io-github-autotest-libvirt.virsh.dump.positive_test.non_acl.invalid_image_format: STARTED
(1/2) type_specific.io-github-autotest-libvirt.virsh.dump.positive_test.non_acl.invalid_image_format: PASS (43.13 s)
(2/2) type_specific.io-github-autotest-libvirt.virsh.dump.positive_test.acl_test.invalid_image_format: STARTED
(2/2) type_specific.io-github-autotest-libvirt.virsh.dump.positive_test.acl_test.invalid_image_format: PASS (44.03 s)
RESULTS : PASS 2 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0

@zhentang-tz zhentang-tz marked this pull request as ready for review October 11, 2025 03:28
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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb4decf and c310b8d.

📒 Files selected for processing (3)
  • libvirt/tests/cfg/guest_kernel_debugging/virsh_dump.cfg (1 hunks)
  • libvirt/tests/cfg/virsh_cmd/monitor/virsh_domstate.cfg (0 hunks)
  • libvirt/tests/src/guest_kernel_debugging/virsh_dump.py (4 hunks)
💤 Files with no reviewable changes (1)
  • libvirt/tests/cfg/virsh_cmd/monitor/virsh_domstate.cfg
🔇 Additional comments (4)
libvirt/tests/src/guest_kernel_debugging/virsh_dump.py (4)

69-69: LGTM: Defensive initialization prevents AttributeError.

Initializing backup_xml to None ensures the guarded sync() call in the finally block (lines 489-490) won't fail if an exception occurs before line 382.


338-338: LGTM: Fixes race condition with asynchronous wait.

Using utils_misc.wait_for() with a 30-second timeout properly addresses the race condition where the log file might not be fully written before the first check, as mentioned in the PR description.


353-359: LGTM: Improved error handling flow for invalid image format.

The refactored logic correctly:

  1. Waits for the error message via check_logfile()
  2. Restores config and restarts services regardless of result
  3. Fails the test only if the expected error message is missing
  4. Returns early to skip remaining test logic

Note: qemu_config.restore() will be called again in the finally block (line 491), but this should be safe if the method is idempotent.


489-490: LGTM: Guards against AttributeError.

The conditional check prevents AttributeError if backup_xml is still None (e.g., if an exception occurred before line 382).

Comment on lines +88 to +89
- invalid_option_live:
dump_options = "--live"
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

Remove trailing whitespace.

The new negative test variant correctly verifies that the obsolete --live option is rejected. However, Line 89 has trailing whitespace after "--live".

Apply this diff to remove the trailing whitespace:

-                - invalid_option_live:
-                    dump_options = "--live"    
+                - invalid_option_live:
+                    dump_options = "--live"
📝 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
- invalid_option_live:
dump_options = "--live"
- invalid_option_live:
dump_options = "--live"
🤖 Prompt for AI Agents
In libvirt/tests/cfg/guest_kernel_debugging/virsh_dump.cfg around lines 88-89,
the line defining dump_options for invalid_option_live contains trailing
whitespace after "--live"; remove the trailing space(s) so the line ends
immediately after the closing quote (no spaces or tabs after "--live"), and save
the file without introducing any other changes.

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.

- pause_dump:
paused_after_start_vm = "yes"
variants:
- live:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can keep '--live' cases in tp-libvirt and remove '--live' cases from CI, so that others can still use them for testing.

dump_options = "--live --reset"
- invalid_option4:
dump_options = "--crash --reset"
- invalid_option_live:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we need to add libvirt version check. For example, func_supported_since_libvirt_ver = (10, 4, 0)

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