-
Notifications
You must be signed in to change notification settings - Fork 259
utils_libvirt/libvirt_service: wait for service to terminate on kill #4291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The function only issued the kill command but didn't wait for it to become effective. This lead to timing issues with test steps afterwards, possibly requiring invocation of `sleep` with absolute times. Instead, now wait for a set timeout for the process to terminate. If it doesn't, log this for better debugging later. Signed-off-by: Sebastian Mitterle <smitterl@redhat.com>
|
WalkthroughA new libvirt service termination timeout configuration is introduced in the base configuration file with a default value of 30 seconds. The libvirt service module is updated to add a verification mechanism that confirms a service process has been fully terminated after issuing a kill command, rather than returning immediately. The verification uses process checking (pidof) and supports both local and remote execution contexts, with logging for success or warning cases when the process remains running. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this 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)
virttest/utils_libvirt/libvirt_service.py (1)
64-68: Verification logic is sound; consider explicit type conversion.The termination verification correctly uses
wait_forto poll for service termination, with appropriate logging for both success and warning cases. Thewait_forfunction internally converts the timeout to float, so string values from config will work.💡 Optional improvements for clarity and robustness
Consider explicitly converting the timeout parameter to an int or float for better code clarity:
- timeout = params.get("libvirt_kill_service_timeout", 30) + timeout = int(params.get("libvirt_kill_service_timeout", 30))Additionally, you could return a boolean to indicate success/failure for programmatic checking by callers:
if not utils_misc.wait_for(_check_service_gone, timeout=timeout, step=0.5): LOG.warning("Service %s may still be running after kill", service_name) + return False else: LOG.debug("Service %s confirmed terminated", service_name) + return True
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
virttest/shared/cfg/base.cfgvirttest/utils_libvirt/libvirt_service.py
🧰 Additional context used
🧬 Code graph analysis (1)
virttest/utils_libvirt/libvirt_service.py (2)
virttest/remote.py (1)
run_remote_cmd(112-151)virttest/utils_misc.py (3)
run(118-135)wait_for(564-599)wait_for(4193-4241)
🪛 Ruff (0.14.10)
virttest/utils_libvirt/libvirt_service.py
61-61: Function call with shell=True parameter identified, security issue
(S604)
🔇 Additional comments (4)
virttest/shared/cfg/base.cfg (1)
867-869: LGTM! Clear configuration addition.The new timeout parameter is well-documented and has a reasonable default value of 30 seconds for waiting for service termination after a kill operation.
virttest/utils_libvirt/libvirt_service.py (3)
5-5: LGTM! Import addition is appropriate.The
utils_miscimport is necessary for thewait_forfunction used in the verification logic.
54-62: Note: Static analysis flagsshell=Trueas potential security risk.The static analysis tool flagged line 61 for using
shell=Truewith string formatting. While this is typically a security concern for command injection, in this test framework context whereservice_namecomes from configuration files (not runtime user input), the risk is minimal.However, if there's ever a possibility of external input influencing
service_name, consider usingshell=Falsewith proper argument list construction.Current implementation is acceptable for the test framework use case, but document if service_name values are strictly controlled.
54-62:pidofis appropriate for this Linux-specific testing framework, thoughpgrepmay be more portable.The code correctly uses
pidofto check process termination, which is standard on supported platforms (RHEL, Fedora). If broader Linux compatibility is desired,pgrepis a robust alternative with wider availability across distributions.
nanli1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is useful.
The function only issued the kill command but didn't wait for it to become effective. This lead to timing issues with test steps afterwards, possibly requiring invocation of
sleepwith absolute times.Instead, now wait for a set timeout for the process to terminate. If it doesn't, log this for better debugging later.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.