mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 16:28:43 -03:30
Make sure we are covering system jobs and template on notifications
This commit is contained in:
@@ -1852,6 +1852,10 @@ class SystemJobTemplateSerializer(UnifiedJobTemplateSerializer):
|
|||||||
jobs = reverse('api:system_job_template_jobs_list', args=(obj.pk,)),
|
jobs = reverse('api:system_job_template_jobs_list', args=(obj.pk,)),
|
||||||
schedules = reverse('api:system_job_template_schedules_list', args=(obj.pk,)),
|
schedules = reverse('api:system_job_template_schedules_list', args=(obj.pk,)),
|
||||||
launch = reverse('api:system_job_template_launch', args=(obj.pk,)),
|
launch = reverse('api:system_job_template_launch', args=(obj.pk,)),
|
||||||
|
notifiers_any = reverse('api:system_job_template_notifiers_any_list', args=(obj.pk,)),
|
||||||
|
notifiers_success = reverse('api:system_job_template_notifiers_success_list', args=(obj.pk,)),
|
||||||
|
notifiers_error = reverse('api:system_job_template_notifiers_error_list', args=(obj.pk,)),
|
||||||
|
|
||||||
))
|
))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@@ -1866,6 +1870,7 @@ class SystemJobSerializer(UnifiedJobSerializer):
|
|||||||
if obj.system_job_template and obj.system_job_template.active:
|
if obj.system_job_template and obj.system_job_template.active:
|
||||||
res['system_job_template'] = reverse('api:system_job_template_detail',
|
res['system_job_template'] = reverse('api:system_job_template_detail',
|
||||||
args=(obj.system_job_template.pk,))
|
args=(obj.system_job_template.pk,))
|
||||||
|
res['notifications'] = reverse('api:system_job_notifications_list', args=(obj.pk,))
|
||||||
if obj.can_cancel or True:
|
if obj.can_cancel or True:
|
||||||
res['cancel'] = reverse('api:system_job_cancel', args=(obj.pk,))
|
res['cancel'] = reverse('api:system_job_cancel', args=(obj.pk,))
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -218,12 +218,16 @@ system_job_template_urls = patterns('awx.api.views',
|
|||||||
url(r'^(?P<pk>[0-9]+)/launch/$', 'system_job_template_launch'),
|
url(r'^(?P<pk>[0-9]+)/launch/$', 'system_job_template_launch'),
|
||||||
url(r'^(?P<pk>[0-9]+)/jobs/$', 'system_job_template_jobs_list'),
|
url(r'^(?P<pk>[0-9]+)/jobs/$', 'system_job_template_jobs_list'),
|
||||||
url(r'^(?P<pk>[0-9]+)/schedules/$', 'system_job_template_schedules_list'),
|
url(r'^(?P<pk>[0-9]+)/schedules/$', 'system_job_template_schedules_list'),
|
||||||
|
url(r'^(?P<pk>[0-9]+)/notifiers_any/$', 'system_job_template_notifiers_any_list'),
|
||||||
|
url(r'^(?P<pk>[0-9]+)/notifiers_error/$', 'system_job_template_notifiers_error_list'),
|
||||||
|
url(r'^(?P<pk>[0-9]+)/notifiers_success/$', 'system_job_template_notifiers_success_list'),
|
||||||
)
|
)
|
||||||
|
|
||||||
system_job_urls = patterns('awx.api.views',
|
system_job_urls = patterns('awx.api.views',
|
||||||
url(r'^$', 'system_job_list'),
|
url(r'^$', 'system_job_list'),
|
||||||
url(r'^(?P<pk>[0-9]+)/$', 'system_job_detail'),
|
url(r'^(?P<pk>[0-9]+)/$', 'system_job_detail'),
|
||||||
url(r'^(?P<pk>[0-9]+)/cancel/$', 'system_job_cancel'),
|
url(r'^(?P<pk>[0-9]+)/cancel/$', 'system_job_cancel'),
|
||||||
|
url(r'^(?P<pk>[0-9]+)/notifications/$', 'system_job_notifications_list'),
|
||||||
)
|
)
|
||||||
|
|
||||||
notifier_urls = patterns('awx.api.views',
|
notifier_urls = patterns('awx.api.views',
|
||||||
|
|||||||
@@ -2223,6 +2223,27 @@ class SystemJobTemplateJobsList(SubListAPIView):
|
|||||||
relationship = 'jobs'
|
relationship = 'jobs'
|
||||||
parent_key = 'system_job_template'
|
parent_key = 'system_job_template'
|
||||||
|
|
||||||
|
class SystemJobTemplateNotifiersAnyList(SubListCreateAttachDetachAPIView):
|
||||||
|
|
||||||
|
model = Notifier
|
||||||
|
serializer_class = NotifierSerializer
|
||||||
|
parent_model = SystemJobTemplate
|
||||||
|
relationship = 'notifiers_any'
|
||||||
|
|
||||||
|
class SystemJobTemplateNotifiersErrorList(SubListCreateAttachDetachAPIView):
|
||||||
|
|
||||||
|
model = Notifier
|
||||||
|
serializer_class = NotifierSerializer
|
||||||
|
parent_model = SystemJobTemplate
|
||||||
|
relationship = 'notifiers_error'
|
||||||
|
|
||||||
|
class SystemJobTemplateNotifiersSuccessList(SubListCreateAttachDetachAPIView):
|
||||||
|
|
||||||
|
model = Notifier
|
||||||
|
serializer_class = NotifierSerializer
|
||||||
|
parent_model = SystemJobTemplate
|
||||||
|
relationship = 'notifiers_success'
|
||||||
|
|
||||||
class JobList(ListCreateAPIView):
|
class JobList(ListCreateAPIView):
|
||||||
|
|
||||||
model = Job
|
model = Job
|
||||||
@@ -2903,6 +2924,12 @@ class SystemJobCancel(RetrieveAPIView):
|
|||||||
else:
|
else:
|
||||||
return self.http_method_not_allowed(request, *args, **kwargs)
|
return self.http_method_not_allowed(request, *args, **kwargs)
|
||||||
|
|
||||||
|
class SystemJobNotificationsList(SubListAPIView):
|
||||||
|
|
||||||
|
model = Notification
|
||||||
|
serializer_class = NotificationSerializer
|
||||||
|
parent_model = SystemJob
|
||||||
|
relationship = 'notifications'
|
||||||
|
|
||||||
class UnifiedJobTemplateList(ListAPIView):
|
class UnifiedJobTemplateList(ListAPIView):
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,8 @@ class SimpleDAG(object):
|
|||||||
return "inventory_update"
|
return "inventory_update"
|
||||||
elif type(obj) == ProjectUpdate:
|
elif type(obj) == ProjectUpdate:
|
||||||
return "project_update"
|
return "project_update"
|
||||||
|
elif type(obj) == SystemJob:
|
||||||
|
return "system_job"
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
def get_dependencies(self, obj):
|
def get_dependencies(self, obj):
|
||||||
|
|||||||
@@ -1065,6 +1065,13 @@ class SystemJobTemplate(UnifiedJobTemplate, SystemJobOptions):
|
|||||||
def cache_timeout_blocked(self):
|
def cache_timeout_blocked(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def notifiers(self):
|
||||||
|
base_notifiers = Notifier.objects.filter(active=True)
|
||||||
|
error_notifiers = list(base_notifiers.filter(unifiedjobtemplate_notifiers_for_errors__in=[self]))
|
||||||
|
success_notifiers = list(base_notifiers.filter(unifiedjobtemplate_notifiers_for_success__in=[self]))
|
||||||
|
any_notifiers = list(base_notifiers.filter(unifiedjobtemplate_notifiers_for_any__in=[self]))
|
||||||
|
return dict(error=list(error_notifiers), success=list(success_notifiers), any=list(any_notifiers))
|
||||||
|
|
||||||
|
|
||||||
class SystemJob(UnifiedJob, SystemJobOptions):
|
class SystemJob(UnifiedJob, SystemJobOptions):
|
||||||
|
|||||||
@@ -393,9 +393,11 @@ def activity_stream_associate(sender, instance, **kwargs):
|
|||||||
obj2_id = entity_acted
|
obj2_id = entity_acted
|
||||||
obj2_actual = obj2.objects.get(id=obj2_id)
|
obj2_actual = obj2.objects.get(id=obj2_id)
|
||||||
object2 = camelcase_to_underscore(obj2.__name__)
|
object2 = camelcase_to_underscore(obj2.__name__)
|
||||||
# Skip recording any inventory source changes here.
|
# Skip recording any inventory source, or system job template changes here.
|
||||||
if isinstance(obj1, InventorySource) or isinstance(obj2_actual, InventorySource):
|
if isinstance(obj1, InventorySource) or isinstance(obj2_actual, InventorySource):
|
||||||
continue
|
continue
|
||||||
|
if isinstance(obj1, SystemJobTemplate) or isinstance(obj2_actual, SystemJobTemplate):
|
||||||
|
continue
|
||||||
activity_entry = ActivityStream(
|
activity_entry = ActivityStream(
|
||||||
operation=action,
|
operation=action,
|
||||||
object1=object1,
|
object1=object1,
|
||||||
|
|||||||
@@ -201,6 +201,11 @@ def handle_work_success(self, result, task_actual):
|
|||||||
instance_name = instance.module_name
|
instance_name = instance.module_name
|
||||||
notifiers = [] # TODO: Ad-hoc commands need to notify someone
|
notifiers = [] # TODO: Ad-hoc commands need to notify someone
|
||||||
friendly_name = "AdHoc Command"
|
friendly_name = "AdHoc Command"
|
||||||
|
elif task_actual['type'] == 'system_job':
|
||||||
|
instance = SystemJob.objects.get(id=task_actual['id'])
|
||||||
|
instance_name = instance.system_job_template.name
|
||||||
|
notifiers = instance.system_job_template.notifiers
|
||||||
|
friendly_name = "System Job"
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
notification_body = instance.notification_data()
|
notification_body = instance.notification_data()
|
||||||
@@ -244,6 +249,11 @@ def handle_work_error(self, task_id, subtasks=None):
|
|||||||
instance_name = instance.module_name
|
instance_name = instance.module_name
|
||||||
notifiers = []
|
notifiers = []
|
||||||
friendly_name = "AdHoc Command"
|
friendly_name = "AdHoc Command"
|
||||||
|
elif task_actual['type'] == 'system_job':
|
||||||
|
instance = SystemJob.objects.get(id=task_actual['id'])
|
||||||
|
instance_name = instance.system_job_template.name
|
||||||
|
notifiers = instance.system_job_template.notifiers
|
||||||
|
friendly_name = "System Job"
|
||||||
else:
|
else:
|
||||||
# Unknown task type
|
# Unknown task type
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user