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.
This commit is contained in:
Jeff Bradberry
2019-09-18 10:47:53 -04:00
parent c76c531b7a
commit 40b03eb6ef
3 changed files with 9 additions and 6 deletions

View File

@@ -22,7 +22,7 @@ from awx.main.models.base import prevent_search
from awx.main.models.rbac import ( from awx.main.models.rbac import (
Role, RoleAncestorEntry, get_roles_on_resource 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.encryption import decrypt_value, get_encryption_key, is_encrypted
from awx.main.utils.polymorphic import build_polymorphic_ctypes_map from awx.main.utils.polymorphic import build_polymorphic_ctypes_map
from awx.main.fields import JSONField, AskForField from awx.main.fields import JSONField, AskForField
@@ -559,7 +559,7 @@ class WebhookMixin(models.Model):
max_length=128 max_length=128
) )
def update_scm_status(self, status): def update_webhook_status(self, status):
if not self.webhook_credential: if not self.webhook_credential:
logger.debug("No credential configured to post back webhook status, skipping.") logger.debug("No credential configured to post back webhook status, skipping.")
return return
@@ -578,7 +578,7 @@ class WebhookMixin(models.Model):
'new': 'pending', 'new': 'pending',
'successful': 'success', 'successful': 'success',
'failed': 'failure', 'failed': 'failure',
'canceled': 'failure', 'canceled': 'failure', # Github doesn't have a 'canceled' status :(
'error': 'error', 'error': 'error',
}, },
'gitlab': { 'gitlab': {
@@ -586,7 +586,7 @@ class WebhookMixin(models.Model):
'running': 'running', 'running': 'running',
'successful': 'success', 'successful': 'success',
'failed': 'failed', 'failed': 'failed',
'error': 'failed', 'error': 'failed', # Gitlab doesn't have an 'error' status distinct from 'failed' :(
'canceled': 'canceled', 'canceled': 'canceled',
}, },
} }
@@ -596,9 +596,10 @@ class WebhookMixin(models.Model):
logger.debug("Skipping webhook job status change: '{}'".format(status)) logger.debug("Skipping webhook job status change: '{}'".format(status))
return return
try: try:
license_type = get_licenser().validate().get('license_type')
data = { data = {
'state': statuses[status], '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')} headers = {service_header[self.webhook_service]: self.webhook_credential.get_input('token')}
response = requests.post(status_api, data=data, headers=headers) response = requests.post(status_api, data=data, headers=headers)

View File

@@ -462,6 +462,8 @@ class JobNotificationMixin(object):
return (notification_subject, notification_body) return (notification_subject, notification_body)
def send_notification_templates(self, status): def send_notification_templates(self, status):
self.update_webhook_status(status)
from awx.main.tasks import send_notifications # avoid circular import from awx.main.tasks import send_notifications # avoid circular import
if status not in ['running', 'succeeded', 'failed']: if status not in ['running', 'succeeded', 'failed']:
raise ValueError(_("status must be either running, succeeded or failed")) raise ValueError(_("status must be either running, succeeded or failed"))

View File

@@ -1423,5 +1423,5 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
def is_isolated(self): def is_isolated(self):
return bool(self.controller_node) return bool(self.controller_node)
def update_scm_status(self, status): def update_webhook_status(self, status):
return return