From bc4d789da08ba6c9deed7dd0f75233c50e049f36 Mon Sep 17 00:00:00 2001 From: beeankha Date: Tue, 19 May 2020 09:13:21 -0400 Subject: [PATCH 1/3] Remove HipChat notification type --- .../0116_v400_remove_hipchat_notifications.py | 34 ++++++++++++ awx/main/models/notifications.py | 2 - awx/main/notifications/hipchat_backend.py | 54 ------------------- .../notificationTemplates.form.js | 28 ---------- awx_collection/README.md | 1 + .../plugins/modules/tower_notification.py | 42 +++++++-------- .../targets/tower_notification/tasks/main.yml | 31 ----------- docs/notification_system.md | 3 +- 8 files changed, 55 insertions(+), 140 deletions(-) create mode 100644 awx/main/migrations/0116_v400_remove_hipchat_notifications.py delete mode 100644 awx/main/notifications/hipchat_backend.py diff --git a/awx/main/migrations/0116_v400_remove_hipchat_notifications.py b/awx/main/migrations/0116_v400_remove_hipchat_notifications.py new file mode 100644 index 0000000000..e366436bdc --- /dev/null +++ b/awx/main/migrations/0116_v400_remove_hipchat_notifications.py @@ -0,0 +1,34 @@ +# Generated by Django 2.2.11 on 2020-05-19 02:27 + +from django.db import migrations, models + + +def remove_hipchat_notifications(apps, schema_editor): + ''' + HipChat notifications are no longer in service, remove any that are found. + ''' + Notification = apps.get_model('main', 'Notification') + Notification.objects.filter(notification_type='hipchat').delete() + NotificationTemplate = apps.get_model('main', 'NotificationTemplate') + NotificationTemplate.objects.filter(notification_type='hipchat').delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0115_v370_schedule_set_null'), + ] + + operations = [ + migrations.RunPython(remove_hipchat_notifications), + migrations.AlterField( + model_name='notification', + name='notification_type', + field=models.CharField(choices=[('email', 'Email'), ('grafana', 'Grafana'), ('irc', 'IRC'), ('mattermost', 'Mattermost'), ('pagerduty', 'Pagerduty'), ('rocketchat', 'Rocket.Chat'), ('slack', 'Slack'), ('twilio', 'Twilio'), ('webhook', 'Webhook')], max_length=32), + ), + migrations.AlterField( + model_name='notificationtemplate', + name='notification_type', + field=models.CharField(choices=[('email', 'Email'), ('grafana', 'Grafana'), ('irc', 'IRC'), ('mattermost', 'Mattermost'), ('pagerduty', 'Pagerduty'), ('rocketchat', 'Rocket.Chat'), ('slack', 'Slack'), ('twilio', 'Twilio'), ('webhook', 'Webhook')], max_length=32), + ), + ] diff --git a/awx/main/models/notifications.py b/awx/main/models/notifications.py index 24d0daee4c..99deadf3d6 100644 --- a/awx/main/models/notifications.py +++ b/awx/main/models/notifications.py @@ -23,7 +23,6 @@ from awx.main.notifications.email_backend import CustomEmailBackend from awx.main.notifications.slack_backend import SlackBackend from awx.main.notifications.twilio_backend import TwilioBackend from awx.main.notifications.pagerduty_backend import PagerDutyBackend -from awx.main.notifications.hipchat_backend import HipChatBackend from awx.main.notifications.webhook_backend import WebhookBackend from awx.main.notifications.mattermost_backend import MattermostBackend from awx.main.notifications.grafana_backend import GrafanaBackend @@ -44,7 +43,6 @@ class NotificationTemplate(CommonModelNameNotUnique): ('twilio', _('Twilio'), TwilioBackend), ('pagerduty', _('Pagerduty'), PagerDutyBackend), ('grafana', _('Grafana'), GrafanaBackend), - ('hipchat', _('HipChat'), HipChatBackend), ('webhook', _('Webhook'), WebhookBackend), ('mattermost', _('Mattermost'), MattermostBackend), ('rocketchat', _('Rocket.Chat'), RocketChatBackend), diff --git a/awx/main/notifications/hipchat_backend.py b/awx/main/notifications/hipchat_backend.py deleted file mode 100644 index 16790644a3..0000000000 --- a/awx/main/notifications/hipchat_backend.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (c) 2016 Ansible, Inc. -# All Rights Reserved. - -import logging - -import requests - -from django.utils.encoding import smart_text -from django.utils.translation import ugettext_lazy as _ - -from awx.main.notifications.base import AWXBaseEmailBackend -from awx.main.notifications.custom_notification_base import CustomNotificationBase - -logger = logging.getLogger('awx.main.notifications.hipchat_backend') - - -class HipChatBackend(AWXBaseEmailBackend, CustomNotificationBase): - - init_parameters = {"token": {"label": "Token", "type": "password"}, - "rooms": {"label": "Destination Rooms", "type": "list"}, - "color": {"label": "Notification Color", "type": "string"}, - "api_url": {"label": "API Url (e.g: https://mycompany.hipchat.com)", "type": "string"}, - "notify": {"label": "Notify room", "type": "bool"}, - "message_from": {"label": "Label to be shown with notification", "type": "string"}} - recipient_parameter = "rooms" - sender_parameter = "message_from" - - def __init__(self, token, color, api_url, notify, fail_silently=False, **kwargs): - super(HipChatBackend, self).__init__(fail_silently=fail_silently) - self.token = token - if color is not None: - self.color = color.lower() - self.api_url = api_url - self.notify = notify - - def send_messages(self, messages): - sent_messages = 0 - - for m in messages: - for rcp in m.recipients(): - r = requests.post("{}/v2/room/{}/notification".format(self.api_url, rcp), - params={"auth_token": self.token}, - verify=False, - json={"color": self.color, - "message": m.subject, - "notify": self.notify, - "from": m.from_email, - "message_format": "text"}) - if r.status_code != 204: - logger.error(smart_text(_("Error sending messages: {}").format(r.text))) - if not self.fail_silently: - raise Exception(smart_text(_("Error sending message to hipchat: {}").format(r.text))) - sent_messages += 1 - return sent_messages diff --git a/awx/ui/client/src/notifications/notificationTemplates.form.js b/awx/ui/client/src/notifications/notificationTemplates.form.js index 2cf6a6ca08..e2c298a4cb 100644 --- a/awx/ui/client/src/notifications/notificationTemplates.form.js +++ b/awx/ui/client/src/notifications/notificationTemplates.form.js @@ -168,22 +168,6 @@ export default ['i18n', function(i18n) { subForm: 'typeSubForm', ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)' }, - rooms: { - label: i18n._('Destination Channels'), - type: 'textarea', - rows: 3, - awPopOver: i18n._('Enter one HipChat channel per line. The pound symbol (#) is not required.'), - dataTitle: i18n._('Destination Channels'), - dataPlacement: 'right', - dataContainer: "body", - awRequiredWhen: { - reqExpression: "room_required", - init: "false" - }, - ngShow: "notification_type.value == 'hipchat'", - subForm: 'typeSubForm', - ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)' - }, token: { labelBind: 'tokenLabel', type: 'sensitive', @@ -344,18 +328,6 @@ export default ['i18n', function(i18n) { subForm: 'typeSubForm', ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)' }, - api_url: { - label: i18n._('API URL'), - type: 'text', - placeholder: 'https://mycompany.hipchat.com', - awRequiredWhen: { - reqExpression: "hipchat_required", - init: "false" - }, - ngShow: "notification_type.value == 'hipchat' ", - subForm: 'typeSubForm', - ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)' - }, message_from: { label: i18n._('Notification Label'), type: 'text', diff --git a/awx_collection/README.md b/awx_collection/README.md index d36addf479..5cc6ab1879 100644 --- a/awx_collection/README.md +++ b/awx_collection/README.md @@ -81,6 +81,7 @@ The following notes are changes that may require changes to playbooks: - `tower_job_template` no longer supports the deprecated `extra_vars_path` parameter, please use `extra_vars` with the lookup plugin to replace this functionality. - The `notification_configuration` parameter of `tower_notification` has changed from a string to a dict. Please use the `lookup` plugin to read an existing file into a dict. - `tower_credential` no longer supports passing a file name to ssh_key_data. + - The HipChat notification type has been removed and can no longer be created using the `tower_notification` module. ## Running Unit Tests diff --git a/awx_collection/plugins/modules/tower_notification.py b/awx_collection/plugins/modules/tower_notification.py index 52d9ccaa5f..2b6edb29d7 100644 --- a/awx_collection/plugins/modules/tower_notification.py +++ b/awx_collection/plugins/modules/tower_notification.py @@ -46,7 +46,6 @@ options: choices: - 'email' - 'grafana' - - 'hipchat' - 'irc' - 'mattermost' - 'pagerduty' @@ -159,7 +158,7 @@ options: api_url: description: - The HipChat API URL. - - This parameter has been deprecated, please use 'notification_configuration' instead. + - The HipChat notification type has been deprecated. type: str color: description: @@ -170,7 +169,7 @@ options: rooms: description: - HipChat rooms to send the notification to. - - This parameter has been deprecated, please use 'notification_configuration' instead. + - The HipChat notification type has been deprecated. type: list elements: str notify: @@ -293,21 +292,6 @@ EXAMPLES = ''' state: present tower_config_file: "~/tower_cli.cfg" -- name: Add HipChat notification - tower_notification: - name: hipchat notification - notification_type: hipchat - notification_configuration: - token: a_token - message_from: user1 - api_url: https://hipchat.example.com - color: red - rooms: - - room-A - notify: yes - state: present - tower_config_file: "~/tower_cli.cfg" - - name: Add IRC notification tower_notification: name: irc notification @@ -336,13 +320,17 @@ RETURN = ''' # ''' from ..module_utils.tower_api import TowerModule +HIPCHAT_PARAMS = ( + 'api_url', 'rooms', +) + OLD_INPUT_NAMES = ( 'username', 'sender', 'recipients', 'use_tls', 'host', 'use_ssl', 'password', 'port', 'channels', 'token', 'account_token', 'from_number', 'to_numbers', 'account_sid', 'subdomain', 'service_key', - 'client_name', 'message_from', 'api_url', 'color', - 'rooms', 'notify', 'url', 'headers', 'server', + 'client_name', 'message_from', 'color', + 'notify', 'url', 'headers', 'server', 'nickname', 'targets', ) @@ -355,7 +343,7 @@ def main(): description=dict(), organization=dict(), notification_type=dict(choices=[ - 'email', 'grafana', 'hipchat', 'irc', 'mattermost', + 'email', 'grafana', 'irc', 'mattermost', 'pagerduty', 'rocketchat', 'slack', 'twilio', 'webhook' ]), notification_configuration=dict(type='dict'), @@ -395,7 +383,7 @@ def main(): # Extract our parameters name = module.params.get('name') - new_name = module.params.get("new_name") + new_name = module.params.get('new_name') description = module.params.get('description') organization = module.params.get('organization') notification_type = module.params.get('notification_type') @@ -403,10 +391,16 @@ def main(): messages = module.params.get('messages') state = module.params.get('state') - # Deprecation warnings + # Deprecation/removal warnings for HipChat notification type + for hipchat_params in HIPCHAT_PARAMS: + if module.params.get(hipchat_params) is not None: + module.deprecate(msg='{0} parameter has been deprecated; the HipChat notification type can no longer be generated'.format(hipchat_params), + version="4.0") + + # Deprecation warnings for all other params for legacy_input in OLD_INPUT_NAMES: if module.params.get(legacy_input) is not None: - module.deprecate(msg='{0} parameter has been deprecated, please use notification_configuration instead.'.format(legacy_input), version="3.6") + module.deprecate(msg='{0} parameter has been deprecated, please use notification_configuration instead'.format(legacy_input), version="3.6") # Attempt to look up the related items the user specified (these will fail the module if not found) organization_id = None diff --git a/awx_collection/tests/integration/targets/tower_notification/tasks/main.yml b/awx_collection/tests/integration/targets/tower_notification/tasks/main.yml index 03025e4b6a..e6bc87a509 100644 --- a/awx_collection/tests/integration/targets/tower_notification/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_notification/tasks/main.yml @@ -6,7 +6,6 @@ email_not: "AWX-Collection-tests-tower_notification-email-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" twillo_not: "AWX-Collection-tests-tower_notification-twillo-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" pd_not: "AWX-Collection-tests-tower_notification-pd-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" - hipchat_not: "AWX-Collection-tests-tower_notification-hipchat-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" irc_not: "AWX-Collection-tests-tower_notification-irc-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" - name: Test deprecation warnings @@ -212,36 +211,6 @@ that: - result is changed -- name: Add HipChat notification - tower_notification: - name: "{{ hipchat_not }}" - organization: Default - notification_type: hipchat - token: a_token - message_from: user1 - api_url: https://hipchat.example.com - color: red - rooms: - - room-A - notify: true - state: present - register: result - -- assert: - that: - - result is changed - -- name: Delete HipChat notification - tower_notification: - name: "{{ hipchat_not }}" - organization: Default - state: absent - register: result - -- assert: - that: - - result is changed - - name: Add IRC notification tower_notification: name: "{{ irc_not }}" diff --git a/docs/notification_system.md b/docs/notification_system.md index a57cae4eab..8b5b04b733 100644 --- a/docs/notification_system.md +++ b/docs/notification_system.md @@ -72,7 +72,6 @@ The currently-defined Notification Types are: * Email * Slack -* HipChat * Mattermost * Rocket.Chat * Pagerduty @@ -83,6 +82,8 @@ The currently-defined Notification Types are: Each of these have their own configuration and behavioral semantics and testing them may need to be approached in different ways. The following sections will give as much detail as possible. +> **Note:** The HipChat notification type will be unavailable as of Tower 4.0 + ## Email The email notification type supports a wide variety of SMTP servers and has support for SSL/TLS connections and timeouts. From dea7ec7845ed7ca41863e0a9ebb37fcbe228e325 Mon Sep 17 00:00:00 2001 From: beeankha Date: Tue, 19 May 2020 11:35:33 -0400 Subject: [PATCH 2/3] Update changelog and README text --- CHANGELOG.md | 6 +++++- awx_collection/README.md | 2 +- docs/notification_system.md | 2 -- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65c4adfa02..666bfc9505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ This is a list of high-level changes for each release of AWX. A full list of commits can be found at `https://github.com/ansible/awx/releases/tag/`. +## 12.0.0 (TBD) +- Removed support for HipChat notifications ([EoL announcement](https://www.atlassian.com/partnerships/slack/faq#faq-98b17ca3-247f-423b-9a78-70a91681eff0)) + + ## 11.2.0 (Apr 29, 2020) - Inventory updates now use collection-based plugins by default (in Ansible 2.9+): @@ -103,7 +107,7 @@ This is a list of high-level changes for each release of AWX. A full list of com - Updated the bundled version of openstacksdk to address a known issue https://github.com/ansible/awx/issues/5821 - Updated the bundled vmware_inventory plugin to the latest version to address a bug https://github.com/ansible/awx/pull/5668 - Fixed a bug that can cause inventory updates to fail to properly save their output when run within a workflow https://github.com/ansible/awx/pull/5666 -- Removed a number of pre-computed fields from the Host and Group models to improve AWX performance. As part of this change, inventory group UIs throughout the interface no longer display status icons https://github.com/ansible/awx/pull/5448 +- Removed a number of pre-computed fields from the Host and Group models to improve AWX performance. As part of this change, inventory group UIs throughout the interface no longer display status icons https://github.com/ansible/awx/pull/5448 ## 9.1.1 (Jan 14, 2020) diff --git a/awx_collection/README.md b/awx_collection/README.md index 5cc6ab1879..911e8dcef7 100644 --- a/awx_collection/README.md +++ b/awx_collection/README.md @@ -81,7 +81,7 @@ The following notes are changes that may require changes to playbooks: - `tower_job_template` no longer supports the deprecated `extra_vars_path` parameter, please use `extra_vars` with the lookup plugin to replace this functionality. - The `notification_configuration` parameter of `tower_notification` has changed from a string to a dict. Please use the `lookup` plugin to read an existing file into a dict. - `tower_credential` no longer supports passing a file name to ssh_key_data. - - The HipChat notification type has been removed and can no longer be created using the `tower_notification` module. + - The HipChat `notification_type` has been removed and can no longer be created using the `tower_notification` module. ## Running Unit Tests diff --git a/docs/notification_system.md b/docs/notification_system.md index 8b5b04b733..bd60bd73b0 100644 --- a/docs/notification_system.md +++ b/docs/notification_system.md @@ -82,8 +82,6 @@ The currently-defined Notification Types are: Each of these have their own configuration and behavioral semantics and testing them may need to be approached in different ways. The following sections will give as much detail as possible. -> **Note:** The HipChat notification type will be unavailable as of Tower 4.0 - ## Email The email notification type supports a wide variety of SMTP servers and has support for SSL/TLS connections and timeouts. From ce5272eae64abf74a2ef5752e74689cff3def68a Mon Sep 17 00:00:00 2001 From: beeankha Date: Wed, 20 May 2020 16:27:01 -0400 Subject: [PATCH 3/3] Make edits to Changelog, remove all HipChat-related params from tower_notification module --- CHANGELOG.md | 3 +-- .../plugins/modules/tower_notification.py | 23 ------------------- .../targets/tower_notification/tasks/main.yml | 16 ++----------- 3 files changed, 3 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 666bfc9505..89b716ba41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,7 @@ This is a list of high-level changes for each release of AWX. A full list of commits can be found at `https://github.com/ansible/awx/releases/tag/`. ## 12.0.0 (TBD) -- Removed support for HipChat notifications ([EoL announcement](https://www.atlassian.com/partnerships/slack/faq#faq-98b17ca3-247f-423b-9a78-70a91681eff0)) - +- Removed support for HipChat notifications ([EoL announcement](https://www.atlassian.com/partnerships/slack/faq#faq-98b17ca3-247f-423b-9a78-70a91681eff0)); all previously-created HipChat notification templates will be deleted due to this removal. ## 11.2.0 (Apr 29, 2020) diff --git a/awx_collection/plugins/modules/tower_notification.py b/awx_collection/plugins/modules/tower_notification.py index 2b6edb29d7..73dbc86aed 100644 --- a/awx_collection/plugins/modules/tower_notification.py +++ b/awx_collection/plugins/modules/tower_notification.py @@ -155,23 +155,12 @@ options: - The label to be shown with the notification. - This parameter has been deprecated, please use 'notification_configuration' instead. type: str - api_url: - description: - - The HipChat API URL. - - The HipChat notification type has been deprecated. - type: str color: description: - The notification color. - This parameter has been deprecated, please use 'notification_configuration' instead. choices: ["yellow", "green", "red", "purple", "gray", "random"] type: str - rooms: - description: - - HipChat rooms to send the notification to. - - The HipChat notification type has been deprecated. - type: list - elements: str notify: description: - The notify channel trigger. @@ -320,10 +309,6 @@ RETURN = ''' # ''' from ..module_utils.tower_api import TowerModule -HIPCHAT_PARAMS = ( - 'api_url', 'rooms', -) - OLD_INPUT_NAMES = ( 'username', 'sender', 'recipients', 'use_tls', 'host', 'use_ssl', 'password', 'port', @@ -366,9 +351,7 @@ def main(): service_key=dict(no_log=True), client_name=dict(), message_from=dict(), - api_url=dict(), color=dict(choices=['yellow', 'green', 'red', 'purple', 'gray', 'random']), - rooms=dict(type='list', elements='str'), notify=dict(type='bool'), url=dict(), headers=dict(type='dict'), @@ -391,12 +374,6 @@ def main(): messages = module.params.get('messages') state = module.params.get('state') - # Deprecation/removal warnings for HipChat notification type - for hipchat_params in HIPCHAT_PARAMS: - if module.params.get(hipchat_params) is not None: - module.deprecate(msg='{0} parameter has been deprecated; the HipChat notification type can no longer be generated'.format(hipchat_params), - version="4.0") - # Deprecation warnings for all other params for legacy_input in OLD_INPUT_NAMES: if module.params.get(legacy_input) is not None: diff --git a/awx_collection/tests/integration/targets/tower_notification/tasks/main.yml b/awx_collection/tests/integration/targets/tower_notification/tasks/main.yml index e6bc87a509..ea3e96b90a 100644 --- a/awx_collection/tests/integration/targets/tower_notification/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_notification/tasks/main.yml @@ -34,19 +34,7 @@ service_key: skeleton client_name: Bill message_from: me - api_url: https://tower.example.com/api/v2 color: green - rooms: - - The Study - - Kitchen - - Ballroom - - Conservatory - - Billiard Room - - Library - - Hall - - Lounge - - Dining Room - - Cellar notify: true url: ansible.com headers: @@ -62,8 +50,8 @@ - assert: that: - "'deprecations' in result" - # The 27 can be count from the size of the OLD_INPUT_NAMES list in the module - - result['deprecations'] | length() == 27 + # The 25 can be count from the size of the OLD_INPUT_NAMES list in the module + - result['deprecations'] | length() == 25 - name: Create Slack notification with custom messages tower_notification: