2018-09-13 00:45:22 +02:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2018-09-13 00:45:22 +02:00
|
|
|
class AnsibletowerHookTests(WebhookTestCase):
|
2021-02-12 08:20:45 +01:00
|
|
|
STREAM_NAME = "ansibletower"
|
2018-09-13 00:45:22 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/ansibletower?api_key={api_key}&stream={stream}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "ansibletower"
|
2018-09-13 00:45:22 +02:00
|
|
|
|
|
|
|
def test_ansibletower_project_update_successful_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower project update successful notification is handled correctly
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "AWX - Project Update"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"Project Update: [#2677 AWX - Project Update]"
|
|
|
|
"(http://awx.example.co.uk/#/jobs/project/2677) was successful."
|
|
|
|
)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("project_update_successful", expected_topic_name, expected_message)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
|
|
|
def test_ansibletower_project_update_failed_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower project update failed notification is handled correctly
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "AWX - Project Update"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"Project Update: [#2678 AWX - Project Update]"
|
|
|
|
"(http://awx.example.co.uk/#/jobs/project/2678) failed."
|
|
|
|
)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("project_update_failed", expected_topic_name, expected_message)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
|
|
|
def test_ansibletower_job_successful_multiple_hosts_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower job successful multiple hosts notification is handled correctly
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "System - Deploy - Zabbix Agent"
|
2019-04-10 05:40:00 +02:00
|
|
|
expected_message = """
|
|
|
|
Job: [#2674 System - Deploy - Zabbix Agent](http://awx.example.co.uk/#/jobs/playbook/2674) was successful:
|
|
|
|
* chat.example.co.uk: Success
|
|
|
|
* devops.example.co.uk: Success
|
|
|
|
* gitlab.example.co.uk: Success
|
|
|
|
* ipa.example.co.uk: Success
|
|
|
|
* mail.example.co.uk: Success
|
|
|
|
""".strip()
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("job_successful_multiple_hosts", expected_topic_name, expected_message)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
|
|
|
def test_ansibletower_job_successful_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower job successful notification is handled correctly
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "System - Deploy - Zabbix Agent"
|
2019-04-10 05:40:00 +02:00
|
|
|
expected_message = """
|
|
|
|
Job: [#2674 System - Deploy - Zabbix Agent](http://awx.example.co.uk/#/jobs/playbook/2674) was successful:
|
|
|
|
* chat.example.co.uk: Success
|
|
|
|
""".strip()
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("job_successful", expected_topic_name, expected_message)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2020-02-01 10:00:06 +01:00
|
|
|
def test_ansibletower_nine_job_successful_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Test to see if awx/ansibletower 9.x.x job successful notifications are
|
|
|
|
handled just as successfully as prior to 9.x.x.
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Demo Job Template"
|
2020-02-01 10:00:06 +01:00
|
|
|
expected_message = """
|
|
|
|
Job: [#1 Demo Job Template](https://towerhost/#/jobs/playbook/1) was successful:
|
|
|
|
* localhost: Success
|
|
|
|
""".strip()
|
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook(
|
|
|
|
"job_complete_successful_awx_9.1.1", expected_topic_name, expected_message
|
|
|
|
)
|
2020-02-01 10:00:06 +01:00
|
|
|
|
2018-09-13 00:45:22 +02:00
|
|
|
def test_ansibletower_job_failed_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower job failed notification is handled correctly
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "System - Updates - Ubuntu"
|
2019-04-10 05:40:00 +02:00
|
|
|
expected_message = """
|
|
|
|
Job: [#2722 System - Updates - Ubuntu](http://awx.example.co.uk/#/jobs/playbook/2722) failed:
|
|
|
|
* chat.example.co.uk: Failed
|
|
|
|
""".strip()
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("job_failed", expected_topic_name, expected_message)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
|
|
|
def test_ansibletower_job_failed_multiple_hosts_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower job failed notification is handled correctly
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "System - Updates - Ubuntu"
|
2019-04-10 05:40:00 +02:00
|
|
|
expected_message = """
|
|
|
|
Job: [#2722 System - Updates - Ubuntu](http://awx.example.co.uk/#/jobs/playbook/2722) failed:
|
|
|
|
* chat.example.co.uk: Failed
|
|
|
|
* devops.example.co.uk: Failed
|
|
|
|
* gitlab.example.co.uk: Failed
|
|
|
|
* ipa.example.co.uk: Failed
|
|
|
|
* mail.example.co.uk: Failed
|
|
|
|
""".strip()
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("job_failed_multiple_hosts", expected_topic_name, expected_message)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
|
|
|
def test_ansibletower_inventory_update_successful_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower inventory update successful notification is handled correctly
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "AWX - Inventory Update"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"Inventory Update: [#2724 AWX - Inventory Update]"
|
|
|
|
"(http://awx.example.co.uk/#/jobs/inventory/2724) was successful."
|
|
|
|
)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("inventory_update_successful", expected_topic_name, expected_message)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
|
|
|
def test_ansibletower_inventory_update_failed_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower inventory update failed notification is handled correctly
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "AWX - Inventory Update"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"Inventory Update: [#2724 AWX - Inventory Update]"
|
|
|
|
"(http://awx.example.co.uk/#/jobs/inventory/2724) failed."
|
|
|
|
)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("inventory_update_failed", expected_topic_name, expected_message)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
|
|
|
def test_ansibletower_adhoc_command_successful_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower adhoc command successful notification is handled correctly
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "shell: uname -r"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"AdHoc Command: [#2726 shell: uname -r]"
|
|
|
|
"(http://awx.example.co.uk/#/jobs/command/2726) was successful."
|
|
|
|
)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("adhoc_command_successful", expected_topic_name, expected_message)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
|
|
|
def test_ansibletower_adhoc_command_failed_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower adhoc command failed notification is handled correctly
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "shell: uname -r"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"AdHoc Command: [#2726 shell: uname -r]"
|
|
|
|
"(http://awx.example.co.uk/#/jobs/command/2726) failed."
|
|
|
|
)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("adhoc_command_failed", expected_topic_name, expected_message)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
|
|
|
def test_ansibletower_system_job_successful_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower system job successful notification is handled correctly
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Cleanup Job Details"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"System Job: [#2721 Cleanup Job Details]"
|
|
|
|
"(http://awx.example.co.uk/#/jobs/system/2721) was successful."
|
|
|
|
)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("system_job_successful", expected_topic_name, expected_message)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
|
|
|
def test_ansibletower_system_job_failed_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower system job failed notification is handled correctly
|
|
|
|
"""
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Cleanup Job Details"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"System Job: [#2721 Cleanup Job Details]"
|
|
|
|
"(http://awx.example.co.uk/#/jobs/system/2721) failed."
|
|
|
|
)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("system_job_failed", expected_topic_name, expected_message)
|