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):
|
|
|
|
STREAM_NAME = 'ansibletower'
|
|
|
|
URL_TEMPLATE = "/api/v1/external/ansibletower?api_key={api_key}&stream={stream}"
|
|
|
|
FIXTURE_DIR_NAME = 'ansibletower'
|
|
|
|
|
|
|
|
def test_ansibletower_project_update_successful_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if ansibletower project update successful notification is handled correctly
|
|
|
|
"""
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "AWX - Project Update"
|
2018-09-13 00:45:22 +02:00
|
|
|
expected_message = ("Project Update: [#2677 AWX - Project Update]"
|
2019-04-10 05:40:00 +02:00
|
|
|
"(http://awx.example.co.uk/#/jobs/project/2677) was successful.")
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('project_update_successful', expected_topic, 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
|
|
|
|
"""
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "AWX - Project Update"
|
2018-09-13 00:45:22 +02:00
|
|
|
expected_message = ("Project Update: [#2678 AWX - Project Update]"
|
2019-04-10 05:40:00 +02:00
|
|
|
"(http://awx.example.co.uk/#/jobs/project/2678) failed.")
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('project_update_failed', expected_topic, 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
|
|
|
|
"""
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "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
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('job_successful_multiple_hosts', expected_topic, 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
|
|
|
|
"""
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "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
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('job_successful', expected_topic, 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.
|
|
|
|
"""
|
|
|
|
expected_topic = "Demo Job Template"
|
|
|
|
expected_message = """
|
|
|
|
Job: [#1 Demo Job Template](https://towerhost/#/jobs/playbook/1) was successful:
|
|
|
|
* localhost: Success
|
|
|
|
""".strip()
|
|
|
|
|
|
|
|
self.send_and_test_stream_message('job_complete_successful_awx_9.1.1', expected_topic, expected_message)
|
|
|
|
|
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
|
|
|
|
"""
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "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
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('job_failed', expected_topic, 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
|
|
|
|
"""
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "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
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('job_failed_multiple_hosts', expected_topic, 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
|
|
|
|
"""
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "AWX - Inventory Update"
|
2018-09-13 00:45:22 +02:00
|
|
|
expected_message = ("Inventory Update: [#2724 AWX - Inventory Update]"
|
2019-04-10 05:40:00 +02:00
|
|
|
"(http://awx.example.co.uk/#/jobs/inventory/2724) was successful.")
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('inventory_update_successful', expected_topic, 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
|
|
|
|
"""
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "AWX - Inventory Update"
|
2018-09-13 00:45:22 +02:00
|
|
|
expected_message = ("Inventory Update: [#2724 AWX - Inventory Update]"
|
2019-04-10 05:40:00 +02:00
|
|
|
"(http://awx.example.co.uk/#/jobs/inventory/2724) failed.")
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('inventory_update_failed', expected_topic, 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
|
|
|
|
"""
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "shell: uname -r"
|
2018-09-13 00:45:22 +02:00
|
|
|
expected_message = ("AdHoc Command: [#2726 shell: uname -r]"
|
2019-04-10 05:40:00 +02:00
|
|
|
"(http://awx.example.co.uk/#/jobs/command/2726) was successful.")
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('adhoc_command_successful', expected_topic, 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
|
|
|
|
"""
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "shell: uname -r"
|
2018-09-13 00:45:22 +02:00
|
|
|
expected_message = ("AdHoc Command: [#2726 shell: uname -r]"
|
2019-04-10 05:40:00 +02:00
|
|
|
"(http://awx.example.co.uk/#/jobs/command/2726) failed.")
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('adhoc_command_failed', expected_topic, 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
|
|
|
|
"""
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "Cleanup Job Details"
|
2018-09-13 00:45:22 +02:00
|
|
|
expected_message = ("System Job: [#2721 Cleanup Job Details]"
|
2019-04-10 05:40:00 +02:00
|
|
|
"(http://awx.example.co.uk/#/jobs/system/2721) was successful.")
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('system_job_successful', expected_topic, 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
|
|
|
|
"""
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "Cleanup Job Details"
|
2018-09-13 00:45:22 +02:00
|
|
|
expected_message = ("System Job: [#2721 Cleanup Job Details]"
|
2019-04-10 05:40:00 +02:00
|
|
|
"(http://awx.example.co.uk/#/jobs/system/2721) failed.")
|
2018-09-13 00:45:22 +02:00
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('system_job_failed', expected_topic, expected_message)
|
2018-09-13 00:45:22 +02:00
|
|
|
|
|
|
|
def get_body(self, fixture_name: str) -> str:
|
|
|
|
return self.webhook_fixture_data("ansibletower", fixture_name, file_type="json")
|