File ansiblegate-take-care-of-failed-skipped-and-unreacha.patch of Package salt.23536
From 6111853f13c9c1e8eaaa1acd521cd3abfbfff766 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
<psuarezhernandez@suse.com>
Date: Thu, 13 Aug 2020 13:49:16 +0100
Subject: [PATCH] ansiblegate: take care of failed, skipped and
unreachable tasks (bsc#1173911)
Add 'retcode' from ansible-playbook execution to the returned data (bsc#1173909)
Always add retcode to ansible.playbooks output
Adjust ansible.playbooks output comment properly
Add new unit test for ansible.playbooks
Add unit tests for ansible.playbooks state
---
tests/unit/modules/test_ansiblegate.py | 12 ++++++++++++
tests/unit/states/test_ansiblegate.py | 7 ++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/tests/unit/modules/test_ansiblegate.py b/tests/unit/modules/test_ansiblegate.py
index 6724d37c40..3d406a9d42 100644
--- a/tests/unit/modules/test_ansiblegate.py
+++ b/tests/unit/modules/test_ansiblegate.py
@@ -209,3 +209,15 @@ description:
timeout=1200,
)
assert ret == {"completed": True, "timeout": 1200}
+
+ @patch("salt.utils.path.which", MagicMock(return_value=True))
+ def test_ansible_playbooks_return_retcode(self):
+ """
+ Test ansible.playbooks execution module function include retcode in the return.
+ :return:
+ """
+ ref_out = {"retcode": 0, "stdout": '{"foo": "bar"}'}
+ cmd_run_all = MagicMock(return_value=ref_out)
+ with patch.dict(ansible.__salt__, {"cmd.run_all": cmd_run_all}):
+ ret = ansible.playbooks("fake-playbook.yml")
+ assert "retcode" in ret
diff --git a/tests/unit/states/test_ansiblegate.py b/tests/unit/states/test_ansiblegate.py
index ac677fc5db..c21a4f642f 100644
--- a/tests/unit/states/test_ansiblegate.py
+++ b/tests/unit/states/test_ansiblegate.py
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Import Salt Testing Libs
import json
import os
@@ -43,6 +42,7 @@ class AnsiblegateTestCase(TestCase, LoaderModuleMockMixin):
def setup_loader_modules(self):
return {ansible: {}}
+ @patch("salt.utils.path.which", MagicMock(return_value=True))
def test_ansible_playbooks_states_success(self):
"""
Test ansible.playbooks states executions success.
@@ -57,7 +57,7 @@ class AnsiblegateTestCase(TestCase, LoaderModuleMockMixin):
with patch.dict(
ansible.__salt__,
{"ansible.playbooks": MagicMock(return_value=success_output)},
- ), patch("salt.utils.path.which", MagicMock(return_value=True)):
+ ):
with patch.dict(ansible.__opts__, {"test": False}):
ret = ansible.playbooks("foobar")
self.assertTrue(ret["result"])
@@ -73,6 +73,7 @@ class AnsiblegateTestCase(TestCase, LoaderModuleMockMixin):
},
)
+ @patch("salt.utils.path.which", MagicMock(return_value=True))
def test_ansible_playbooks_states_failed(self):
"""
Test ansible.playbooks failed states executions.
@@ -87,7 +88,7 @@ class AnsiblegateTestCase(TestCase, LoaderModuleMockMixin):
with patch.dict(
ansible.__salt__,
{"ansible.playbooks": MagicMock(return_value=failed_output)},
- ), patch("salt.utils.path.which", MagicMock(return_value=True)):
+ ):
with patch.dict(ansible.__opts__, {"test": False}):
ret = ansible.playbooks("foobar")
self.assertFalse(ret["result"])
--
2.29.2