From 40b03eb6efef3260b073e34d02bb0bb021e8a4d0 Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Wed, 18 Sep 2019 10:47:53 -0400 Subject: [PATCH] Enable the call to update_webhook_status by calling it directly within send_notification_templates. Also, update the context field in the payload to be either 'ansible/awx' or 'ansible/tower', depending on which is being used. --- awx/main/models/mixins.py | 11 ++++++----- awx/main/models/notifications.py | 2 ++ awx/main/models/unified_jobs.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/awx/main/models/mixins.py b/awx/main/models/mixins.py index e1f1707ffb..e2e9959efa 100644 --- a/awx/main/models/mixins.py +++ b/awx/main/models/mixins.py @@ -22,7 +22,7 @@ from awx.main.models.base import prevent_search from awx.main.models.rbac import ( Role, RoleAncestorEntry, get_roles_on_resource ) -from awx.main.utils import parse_yaml_or_json, get_custom_venv_choices +from awx.main.utils import parse_yaml_or_json, get_custom_venv_choices, get_licenser from awx.main.utils.encryption import decrypt_value, get_encryption_key, is_encrypted from awx.main.utils.polymorphic import build_polymorphic_ctypes_map from awx.main.fields import JSONField, AskForField @@ -559,7 +559,7 @@ class WebhookMixin(models.Model): max_length=128 ) - def update_scm_status(self, status): + def update_webhook_status(self, status): if not self.webhook_credential: logger.debug("No credential configured to post back webhook status, skipping.") return @@ -578,7 +578,7 @@ class WebhookMixin(models.Model): 'new': 'pending', 'successful': 'success', 'failed': 'failure', - 'canceled': 'failure', + 'canceled': 'failure', # Github doesn't have a 'canceled' status :( 'error': 'error', }, 'gitlab': { @@ -586,7 +586,7 @@ class WebhookMixin(models.Model): 'running': 'running', 'successful': 'success', 'failed': 'failed', - 'error': 'failed', + 'error': 'failed', # Gitlab doesn't have an 'error' status distinct from 'failed' :( 'canceled': 'canceled', }, } @@ -596,9 +596,10 @@ class WebhookMixin(models.Model): logger.debug("Skipping webhook job status change: '{}'".format(status)) return try: + license_type = get_licenser().validate().get('license_type') data = { 'state': statuses[status], - 'context': 'tower', + 'context': 'ansible/awx' if license_type == 'open' else 'ansible/tower', } headers = {service_header[self.webhook_service]: self.webhook_credential.get_input('token')} response = requests.post(status_api, data=data, headers=headers) diff --git a/awx/main/models/notifications.py b/awx/main/models/notifications.py index ef428bcdfa..b04f151295 100644 --- a/awx/main/models/notifications.py +++ b/awx/main/models/notifications.py @@ -462,6 +462,8 @@ class JobNotificationMixin(object): return (notification_subject, notification_body) def send_notification_templates(self, status): + self.update_webhook_status(status) + from awx.main.tasks import send_notifications # avoid circular import if status not in ['running', 'succeeded', 'failed']: raise ValueError(_("status must be either running, succeeded or failed")) diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index 80848e7ac9..8ed1b275e7 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -1423,5 +1423,5 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique def is_isolated(self): return bool(self.controller_node) - def update_scm_status(self, status): + def update_webhook_status(self, status): return