mirror of
https://github.com/ansible/awx.git
synced 2026-05-25 09:37:45 -02:30
AC-990 Make job event filtering by host work even when not capturing hosts M2M. Also fix unit tests to skip checking hosts M2M.
This commit is contained in:
@@ -119,6 +119,12 @@ class FieldLookupBackend(BaseFilterBackend):
|
||||
if key in self.RESERVED_NAMES:
|
||||
continue
|
||||
|
||||
# HACK: Make job event filtering by host name mostly work even
|
||||
# when not capturing job event hosts M2M.
|
||||
if queryset.model._meta.object_name == 'JobEvent' and key.startswith('hosts__name'):
|
||||
key = key.replace('hosts__name', 'or__host__name')
|
||||
or_filters.append((False, 'host__name__isnull', True))
|
||||
|
||||
# Custom __int filter suffix (internal use only).
|
||||
q_int = False
|
||||
if key.endswith('__int'):
|
||||
|
||||
@@ -756,7 +756,8 @@ class JobEvent(BaseModel):
|
||||
self.update_parent_failed_and_changed()
|
||||
# FIXME: The update_hosts() call (and its queries) are the current
|
||||
# performance bottleneck....
|
||||
#self.update_hosts()
|
||||
if getattr(settings, 'CAPTURE_JOB_EVENT_HOSTS', False):
|
||||
self.update_hosts()
|
||||
self.update_host_summary_from_stats()
|
||||
|
||||
def update_parent_failed_and_changed(self):
|
||||
|
||||
@@ -931,6 +931,7 @@ class JobStartCancelTest(BaseJobTestMixin, django.test.LiveServerTestCase):
|
||||
response = self.get(url)
|
||||
|
||||
# Also test job event list for each host.
|
||||
if getattr(settings, 'CAPTURE_JOB_EVENT_HOSTS', False):
|
||||
for host in Host.objects.filter(pk__in=host_ids):
|
||||
url = reverse('api:host_job_events_list', args=(host.pk,))
|
||||
with self.current_user(self.user_sue):
|
||||
|
||||
@@ -319,6 +319,7 @@ class RunJobTest(BaseCeleryTest):
|
||||
self.assertEqual(evt.failed, should_be_failed)
|
||||
if not async:
|
||||
self.assertEqual(evt.changed, should_be_changed)
|
||||
if getattr(settings, 'CAPTURE_JOB_EVENT_HOSTS', False):
|
||||
self.assertEqual(set(evt.hosts.values_list('pk', flat=True)),
|
||||
host_pks)
|
||||
qs = job_events.filter(event='playbook_on_play_start')
|
||||
@@ -330,6 +331,7 @@ class RunJobTest(BaseCeleryTest):
|
||||
self.assertEqual(evt.failed, should_be_failed)
|
||||
if not async:
|
||||
self.assertEqual(evt.changed, should_be_changed)
|
||||
if getattr(settings, 'CAPTURE_JOB_EVENT_HOSTS', False):
|
||||
self.assertEqual(set(evt.hosts.values_list('pk', flat=True)),
|
||||
host_pks)
|
||||
qs = job_events.filter(event='playbook_on_task_start')
|
||||
@@ -341,6 +343,7 @@ class RunJobTest(BaseCeleryTest):
|
||||
self.assertEqual(evt.failed, should_be_failed)
|
||||
if not async:
|
||||
self.assertEqual(evt.changed, should_be_changed)
|
||||
if getattr(settings, 'CAPTURE_JOB_EVENT_HOSTS', False):
|
||||
self.assertEqual(set(evt.hosts.values_list('pk', flat=True)),
|
||||
host_pks)
|
||||
if check_ignore_errors:
|
||||
@@ -360,6 +363,7 @@ class RunJobTest(BaseCeleryTest):
|
||||
self.assertEqual(evt.failed, should_be_failed)
|
||||
if not async:
|
||||
self.assertEqual(evt.changed, should_be_changed)
|
||||
if getattr(settings, 'CAPTURE_JOB_EVENT_HOSTS', False):
|
||||
self.assertEqual(set(evt.hosts.values_list('pk', flat=True)),
|
||||
host_pks)
|
||||
if async:
|
||||
@@ -371,6 +375,7 @@ class RunJobTest(BaseCeleryTest):
|
||||
self.assertTrue(evt.play, evt)
|
||||
self.assertTrue(evt.task, evt)
|
||||
self.assertEqual(evt.failed, False)#should_be_failed)
|
||||
if getattr(settings, 'CAPTURE_JOB_EVENT_HOSTS', False):
|
||||
self.assertEqual(set(evt.hosts.values_list('pk', flat=True)),
|
||||
host_pks)
|
||||
qs = job_events.filter(event=('runner_on_async_%s' % runner_status))
|
||||
@@ -383,6 +388,7 @@ class RunJobTest(BaseCeleryTest):
|
||||
self.assertTrue(evt.play, evt)
|
||||
self.assertTrue(evt.task, evt)
|
||||
self.assertEqual(evt.failed, should_be_failed)
|
||||
if getattr(settings, 'CAPTURE_JOB_EVENT_HOSTS', False):
|
||||
self.assertEqual(set(evt.hosts.values_list('pk', flat=True)),
|
||||
host_pks)
|
||||
qs = job_events.filter(event__startswith='runner_')
|
||||
|
||||
@@ -300,6 +300,9 @@ ANSIBLE_PARAMIKO_RECORD_HOST_KEYS = False
|
||||
# the celery task.
|
||||
AWX_TASK_ENV = {}
|
||||
|
||||
# Flag to enable/disable updating hosts M2M when saving job events.
|
||||
CAPTURE_JOB_EVENT_HOSTS = False
|
||||
|
||||
# Not possible to get list of regions without authenticating, so use this list
|
||||
# instead (based on docs from:
|
||||
# http://docs.rackspace.com/loadbalancers/api/v1.0/clb-devguide/content/Service_Access_Endpoints-d1e517.html)
|
||||
|
||||
Reference in New Issue
Block a user