Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add test for ansible playbook bin path
  • Loading branch information
TheFieryLynx committed Mar 14, 2024
commit 1aa4f2402321e6b78a2f68fe3120313bb88b099b
2 changes: 1 addition & 1 deletion src/cotea/runner.py
Original file line number Diff line number Diff line change
@@ -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")
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
@@ -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():
@@ -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():
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


@@ -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():
@@ -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():
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
@@ -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