Fix the issue of no 'failed' field in failed ansible module result #2063
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:
Fixes #1941
Type of change
Approach
What is the motivation for this PR?
For failed ansible modules, ansible removes fields including {'failed': True} in the result dict before calling callback function of plugins like pytest_ansible. Because pytest_ansible uses a same callback function for succeeded and failed ansible modules, no field like 'failed' is added back to failed ansible module results by pytest_ansible. If we call
res.is_failed()
, it will only return True if the ansible module result has non-zerorc
field.For more details, please refer to:
is_failed
property of failed result of some ansible modules is False ansible/pytest-ansible#47Related PR:
How did you do it?
The list of keys to be removed from failed ansible module results is pre-defined in module variable
ansible.executor.task_result._IGNORE
. This change override this variable to exclude thefailed
key.How did you verify/test it?
Prepared a test script:
Host
10.250.0.101
is the vlab-01 vs sonic host. It is up and running. Without this fix, thewait_for
call will pass. With this fix, it will fail as expected. Full log of running this script:The failed ansible module has field
{"failed": true}
now.Any platform specific information?
Supported testbed topology if it's a new test case?
Documentation