2021-01-08 13:41:50 +01:00
|
|
|
From 6111853f13c9c1e8eaaa1acd521cd3abfbfff766 Mon Sep 17 00:00:00 2001
|
2020-09-08 15:26:08 +02:00
|
|
|
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
|
|
|
|
---
|
2021-01-08 13:41:50 +01:00
|
|
|
tests/unit/modules/test_ansiblegate.py | 12 ++++++++++++
|
|
|
|
tests/unit/states/test_ansiblegate.py | 7 ++++---
|
|
|
|
2 files changed, 16 insertions(+), 3 deletions(-)
|
2020-09-08 15:26:08 +02:00
|
|
|
|
|
|
|
diff --git a/tests/unit/modules/test_ansiblegate.py b/tests/unit/modules/test_ansiblegate.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 6724d37c40..3d406a9d42 100644
|
2020-09-08 15:26:08 +02:00
|
|
|
--- a/tests/unit/modules/test_ansiblegate.py
|
|
|
|
+++ b/tests/unit/modules/test_ansiblegate.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -209,3 +209,15 @@ description:
|
|
|
|
timeout=1200,
|
|
|
|
)
|
2020-09-08 15:26:08 +02:00
|
|
|
assert ret == {"completed": True, "timeout": 1200}
|
|
|
|
+
|
2021-01-08 13:41:50 +01:00
|
|
|
+ @patch("salt.utils.path.which", MagicMock(return_value=True))
|
2020-09-08 15:26:08 +02:00
|
|
|
+ def test_ansible_playbooks_return_retcode(self):
|
2021-01-08 13:41:50 +01:00
|
|
|
+ """
|
2020-09-08 15:26:08 +02:00
|
|
|
+ Test ansible.playbooks execution module function include retcode in the return.
|
|
|
|
+ :return:
|
2021-01-08 13:41:50 +01:00
|
|
|
+ """
|
|
|
|
+ ref_out = {"retcode": 0, "stdout": '{"foo": "bar"}'}
|
2020-09-08 15:26:08 +02:00
|
|
|
+ cmd_run_all = MagicMock(return_value=ref_out)
|
2021-01-08 13:41:50 +01:00
|
|
|
+ with patch.dict(ansible.__salt__, {"cmd.run_all": cmd_run_all}):
|
2020-09-08 15:26:08 +02:00
|
|
|
+ ret = ansible.playbooks("fake-playbook.yml")
|
2021-01-08 13:41:50 +01:00
|
|
|
+ assert "retcode" in ret
|
2020-09-08 15:26:08 +02:00
|
|
|
diff --git a/tests/unit/states/test_ansiblegate.py b/tests/unit/states/test_ansiblegate.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index ac677fc5db..c21a4f642f 100644
|
|
|
|
--- a/tests/unit/states/test_ansiblegate.py
|
2020-09-08 15:26:08 +02:00
|
|
|
+++ b/tests/unit/states/test_ansiblegate.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -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: {}}
|
|
|
|
|
2020-09-08 15:26:08 +02:00
|
|
|
+ @patch("salt.utils.path.which", MagicMock(return_value=True))
|
2021-01-08 13:41:50 +01:00
|
|
|
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)):
|
2020-09-08 15:26:08 +02:00
|
|
|
+ ):
|
2021-01-08 13:41:50 +01:00
|
|
|
with patch.dict(ansible.__opts__, {"test": False}):
|
|
|
|
ret = ansible.playbooks("foobar")
|
|
|
|
self.assertTrue(ret["result"])
|
|
|
|
@@ -73,6 +73,7 @@ class AnsiblegateTestCase(TestCase, LoaderModuleMockMixin):
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2020-09-08 15:26:08 +02:00
|
|
|
+ @patch("salt.utils.path.which", MagicMock(return_value=True))
|
2021-01-08 13:41:50 +01:00
|
|
|
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)):
|
2020-09-08 15:26:08 +02:00
|
|
|
+ ):
|
2021-01-08 13:41:50 +01:00
|
|
|
with patch.dict(ansible.__opts__, {"test": False}):
|
|
|
|
ret = ansible.playbooks("foobar")
|
|
|
|
self.assertFalse(ret["result"])
|
2020-09-08 15:26:08 +02:00
|
|
|
--
|
2021-01-08 13:41:50 +01:00
|
|
|
2.29.2
|
2020-09-08 15:26:08 +02:00
|
|
|
|
|
|
|
|