Fix AnsibleHostBase._run: normalize 'failed' key for ansible-core >= 2.21#25482
Open
xwjiang-ms wants to merge 1 commit into
Open
Fix AnsibleHostBase._run: normalize 'failed' key for ansible-core >= 2.21#25482xwjiang-ms wants to merge 1 commit into
xwjiang-ms wants to merge 1 commit into
Conversation
…2.21 The _IGNORE hack that prevented ansible from stripping 'failed' from task results no longer works in ansible-core >= 2.21, which changed post-processing so that 'failed' is absent from successful results. Multiple test modules raise KeyError: 'failed' when they access rc['failed'] after a successful self.shell()/self.command() call: - common/helpers/tacacs/tacacs_helper.py - common/dualtor/dual_tor_io.py - bgp/route_checker.py - macsec/test_dataplane.py Normalize hostname_res in _run() to always include 'failed' based on is_failed before returning. Single-point fix covering all call sites. Signed-off-by: xwjiang-ms <xiaweijiang@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: 'failed' in AnsibleHostBase._run caused by ansible-core >= 2.21 changing how task results are post-processed.
Type of change
Back port request
Approach
What is the motivation for this PR?
The existing _IGNORE hack in �ase.py prevents ansible from stripping 'failed' from task results. This hack no longer works in ansible-core >= 2.21, which changed post-processing so that 'failed' is absent from successful command results.
Multiple test modules hit KeyError: 'failed' when they access
c['failed'] after a successful self.shell() or self.command() call, observed when running with the latest sonic-mgmt docker:
How did you do it?
Normalize hostname_res in _run() to always include 'failed' (based on hostname_res.is_failed) before returning. This is a single-point fix that covers all call sites without requiring per-file changes.
python if 'failed' not in hostname_res: hostname_res['failed'] = hostname_res.is_failedThis approach is backward-compatible — it has no effect when ansible-core already includes 'failed' in the result.
How did you verify/test it?
c['failed']
Any platform specific information?
N/A — this is a framework-level fix affecting all platforms.
Supported testbed topology if it's a new test case?
N/A
Documentation
N/A