From 54cd6249b292c3d10b49d5b21d6096ab6b2c8895 Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Thu, 18 Jun 2020 08:55:43 +0000 Subject: [PATCH] Workaround for no Exception issue for some failed ansible modules 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: https://github.com/ansible/pytest-ansible/issues/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 --- tests/common/devices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common/devices.py b/tests/common/devices.py index 4a59f292c42..fc277479e23 100644 --- a/tests/common/devices.py +++ b/tests/common/devices.py @@ -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