-
Notifications
You must be signed in to change notification settings - Fork 64
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
The is_failed
property of failed result of some ansible modules is False
#47
Comments
wangxin
changed the title
The
The Jun 18, 2020
is_failed
property of failed result of some ansible modules is Trueis_failed
property of failed result of some ansible modules is False
3 tasks
wangxin
added a commit
to sonic-net/sonic-mgmt
that referenced
this issue
Jun 28, 2020
) Currently pytest-ansible depends on the 'failed' or 'rc' field in the module result to determine whether the result is failed. Some ansible modules only have 'failed' field in their results. Due to an issue of pytest-ansible: ansible/pytest-ansible#47 The module results returned by pytest-ansible do not have such 'failed' field even when the ansible module failed. In this case, the `is_failed` property will always be `False`. Consequent, no exception will be raised when running some ansible module failed. This commit is a workaround for this issue. According to current ansible behavior, the 'exception' field will be available in failed ansible module result most of the time. When such field is observed in the result, we raise `RunAnsibleModuleFail` exception too. Signed-off-by: Xin Wang <xiwang5@microsoft.com>
This was referenced Aug 7, 2020
I think #48 addresses part of the problem here I'd be happy to review any further fixes if you send a PR |
closing the issue as there is no comment further and #48 addresses the problem here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a simple script with content like below:
test_failed.py:
This script called the ansible
copy
module with some arguments that will make it fail.In the log, we can see that the module failed with exception. However, the
is_failed
property of the test result isFalse
. This does not make sense.The reason is that pytest-ansible uses
ResultAccumulator
as callback to get the ansible module execution result. However, when ansible calls the ResultAccumulator::v2_runner_on_failed callback function, the 'failed' and 'skipped' keys are removed from the task_result. Without this 'failed' key in the result dictionary, callingresults.py::ModuleResult.is_failed
will always get 'False' unless the result dictionary has key 'rc' and its value is none-zero.Ansible called the callback defined in ResultAccumulator here:
https://github.com/ansible/ansible/blob/stable-2.8/lib/ansible/plugins/strategy/__init__.py#L523
Then before passing the task_result to the callback, ansible called the
clean_copy()
method of TaskResult:https://github.com/ansible/ansible/blob/stable-2.8/lib/ansible/executor/task_queue_manager.py#L325
The
clean_copy()
method of TaskResult removed keys 'failed' and 'skipped' from the result._result dictionary:https://github.com/ansible/ansible/blob/stable-2.8/lib/ansible/executor/task_result.py#L146
IMO, the ResultAccumulator.v2_runner_on_failed method should add back the 'failed' key to the result dictionary. And the v2_runner_on_ok method should not be same as the v2_runner_on_failed method.
The text was updated successfully, but these errors were encountered: