aboutsummaryrefslogtreecommitdiffstats
path: root/xtesting
diff options
context:
space:
mode:
authorAjay Kumar <ajay4.kumar@orange.com>2021-04-28 16:34:26 +0530
committerCédric Ollivier <cedric.ollivier@orange.com>2021-04-29 09:18:16 +0200
commit7d2fb79b5b03abdb7b0717b81c63c4906bb7c169 (patch)
treed7b7c31ea9c525516b984e4f8bcbd97c4cfe0b47 /xtesting
parent95611ad4a2943831f710c32867d8636f03021346 (diff)
Allow printing playbook output to console
User can specify quiet: False in "testcases.yaml" if he wants to print the output on console. Co-Authored-By: Cédric Ollivier <cedric.ollivier@orange.com> Signed-off-by: Ajay kumar <ajay4.kumar@orange.com> Change-Id: I30fa21bdcc2ed97757cd3c0b4720f9413466833f Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'xtesting')
-rw-r--r--xtesting/core/ansible.py3
-rw-r--r--xtesting/tests/unit/core/test_ansible.py84
2 files changed, 69 insertions, 18 deletions
diff --git a/xtesting/core/ansible.py b/xtesting/core/ansible.py
index 21148a18..7ccace9f 100644
--- a/xtesting/core/ansible.py
+++ b/xtesting/core/ansible.py
@@ -54,7 +54,8 @@ class Ansible(testcase.TestCase):
try:
if not os.path.exists(self.res_dir):
os.makedirs(self.res_dir)
- kwargs["quiet"] = True
+ if "quiet" not in kwargs:
+ kwargs["quiet"] = True
kwargs["artifact_dir"] = self.res_dir
runner = ansible_runner.run(**kwargs)
self.details = runner.stats
diff --git a/xtesting/tests/unit/core/test_ansible.py b/xtesting/tests/unit/core/test_ansible.py
index 22785e8f..37694e81 100644
--- a/xtesting/tests/unit/core/test_ansible.py
+++ b/xtesting/tests/unit/core/test_ansible.py
@@ -43,8 +43,9 @@ class RunTesting(unittest.TestCase):
@mock.patch("os.path.isdir", return_value=False)
def test_fail2(self, isdir):
private_data_dir = "titi"
- self.assertEqual(self.test.run(
- private_data_dir=private_data_dir), self.test.EX_RUN_ERROR)
+ self.assertEqual(
+ self.test.run(private_data_dir=private_data_dir),
+ self.test.EX_RUN_ERROR)
isdir.assert_called_once_with(private_data_dir)
@mock.patch("ansible_runner.run", side_effect=Exception)
@@ -53,8 +54,9 @@ class RunTesting(unittest.TestCase):
@mock.patch("os.path.isdir", return_value=True)
def test_fail3(self, *args):
private_data_dir = "titi"
- self.assertEqual(self.test.run(
- private_data_dir=private_data_dir), self.test.EX_RUN_ERROR)
+ self.assertEqual(
+ self.test.run(private_data_dir=private_data_dir),
+ self.test.EX_RUN_ERROR)
args[0].assert_called_once_with(private_data_dir)
args[1].assert_called_once_with(self.test.res_dir)
args[2].assert_not_called()
@@ -68,8 +70,9 @@ class RunTesting(unittest.TestCase):
@mock.patch("os.path.isdir", return_value=True)
def test_fail4(self, *args):
private_data_dir = "titi"
- self.assertEqual(self.test.run(
- private_data_dir=private_data_dir), self.test.EX_RUN_ERROR)
+ self.assertEqual(
+ self.test.run(private_data_dir=private_data_dir),
+ self.test.EX_RUN_ERROR)
args[0].assert_called_once_with(private_data_dir)
args[1].assert_called_once_with(self.test.res_dir)
args[2].assert_called_once_with(self.test.res_dir)
@@ -83,8 +86,9 @@ class RunTesting(unittest.TestCase):
@mock.patch("os.path.isdir", return_value=True)
def test_fail5(self, *args):
private_data_dir = "titi"
- self.assertEqual(self.test.run(
- private_data_dir=private_data_dir), self.test.EX_RUN_ERROR)
+ self.assertEqual(
+ self.test.run(private_data_dir=private_data_dir),
+ self.test.EX_RUN_ERROR)
args[0].assert_called_once_with(private_data_dir)
args[1].assert_called_once_with(self.test.res_dir)
args[2].assert_called_once_with(self.test.res_dir)
@@ -96,26 +100,71 @@ class RunTesting(unittest.TestCase):
@mock.patch("os.path.isdir", return_value=True)
def test_fail6(self, *args):
private_data_dir = "titi"
- self.assertEqual(self.test.run(
+ self.assertEqual(
+ self.test.run(
+ private_data_dir=private_data_dir, quiet=False,
+ artifact_dir="overridden"),
+ self.test.EX_RUN_ERROR)
+ args[0].assert_called_once_with(private_data_dir)
+ args[1].assert_called_once_with(self.test.res_dir)
+ args[2].assert_called_once_with(self.test.res_dir)
+ args[3].assert_called_with(
private_data_dir=private_data_dir, quiet=False,
- artifact_dir="overridden"), self.test.EX_RUN_ERROR)
+ artifact_dir=self.test.res_dir)
+
+ @mock.patch("ansible_runner.run",
+ return_value=munch.Munch(rc=0, stats={"foo": "bar"}))
+ @mock.patch("os.makedirs")
+ @mock.patch("os.path.exists", return_value=False)
+ @mock.patch("os.path.isdir", return_value=True)
+ def test_res_ok1(self, *args):
+ private_data_dir = "titi"
+ self.assertEqual(
+ self.test.run(
+ private_data_dir=private_data_dir, quiet=False,
+ artifact_dir="overridden"),
+ self.test.EX_OK)
+ args[0].assert_called_once_with(private_data_dir)
+ args[1].assert_called_once_with(self.test.res_dir)
+ args[2].assert_called_once_with(self.test.res_dir)
+ args[3].assert_called_with(
+ private_data_dir=private_data_dir, quiet=False,
+ artifact_dir=self.test.res_dir)
+ self.assertEqual(self.test.is_successful(), self.test.EX_OK)
+ self.assertEqual(self.test.details, {"foo": "bar"})
+
+ @mock.patch("ansible_runner.run",
+ return_value=munch.Munch(rc=0, stats={"foo": "bar"}))
+ @mock.patch("os.makedirs")
+ @mock.patch("os.path.exists", return_value=False)
+ @mock.patch("os.path.isdir", return_value=True)
+ def test_res_ok2(self, *args):
+ private_data_dir = "titi"
+ self.assertEqual(
+ self.test.run(
+ private_data_dir=private_data_dir, quiet=True,
+ artifact_dir="overridden"),
+ self.test.EX_OK)
args[0].assert_called_once_with(private_data_dir)
args[1].assert_called_once_with(self.test.res_dir)
args[2].assert_called_once_with(self.test.res_dir)
args[3].assert_called_with(
private_data_dir=private_data_dir, quiet=True,
artifact_dir=self.test.res_dir)
+ self.assertEqual(self.test.is_successful(), self.test.EX_OK)
+ self.assertEqual(self.test.details, {"foo": "bar"})
@mock.patch("ansible_runner.run",
return_value=munch.Munch(rc=0, stats={"foo": "bar"}))
@mock.patch("os.makedirs")
@mock.patch("os.path.exists", return_value=False)
@mock.patch("os.path.isdir", return_value=True)
- def test_res_ok(self, *args):
+ def test_res_ok3(self, *args):
private_data_dir = "titi"
- self.assertEqual(self.test.run(
- private_data_dir=private_data_dir, quiet=False,
- artifact_dir="overridden"), self.test.EX_OK)
+ self.assertEqual(
+ self.test.run(
+ private_data_dir=private_data_dir, artifact_dir="overridden"),
+ self.test.EX_OK)
args[0].assert_called_once_with(private_data_dir)
args[1].assert_called_once_with(self.test.res_dir)
args[2].assert_called_once_with(self.test.res_dir)
@@ -132,9 +181,10 @@ class RunTesting(unittest.TestCase):
@mock.patch("os.path.isdir", return_value=True)
def test_res_ko(self, *args):
private_data_dir = "titi"
- self.assertEqual(self.test.run(
- private_data_dir=private_data_dir, quiet=False,
- artifact_dir="overridden"), self.test.EX_OK)
+ self.assertEqual(
+ self.test.run(
+ private_data_dir=private_data_dir, artifact_dir="overridden"),
+ self.test.EX_OK)
args[0].assert_called_once_with(private_data_dir)
args[1].assert_called_once_with(self.test.res_dir)
args[2].assert_called_once_with(self.test.res_dir)