-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ispras/internal-ansible-exceptions
Internal ansible exceptions
- Loading branch information
Showing
9 changed files
with
137 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,4 @@ jobs: | |
cd ./src | ||
python cotea_ok_case.py | ||
python cotea_ansible_error_case.py | ||
python cotea_internal_error_case.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
cotea.egg-info/ | ||
__pycache__/ | ||
dist/ | ||
|
||
build/ | ||
venv/ | ||
.venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
[host1] | ||
host1 ansible_host=localhost ansible_connection=ssh ansible_ssh_port=2223 ansible_user=root ansible_password=veronika | ||
|
||
[targets] | ||
host1 | ||
[host1] | ||
localhost ansible_connection=ssh ansible_ssh_port=2222 ansible_user=root ansible_password=veronika ansible_ssh_common_args='-o StrictHostKeyChecking=no' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import unittest | ||
|
||
|
||
class TestCotea(unittest.TestCase): | ||
|
||
def tearDown(self) -> None: | ||
from cotea.utils import remove_modules_from_imported | ||
|
||
# Remove any Ansible-related objects from memory | ||
# to clear previous execution context | ||
remove_modules_from_imported(module_name_like="cotea") | ||
|
||
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" | ||
|
||
arg_maker = argument_maker() | ||
arg_maker.add_arg("-i", inv_path) | ||
r = runner(pb_path, arg_maker, show_progress_bar=True) | ||
|
||
try: | ||
while r.has_next_play(): | ||
while r.has_next_task(): | ||
r.run_next_task() | ||
r.finish_ansible() | ||
except Exception as e: | ||
r.finish_ansible() | ||
self.assertTrue(hasattr(e, "message"), msg="Exception is expected to have 'message' attribute") | ||
self.assertTrue(e.message.startswith(f"the playbook: {pb_path} could not be found"), | ||
msg="Unexpected exception message") | ||
else: | ||
self.assertFalse(True, msg="Ansible is supposed to fail due to syntax error " | ||
"and its' exception should be passed to main thread") | ||
|
||
def test_incorrect_syntax_case(self): | ||
from cotea.runner import runner | ||
from cotea.arguments_maker import argument_maker | ||
|
||
pb_path = "cotea_run_files/incorrect.yaml" | ||
inv_path = "cotea_run_files/inv" | ||
|
||
arg_maker = argument_maker() | ||
arg_maker.add_arg("-i", inv_path) | ||
r = runner(pb_path, arg_maker, show_progress_bar=True) | ||
|
||
try: | ||
while r.has_next_play(): | ||
while r.has_next_task(): | ||
r.run_next_task() | ||
r.finish_ansible() | ||
except Exception as e: | ||
r.finish_ansible() | ||
# NOTE: e should be AnsibleParserError, but "isinstance" returns False for some reason | ||
self.assertTrue(hasattr(e, "message"), msg="Exception is expected to have 'message' attribute") | ||
self.assertTrue(e.message.startswith("couldn't resolve module/action"), | ||
msg="Unexpected exception message") | ||
else: | ||
self.assertFalse(True, msg="Ansible is supposed to fail due to syntax error " | ||
"and its' exception should be passed to main thread") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
- name: Play1 | ||
hosts: all | ||
tasks: | ||
- name: Syntactically incorrect command | ||
battle_star_engine: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
[host1] | ||
host1 ansible_host=localhost ansible_connection=ssh ansible_ssh_port=2222 ansible_user=root ansible_password=amella | ||
|
||
[targets] | ||
host1 | ||
localhost ansible_connection=ssh ansible_ssh_port=2222 ansible_user=root ansible_password=amella ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' |