Skip to content

Commit

Permalink
Workaround for no Exception issue for some failed ansible modules (#1786
Browse files Browse the repository at this point in the history
)

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>
  • Loading branch information
wangxin committed Jun 28, 2020
1 parent 1d2fa82 commit 1706d54
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tests/common/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def run_module(module_args, complex_args):
logging.debug("{}::{}#{}: [{}] AnsibleModule::{} Result => {}"\
.format(filename, function_name, line_number, self.hostname, self.module_name, json.dumps(res)))

if res.is_failed and not module_ignore_errors:
if (res.is_failed or 'exception' in res) and not module_ignore_errors:
raise RunAnsibleModuleFail("run module {} failed".format(self.module_name), res)

return res
Expand Down

0 comments on commit 1706d54

Please sign in to comment.