Fix KeyError in analyzer_logrotate error handler#24651
Open
XuChen-MSFT wants to merge 1 commit into
Open
Conversation
When logrotate fails on DUT and the Ansible result dict does not contain
the expected 'stdout'/'stderr'/'rc' keys, the error handler crashes with
KeyError('stdout'). This unhandled exception kills the parallel_run worker
process, blocking all tests that use the loganalyzer fixture (autouse=True).
Use dict.get() with defaults instead of direct key access so the handler
logs a warning and continues, which was the original intent.
Fixes: https://msazure.visualstudio.com/One/_workitems/edit/37977676
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of PR
Summary:
Fix
KeyError('stdout')inanalyzer_logrotateerror handler that crashes the parallel worker process whenlogrotatefails on DUT.Fixes https://msazure.visualstudio.com/One/_workitems/edit/37977676
Type of change
Back port request
Approach
What is the motivation for this PR?
When
logrotate -f /etc/logrotate.conffails on a DUT, theanalyzer_logrotatefunction is supposed to catch theRunAnsibleModuleFailexception and log a warning. However, the error handler accessese.results["stdout"]directly. In some failure scenarios (e.g., Ansible connection issues, module-level failures), the result dictionary does not containstdout/stderr/rckeys, causing an unhandledKeyError('stdout').This
KeyErrorcrashes theparallel_runworker process (exit code 1), which then blocks all tests using theloganalyzerfixture (autouse=True) with a setup error:KQL analysis shows this pattern affected 63 tests across multiple testbeds/SKUs in the last 14 days.
How did you do it?
Changed
e.results["stdout"]toe.results.get("stdout", "")(and same forstderrandrc) so the error handler gracefully handles missing keys and logs a warning instead of crashing.How did you verify/test it?
dict.get()with defaultsRunAnsibleModuleFail.resultsattribute is dict-like (inherits from Ansible result objects) and supports.get()Any platform specific information?
No — this affects all platforms. The
loganalyzerfixture isautouse=Trueand runs on every DUT.Supported testbed topology if it's a new test case?
N/A — bug fix only.
Documentation
N/A — no new features.