Skip to content

Commit

Permalink
add test for ansible playbook bin path
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFieryLynx committed Mar 14, 2024
1 parent b1dae5c commit 1aa4f24
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cotea/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, pb_path, arg_maker, debug_mod=None, show_progress_bar=False,
self.progress_bar = ansible_progress_bar()
self.execution_tree = AnsibleExecTree()

if os.path.exists(ansible_pb_bin):
if os.path.isfile(ansible_pb_bin):
self.ansible_pb_bin = ansible_pb_bin
else:
raise Exception(f"Ansible playbook bin {ansible_pb_bin} not found")
Expand Down
9 changes: 7 additions & 2 deletions src/cotea_ansible_error_case.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import shutil
import unittest

from cotea.runner import runner
Expand All @@ -10,7 +11,9 @@ def run_ansible_error_case(pb_path, inv_path):
arg_maker = argument_maker()
arg_maker.add_arg("-i", inv_path)

r = runner(pb_path, arg_maker, show_progress_bar=True)
bin_path = shutil.which('ansible-playbook')

r = runner(pb_path, arg_maker, show_progress_bar=True, ansible_pb_bin=bin_path)

while r.has_next_play():
while r.has_next_task():
Expand All @@ -30,7 +33,9 @@ def run_ansible_error_case_with_ignore(pb_path, inv_path):
arg_maker = argument_maker()
arg_maker.add_arg("-i", inv_path)

r = runner(pb_path, arg_maker, show_progress_bar=True)
bin_path = shutil.which('ansible-playbook')

r = runner(pb_path, arg_maker, show_progress_bar=True, ansible_pb_bin=bin_path)

while r.has_next_play():
while r.has_next_task():
Expand Down
27 changes: 25 additions & 2 deletions src/cotea_internal_error_case.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import shutil
import unittest


Expand All @@ -10,16 +11,37 @@ def tearDown(self) -> None:
# to clear previous execution context
remove_modules_from_imported(module_name_like="cotea")

def test_incorrect_playbook_bin_path(self):
from cotea.runner import runner
from cotea.arguments_maker import argument_maker

pb_path = "cotea_run_files/ok.yaml"
inv_path = "cotea_run_files/inv"
ansible_pb_bin = "/path/to/.venv/bin/ansible-playbook"

arg_maker = argument_maker()
arg_maker.add_arg("-i", inv_path)

try:
runner(pb_path, arg_maker, show_progress_bar=True, ansible_pb_bin=ansible_pb_bin)
except Exception as e:
self.assertTrue(str(e) == f"Ansible playbook bin {ansible_pb_bin} not found",
msg="Unexpected exception message")
else:
self.assertFalse(True, msg="Ansible is supposed to fail due to incorrect ansible playbook bin path")

def test_incorrect_playbook_path_case(self):
from cotea.runner import runner
from cotea.arguments_maker import argument_maker

pb_path = "cotea_run_files/#%|&"
inv_path = "cotea_run_files/inv"

bin_path = shutil.which('ansible-playbook')

arg_maker = argument_maker()
arg_maker.add_arg("-i", inv_path)
r = runner(pb_path, arg_maker, show_progress_bar=True)
r = runner(pb_path, arg_maker, show_progress_bar=True, ansible_pb_bin=bin_path)

try:
while r.has_next_play():
Expand All @@ -41,10 +63,11 @@ def test_incorrect_syntax_case(self):

pb_path = "cotea_run_files/incorrect.yaml"
inv_path = "cotea_run_files/inv"
bin_path = shutil.which('ansible-playbook')

arg_maker = argument_maker()
arg_maker.add_arg("-i", inv_path)
r = runner(pb_path, arg_maker, show_progress_bar=True)
r = runner(pb_path, arg_maker, show_progress_bar=True, ansible_pb_bin=bin_path)

try:
while r.has_next_play():
Expand Down
5 changes: 4 additions & 1 deletion src/cotea_ok_case.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import shutil
import unittest

from cotea.runner import runner
Expand All @@ -24,7 +25,9 @@ def run_cotea_ok_case(pb_path, inv_path):
arg_maker = argument_maker()
arg_maker.add_arg("-i", inv_path)

r = runner(pb_path, arg_maker, show_progress_bar=True)
bin_path = shutil.which('ansible-playbook')

r = runner(pb_path, arg_maker, show_progress_bar=True, ansible_pb_bin=bin_path)
plays_ind = 0
tasks_ind = 0

Expand Down

0 comments on commit 1aa4f24

Please sign in to comment.