1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

AC-1191 Fix limit parameter on callback jobs to intersect with any limit specified on the job template.

This commit is contained in:
Chris Church 2014-04-14 23:40:06 -04:00
parent 55da67fa91
commit 1d417fe573
2 changed files with 7 additions and 2 deletions

View File

@ -1224,7 +1224,7 @@ class JobTemplateCallback(GenericAPIView):
data = dict(msg='Cannot start automatically, user input required!') data = dict(msg='Cannot start automatically, user input required!')
# FIXME: Log! # FIXME: Log!
return Response(data, status=status.HTTP_400_BAD_REQUEST) return Response(data, status=status.HTTP_400_BAD_REQUEST)
limit = ':'.join(filter(None, [job_template.limit, host.name])) limit = ':&'.join(filter(None, [job_template.limit, host.name]))
job = job_template.create_job(limit=limit, launch_type='callback') job = job_template.create_job(limit=limit, launch_type='callback')
result = job.signal_start() result = job.signal_start()
if not result: if not result:

View File

@ -1272,6 +1272,11 @@ class JobTemplateCallbackTest(BaseJobTestMixin, django.test.LiveServerTestCase):
self.assertEqual(job.hosts.count(), 1) self.assertEqual(job.hosts.count(), 1)
self.assertEqual(job.hosts.all()[0], host) self.assertEqual(job.hosts.all()[0], host)
# Set a limit on the job template to verify the callback job limit is
# set to the intersection of this limit and the host name.
job_template.limit = 'bakers:slicers:packagers'
job_template.save(update_fields=['limit'])
# Try when hostname is also an IP address, even if a different one is # Try when hostname is also an IP address, even if a different one is
# specified via ansible_ssh_host. # specified via ansible_ssh_host.
host_qs = job_template.inventory.hosts.order_by('pk') host_qs = job_template.inventory.hosts.order_by('pk')
@ -1295,7 +1300,7 @@ class JobTemplateCallbackTest(BaseJobTestMixin, django.test.LiveServerTestCase):
self.assertEqual(jobs_qs.count(), 5) self.assertEqual(jobs_qs.count(), 5)
job = jobs_qs[0] job = jobs_qs[0]
self.assertEqual(job.launch_type, 'callback') self.assertEqual(job.launch_type, 'callback')
self.assertEqual(job.limit, host.name) self.assertEqual(job.limit, ':&'.join([job_template.limit, host.name]))
self.assertEqual(job.hosts.count(), 1) self.assertEqual(job.hosts.count(), 1)
self.assertEqual(job.hosts.all()[0], host) self.assertEqual(job.hosts.all()[0], host)